/* Shared layout for every game page: header, home (intro, featured card, mode cards), room lobby,
   buttons, inputs, keycaps, modal and toast. Load after /site.css and before the game's own CSS so
   all games keep the same patterns. Colour tokens come from /site.css. */

/* ---------- Base, buttons, inputs, header, intro, featured card, mode cards, join form ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 var(--font-ui); font-feature-settings: "palt" 0;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
.hidden { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.02em; margin: 0; }
button, input, select { font: inherit; color: inherit; }

/* ---------- buttons ---------- */
button {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: 11px;
  padding: 9px 16px; cursor: pointer; font-weight: 500; line-height: 1.3;
  transition: background .12s, border-color .12s, transform .06s, opacity .12s;
}
button:hover { background: var(--surface-2); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; transform: none; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--line); outline-offset: 2px; }
button.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
button.primary:hover { opacity: .88; background: var(--primary); }
button.lg { padding: 12px 22px; font-size: 16px; font-weight: 600; border-radius: 13px; }
button.block { width: 100%; }
button.ghost { border-color: transparent; background: transparent; color: var(--sub); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.link { border: 0; background: none; padding: 0; color: var(--text); font-weight: 500; text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
button.link:hover { text-decoration-color: currentColor; background: none; }
.icon-btn { width: 38px; height: 38px; padding: 0; display: inline-grid; place-items: center; border-color: transparent; background: transparent; color: var(--sub); border-radius: 10px; font-weight: 600; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input, select { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 11px; padding: 9px 12px; outline: none; }
input:focus { border-color: var(--text); }
kbd { font: 500 12px var(--font-ui); background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; margin-right: 3px; }
.eyebrow { font-size: 12.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--sub); display: inline-flex; align-items: center; gap: 7px; }
.muted { color: var(--sub); font-size: 14px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; max-width: 1040px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 9px; border: 0; background: none; padding: 4px 2px; font: 700 17px var(--font-display); letter-spacing: -.02em; }
.brand svg { color: var(--accent); }
.brand:hover { background: none; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.online { font-size: 13px; color: var(--sub); display: inline-flex; align-items: center; gap: 6px; margin-right: 6px; }
.online i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.online.live i { background: var(--success); }
.name-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 99px; border-color: var(--border); font-size: 14px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font: 600 12px var(--font-display); color: #fff; background: var(--line); }

/* ---------- home ---------- */
.view { max-width: 1040px; margin: 0 auto; padding: 0 24px 48px; }
.intro { padding: 36px 0 28px; max-width: 600px; }
.intro h1 { font-size: clamp(36px, 6vw, 56px); line-height: 1; font-weight: 700; margin-bottom: 14px; }
.intro p { color: var(--sub); margin: 0; font-size: 16.5px; }
.intro .link { color: var(--text); }

.daily {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 26px 28px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.daily::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); }
.daily h2 { font-size: 26px; margin: 6px 0 4px; }
.daily p { margin: 0; color: var(--sub); }
.daily p b { color: var(--text); font-weight: 600; }
.spark { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.daily-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; flex-shrink: 0; }
.daily-actions .lg { min-width: 160px; }
.daily-actions .link { font-size: 14px; color: var(--sub); }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.mode { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 24px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 6px; }
.mode h3 { font-size: 20px; }
.mode > p { color: var(--sub); margin: 0 0 12px; font-size: 14.5px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.join { display: flex; gap: 8px; }
.join input { width: 120px; text-transform: uppercase; letter-spacing: .3em; font: 600 18px var(--font-display); text-align: center; padding: 8px 10px; }
.field { width: 100%; display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; text-align: left; }
.field .label { font-size: 13px; font-weight: 500; color: var(--sub); }
.field .seg { display: flex; } .field .seg button { flex: 1; padding: 7px 6px; font-size: 13.5px; }

/* ---------- Header extras and name dialog ---------- */
.name-form { display: flex; gap: 8px; } .name-form input { flex: 1; }
.brand-group { display: flex; align-items: center; gap: 4px; }
.site-link { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: var(--sub); }
.site-link:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; font-size: 14px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; color: var(--sub); font-weight: 500; }
.seg button:hover { background: transparent; color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.seg button:focus { outline: none; }
.seg button:focus-visible { box-shadow: 0 0 0 2px var(--line) inset; }

/* ---------- Room lobby ---------- */
.lobby { background: var(--surface); border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); padding: 32px; max-width: 440px; width: 100%; margin: 12px auto 0; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.lobby .code { font: 700 56px/1.05 var(--font-display); letter-spacing: .14em; margin-right: -.14em; }
.lobby .link { font-size: 14px; color: var(--sub); margin-bottom: 18px; }
.players { list-style: none; margin: 0 0 18px; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 6px; }
.players li { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 12px; background: var(--surface-2); text-align: left; }
.players li.empty { background: none; border: 1.5px dashed var(--border-strong); color: var(--muted); grid-template-columns: 1fr; text-align: center; font-size: 14px; }
.players .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .nm .crown { color: var(--accent); margin-left: 6px; font-size: 12px; font-weight: 600; }
.players .nm em { font-style: normal; font-weight: 400; color: var(--sub); margin-left: 6px; font-size: 13px; }
.players .st { font-size: 13px; color: var(--sub); }
.players .st.ok { color: var(--success); font-weight: 600; }
.status { margin: 6px 0 0; font-size: 14px; color: var(--sub); min-height: 21px; }

/* ---------- Modal and toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(12, 12, 16, .42); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 26px; width: min(440px, 100%); box-shadow: 0 24px 64px rgba(0,0,0,.28); max-height: 88vh; overflow: auto; animation: rise .2s ease-out; }
.modal-card h2 { font-size: 24px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--primary); color: var(--primary-ink); padding: 10px 18px; border-radius: 12px; z-index: 70; font-size: 14px; font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,.25); max-width: calc(100vw - 32px); animation: rise .2s ease-out; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Keycaps ---------- */
kbd.kc { display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 4px; margin: 0;
  font: 700 10.5px/1 var(--font-ui); color: var(--sub); background: var(--surface);
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; letter-spacing: 0; vertical-align: 1px; }
kbd.kc.sm { height: 15px; min-width: 0; font-size: 9.5px; padding: 0 3px; }

/* ---------- Practice list (one row per option, chevron on the right) ---------- */
.diff-list { list-style: none; margin: 0 -10px; padding: 0; }
.diff-list button { width: 100%; display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center; border: 0; background: none; border-radius: 11px; padding: 10px; text-align: left; }
.diff-list button:hover { background: var(--surface-2); }
.diff-list .dn { font-weight: 600; display: flex; align-items: center; gap: 10px; }
.diff-list .pips { display: inline-flex; gap: 3px; }
.diff-list .pips i { width: 6px; height: 6px; border-radius: 2px; background: var(--border-strong); }
.diff-list .pips i.f { background: var(--text); }
.diff-list .meta { color: var(--sub); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.diff-list .chev { color: var(--muted); }
.help-h { font-size: 14px; margin: 18px 0 8px; color: var(--sub); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }

/* ---------- Player chips (opponents / scores during a game) ---------- */
.chip { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 2px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 7px 12px; min-width: 150px; flex: 1 1 150px; max-width: 260px; position: relative; overflow: hidden; }
.chip.me { border-color: var(--border-strong); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip .dot.on { background: var(--success); }
.chip .nm { color: var(--text); font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .nm em { font-style: normal; font-weight: 400; color: var(--sub); }
.chip .wl { font: 600 14px var(--font-display); color: var(--text); font-variant-numeric: tabular-nums; }
.chip .st { grid-column: 2 / 4; font-size: 12.5px; }
.chip .st.ok { color: var(--success); font-weight: 500; }
.chip .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--line); transition: width .3s; }

/* ---------- In-game header: title + timer ---------- */
.game { max-width: 760px; display: flex; flex-direction: column; gap: 12px; }
.game-head { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; margin-left: -8px; }
.game-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.game-title b { font: 600 17px var(--font-display); letter-spacing: -.01em; }
.game-title span { font-size: 13px; color: var(--sub); }
.timer { font: 600 28px/1 var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -.02em; min-width: 5ch; text-align: right; }
.timer.done { color: var(--success); }
.game-head { grid-template-columns: auto 1fr auto auto auto; }

@media (max-width: 720px) {
  .timer { font-size: 24px; }
  .topbar { padding: 12px 16px; }
  .view { padding: 0 16px 32px; }
  .online { display: none; }
  .intro { padding: 20px 0 20px; }
  .daily { flex-direction: column; align-items: stretch; padding: 22px; }
  .daily-actions .lg { width: 100%; }
  .modes { grid-template-columns: 1fr; }
  .lobby { padding: 24px 18px; }
  .lobby .code { font-size: 46px; }
  .name-chip #nameLabel { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ---------- Connection cover: hides a room's board while the connection is down, so a stale game
   never looks playable. Shown by each game's websocket code (connCover in app.js / triples.js). ---------- */
.conn-cover { position: fixed; inset: 64px 0 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .2s; }
.conn-cover > div { max-width: 340px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px 24px; box-shadow: var(--shadow); }
.conn-cover b { display: block; font: 700 19px var(--font-display); margin: 10px 0 6px; }
.conn-cover p { margin: 0 0 14px; color: var(--sub); font-size: 14px; }
.conn-cover .spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent, var(--ink)); display: inline-block; animation: conn-spin .8s linear infinite; }
@keyframes conn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .conn-cover .spin { animation-duration: 2.4s; } }

/* Links to the game's rules and technique pages (also what search engines follow). */
.learn-links { margin: 20px 0 0; text-align: center; font-size: 14px; color: var(--sub); }
.learn-links a { color: var(--sub); text-underline-offset: 3px; }
.learn-links a:hover { color: var(--text); }

/* Open public rooms on a game's home page, and the host's Remove button (see /room-ui.js). */
.tp-public { margin-top: 14px; }
.tp-public:empty { display: none; }
.tp-public h4 { margin: 0 0 6px; font-size: 13px; font-weight: 500; color: var(--sub); }
.tp-public ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.tp-public li button { width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; text-align: left; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); border: 0; }
.tp-public li button:disabled { opacity: .55; }
.tp-public .cd { font: 600 14px var(--font-display); letter-spacing: .12em; }
.tp-public .meta { font-size: 13px; color: var(--sub); }
.tp-public p { margin: 0; font-size: 13px; color: var(--sub); }
.players .kick { padding: 2px 8px; font-size: 12px; margin-left: 8px; }
.tp-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 8px; vertical-align: 1px; }

