:root {
  --bg-1: #f4eee3;
  --bg-2: #e5d6ba;
  --panel: rgba(255, 250, 241, 0.85);
  --panel-border: rgba(74, 61, 48, 0.16);
  --ink: #2f2a24;
  --ink-soft: #5d544b;
  --accent: #0f766e;
  --accent-strong: #0c5f59;
  --warm: #b45309;
  --danger: #b91c1c;
  --board-bg: linear-gradient(145deg, #ead8b6 0%, #d7bc8d 100%);
  --board-line: #5a4328;
  --shadow: 0 24px 48px rgba(70, 43, 13, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Sora", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
}

body {
  position: relative;
  overflow-x: hidden;
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(1px);
  z-index: 0;
  pointer-events: none;
}

.bg-shape-a {
  width: 38vw;
  height: 38vw;
  right: -8vw;
  top: -10vw;
  background: radial-gradient(circle at 40% 40%, rgba(180, 83, 9, 0.3), rgba(180, 83, 9, 0));
}

.bg-shape-b {
  width: 34vw;
  height: 34vw;
  left: -10vw;
  bottom: -10vw;
  background: radial-gradient(circle at 55% 45%, rgba(15, 118, 110, 0.26), rgba(15, 118, 110, 0));
}

.layout {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 340px minmax(360px, 1fr) 300px;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(7px);
}

.hero {
  padding: 24px;
  animation: rise-in 450ms ease both;
}

.kicker {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

h1 {
  margin: 8px 0 10px;
  font-family: "Alfa Slab One", serif;
  font-weight: 400;
  letter-spacing: 0.03em;
  color: #3d2a17;
  font-size: clamp(2rem, 4.2vw, 3.3rem);
}

.subtitle {
  margin: 0 0 18px;
  color: var(--ink-soft);
  line-height: 1.45;
  font-size: 0.95rem;
}

.games-hub-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 18px;
  padding: 0.8rem 1.05rem;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.1);
  border: 1px solid rgba(15, 118, 110, 0.22);
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.games-hub-link:hover {
  transform: translateY(-1px);
  background: rgba(180, 83, 9, 0.12);
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.16);
}

.controls {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 0.88rem;
}

select,
input,
button {
  font: inherit;
}

select,
input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(47, 42, 36, 0.22);
  background: rgba(255, 255, 255, 0.75);
  padding: 10px 12px;
  color: var(--ink);
}

input {
  appearance: none;
}

[hidden] {
  display: none !important;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button-row-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.btn {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  padding: 11px 12px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: #f9fffd;
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.28);
}

.btn-secondary {
  background: linear-gradient(145deg, #e9dcc6, #dcc7a2);
  color: #3d3226;
}

.btn-danger {
  background: linear-gradient(145deg, #cf4b3c, #a72626);
  color: #fff8f7;
  box-shadow: 0 10px 20px rgba(167, 38, 38, 0.24);
}

.btn-sound {
  background: linear-gradient(145deg, #f2eadb, #e4d3b5);
  color: #3a3024;
  border: 1px solid rgba(76, 58, 35, 0.25);
}

.btn-sound[aria-pressed="false"] {
  background: linear-gradient(145deg, #ded6c8, #cfc5b0);
  color: #615649;
}

.btn-copy,
.btn-ghost {
  background: rgba(255, 255, 255, 0.7);
  color: #3a3024;
  border: 1px solid rgba(76, 58, 35, 0.18);
}

.mode-block {
  display: grid;
  gap: 12px;
}

.online-controls {
  margin-top: 4px;
  padding-top: 4px;
}

.mode-note,
.inline-note,
.room-note {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.4;
}

.mode-note {
  color: #5c5145;
}

.inline-note {
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(185, 28, 28, 0.08);
  border: 1px solid rgba(185, 28, 28, 0.18);
  color: #8e1d1d;
}

.online-room-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(47, 42, 36, 0.12);
  background: rgba(255, 255, 255, 0.62);
}

.room-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.room-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.1);
  color: #21443f;
  font-weight: 700;
}

.status-card {
  margin-top: 16px;
  border-radius: 16px;
  border: 1px solid rgba(47, 42, 36, 0.15);
  background: rgba(255, 255, 255, 0.62);
  padding: 12px;
}

.status-top {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.turn-badge,
.phase-badge {
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 10px;
}

.turn-badge {
  color: #f9fffd;
  background: var(--accent);
}

.phase-badge {
  color: #3d2f21;
  background: #eadfcf;
}

#statusText {
  margin: 0;
  min-height: 2.6em;
  font-size: 0.9rem;
  color: #443a2f;
  line-height: 1.35;
}

.score-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.score-grid article {
  margin: 0;
  border-radius: 14px;
  padding: 10px;
  text-align: center;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(47, 42, 36, 0.12);
}

.score-grid h3 {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6a5a49;
}

.score-grid p {
  margin: 5px 0 0;
  font-size: 1.4rem;
  font-weight: 800;
  color: #2f2922;
}

.board-panel {
  padding: 18px;
  display: grid;
  gap: 12px;
  animation: rise-in 540ms ease both;
}

.board-shell {
  position: relative;
  width: min(100%, 760px);
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  border-radius: 28px;
  overflow: hidden;
  background: var(--board-bg);
  border: 4px solid rgba(90, 67, 40, 0.58);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4), inset 0 18px 40px rgba(255, 255, 255, 0.18),
    0 24px 34px rgba(69, 49, 24, 0.2);
}

