:root {
  --bg: #1d2430;
  --bg2: #232c3b;
  --panel: rgba(28, 36, 49, 0.92);
  --ink: #e8edf4;
  --muted: #93a1b5;
  --accent: #ffcb05;       /* poké yellow — "forward / confirm" */
  --accent2: #3b6fd6;      /* poké blue */
  --good: #3ca84b;
  --danger: #e6194b;       /* "cancel / destructive" */
  --line: rgba(255,255,255,0.10);
  --radius: 12px;
  --radius-sm: 8px;

  /* semantic accents (single source of truth) */
  --turn: #46c265;         /* active player / your turn */
  --turn-soft: rgba(70,194,101,.16);
  --waiting: #93a1b5;      /* someone else's turn */
  --ring: #6aa8ff;         /* keyboard focus ring */

  /* spacing scale */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;

  /* elevation */
  --shadow-sm: 0 2px 8px rgba(0,0,0,.28);
  --shadow-md: 0 8px 24px rgba(0,0,0,.38);
  --shadow-lg: 0 18px 55px rgba(0,0,0,.5);

  font-size: 15px;
}
/* stable-width digits everywhere a number can change under the player's eye */
.pscore, #deckCount, .final-scores b, .fig-chip b, .count-tween { font-variant-numeric: tabular-nums; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  /* layered "table surface": base + faint linen noise + center-bright vignette */
  background:
    radial-gradient(120% 90% at 50% 42%, transparent 38%, rgba(0,0,0,.42) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E"),
    radial-gradient(1200px 800px at 70% -10%, #2b3950, transparent),
    var(--bg);
  background-color: var(--bg);
  color: var(--ink);
  overflow: hidden;
}
body.theme-pokesonne { --bg: #182233; }
#app, .screen { position: absolute; inset: 0; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; transition: filter .12s, background .12s, box-shadow .12s, transform .06s; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: not-allowed; filter: grayscale(.3); }
input { font: inherit; }

/* ---------- button language: primary=forward/confirm · ghost/secondary · danger=cancel ---------- */
button.primary {
  background: linear-gradient(180deg, var(--accent), #f0a500);
  color: #2a2300; border: none; padding: 11px 22px; border-radius: 10px;
  font-weight: 700; letter-spacing: .3px;
  box-shadow: 0 4px 14px rgba(255,203,5,.25);
}
button.primary:hover:not(:disabled) { filter: brightness(1.06); }
button.ghost, button.btn-secondary {
  background: rgba(255,255,255,.06); color: var(--ink);
  border: 1px solid var(--line); padding: 8px 14px; border-radius: 9px;
}
button.ghost:hover:not(:disabled), button.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,.12); }
button.btn-danger {
  background: rgba(230,25,75,.16); color: #ff9bb3;
  border: 1px solid rgba(230,25,75,.5); padding: 8px 14px; border-radius: 9px;
}
button.btn-danger:hover:not(:disabled) { background: rgba(230,25,75,.28); }
button.ghost.small, .small { font-size: .82rem; padding: 6px 10px; }
button.sel { outline: 2px solid var(--accent); background: rgba(255,203,5,.15); }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; }
.hint { color: var(--muted); font-size: .85rem; }

