:root {
  --bg-deep: #0b1e10;
  --bg-mid: #132a18;
  --panel-bg: #1a2e1f;
  --panel-border: rgba(255, 255, 255, 0.08);
  --board: #0e7a1a;
  --board-dark: #0a6414;
  --line: #0a6414;
  --text: #e8f0e6;
  --text-dim: rgba(232, 240, 230, 0.55);
  --accent: #36c644;
  --accent-dim: rgba(74, 222, 128, 0.15);
  --stone-white-a: #fff;
  --stone-white-b: #b3b3b3;
  --last-move: #ef4444;
  --star: rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
}

html,
body {
  height: 105%;
}

body {
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Hiragino Sans",
    "Noto Sans JP",
    sans-serif;
  color: var(--text);
  background: var(--bg-deep);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(30, 80, 40, 0.5) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(20, 60, 30, 0.3) 0%, transparent 50%);
}

.app {
  min-height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 8px 24px rgba(0, 0, 0, 0.35);
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.title {
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Hiragino Sans",
    "Noto Sans JP",
    sans-serif;
  font-size: clamp(1.1rem, 1.6vw + 0.5rem, 1.5rem);
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--text);
}

.mode-tabs,
.level-tabs {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.tab,
.level-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 13px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.15s, background 0.15s, box-shadow 0.15s;
}

.tab:hover,
.level-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.tab.active,
.level-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.settings-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-wrap.hidden {
  display: none;
}

.ai-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 500;
}

.actions {
  display: flex;
  gap: 6px;
}

.action-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
}

.action-btn:active {
  background: rgba(255, 255, 255, 0.14);
}

.action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.action-btn.primary {
  background: rgba(74, 222, 128, 0.15);
  border-color: rgba(74, 222, 128, 0.25);
  color: var(--accent);
}

.action-btn.primary:hover {
  background: rgba(74, 222, 128, 0.22);
  border-color: rgba(74, 222, 128, 0.35);
}

.hud-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 8px 24px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.hud-info {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.turn-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.9rem;
}

