/* ── Game Page Layout ─────────────────────────────────────────────── */
body.site-game {
  overflow: hidden;
}

.is-hidden {
  display: none !important;
}

/* PC-only / Mobile-only visibility helpers */
.pc-only   { display: block; }
.mobile-only { display: none; }

.game-shell {
  display: grid;
  width: min(1120px, 100vw);
  height: 100dvh;
  margin: 0 auto;
  padding: clamp(8px, 1.6dvh, 16px);
  align-items: stretch;
}

/* ── Game Panel (main card) ───────────────────────────────────────── */
.game-panel {
  display: grid;
  grid-template-columns: minmax(240px, 290px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "top top"
    "side board";
  gap: clamp(10px, 1.8dvh, 16px);
  min-height: 0;
  padding: clamp(12px, 2dvh, 18px);
  overflow: hidden;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(var(--panel-blur));
  -webkit-backdrop-filter: blur(var(--panel-blur));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.06);
}

/* ── Top Bar ──────────────────────────────────────────────────────── */
.topbar {
  grid-area: top;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding-bottom: clamp(8px, 1.2dvh, 12px);
  border-bottom: 1px solid var(--line);
  margin-bottom: clamp(2px, 0.5dvh, 4px);
}

.back-button span {
  transform: translateY(-1px);
  display: block;
}

.title-block {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  margin-right: auto;
}

.game-title-logo {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  box-shadow: 0 3px 12px var(--blue-glow);
}

.title-block h1 {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Small Buttons in Topbar ──────────────────────────────────────── */
.small-button {
  min-height: 34px;
  padding: 0 16px;
  font-size: 13px;
}

/* ── Level Chip ───────────────────────────────────────────────────── */
.level-chip {
  display: grid;
  min-width: 80px;
  height: 34px;
  padding: 0 14px;
  place-items: center;
  border: 1px solid rgba(107,127,232,0.3);
  border-radius: var(--radius-pill);
  background: rgba(107,127,232,0.12);
  color: var(--blue);
  text-align: center;
  font-weight: 800;
  font-size: 13px;
}

/* ── Sidebar ──────────────────────────────────────────────────────── */
.play-sidebar {
  grid-area: side;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  align-content: start;
  gap: clamp(8px, 1.4dvh, 12px);
  min-height: 0;
  overflow: hidden;
}

/* ── Difficulty Buttons ───────────────────────────────────────────── */
.difficulty-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.difficulty-button {
  min-height: 34px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-pill);
  background: rgba(255,255,255,0.05);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 120ms ease;
}

.difficulty-button:hover {
  background: rgba(255,255,255,0.1);
  color: var(--ink);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}

.difficulty-button.is-active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dim) 100%);
  color: #fff;
  box-shadow: 0 2px 12px var(--blue-glow);
}

/* ── Status Strip ─────────────────────────────────────────────────── */
.status-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(5px, 0.9dvh, 8px);
}

.status-strip > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  padding: clamp(8px, 1.2dvh, 11px) clamp(10px, 1.5dvh, 14px);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.03);
}

.label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.status-strip strong {
  font-size: clamp(18px, 2vw, 24px);
  font-weight: 900;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* ── Info Row ─────────────────────────────────────────────────────── */
.info-row {
  display: grid;
  gap: 6px;
  align-items: start;
  min-height: clamp(20px, 3dvh, 30px);
}

.message {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.55;
  white-space: normal;
}

.seed {
  flex: 0 0 auto;
  color: var(--subtle);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.message.success {
  color: var(--green);
}

.message.error {
  color: var(--rose);
}

/* ── Control Buttons ──────────────────────────────────────────────── */
.controls {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(5px, 0.9dvh, 8px);
}

.button {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.2);
}

.button:active,
.icon-button:active {
  transform: translateY(0);
}

.button.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dim) 100%);
  color: #fff;
  box-shadow: 0 2px 12px var(--blue-glow);
}