/* Countdown before a game and the host's pause cover (see /room-ui.js). */
.room-cd { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(3px); pointer-events: none; }
.room-cd span { font: 800 120px/1 var(--font-display); color: var(--text); }
.room-cd span.pop { animation: room-pop .9s ease; }
@keyframes room-pop { 0% { transform: scale(1.6); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(.92); opacity: .85; } }
.room-pause { position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(6px); }
.room-pause-card { display: grid; justify-items: center; gap: 8px; padding: 28px 36px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); text-align: center; }
.room-pause-card b { font: 700 32px var(--font-display); }
.room-pause-card p { margin: 0 0 8px; color: var(--sub); }
button:disabled { opacity: .5; cursor: default; }

/* rematch panel under results (room-ui.js renderRematch) */
.room-rematch { border-top: 1px solid var(--border); padding-top: 14px; }
.room-rematch .who { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.room-rematch .who span { padding: 4px 10px; border-radius: 999px; font-size: 13.5px; background: var(--surface-2); color: var(--sub); }
.room-rematch .who span.in { background: color-mix(in srgb, var(--pc) 18%, var(--surface)); color: var(--text); font-weight: 600; }
.room-rematch .muted { text-align: center; margin: 8px 0 0; }
.room-rematch .modal-actions { justify-content: center; flex-wrap: wrap; }
.room-rounds-fold { margin-top: 14px; font-size: 14px; }
.room-rounds-fold summary { cursor: pointer; color: var(--sub); }

/* "How to play" sits beside the game's name, not among the account controls. */
.help-btn { width: 28px; height: 28px; min-width: 28px; font-size: 14px; margin-left: 2px; color: var(--sub); }
.help-btn:hover { color: var(--text); }

/* leaderboards and scoreboards (Loop Fence, Nurikabe) */
.lb { list-style: none; margin: 0; padding: 0; }
.lb li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; padding: 8px 10px; border-radius: 10px; font-size: 14.5px; }
.lb li:nth-child(-n+3) .rk { color: var(--accent); }
.lb .rk { font: 600 14px var(--font-display); color: var(--muted); }
.lb .tm { font: 600 14.5px var(--font-display); font-variant-numeric: tabular-nums; }
.lb li.me { background: var(--accent-soft); }
.lb li.empty { grid-template-columns: 1fr; color: var(--sub); text-align: center; padding: 20px; }

