:root {
  --ink: #f3efe1;
  --muted: rgba(243, 239, 225, 0.7);
  --bg: #10120f;
  --board-a: #21483b;
  --board-b: #1b3f35;
  --gold: #f5cd58;
  --cyan: #75e2df;
  --danger: #ff6b57;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Optima, Avenir Next, Candara, Trebuchet MS, sans-serif;
  user-select: none;
  touch-action: none;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.app {
  position: relative;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% 18%, rgba(117, 226, 223, 0.16), transparent 28%),
    radial-gradient(circle at 86% 78%, rgba(245, 205, 88, 0.13), transparent 30%),
    linear-gradient(135deg, #12150f 0%, #0c1715 48%, #15140d 100%);
}

.hidden {
  display: none !important;
}

.start-panel {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: clamp(18px, 3vw, 28px);
  padding: 24px;
  text-align: center;
}

.brand-mark {
  position: relative;
  width: min(34vw, 180px);
  aspect-ratio: 1;
  animation: breathe 4s ease-in-out infinite;
}

.hex-mark {
  width: min(42vw, 220px);
  aspect-ratio: 220 / 190;
  filter: drop-shadow(0 20px 38px rgba(0, 0, 0, 0.34));
}

.hex-mark svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.hex-cells polygon {
  fill: rgba(33, 72, 59, 0.7);
  stroke: rgba(181, 239, 197, 0.86);
  stroke-width: 3;
  stroke-linejoin: round;
}

.hex-cells polygon:nth-child(even) {
  fill: rgba(27, 63, 53, 0.86);
}

.piece {
  stroke-width: 1.5;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.35));
}

.black-piece {
  fill: #080807;
  stroke: rgba(255, 255, 255, 0.2);
}

.white-piece {
  fill: #f6f2e6;
  stroke: rgba(40, 32, 18, 0.24);
}

h1 {
  margin: 0;
  max-width: min(1040px, 94vw);
  font-family: Didot, Bodoni 72, Georgia, serif;
  font-size: clamp(38px, 8.2vw, 96px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.05;
  text-wrap: balance;
  white-space: pre-line;
}

:lang(zh-Hant) h1 {
  font-family: "Songti TC", "Noto Serif TC", "PingFang TC", Georgia, serif;
  font-size: clamp(30px, 5.8vw, 70px);
  line-height: 1.22;
}

.start-panel p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(16px, 2.2vw, 22px);
}

.size-row,
.side-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.size-btn,
.side-btn,
.ghost-btn,
.icon-text,
.mode-toggle {
  min-height: 44px;
  border-radius: 8px;
  background: rgba(243, 239, 225, 0.11);
  box-shadow: inset 0 0 0 1px rgba(243, 239, 225, 0.18);
  backdrop-filter: blur(18px);
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.size-btn {
  min-width: 92px;
  padding: 0 20px;
  font-weight: 800;
}

.side-btn {
  min-width: 118px;
  padding: 0 16px;
  color: var(--muted);
  font-weight: 800;
}

.side-btn.active {
  color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(245, 205, 88, 0.45), 0 0 26px rgba(245, 205, 88, 0.13);
}

.ghost-btn {
  padding: 0 22px;
  color: var(--cyan);
}

.size-btn:hover,
.ghost-btn:hover,
.icon-text:hover,
.mode-toggle:hover {
  transform: translateY(-2px);
  background: rgba(243, 239, 225, 0.18);
}

.game-shell {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #0b100d;
}

.board-canvas,
.three-host {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.board-canvas {
  cursor: grab;
}

.board-canvas.dragging {
  cursor: grabbing;
}

.hud {
  position: absolute;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.hud.top {
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
}

.hud > * {
  pointer-events: auto;
}

.score-pill,
.turn-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  background: rgba(8, 12, 9, 0.62);
  box-shadow: inset 0 0 0 1px rgba(243, 239, 225, 0.15);
  backdrop-filter: blur(16px);
  white-space: nowrap;
}

.score-pill span {
  color: var(--muted);
  font-size: 12px;
}

.score-pill b {
  min-width: 22px;
  font-size: 19px;
  text-align: right;
}

.score-pill.black::before,
.score-pill.white::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.score-pill.black::before {
  background: #0c0c0a;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.score-pill.white::before {
  background: #f6f2e6;
}

.turn-badge {
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
}

.icon-text {
  width: 38px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}

.mode-toggle {
  position: absolute;
  z-index: 6;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 54px;
  height: 54px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--cyan);
}

.mode-toggle.active {
  color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(245, 205, 88, 0.45), 0 0 32px rgba(245, 205, 88, 0.18);
}

.mode-toggle canvas {
  width: 40px;
  height: 40px;
  display: block;
}

.message {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 72px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 30px));
  padding: 12px 16px;
  border-radius: 8px;
  background: rgba(10, 13, 10, 0.78);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(243, 239, 225, 0.16), 0 20px 40px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(18px);
  text-align: center;
}

.thinking-overlay {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  font-size: clamp(28px, 7vw, 72px);
  font-weight: 800;
  letter-spacing: 0;
  pointer-events: auto;
}

.thinking-overlay > span:first-child {
  text-shadow: 0 4px 28px rgba(0, 0, 0, 0.72);
}

.thinking-dots::after {
  display: inline-block;
  width: 1.5em;
  text-align: left;
  content: "";
  animation: thinkingDots 3s steps(3, end) infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.04) rotate(2deg); }
}

@keyframes thinkingDots {
  0% { content: ""; }
  33% { content: "."; }
  66% { content: ".."; }
  100% { content: "..."; }
}

@media (max-width: 650px) {
  .hud.top {
    top: max(10px, env(safe-area-inset-top));
    gap: 6px;
  }

  .score-pill {
    gap: 5px;
    height: 34px;
    padding: 0 8px;
  }

  .score-pill span {
    display: none;
  }

  .side-btn {
    min-width: 112px;
  }

  .turn-badge {
    height: 34px;
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .icon-text {
    width: 34px;
    min-height: 34px;
  }
}