/* ---------- home ---------- */
#home, #lobby { display: grid; place-items: center; padding: 20px; }
.lang-toggle { position: absolute; top: 14px; right: 14px; z-index: 5; }
.topbar .lang-toggle { position: static; }
.home-card, .lobby-card {
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px; width: min(680px, 94vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.logo { font-size: 2.8rem; margin: 0; font-weight: 900; letter-spacing: -1px; text-shadow: 0 2px 12px rgba(0,0,0,.4); }
.logo span, .brand span { color: var(--accent); }
.logo span { text-shadow: 0 0 18px rgba(255,203,5,.35); }
.tag { color: var(--muted); margin: 4px 0 22px; }
.home-form label { display: block; margin-bottom: 14px; color: var(--muted); font-size: .85rem; }
.home-form input, .join-row input, .chat-input input {
  width: 100%; margin-top: 6px; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--line); background: #161c26; color: var(--ink);
}
.home-actions { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.join-row { display: flex; gap: 8px; }
.join-row input { width: 120px; text-transform: uppercase; letter-spacing: 3px; text-align: center; margin: 0; }
.code { font-family: ui-monospace, monospace; letter-spacing: 3px; color: var(--accent); font-weight: 800; }

/* ---------- lobby ---------- */
.lobby-head { display: flex; justify-content: space-between; align-items: center; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; margin: 18px 0; }
.player-list, .score-list { list-style: none; padding: 0; margin: 0; }
.player-list li { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px; background: rgba(255,255,255,.045); border: 1px solid var(--line); margin-bottom: 7px; }
.player-list .pname { font-weight: 600; }
.swatch { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); flex: none; }
.badge { font-size: .68rem; padding: 2px 7px; border-radius: 20px; background: rgba(255,255,255,.12); color: var(--muted); }
.badge.host { background: rgba(255,203,5,.2); color: var(--accent); }
.badge.bot { background: rgba(59,111,214,.25); color: #9bc0ff; }
.badge.off { background: rgba(230,25,75,.2); color: #ff9bb3; }
.color-picker { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 18px; }
.color-picker .swatch { width: 30px; height: 30px; cursor: pointer; transition: transform .1s; }
.notouch-device .color-picker .swatch:not(.taken):hover { transform: scale(1.12); }
.color-picker .swatch.sel { outline: 3px solid var(--accent); outline-offset: 2px; }
.color-picker .swatch.taken { opacity: .25; cursor: not-allowed; }
.exp-picker { display: flex; flex-direction: column; gap: 5px; max-height: 210px; overflow: auto; padding-right: 4px; }
.exp-row { display: flex; gap: 8px; align-items: center; font-size: .88rem; padding: 7px 9px; border-radius: 8px; background: rgba(255,255,255,.03); cursor: pointer; transition: background .12s; }
.notouch-device .exp-row:not(.soon):hover { background: rgba(255,255,255,.07); }
.exp-row input { accent-color: var(--accent); }
.exp-row.soon { opacity: .5; cursor: default; }
.exp-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-n { font-variant-numeric: tabular-nums; font-size: .7rem; color: var(--muted); background: rgba(255,255,255,.06); border-radius: 10px; padding: 1px 7px; flex: none; }
.exp-picker .tagrc { font-size: .62rem; color: var(--good); border: 1px solid var(--good); border-radius: 12px; padding: 0 6px; flex: none; }
.exp-picker .tagbeta { font-size: .62rem; color: var(--muted); border: 1px solid var(--line); border-radius: 12px; padding: 0 6px; flex: none; }
.host-controls { display: flex; gap: 8px; margin-top: 6px; }
.lobby-foot { display: flex; align-items: center; gap: 16px; margin-top: 8px; }

/* ---------- game ---------- */
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#board.placing { cursor: crosshair; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 46px; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; padding: 0 14px;
  background: linear-gradient(180deg, rgba(13,17,23,.85), transparent); pointer-events: none;
}
.topbar button { pointer-events: auto; }
.brand { font-weight: 900; font-size: 1.1rem; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 12px; }
.conn-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px var(--good); }
.conn-dot.bad { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

.panel {
  position: absolute; z-index: 4; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(7px); padding: 12px;
}
.panel h3 { margin: 2px 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.panel.left { top: 54px; left: 10px; width: 230px; max-height: calc(100vh - 70px); overflow: hidden; display: flex; flex-direction: column; }
.panel.right { top: 54px; right: 10px; width: 210px; text-align: center; }
.panel.chat { bottom: 10px; left: 10px; width: 230px; }

/* ---- player cards: color bar + outlined name + big score + follower grid ---- */
.score-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.player-card {
  position: relative; display: flex; gap: var(--sp-2); align-items: center;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) 12px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,.045); overflow: hidden;
  transition: background .15s, box-shadow .2s, opacity .2s;
}
.player-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--pc); }
.score-list .player-card:not(.turn) { opacity: .82; }
.player-card.turn {
  background: rgba(255,255,255,.07); opacity: 1;
  box-shadow: 0 0 0 1px var(--pc), 0 0 18px -3px var(--pc); /* fallback for engines without color-mix */
}
@supports (background: color-mix(in srgb, red, blue)) {
  .player-card.turn { box-shadow: 0 0 0 1px color-mix(in srgb, var(--pc) 55%, transparent), 0 0 18px -3px var(--pc); }
}
.player-card.pulse { animation: cardPulse .7s ease-out; }
@keyframes cardPulse { 0% { box-shadow: 0 0 0 2px var(--pc), 0 0 26px 0 var(--pc); } 100% {} }
.pc-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--good); box-shadow: 0 0 6px var(--good); }
.pc-dot.off { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.pc-dot.bot { background: var(--accent2); box-shadow: 0 0 6px var(--accent2); }
.pc-main { flex: 1; min-width: 0; }
.pc-row1 { display: flex; align-items: baseline; gap: var(--sp-2); }
.pc-row1 .pname {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700;
  color: var(--pc); text-shadow: 0 1px 2px rgba(0,0,0,.75), 0 0 2px rgba(0,0,0,.9);
}
.pc-row1 .pscore { font-weight: 900; font-size: 1.18rem; }
.pc-figs { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 4px; }
.fig-chip {
  display: inline-flex; align-items: center; gap: 2px; font-size: .72rem; color: var(--ink);
  background: rgba(255,255,255,.06); border-radius: 6px; padding: 1px 5px 1px 3px; line-height: 1.55;
}
.fig-chip.empty { opacity: .3; }
.fig-chip .fig-ic { display: inline-flex; font-size: .82em; }
.fig-chip .mico { fill: var(--pc); }
.fig-chip b { font-weight: 800; }
.fig-chip.goods { color: #e3c069; }
.deck-info { font-size: .82rem; color: var(--muted); margin: 8px 2px; }
.log-box { flex: 1; overflow: auto; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; }
.log-box div { margin-bottom: 4px; }

/* action bar — concise color-coded "whose turn / what to do" */
.turn-banner { font-weight: 800; padding: 9px 11px; border-radius: 9px; background: rgba(255,255,255,.05); margin-bottom: 10px; font-size: .92rem; line-height: 1.32; border-left: 3px solid transparent; }
.turn-banner.you { background: var(--turn-soft); color: #c2f0cc; border-left-color: var(--turn); }
.turn-banner.waiting { color: var(--muted); border-left-color: var(--waiting); }
.turn-banner.sweep { position: relative; overflow: hidden; }
.turn-banner.sweep::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(110deg, transparent 20%, rgba(255,255,255,.35) 50%, transparent 80%);
  transform: translateX(-100%); animation: bannerSweep .9s ease-out 1;
}
@keyframes bannerSweep { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .turn-banner.sweep::after, .confirm-bar .primary, .conn-dot.bad { animation: none; } }
.tile-preview-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#tilePreview { background: #0e1218; border-radius: 8px; border: 1px solid var(--line); image-rendering: pixelated; }
.action-hint { font-size: .82rem; color: var(--muted); margin: 10px 4px; min-height: 2.4em; }
/* figure picker — player-colored chips with supply + disabled-at-0 */
.figure-picker { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 6px 0 8px; }
.fig-btn { display: inline-flex; align-items: center; gap: 4px; font-size: .76rem; background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; color: var(--ink); }
.fig-btn .fig-ic { display: inline-flex; }
.fig-btn .mico { fill: var(--pc); }
.fig-btn b { font-weight: 800; opacity: .85; }
.fig-btn.sel { outline: 2px solid var(--accent); background: rgba(255,203,5,.15); }
.zoom-controls { display: flex; gap: 6px; justify-content: center; margin-top: 12px; }
.preview-actions { display: flex; gap: 6px; align-items: center; justify-content: center; }
#tilePreview { cursor: pointer; }
/* staged-move confirm bar */
.confirm-bar { display: flex; gap: 8px; justify-content: center; margin: 8px 0; }
.confirm-bar button { flex: 1; padding: 10px 6px; }
.confirm-bar .primary { box-shadow: 0 4px 14px rgba(255,203,5,.25), 0 0 0 0 var(--accent); animation: confirmPulse 1.4s ease-in-out infinite; }
@keyframes confirmPulse { 0%,100% { box-shadow: 0 4px 14px rgba(255,203,5,.25); } 50% { box-shadow: 0 4px 14px rgba(255,203,5,.25), 0 0 14px 2px rgba(255,203,5,.5); } }
.pref-row { display: flex; align-items: center; gap: 6px; font-size: .76rem; color: var(--muted); justify-content: center; margin-top: 10px; cursor: pointer; }
.pref-row input { accent-color: var(--accent); }

.chat-log { height: 120px; overflow: auto; font-size: .8rem; margin-bottom: 8px; }
.chat-log div { margin-bottom: 3px; }
.chat-log .who { color: var(--accent); font-weight: 700; }
.chat-input { display: flex; gap: 6px; }
.chat-input input { margin: 0; }

/* clickable, colour-coded log lines */
.log-box .log-click { cursor: pointer; border-radius: 5px; padding: 1px 3px; margin: 0 -3px 4px; }
.notouch-device .log-box .log-click:hover { background: rgba(255,255,255,.08); }
.log-box .who { font-weight: 700; }

/* screen-reader-only */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* reconnecting banner + pulsing conn dot */
.net-banner { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); z-index: 8;
  background: rgba(230,25,75,.92); color: #fff; font-weight: 700; font-size: .82rem; padding: 6px 14px; border-radius: 20px; box-shadow: var(--shadow-md); }
.conn-dot.bad { animation: dotPulse 1s ease-in-out infinite; }
@keyframes dotPulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* non-blocking toasts */
.toast { position: fixed; top: 16px; left: 50%; transform: translate(-50%, -16px); z-index: 30;
  background: var(--bg2); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .3s, transform .3s; font-size: .88rem; max-width: 80vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(230,25,75,.6); }

/* help / rules overlay */
.help-card { max-width: 460px; text-align: left; }
.help-card h2 { text-align: center; }
.help-body p { color: var(--ink); font-size: .9rem; line-height: 1.5; margin: 9px 0; }
.help-card .primary { display: block; margin: 18px auto 0; }

.overlay { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(8,11,16,.78); }
.overlay-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 28px 34px; text-align: center; min-width: 320px; }
.final-scores { list-style: none; padding: 0; margin: 16px 0; }
.final-scores li { display: flex; justify-content: space-between; gap: 30px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.final-scores li.win { color: var(--accent); font-weight: 800; }

/* on touch devices, don't let :hover styles stick after a tap */
@media (hover: none) {
  button.ghost:hover, button.btn-secondary:hover { background: rgba(255,255,255,.06); }
  button.btn-danger:hover { background: rgba(230,25,75,.16); }
  button.primary:hover { filter: none; }
}

/* bigger touch targets */
@media (pointer: coarse) {
  button.ghost.small, .small { min-height: 38px; }
  .fig-btn { min-height: 44px; padding: 8px 12px; }
  .confirm-bar button { min-height: 48px; }
  #skipMeeple, #abbeyBtn, #recallBtn, #flyBtn { min-height: 44px; width: 100%; }
  .zoom-controls button { min-width: 44px; min-height: 38px; }
  .chat-input button, .chat-input input { min-height: 38px; }
  .pref-row { min-height: 38px; }
}

@media (max-width: 760px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .panel.left { width: 190px; }
  .panel.right { width: 174px; }
  .panel.chat { display: none; }
}

/* phones: scores dock to a top strip, actions to a bottom thumb-bar, board fills the middle */
@media (max-width: 620px) {
  .panel.left {
    top: 50px; left: 4px; right: 4px; width: auto; max-height: 23vh; padding: 6px;
  }
  .panel.left h3, .panel.left .log-box, .panel.left .deck-info { display: none; }
  .panel.left .score-list { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 2px; }
  .panel.left .player-card { min-width: 116px; flex: 0 0 auto; }
  .net-banner { top: calc(50px + 23vh + 6px); }                 /* clear the score strip */
  .panel.right .action-hint { flex-basis: 100%; margin: 4px 0; } /* prompt spans the bar */
  .panel.right {
    top: auto; bottom: 4px; left: 4px; right: 4px; width: auto; text-align: center;
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 10px;
    max-height: 44vh; overflow-y: auto; padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .panel.right .turn-banner { flex-basis: 100%; margin: 0; }
  .panel.right .tile-preview-wrap { flex-direction: row; gap: 10px; }
  .panel.right .zoom-controls { margin-top: 0; }
  .panel.right .figure-picker, .panel.right #confirmBar { flex-basis: 100%; }
}