.button.primary:hover {
  background: linear-gradient(135deg, #7d8ff0 0%, var(--blue) 100%);
  box-shadow: 0 4px 18px var(--blue-glow);
}

.button.danger {
  color: var(--rose);
  border-color: rgba(224,115,153,0.2);
}

.button.danger:hover {
  background: rgba(224,115,153,0.1);
  border-color: rgba(224,115,153,0.4);
}

/* ── Board Area ───────────────────────────────────────────────────── */
.board-wrap {
  grid-area: board;
  display: grid;
  width: 100%;
  min-height: 0;
  place-items: center;
}

.board {
  --cols: 8;
  --rows: 9;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: clamp(5px, 1.1dvh, 9px);
  width: min(100%, calc((100dvh - 120px) * var(--cols) / var(--rows)), 680px);
  max-height: 100%;
  aspect-ratio: var(--cols) / var(--rows);
  padding: clamp(8px, 1.6dvh, 14px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(ellipse 80% 60% at 50% 30%, rgba(107,127,232,0.07) 0%, transparent 70%),
    rgba(255,255,255,0.025);
  touch-action: none;
  user-select: none;
}

/* ── Path SVG Layer ───────────────────────────────────────────────── */
.path-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.path-layer line {
  stroke: var(--blue);
  stroke-width: clamp(5px, 1.3dvh, 10px);
  stroke-linecap: round;
  opacity: 0.85;
}

/* ── Node Cells ───────────────────────────────────────────────────── */
.node {
  position: relative;
  z-index: 2;
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--node);
  color: var(--node-text);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08), 0 1px 3px rgba(0,0,0,0.3);
  font-size: clamp(12px, 1.8vw, 22px);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition:
    transform 140ms ease,
    background 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease;
}

.node:hover {
  transform: scale(1.06);
  background: rgba(255,255,255,0.13);
}

.node.fixed .node-value {
  text-decoration: underline;
  text-underline-offset: 0.17em;
  text-decoration-thickness: 0.06em;
}

.node.filled,
.node.current,
.node.given-filled {
  color: var(--fixed);
  background: var(--blue);
  box-shadow: 0 0 0 clamp(1px, 0.3dvh, 3px) var(--blue-glow), 0 2px 8px rgba(0,0,0,0.3);
}