/* ---------- game toolbar: tools (1, 2…), hint (H), undo (Z), redo (Y). Same in every game. ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tools button { flex-direction: column; gap: 0; padding: 6px 14px; min-width: 76px; }
.tools .tl { display: inline-flex; align-items: center; gap: 6px; }
.tools .tl kbd.kc { margin-left: 2px; }
.tools button.on kbd.kc { color: var(--text); }
.tools .how { font-size: 11px; line-height: 1.3; color: var(--muted); font-weight: 500; white-space: nowrap; margin-top: 2px; }
.tools .how .t { display: none; }
.history-btns { display: flex; gap: 2px; align-items: center; }
.hint-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 10px; border-color: transparent; background: transparent; color: var(--sub); font-weight: 500; font-size: 14px; }
.hint-btn:hover { background: var(--surface-2); color: var(--text); }
.hint-btn svg { color: var(--hint, #e0870b); }
.hint-btn .count { font: 600 12px var(--font-display); background: var(--surface-2); border-radius: 99px; padding: 0 7px; min-width: 20px; text-align: center; }
.hint-btn kbd.kc { margin-left: 1px; }
.hint-btn.thinking svg { animation: think 1s ease-in-out infinite; }
@keyframes think { 50% { opacity: .3; } }
.key-btn { display: inline-flex; align-items: center; gap: 5px; height: 38px; padding: 0 9px; border-color: transparent; background: transparent; color: var(--sub); border-radius: 10px; }
.key-btn:hover { background: var(--surface-2); color: var(--text); }
@media (max-width: 720px) {
  .toolbar { flex-wrap: wrap; }
  .seg.tools { flex: 1 1 100%; }
  .seg.tools button { min-width: 0; flex: 1; padding: 6px 4px; }
  .history-btns { margin-left: auto; }
}
@media (hover: none), (pointer: coarse) {
  kbd.kc { display: none; }
  .tools .how .m { display: none; }
  .tools .how .t { display: inline; }
}
.controls-grid { display: grid; grid-template-columns: minmax(150px, auto) 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
.controls-grid dt { font-weight: 600; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.controls-grid dd { margin: 0; color: var(--sub); }
.controls-grid .or { font-weight: 400; color: var(--muted); }
.controls-grid kbd.kc { display: inline-grid; }
@media (max-width: 520px) { .controls-grid { grid-template-columns: 1fr; gap: 2px; } .controls-grid dd { margin-bottom: 8px; } }
.rules { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.rule { display: flex; gap: 12px; align-items: flex-start; }
.rule p { margin: 0; }
.rule .n { flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font: 600 13px var(--font-display); margin-top: 1px; }