#boardSvg,
#nodeLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#boardSvg {
  z-index: 1;
}

#nodeLayer {
  z-index: 2;
}

#boardSvg line {
  stroke: var(--board-line);
  stroke-width: 1.4;
  stroke-linecap: round;
}

#boardSvg circle {
  fill: rgba(70, 50, 28, 0.22);
}

.node {
  position: absolute;
  width: clamp(26px, 3.8vw, 38px);
  height: clamp(26px, 3.8vw, 38px);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  border: 0;
  padding: 0;
  cursor: pointer;
  background: radial-gradient(circle at 40% 35%, rgba(255, 255, 255, 0.8), rgba(73, 58, 38, 0.25));
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.4);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.node.piece-white {
  background: radial-gradient(circle at 35% 28%, #ffffff, #f7ecd8 68%, #dbc8a1 100%);
  box-shadow: 0 8px 14px rgba(77, 61, 41, 0.26), inset 0 2px 6px rgba(255, 255, 255, 0.9);
}

.node.piece-black {
  background: radial-gradient(circle at 35% 28%, #2f414d, #18252f 66%, #10171d 100%);
  box-shadow: 0 8px 14px rgba(21, 29, 36, 0.36), inset 0 1px 4px rgba(174, 205, 222, 0.18);
}

.node.selectable {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.28), 0 0 0 8px rgba(15, 118, 110, 0.13);
}

.node.destination {
  box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.28), 0 0 0 8px rgba(180, 83, 9, 0.13);
}

.node.selected {
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.45), 0 0 0 10px rgba(180, 83, 9, 0.15);
}

.node.capture-target {
  animation: pulse-danger 1s infinite;
}

.node.ai-preview-source {
  box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.52), 0 0 0 10px rgba(180, 83, 9, 0.2);
  animation: ai-move-source 0.9s ease-in-out infinite;
}

.node.ai-preview-destination {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.52), 0 0 0 12px rgba(15, 118, 110, 0.17);
  animation: ai-move-destination 0.95s ease-in-out infinite;
}

.node.ai-moving-from {
  opacity: 0.18;
}

.node.ai-capture-queued {
  animation: pulse-danger 0.7s ease-in-out infinite;
}

.ai-travel-piece {
  position: absolute;
  width: clamp(26px, 3.8vw, 38px);
  height: clamp(26px, 3.8vw, 38px);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  left: -100px;
  top: -100px;
  transition:
    left var(--ai-travel-ms, 760ms) cubic-bezier(0.2, 0.78, 0.2, 1),
    top var(--ai-travel-ms, 760ms) cubic-bezier(0.2, 0.78, 0.2, 1),
    opacity 120ms ease;
}

.ai-travel-piece.active {
  opacity: 1;
}