.node.current {
  transform: scale(1.06);
  background: linear-gradient(135deg, var(--blue) 0%, #8090f0 100%);
  box-shadow:
    0 0 0 clamp(2px, 0.45dvh, 4px) var(--blue-glow),
    0 4px 16px rgba(107,127,232,0.4);
}

.node.hint {
  animation: pulse 680ms ease-in-out 2;
  background: var(--amber);
  color: #1a1200;
}

.node.wrong {
  animation: shake 230ms ease-in-out 2;
  background: var(--rose);
  color: #fff;
}

/* Completion wave colours */
.node.complete-1 { background: var(--blue); }
.node.complete-2 { background: var(--amber); color: #1a1200; }
.node.complete-3 { background: var(--rose); }
.node.complete-4 { background: var(--coral); }
.node.complete-5 { background: var(--violet); }
.node.complete-6 { background: var(--green); }

/* ── Modal ────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-card {
  width: min(420px, 100%);
  padding: 20px 22px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: rgba(20,24,44,0.92);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--muted);
  line-height: 1.65;
}

.modal-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.modal-heading h2 {
  color: var(--ink);
}

.modal-card p {
  font-size: 14px;
  line-height: 1.65;
  margin-bottom: 10px;
}

.modal-card p:last-child {
  margin-bottom: 0;
}

.victory-card {
  position: relative;
  display: grid;
  gap: 14px;
  overflow: hidden;
}

.victory-card::before {
  content: "";
  position: absolute;
  inset: -35%;
  z-index: -1;
  background:
    radial-gradient(circle at 50% 40%, rgba(245, 194, 107, 0.35), transparent 25%),
    conic-gradient(from 90deg, transparent, rgba(107,127,232,0.3), transparent, rgba(91,191,153,0.24), transparent);
  opacity: 0;
  transform: scale(0.78) rotate(0deg);
}

.victory-summary {
  color: var(--ink);
  font-size: 20px !important;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.celebration-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.celebration-burst span {
  position: absolute;
  top: 18px;
  left: 50%;
  width: 10px;
  height: 22px;
  border-radius: 3px;
  background: var(--amber);
  transform: translate(-50%, -20px) rotate(var(--spin, 0deg));
}

.celebration-burst span:nth-child(2) { --spin: 34deg;  background: var(--blue); }
.celebration-burst span:nth-child(3) { --spin: 92deg;  background: var(--green); }
.celebration-burst span:nth-child(4) { --spin: 151deg; background: var(--rose); }
.celebration-burst span:nth-child(5) { --spin: 223deg; background: var(--violet); }
.celebration-burst span:nth-child(6) { --spin: 288deg; background: var(--coral); }
.celebration-burst span:nth-child(7) { --spin: 18deg;  background: var(--green); }
.celebration-burst span:nth-child(8) { --spin: 61deg;  background: #8fd7ff; }
.celebration-burst span:nth-child(9) { --spin: 119deg; background: var(--amber); }
.celebration-burst span:nth-child(10) { --spin: 190deg; background: var(--blue); }
.celebration-burst span:nth-child(11) { --spin: 253deg; background: var(--rose); }
.celebration-burst span:nth-child(12) { --spin: 323deg; background: var(--green); }

.modal.is-celebration .victory-card {
  animation: record-pop 620ms cubic-bezier(.2, 1.25, .28, 1) 1 both;
  border-color: rgba(245, 194, 107, 0.45);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(245, 194, 107, 0.14),
    0 0 70px rgba(245, 194, 107, 0.28),
    inset 0 1px 0 rgba(255,255,255,0.08);
}

.modal.is-celebration .victory-card::before {
  animation: record-glow 1400ms ease-out 1 both;
}

.modal.is-celebration .modal-heading h2 {
  color: #ffe5a0;
  text-shadow: 0 0 18px rgba(245, 194, 107, 0.5);
}

.modal.is-celebration .victory-summary {
  color: #ffffff;
  text-shadow: 0 0 18px rgba(107,127,232,0.5);
}

.modal.is-celebration #victoryNewGameButton {
  animation: record-button-pulse 1100ms ease-in-out 2;
}

.modal.is-celebration .celebration-burst {
  opacity: 1;
}

.modal.is-celebration .celebration-burst span:nth-child(1) { animation: confetti-a 900ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(2) { animation: confetti-b 980ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(3) { animation: confetti-c 920ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(4) { animation: confetti-d 1000ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(5) { animation: confetti-e 940ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(6) { animation: confetti-f 1040ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(7) { animation: confetti-g 1120ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(8) { animation: confetti-h 1180ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(9) { animation: confetti-i 1080ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(10) { animation: confetti-j 1240ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(11) { animation: confetti-k 1160ms ease-out 1 both; }
.modal.is-celebration .celebration-burst span:nth-child(12) { animation: confetti-l 1280ms ease-out 1 both; }

/* ── Records Modal ────────────────────────────────────────────────── */
.record-modal-card {
  display: grid;
  gap: 14px;
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  align-items: stretch;
}

.record-card {
  height: 100%;
  padding: clamp(10px, 1.8dvh, 14px);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04);
}

.record-card strong,
.record-card span,
.record-card small {
  display: block;
}

.record-card strong {
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.record-card span {
  color: var(--blue);
  font-size: clamp(20px, 2vw, 26px);
  font-weight: 900;
  letter-spacing: -0.01em;
}

.record-card small {
  margin-top: 5px;
  color: var(--subtle);
  font-size: 12px;
}

.full-button {
  width: 100%;
}

/* ── Sidebar Inline Records (PC only) ─────────────────────────────── */
.sidebar-records {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.sidebar-records-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2px;
}

.sidebar-records-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.btn-clear-inline {
  padding: 2px 8px;
  border: 1px solid rgba(224,115,153,0.25);
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.danger-text {
  color: var(--rose);
}

.btn-clear-inline:hover {
  background: rgba(224,115,153,0.1);
  border-color: rgba(224,115,153,0.45);
}

/* Override record-grid inside sidebar: 2 cols */
.sidebar-records .record-grid {
  grid-template-columns: 1fr;
  gap: 6px;
  overflow-y: auto;
  min-height: 0;
}

/* ── Mobile Layout ────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .game-shell {
    width: 100vw;
    padding: 6px;
  }

  .game-panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "top"
      "difficulty"
      "status"
      "board"
      "info"
      "controls";
    gap: 0;
    min-width: 0;
    padding: 9px;
  }

  .topbar {
    align-items: center;
    min-width: 0;
    margin-bottom: 6px;
    padding-bottom: 8px;
  }

  .title-block h1 {
    font-size: 18px;
  }

  .icon-button {
    width: 32px;
    height: 32px;
    font-size: 20px;
  }

  .level-chip {
    min-width: 76px;
    height: 32px;
    font-size: 12px;
  }

  .small-button {
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }

  .play-sidebar {
    display: contents;
  }

  /* On mobile: hide PC-only sidebar records, show modal records button */
  .pc-only   { display: none; }
  .mobile-only { display: block; }

  .difficulty-row {
    grid-area: difficulty;
    grid-template-columns: repeat(4, 1fr);
    min-width: 0;
    margin-bottom: 6px;
  }

  .status-strip {
    grid-area: status;
    grid-template-columns: repeat(3, 1fr);
    min-width: 0;
    margin-bottom: 6px;
  }

  .board-wrap {
    min-width: 0;
  }

  .board {
    width: min(100%, calc(100vw - 30px), calc((100dvh - 255px) * var(--cols) / var(--rows)));
    gap: clamp(3px, 0.9dvh, 7px);
    padding: 6px;
  }

  .node {
    font-size: clamp(11px, 3.5vw, 18px);
  }

  .info-row {
    grid-area: info;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 6px 2px;
  }

  .message {
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .controls {
    grid-area: controls;
    grid-template-columns: repeat(4, 1fr);
  }

  .record-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

@media (max-width: 460px) {
  .topbar {
    gap: 6px;
  }

  .title-block {
    gap: 6px;
  }

  .title-block h1 {
    display: none;
  }

  .game-title-logo {
    width: 32px;
    height: 32px;
  }

  .top-actions {
    gap: 4px;
  }
}

/* ── Short Screens ────────────────────────────────────────────────── */
@media (max-height: 700px) {
  .eyeline,
  .seed {
    display: none;
  }

  h1 {
    font-size: 24px;
  }

  .status-strip > div {
    padding: 5px 8px;
  }

  .message {
    font-size: 12px;
  }

  .board {
    width: min(100%, calc(100vw - 30px), calc((100dvh - 205px) * var(--cols) / var(--rows)));
  }
}

/* ── Animations ───────────────────────────────────────────────────── */
@keyframes pulse {
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 0 8px rgba(245, 194, 107, 0.2);
  }
}

@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px);  }
}

