/* =========================================================
   Home hero
   ========================================================= */
.hero { display: grid; grid-template-columns: 1.05fr 1fr; gap: 48px; align-items: center; padding-top: 3vh; padding-bottom: 48px; }
.hero-title { font: 800 clamp(3rem, 8vw, 5.6rem)/.92 var(--font-display); letter-spacing: -0.045em; margin: 0 0 20px; }
.hero-lead { font-size: 1.1rem; color: var(--muted); max-width: 520px; }
.hero-lead strong { color: var(--text); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 26px 0 16px; }
.hero-links { display: flex; flex-wrap: wrap; gap: 18px; font-size: .92rem; }
.hero-links a, .hero-links .link-btn { color: var(--muted); }
.hero-links a:hover, .hero-links .link-btn:hover { color: var(--text); }
.hero-facts { display: flex; flex-wrap: wrap; gap: 28px; margin: 36px 0 0; }
.hero-facts div { display: flex; align-items: baseline; gap: 8px; }
.hero-facts dt { font: 800 1.6rem var(--font-display); color: var(--accent); }
.hero-facts dd { margin: 0; color: var(--muted); font-size: .85rem; max-width: 150px; }

.hero-visual { perspective: 1200px; }
.preview-board {
  position: relative;
  display: grid; grid-template-columns: 92px repeat(3, 1fr); gap: 8px;
  padding: 16px; border-radius: var(--radius-lg);
  background: linear-gradient(160deg, color-mix(in srgb, var(--pitch) 70%, transparent), var(--surface));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: rotateY(-8deg) rotateX(6deg);
  transition: transform 600ms var(--ease);
}
.preview-board:hover { transform: rotateY(-2deg) rotateX(2deg); }
.preview-corner { display: grid; place-items: center; }
.preview-cell { animation: cell-in 500ms var(--ease) both; animation-delay: var(--d); }
.preview-line { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.preview-line line { stroke: var(--player-one); stroke-width: 1.2; stroke-linecap: round; stroke-dasharray: 140; stroke-dashoffset: 140; animation: draw-line 900ms 900ms var(--ease) forwards; filter: drop-shadow(0 0 4px var(--player-one)); vector-effect: non-scaling-stroke; }
.preview-line line { stroke-width: 5px; }

.feature-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.feature .icon { color: var(--accent); margin-bottom: 10px; }
.feature p { color: var(--muted); margin: 0; font-size: .92rem; }

/* =========================================================
   Board (shared by home preview, game and admin preview)
   ========================================================= */
.axis {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  text-align: center; padding: 8px 6px; min-height: 64px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  font-weight: 600; font-size: .8rem; line-height: 1.2;
}
.axis .icon { color: var(--accent); width: 18px; height: 18px; }
.axis span { overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; max-width: 100%; }
.axis.is-active { border-color: color-mix(in srgb, var(--accent) 55%, transparent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }

.cell {
  position: relative; aspect-ratio: 1 / 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 6px; border-radius: 14px;
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  color: var(--text); font: inherit; text-align: center;
  transition: transform var(--fast) var(--ease), border-color var(--fast), box-shadow var(--fast), background var(--med);
  overflow: hidden;
}
.cell-plus { font: 300 1.8rem/1 var(--font-display); color: var(--faint); transition: color var(--fast), transform var(--fast); }
.cell-name { font-weight: 600; font-size: .78rem; line-height: 1.15; max-width: 100%; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cell .avatar { width: 46%; height: auto; aspect-ratio: 1; max-width: 64px; font-size: clamp(.8rem, 2.4vw, 1.3rem); }

button.cell { cursor: pointer; }
button.cell:disabled { cursor: default; }
button.cell:not(:disabled):hover { transform: scale(1.035); border-color: var(--border-strong); }
button.cell:not(:disabled):hover .cell-plus { color: var(--accent); transform: scale(1.15); }
.cell.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent), 0 10px 30px -10px var(--accent); transform: scale(1.03); }
.cell.is-selected .cell-plus { color: var(--accent); }

.cell.is-claimed.owner-1 { background: linear-gradient(160deg, color-mix(in srgb, var(--player-one) 30%, transparent), color-mix(in srgb, var(--player-one-2) 14%, transparent)); border-color: color-mix(in srgb, var(--player-one) 60%, transparent); box-shadow: var(--glow-1); }
.cell.is-claimed.owner-2 { background: linear-gradient(160deg, color-mix(in srgb, var(--player-two) 30%, transparent), color-mix(in srgb, var(--player-two-2) 14%, transparent)); border-color: color-mix(in srgb, var(--player-two) 60%, transparent); box-shadow: var(--glow-2); }
.cell.is-claimed .cell-plus { display: none; }
.cell.is-win { animation: win-pulse 1.4s var(--ease) infinite; z-index: 1; }
.cell .cell-diff { position: absolute; top: 6px; right: 6px; font-size: .62rem; font-weight: 700; letter-spacing: .06em; padding: 2px 6px; border-radius: 6px; background: rgba(0,0,0,.35); color: var(--muted); }

/* Animations */
.cell.anim-reveal { animation: reveal 520ms var(--ease); }
.cell.anim-correct::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: 0 0 0 0 var(--success); animation: ring 700ms ease-out; }
.cell.anim-wrong { animation: shake 420ms cubic-bezier(.36,.07,.19,.97); border-color: var(--danger) !important; }
@keyframes reveal { 0% { transform: rotateY(90deg) scale(.9); } 100% { transform: rotateY(0) scale(1); } }
@keyframes ring { from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 70%, transparent); } to { box-shadow: 0 0 0 16px transparent; } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-7px); } 40%, 60% { transform: translateX(7px); } }
@keyframes win-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes cell-in { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
@keyframes draw-line { to { stroke-dashoffset: 0; } }

/* =========================================================
   Game screen
   ========================================================= */
.game-shell { display: flex; flex-direction: column; gap: 18px; }

.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.score-player { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); transition: border-color var(--med), box-shadow var(--med), opacity var(--med); min-width: 0; }
.score-player.p2 { justify-content: flex-end; }
.score-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.score-meta.right { text-align: right; }
.score-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-sub { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.score-value { font: 800 2rem/1 var(--font-display); }
.score-player.p1 .score-value { color: var(--player-one); }
.score-player.p2 .score-value { color: var(--player-two); }
.score-player.is-turn.p1 { border-color: color-mix(in srgb, var(--player-one) 60%, transparent); box-shadow: var(--glow-1); }
.score-player.is-turn.p2 { border-color: color-mix(in srgb, var(--player-two) 60%, transparent); box-shadow: var(--glow-2); }
.game-over .score-player:not(.is-winner) { opacity: .6; }

.turn-indicator { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 14px; text-align: center; }
.turn-label { font-size: .68rem; letter-spacing: .2em; color: var(--muted); font-weight: 700; }
.turn-name { font: 700 1rem var(--font-display); white-space: nowrap; }
.turn-name.p1 { color: var(--player-one); }
.turn-name.p2 { color: var(--player-two); }
.turn-name.thinking::after { content: "…"; animation: blink 1s steps(2) infinite; }
.game-meta { font-size: .72rem; color: var(--faint); text-transform: uppercase; letter-spacing: .1em; }
@keyframes blink { 50% { opacity: 0; } }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.board-wrap { display: flex; justify-content: center; }
.board {
  position: relative; width: 100%; max-width: min(680px, calc((100dvh - var(--header-h) - 150px) * 1.12));
  min-width: min(100%, 420px);
  display: grid; grid-template-columns: minmax(80px, 128px) repeat(3, minmax(0, 1fr)); gap: 10px;
  padding: 14px; border-radius: var(--radius-lg);
  background: linear-gradient(160deg, color-mix(in srgb, var(--pitch) 55%, transparent), var(--surface));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.board-corner { display: grid; place-items: center; }
.board[aria-busy="true"] .cell { opacity: .5; }
.skeleton-line { display: block; width: 70%; height: 10px; border-radius: 6px; background: linear-gradient(90deg, var(--surface), var(--surface-2), var(--surface)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.win-line { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 2; }
.win-line line { stroke-width: 7; stroke-linecap: round; opacity: 0; }
.win-line.show line { opacity: .95; animation: draw-line 650ms var(--ease) forwards; }
.win-line.owner-1 line { stroke: var(--player-one); filter: drop-shadow(0 0 8px var(--player-one)); }
.win-line.owner-2 line { stroke: var(--player-two); filter: drop-shadow(0 0 8px var(--player-two)); }

/* Side panel */
.side-panel { position: sticky; top: calc(var(--header-h) + 16px); display: flex; flex-direction: column; gap: 14px; min-height: 260px; }
.panel-empty { padding: 10px 0; }
.panel-empty h2 { margin-bottom: 6px; }
.panel-kicker { font-weight: 600; margin: 0 0 10px; }
.cell-criteria { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.crit-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; font-size: .85rem; }
.crit-chip .icon { color: var(--accent); width: 16px; height: 16px; }
.crit-plus { color: var(--faint); font-weight: 700; }
.combo { position: relative; }
.results {
  list-style: none; margin: 6px 0 0; padding: 6px;
  max-height: 300px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface-raised); border: 1px solid var(--border-strong); border-radius: 14px;
  box-shadow: var(--shadow-lg);
}
.result { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.result[aria-selected="true"], .result:hover { background: var(--surface-2); }
.result.is-used { opacity: .45; cursor: not-allowed; }
.result .avatar { width: 34px; height: 34px; font-size: .8rem; }
.result-name { font-weight: 600; }
.result-meta { font-size: .78rem; color: var(--muted); }
.result-tag { margin-left: auto; font-size: .7rem; color: var(--faint); }
.answer-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.panel-foot { margin-top: auto; display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }

/* Result modal */
.result-card { text-align: center; padding: 32px 24px; background: radial-gradient(400px 200px at 50% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent), var(--surface-raised); }
.result-kicker { font-size: .78rem; letter-spacing: .2em; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.result-card h2 { font-size: clamp(1.6rem, 6vw, 2.4rem); margin-bottom: 4px; }
.result-card h2.p1 { color: var(--player-one); }
.result-card h2.p2 { color: var(--player-two); }
.result-score { font: 800 2.4rem var(--font-display); margin: 6px 0 18px; }
.result-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 0; text-align: left; }
.result-stats div { padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.result-stats dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.result-stats dd { margin: 4px 0 0; font-weight: 700; }
.result-stats .wide { grid-column: span 2; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1100px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 32px; padding-top: 0; }
  .preview-board { transform: none; }
  .feature-strip { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .side-panel { position: static; min-height: 0; }
  .board { max-width: 560px; }
}
@media (max-width: 560px) {
  .scoreboard { grid-template-columns: 1fr 1fr; }
  .turn-indicator { grid-column: 1 / -1; grid-row: 1; flex-direction: row; justify-content: center; gap: 8px; padding: 0; }
  .score-player { padding: 10px; gap: 8px; }
  .score-player .avatar { display: none; }
  .score-value { font-size: 1.5rem; }
  .board { grid-template-columns: 74px repeat(3, minmax(0, 1fr)); gap: 6px; padding: 8px; border-radius: 18px; }
  .axis { font-size: .62rem; padding: 4px 2px; min-height: 52px; border-radius: 9px; gap: 3px; letter-spacing: -0.01em; }
  .axis .icon { width: 14px; height: 14px; }
  .cell { border-radius: 10px; padding: 3px; gap: 3px; }
  .cell-name { font-size: .62rem; }
  .cell .cell-diff { top: 3px; right: 3px; padding: 1px 4px; font-size: .55rem; }
  .preview-board { grid-template-columns: 74px repeat(3, 1fr); gap: 6px; padding: 10px; }
  .hero-facts { gap: 18px; }
  .result-stats { grid-template-columns: 1fr; }
  .result-stats .wide { grid-column: auto; }
}

/* =========================================================
   Labels: full on wide screens, short on phones
   ========================================================= */
.axis .lbl-short { display: none; }

/* Help button next to the turn indicator */
.turn-indicator { position: relative; }
.help-btn {
  width: 26px; height: 26px; margin-top: 4px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted);
  font: 700 .8rem var(--font-display); cursor: pointer;
  transition: color var(--fast), border-color var(--fast);
}
.help-btn:hover { color: var(--text); border-color: var(--accent); }

/* Move log (side panel when no cell is selected) */
.move-log { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.move-log h3 { font: 600 .72rem var(--font-body); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.move-log ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 340px; overflow-y: auto; }
.move { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--surface); }
.move-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.move.p1 .move-dot { background: var(--player-one); }
.move.p2 .move-dot { background: var(--player-two); }
.move-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.move-body strong { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.move-body small { color: var(--muted); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.move-res { font-weight: 700; }
.move.ok .move-res { color: var(--success); }
.move.bad .move-res { color: var(--danger); }
.move.bad strong { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 60%, transparent); }

/* Onboarding */
.onboard-steps { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 12px; }
.onboard-steps li { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.onboard-steps .step-no { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font: 800 .9rem var(--font-display); color: var(--accent-ink); background: var(--accent); }
.onboard-steps div { color: var(--muted); font-size: .92rem; }
.onboard-steps strong { color: var(--text); }

.sheet-handle { display: none; }
.sheet-backdrop { display: none; }

/* =========================================================
   Phones / tablets: answer form becomes a bottom sheet
   ========================================================= */
@media (max-width: 860px) {
  /* backdrop-filter on the card would trap position:fixed children */
  .side-panel { backdrop-filter: none; -webkit-backdrop-filter: none; }
  .answer-form {
    position: fixed; left: 0; right: 0; bottom: var(--kb, 0px); z-index: 70;
    max-height: calc(100dvh - var(--kb, 0px) - 56px); overflow-y: auto; overscroll-behavior: contain;
    padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
    background: var(--surface-raised); border-top: 1px solid var(--border-strong);
    border-radius: 22px 22px 0 0; box-shadow: 0 -20px 50px -10px rgba(0, 0, 0, .6);
    animation: sheet-up 260ms var(--ease);
  }
  .answer-form .sheet-handle { display: block; width: 44px; height: 5px; border-radius: 99px; background: var(--border-strong); margin: 0 auto 12px; }
  .answer-form .results { max-height: 38dvh; }
  .answer-form .input { font-size: 16px; } /* prevents iOS zoom on focus */
  .sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(3, 7, 14, .55); backdrop-filter: blur(2px); animation: fade-in 200ms ease; }
  .sheet-backdrop[hidden] { display: none; }
  body.sheet-open { overflow: hidden; }
  .move-log ol { max-height: none; }
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 560px) {
  .axis .lbl-full { display: none; }
  .axis .lbl-short { display: block; }
  .axis { font-size: .72rem; line-height: 1.15; }
  .turn-indicator { flex-wrap: wrap; }
  .help-btn { margin-top: 0; width: 24px; height: 24px; }
}

/* Pass entries in the move log */
.move.pass .move-res { color: var(--muted); }
.move.pass strong { color: var(--muted); }

/* After-game answers */
.answers-list { list-style: decimal inside; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; max-height: 55dvh; overflow-y: auto; }
.answers-list li { padding: 8px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.answers-list small { display: block; color: var(--muted); font-size: .76rem; margin-left: 1.2em; }
.game-over button.cell:not(:disabled) { cursor: help; }
.answer-actions [data-pass] { margin-right: auto; }

/* Online invite */
.invite-box { margin-top: 14px; padding: 14px; border-radius: 14px; background: color-mix(in srgb, var(--accent) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.invite-box .input { font-size: .85rem; font-family: var(--font-mono); }

/* Room code */
.room-code-box { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.room-code { font: 800 2rem/1.1 var(--font-mono); letter-spacing: .25em; color: var(--accent); user-select: all; }

/* Side panel footer: three buttons must wrap inside the 340px panel instead of overflowing */
.panel-foot { flex-wrap: wrap; justify-content: flex-start; }
.panel-foot .btn { flex: 1 1 auto; min-width: 0; }
.panel-foot .btn.danger { flex: 0 0 auto; margin-left: auto; }
/* Move log: long names are ellipsised, never a horizontal scrollbar */
.move-log ol { overflow-x: hidden; }
.move { min-width: 0; }
