/* Box Hockey: a dark table with a plywood box on it. */
:root {
  --bg: #14110d;
  --panel: #1f1a14;
  --panel2: #2a231b;
  --line: #3a3026;
  --text: #ede4d6;
  --muted: #a3978a;
  --me: #3aa6ff;
  --them: #ff5f5f;
  --accent: #e0a24a;
  --ok: #6fcf7a;
}

* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: dark; }
body {
  margin: 0;
  background: radial-gradient(900px 500px at 50% 0%, #2a221a 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.app { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto 1fr; }

/* ---------- header ---------- */
header.top { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--line); background: rgba(0, 0, 0, .25); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.brand .mark { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.status { color: var(--muted); font-size: .85rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; }
button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 7px 12px; cursor: pointer; }
button:hover { background: #352c22; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: #9a6a2a; border-color: var(--accent); color: #fff; }
button.primary:hover { background: #b07a30; }
button.wide { width: 100%; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--them); color: #fff; font-size: .75rem; text-align: center; }
.only-narrow { display: none; }

/* ---------- main layout ---------- */
.main { display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.stage { position: relative; display: flex; align-items: center; justify-content: center; padding: 10px; min-height: 0; min-width: 0; }
canvas#rink { display: block; touch-action: none; border-radius: 4px; box-shadow: 0 18px 40px rgba(0, 0, 0, .55); user-select: none; }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; pointer-events: none; text-align: center; }
.overlay .big { font-size: clamp(2.4rem, 8vw, 5rem); font-weight: 900; letter-spacing: .04em; color: #fff; text-shadow: 0 4px 24px rgba(0, 0, 0, .7), 0 0 30px rgba(224, 162, 74, .5); min-height: 1.1em; }
.overlay .small { font-size: clamp(.95rem, 2.2vw, 1.25rem); color: #fff; text-shadow: 0 2px 10px rgba(0, 0, 0, .8); min-height: 1.3em; }
.overlay .big.flash { animation: flash .9s ease-out; }
@keyframes flash { 0% { transform: scale(.6); opacity: 0; } 20% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.panel { pointer-events: auto; background: rgba(20, 17, 13, .92); border: 1px solid var(--line); border-radius: 14px; padding: 18px 22px; max-width: min(92%, 420px); box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
.panel h2 { margin: 0 0 8px; font-size: 1.3rem; }
.panel p { margin: 6px 0; }
.panel .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 2.6rem; letter-spacing: .3em; padding-left: .3em; font-weight: 700; color: var(--accent); margin: 6px 0; }
.note { color: var(--muted); font-size: .85rem; }

/* ---------- side panel ---------- */
.side { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: rgba(0, 0, 0, .2); }
.scores { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.score { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--panel); border-left: 4px solid var(--line); }
.score.me { border-left-color: var(--me); }
.score.them { border-left-color: var(--them); }
.score .who { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.score .pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 9em; }
.score .tag { color: var(--muted); font-size: .7rem; }
.score .pts { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.score.off { opacity: .5; }
.score.turn { box-shadow: 0 0 0 1px var(--accent) inset, 0 0 16px -6px var(--accent); }
.score.turn .tag::after { content: ' · to flick'; color: var(--accent); }
.vs { color: var(--muted); font-size: .8rem; }
.target { padding: 4px 12px; color: var(--muted); font-size: .8rem; text-align: center; border-bottom: 1px solid var(--line); }
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.log { flex: 1; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; scroll-behavior: smooth; }
.msg { font-size: .9rem; word-break: break-word; }
.msg b { margin-right: 6px; }
.msg.me b { color: var(--me); }
.msg.them b { color: var(--them); }
.msg.sys { color: var(--muted); font-style: italic; font-size: .82rem; }
#chat-form { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); }
#chat-form input { flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); background: #efe6d8; color: #1a1510; font-weight: 600; padding: 9px 14px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }

/* ---------- dialogs ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 22px 24px; width: min(94vw, 560px); max-height: 92vh; box-shadow: 0 20px 60px rgba(0, 0, 0, .7); }
dialog::backdrop { background: rgba(0, 0, 0, .65); }
dialog h2 { margin: 0 0 8px; font-size: 1.35rem; }
dialog h3 { margin: 8px 0 6px; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
dialog p { margin: 8px 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); margin: 10px 0; }
.field input, .field select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.lobby-grid section { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.or { text-align: center; color: var(--muted); font-size: .8rem; margin: 10px 0 6px; }
.join-row { display: flex; gap: 6px; }
.join-row input { flex: 1; min-width: 0; font: inherit; font-family: ui-monospace, Consolas, monospace; font-size: 1.2rem; letter-spacing: .25em; text-transform: uppercase; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; text-align: center; }
.rules ul { padding-left: 20px; } .rules li { margin: 5px 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* ---------- narrow screens: chat slides up over the rink ---------- */
@media (max-width: 820px) {
  .main { grid-template-columns: 1fr; }
  .only-narrow { display: inline-block; }
  .side { position: fixed; left: 0; right: 0; bottom: 0; height: min(55vh, 420px); border-left: 0; border-top: 1px solid var(--line); background: rgba(20, 17, 13, .97); transform: translateY(100%); transition: transform .25s; z-index: 40; }
  .app.chat-open .side { transform: none; }
  .scores { padding: 8px 10px; }
  .lobby-grid { grid-template-columns: 1fr; }
  header.top h1 { font-size: 1rem; }
  .status { font-size: .75rem; }
}