@keyframes record-pop {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.88);
  }
  58% {
    opacity: 1;
    transform: translateY(-4px) scale(1.04);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes record-glow {
  0% {
    opacity: 0;
    transform: scale(0.55) rotate(0deg);
  }
  28% {
    opacity: 1;
  }
  100% {
    opacity: 0.18;
    transform: scale(1.05) rotate(28deg);
  }
}

@keyframes record-button-pulse {
  50% {
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 0 24px rgba(245, 194, 107, 0.28), 0 4px 18px var(--blue-glow);
  }
}

@keyframes confetti-a {
  to { transform: translate(-190px, 210px) rotate(260deg); opacity: 0; }
}

@keyframes confetti-b {
  to { transform: translate(-126px, 245px) rotate(340deg); opacity: 0; }
}

@keyframes confetti-c {
  to { transform: translate(-48px, 200px) rotate(300deg); opacity: 0; }
}

@keyframes confetti-d {
  to { transform: translate(34px, 230px) rotate(360deg); opacity: 0; }
}

@keyframes confetti-e {
  to { transform: translate(116px, 244px) rotate(310deg); opacity: 0; }
}

@keyframes confetti-f {
  to { transform: translate(198px, 202px) rotate(390deg); opacity: 0; }
}

@keyframes confetti-g {
  to { transform: translate(-214px, 92px) rotate(230deg); opacity: 0; }
}

@keyframes confetti-h {
  to { transform: translate(-156px, 125px) rotate(290deg); opacity: 0; }
}

@keyframes confetti-i {
  to { transform: translate(-12px, 118px) rotate(330deg); opacity: 0; }
}

@keyframes confetti-j {
  to { transform: translate(82px, 120px) rotate(260deg); opacity: 0; }
}

@keyframes confetti-k {
  to { transform: translate(166px, 130px) rotate(335deg); opacity: 0; }
}

@keyframes confetti-l {
  to { transform: translate(226px, 98px) rotate(420deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .modal.is-celebration .celebration-burst span,
  .modal.is-celebration .victory-card,
  .modal.is-celebration .victory-card::before,
  .modal.is-celebration #victoryNewGameButton {
    animation: none;
  }
}