.turn-stone {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.turn-stone.black {
  background:
    radial-gradient(circle at 36% 30%, rgba(255, 255, 255, 0.1) 0%, transparent 28%),
    radial-gradient(ellipse at 40% 35%, #3a3a3a 0%, #181818 45%, #0e0e0e 80%, #080808 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.turn-stone.white {
  background: radial-gradient(circle at 35% 30%, #fff 0%, #d0d0d0 70%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.score-area {
  width: 100%;
}

.score-counts {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.88rem;
}

.score-disc {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.score-disc.black {
  background:
    radial-gradient(circle at 36% 30%, rgba(255, 255, 255, 0.1) 0%, transparent 28%),
    radial-gradient(ellipse at 40% 35%, #3a3a3a 0%, #181818 45%, #0e0e0e 80%, #080808 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.score-disc.white {
  background: radial-gradient(circle at 35% 30%, #fff, #d0d0d0);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.score-num {
  min-width: 22px;
  text-align: center;
}

.score-sep {
  color: var(--text-dim);
  margin: 0 2px;
  font-weight: 400;
}

.score-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  display: flex;
}

.score-bar-black {
  background: #333;
  height: 100%;
  transition: width 0.4s ease;
  border-radius: 2px 0 0 2px;
}

.score-bar-white {
  background: #e0e0e0;
  height: 100%;
  transition: width 0.4s ease;
  border-radius: 0 2px 2px 0;
}

.state {
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
  text-align: right;
  justify-self: end;
}

.precision-note {
  margin: 8px 0 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--accent-dim);
  font-size: 0.78rem;
  color: var(--accent);
  border: 1px solid rgba(74, 222, 128, 0.12);
}

.precision-note.hidden {
  display: none;
}

.board-shell {
  flex: 1;
  min-height: 500px;
  position: relative;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.board {
  --cell-size: 14px;
  position: relative;
  display: grid;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  max-height: 100%;
  grid-template-columns: repeat(32, minmax(0, 1fr));
  grid-template-rows: repeat(32, minmax(0, 1fr));
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid rgba(0, 0, 0, 0.4);
  background-color: var(--board);
  background-image:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0%, transparent 50%, rgba(0, 0, 0, 0.06) 100%);
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.25),
    inset 0 -1px 2px rgba(255, 255, 255, 0.05),
    0 4px 16px rgba(0, 0, 0, 0.3);
}

.cell {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  position: relative;
  border: none;
  margin: 0;
  padding: 0;
  background: transparent;
  box-shadow: inset -1px -1px 0 var(--line);
  cursor: pointer;
  touch-action: manipulation;
  overflow: hidden;
}

.cell:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: -2px;
  z-index: 3;
}

.cell.armed {
  outline: 2px solid rgba(255, 215, 0, 0.95);
  outline-offset: -2px;
  z-index: 3;
}

.cell.legal {
  background: #1ba12a;
}

.cell.legal:hover {
  background: #1cad2d;
}

.star-point {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--star);
  pointer-events: none;
  z-index: 1;
  transform: translate(-50%, -50%);
}

.stone,
.hint {
  position: absolute;
  width: 78%;
  height: 78%;
  border-radius: 50%;
  top: calc(50% - 0.5px);
  left: calc(50% - 0.5px);
  transform: translate(-50%, -50%);
}

.stone {
  z-index: 2;
}

.stone.black {
  background: radial-gradient(circle at 34% 28%, #292929 0, #0a0a0a 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.stone.white {
  background: radial-gradient(circle at 34% 28%, var(--stone-white-a) 0, var(--stone-white-b) 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.stone.pop {
  animation: piece-pop 0.15s ease-out;
}

.last-move-marker {
  position: absolute;
  width: 3px;
  height: 3px;
  background: var(--last-move);
  top: calc(50% - 0.5px);
  left: calc(50% - 0.5px);
  transform: translate(-50%, -50%);
  z-index: 4;
  pointer-events: none;
}

.hint {
  z-index: 1;
  opacity: 0.5;
  width: 1px;
  height: 1px;
}

.hint.black {
  background: #000;
}

.hint.white {
  background: #fff;
}

.game-over-overlay {
  position: fixed;
  inset: 0;
  --game-over-preview-size: clamp(132px, min(68vw, 38dvh), 260px);
  padding:
    max(12px, env(safe-area-inset-top))
    12px
    max(12px, env(safe-area-inset-bottom));
  border-radius: 0;
  background: rgba(11, 30, 16, 0.82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.game-over-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.game-over-title {
  font-size: clamp(1.3rem, 3vw, 2rem);
  font-weight: 400;
  color: var(--text);
  text-align: center;
}

.game-over-score {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(1rem, 2vw, 1.3rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.game-over-board {
  width: var(--game-over-preview-size);
  height: var(--game-over-preview-size);
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.16);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  flex-shrink: 0;
}

.game-over-board.hidden {
  display: none;
}

.game-over-board img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.game-over-actions {
  width: var(--game-over-preview-size);
  display: grid;
  gap: 8px;
  flex-shrink: 0;
}

.game-over-disc {
  width: 18px;
  height: 18px;
  border-radius: 50%;
}

.game-over-disc.black {
  background: radial-gradient(circle at 35% 30%, #555, #111);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.game-over-disc.white {
  background: radial-gradient(circle at 35% 30%, #fff, #ccc);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.game-over-sep {
  color: var(--text-dim);
  font-weight: 400;
}

.game-over-btn {
  appearance: none;
  border: 1px solid rgba(74, 222, 128, 0.3);
  background: rgba(74, 222, 128, 0.15);
  color: var(--accent);
  border-radius: 999px;
  padding: 9px 22px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.game-over-btn:hover {
  background: rgba(74, 222, 128, 0.25);
}

.game-over-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.game-over-btn:disabled:hover {
  background: rgba(74, 222, 128, 0.15);
}

.game-over-btn.share {
  border-color: rgba(255, 255, 255, 0.25);
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0) 40%),
    linear-gradient(140deg, rgba(32, 32, 32, 0.98), rgba(6, 6, 6, 0.98));
  color: #f7fafc;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
}

.game-over-btn.share:hover {
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0) 40%),
    linear-gradient(140deg, rgba(42, 42, 42, 0.98), rgba(10, 10, 10, 0.98));
}

.game-over-btn.share:disabled:hover {
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0) 40%),
    linear-gradient(140deg, rgba(32, 32, 32, 0.98), rgba(6, 6, 6, 0.98));
}

.game-over-btn.save {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.game-over-btn.save:hover {
  background: rgba(255, 255, 255, 0.16);
}

.game-over-btn.save:disabled:hover {
  background: rgba(255, 255, 255, 0.1);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 14px);
  padding: 9px 13px;
  border-radius: 999px;
  color: #f5fff4;
  background: rgba(15, 28, 16, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.36);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  font-size: 0.85rem;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes piece-pop {
  from {
    transform: translate(-50%, -50%) scale(0);
  }

  to {
    transform: translate(-50%, -50%) scale(1);
  }
}

@media (max-width: 599px) {
  .app {
    padding: 6px 6px 8px;
    gap: 6px;
  }

  .top-panel {
    padding: 10px;
  }

  .tab,
  .level-btn {
    padding: 5px 10px;
    font-size: 0.78rem;
  }

  .action-btn {
    padding: 5px 10px;
    font-size: 0.78rem;
  }

  .state {
    font-size: 0.76rem;
  }

  .board-shell {
    padding: 4px;
    min-height: 0;
    flex: 0 0 auto;
    width: 100%;
    aspect-ratio: 1 / 1;
  }

  .hud-row {
    gap: 6px;
    padding: 8px 10px;
  }

  .hud-info {
    gap: 6px;
  }

  .game-over-overlay {
    --game-over-preview-size: clamp(112px, min(62vw, 30dvh), 200px);
    gap: 10px;
    padding:
      max(10px, env(safe-area-inset-top))
      10px
      max(10px, env(safe-area-inset-bottom));
  }

  .star-point {
    width: 4px;
    height: 4px;
  }
}

.site-footer {
  text-align: center;
  padding: 10px 14px 14px;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.6;
  flex-shrink: 0;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}

.site-footer a:hover {
  text-decoration: underline;
  color: #6ee7a0;
}

.footer-divider {
  display: inline-block;
  width: 28px;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  vertical-align: middle;
  margin: 0 6px;
}

.description {
  max-width: 720px;
  margin: 8px auto 0;
  padding: 18px 20px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 0.88rem;
  line-height: 1.8;
  color: var(--text-dim);
}

.description h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.description p {
  margin: 0;
}

@media (max-width: 599px) {
  .description {
    padding: 14px 14px;
    font-size: 0.82rem;
  }
}