.ai-travel-piece.piece-white {
  background: radial-gradient(circle at 35% 28%, #ffffff, #f7ecd8 68%, #dbc8a1 100%);
  box-shadow: 0 10px 16px rgba(77, 61, 41, 0.28), inset 0 2px 6px rgba(255, 255, 255, 0.95);
}

.ai-travel-piece.piece-black {
  background: radial-gradient(circle at 35% 28%, #2f414d, #18252f 66%, #10171d 100%);
  box-shadow: 0 10px 16px rgba(21, 29, 36, 0.38), inset 0 1px 4px rgba(174, 205, 222, 0.18);
}

.node.in-mill::after {
  content: "";
  position: absolute;
  inset: -6px;
  border: 2px dashed rgba(15, 118, 110, 0.65);
  border-radius: 999px;
}

.node.last-move::before {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px solid rgba(180, 83, 9, 0.52);
  border-radius: 999px;
}

.legend {
  margin-top: 4px;
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  color: #4a4035;
}

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

.reserve-trays {
  margin-top: 8px;
  display: grid;
  gap: 8px;
  border: 1px solid rgba(72, 56, 33, 0.15);
  background: rgba(255, 255, 255, 0.52);
  border-radius: 14px;
  padding: 10px;
}

.reserve-card {
  display: grid;
  gap: 6px;
}

.reserve-card h3 {
  margin: 0;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5d4f3d;
}

.reserve-tray {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.reserve-slot {
  position: relative;
  width: 20px;
  height: 16px;
  border: 1.8px solid rgba(82, 61, 32, 0.7);
  border-top: none;
  border-radius: 0 0 9px 9px;
  background: linear-gradient(180deg, rgba(233, 218, 189, 0.35), rgba(216, 189, 144, 0.4));
  transition: opacity 180ms ease, transform 180ms ease;
}

.reserve-slot::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 1px;
  width: 12px;
  height: 12px;
  transform: translateX(-50%);
  border-radius: 50%;
  transition: opacity 180ms ease, transform 180ms ease;
}

.reserve-slot.slot-white::after {
  background: #ffffff;
  border: 1px solid rgba(74, 58, 37, 0.62);
  box-shadow: 0 1px 2px rgba(77, 61, 41, 0.32), inset 0 0 0 1px rgba(255, 255, 255, 0.9);
}

.reserve-slot.slot-black::after {
  background: radial-gradient(circle at 35% 30%, #2e414e, #18252f 75%, #0f171e 100%);
  box-shadow: 0 1px 2px rgba(13, 18, 24, 0.26);
}

.reserve-slot.empty::after {
  opacity: 0.12;
  transform: translateX(-50%) scale(0.7);
}

.reserve-slot.filled::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.opening-progress {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: #4f4437;
}

.dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  display: inline-block;
}

.dot.white {
  background: #fff;
  border: 1px solid rgba(70, 55, 35, 0.5);
}

.dot.black {
  background: #1f2a34;
}

.log-panel {
  padding: 18px;
  animation: rise-in 620ms ease both;
}

.log-panel h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: #352c23;
}

#moveLog {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: min(68vh, 720px);
  overflow: auto;
  display: grid;
  gap: 7px;
}

#moveLog li {
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(47, 42, 36, 0.13);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 0.83rem;
  color: #43392f;
}

#moveLog li.human {
  border-left: 4px solid var(--accent);
}

#moveLog li.ai {
  border-left: 4px solid var(--warm);
}

#moveLog li.online-self {
  border-left: 4px solid var(--accent);
}

#moveLog li.online-opponent {
  border-left: 4px solid #6b5540;
}

@keyframes pulse-danger {
  0%,
  100% {
    box-shadow: 0 0 0 2px rgba(185, 28, 28, 0.42), 0 0 0 8px rgba(185, 28, 28, 0.16);
  }
  50% {
    box-shadow: 0 0 0 2px rgba(185, 28, 28, 0.62), 0 0 0 12px rgba(185, 28, 28, 0.07);
  }
}

@keyframes ai-move-source {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@keyframes ai-move-destination {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(0.98);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.12);
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1160px) {
  .layout {
    grid-template-columns: 1fr;
    max-width: 840px;
  }

  .board-panel {
    order: 1;
  }

  .hero {
    order: 2;
  }

  .log-panel {
    order: 3;
  }

  #moveLog {
    max-height: 220px;
  }
}

@media (max-width: 640px) {
  .layout {
    padding: 14px;
    gap: 14px;
  }

  .panel {
    border-radius: 18px;
  }

  .hero,
  .board-panel,
  .log-panel {
    padding: 14px;
  }

  .board-shell {
    width: min(100%, 92vw);
    border-radius: 20px;
    border-width: 3px;
  }

  .node {
    width: clamp(22px, 7vw, 32px);
    height: clamp(22px, 7vw, 32px);
  }

  .ai-travel-piece {
    width: clamp(22px, 7vw, 32px);
    height: clamp(22px, 7vw, 32px);
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .button-row-3 {
    grid-template-columns: 1fr;
  }

  .score-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .status-top {
    gap: 6px;
  }

  .turn-badge,
  .phase-badge {
    font-size: 0.7rem;
  }
}

@media (max-width: 420px) {
  .layout {
    padding: 10px;
    gap: 10px;
  }

  .hero,
  .board-panel,
  .log-panel {
    padding: 12px;
  }

  .node {
    width: clamp(20px, 7.4vw, 28px);
    height: clamp(20px, 7.4vw, 28px);
  }

  .ai-travel-piece {
    width: clamp(20px, 7.4vw, 28px);
    height: clamp(20px, 7.4vw, 28px);
  }

  .legend {
    font-size: 0.8rem;
  }

  .reserve-slot {
    width: 18px;
    height: 14px;
  }

  .reserve-slot::after {
    width: 10px;
    height: 10px;
  }

  .opening-progress {
    font-size: 0.78rem;
  }
}
