:root {
  --board: #1f4d3a;
  --board-dark: #163a2b;
  --frame: #8a5a2b;
  --chalk: #f6f3e7;
  --muted: #a9c7b6;
  --accent: #ffd23f;
  --accent-ink: #3a2600;
  --good: #7ed957;
  --tile: #fffdf6;
  --tile-ink: #23302a;
  --tile-w: min(11vw, 96px);
  --sign-w: min(7.2vw, 62px);
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--board-dark); color: var(--chalk); font-family: var(--font); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700; color: var(--chalk); cursor: pointer;
  background: #2c6a50; border: 2px solid #4c9a78; border-bottom-width: 4px; border-radius: 12px;
  padding: 8px 14px; font-size: 1rem; line-height: 1.1;
  transition: transform 0.06s ease, background 0.15s;
}
.btn:hover { background: #357c5e; }
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: #c79a00; }
.btn.primary:hover { background: #ffe06e; }
.btn.huge { font-size: 1.5rem; padding: 14px 28px; width: 100%; margin-top: 16px; }
.btn:disabled { opacity: 0.45; cursor: default; }

/* ---------- panels & lobby ---------- */
.panel {
  background: var(--board); border: 8px solid var(--frame); border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), inset 0 0 60px rgba(0, 0, 0, 0.25); padding: 22px;
}
.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  padding: 16px; z-index: 20; overflow-y: auto;
  background: radial-gradient(ellipse at top, #3d7f63 0%, var(--board-dark) 75%);
}
h1 { margin: 0 0 8px; font-size: 2.2rem; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
.lobby-panel { width: min(520px, 100%); }
.lobby-panel label { display: block; font-weight: 700; margin: 14px 0 6px; }
.lobby-panel small { color: var(--muted); font-weight: 400; }
.tagline { color: var(--muted); margin: 0; }
input {
  font: inherit; font-size: 1.2rem; width: 100%; margin-top: 6px; padding: 10px 12px; color: var(--chalk);
  background: var(--board-dark); border: 2px solid #4c9a78; border-radius: 12px; outline: none;
  -webkit-user-select: text; user-select: text;
}
input:focus { border-color: var(--accent); }
.how { margin-top: 14px; font-size: 0.92rem; color: var(--muted); }
.how p { margin: 6px 0; }
#lobby-msg { min-height: 1.2em; margin: 10px 0 0; text-align: center; }

/* ---------- game ---------- */
.game {
  position: fixed; inset: 0; display: flex; flex-direction: column; touch-action: none;
  background: radial-gradient(ellipse at top, #2c6a50 0%, var(--board) 45%, var(--board-dark) 100%);
}
/* Above the overlay, so the way home works while waiting or after a round. */
.top { position: relative; z-index: 16; display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.pill { background: rgba(0, 0, 0, 0.3); border-radius: 999px; padding: 7px 14px; font-weight: 700; white-space: nowrap; }
.scores { flex: 1; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; min-width: 0; }
.score { background: rgba(0, 0, 0, 0.3); border-radius: 999px; padding: 7px 14px; font-weight: 700; white-space: nowrap; }
.score.me { outline: 2px solid var(--accent); }
.score.away { opacity: 0.5; }

.board { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: min(3.5vh, 26px); padding: 0 2vw 4vh; min-height: 0; }
.goal { text-align: center; }
.goal-label { color: var(--muted); font-size: 1.1rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.goal-num { font-size: min(18vh, 22vw, 150px); line-height: 1; font-weight: 800; color: var(--accent); text-shadow: 0 5px 0 rgba(0, 0, 0, 0.3); }

.row { display: flex; align-items: center; gap: 0.8vw; }
.tile, .sign {
  font: inherit; font-weight: 800; cursor: pointer; border: 0; padding: 0;
  display: flex; align-items: center; justify-content: center; touch-action: none;
}
.tile {
  width: var(--tile-w); height: calc(var(--tile-w) * 1.15); font-size: calc(var(--tile-w) * 0.5);
  background: var(--tile); color: var(--tile-ink); border-radius: calc(var(--tile-w) * 0.18);
  box-shadow: 0 calc(var(--tile-w) * 0.08) 0 #c9c2a8, 0 10px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.tile.sel { background: var(--accent); transform: translateY(-10%); }
.tile.drag { transition: none; z-index: 5; pointer-events: none; box-shadow: 0 18px 30px rgba(0, 0, 0, 0.5); }
.sign {
  width: var(--sign-w); height: var(--sign-w); font-size: calc(var(--sign-w) * 0.62); border-radius: 50%;
  background: rgba(0, 0, 0, 0.28); color: var(--chalk); border: 2px dashed rgba(246, 243, 231, 0.55);
}
.sign.open { background: var(--accent); color: var(--accent-ink); border-style: solid; }
.br {
  font: inherit; font-weight: 800; border: 0; padding: 0; background: none; cursor: pointer; touch-action: none;
  width: calc(var(--sign-w) * 0.5); margin: 0 -0.6vw; font-size: calc(var(--tile-w) * 1.05); line-height: 1;
  color: var(--accent); text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}
.row.locked .tile, .row.locked .sign, .row.locked .br { cursor: default; }

.mine { display: flex; align-items: baseline; gap: 14px; font-weight: 800; }
.eq { font-size: min(8vh, 60px); color: var(--muted); }
.result { font-size: min(11vh, 16vw, 90px); line-height: 1; }
.result.hit { color: var(--good); }
.rival { background: rgba(0, 0, 0, 0.3); border-radius: 999px; padding: 8px 18px; font-size: 1.15rem; }
.rival b { color: var(--accent); font-size: 1.4em; margin-left: 4px; }

.picker {
  position: fixed; z-index: 10; display: flex; gap: 8px; padding: 8px; border-radius: 999px;
  background: var(--board-dark); border: 3px solid var(--frame); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -100%);
}
.picker .sign { --sign-w: 56px; border-style: solid; background: #2c6a50; }
.picker .sign.cur { background: var(--accent); color: var(--accent-ink); }
.picker .sign.paren { font-size: 26px; letter-spacing: -2px; }

.overlay { position: fixed; inset: 0; z-index: 15; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(8, 24, 17, 0.72); }
.overlay-panel { width: min(520px, 100%); text-align: center; }
.overlay-panel h2 { margin: 0 0 10px; font-size: 1.9rem; }
.overlay-panel p { margin: 8px 0; }
.count { font-size: 6rem; font-weight: 800; color: var(--accent); line-height: 1; }
.join-url { display: block; margin-top: 4px; color: var(--accent); font-weight: 700; word-break: break-all; -webkit-user-select: text; user-select: text; }
.sum { font-size: 1.25rem; font-weight: 700; white-space: nowrap; }
.sum small { display: block; color: var(--muted); font-weight: 400; font-size: 0.85rem; }

@media (orientation: portrait) {
  :root { --tile-w: min(11vw, 96px); --sign-w: min(7.2vw, 62px); }
  .row { gap: 0.5vw; }
}
