:root {
  --pitch: #0f3d24; --pitch2: #124a2b; --line: rgba(255,255,255,.14);
  --panel: rgba(4, 24, 14, .72); --text: #eef5ef; --muted: #a9c3b1;
  --home: #2f6fdb; --home-soft: #2f6fdb33; --away: #d6363b; --away-soft: #d6363b33;
  --wood: #c7a46a; --wood-soft: #c7a46a33; --red: #111; --card: #f6f1e4; --card-text: #1b241e;
  --yellow: #f4c430; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html { background: var(--pitch); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text);
  background: repeating-linear-gradient(90deg, var(--pitch) 0 80px, var(--pitch2) 80px 160px) fixed;
  min-height: 100vh; -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; }
button {
  cursor: pointer; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--text);
  padding: .55em 1em; border-radius: 8px;
}
button:hover:not(:disabled) { background: rgba(255,255,255,.16); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #f6f1e4; color: #10301d; border-color: #f6f1e4; font-weight: 600; }
button.primary:hover { background: #fff; }
button.warn { background: var(--yellow); color: #222; border-color: var(--yellow); font-weight: 600; }
button.small { font-size: .85rem; padding: .4em .8em; }
button.ghost { background: transparent; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; }
input, select {
  background: rgba(255,255,255,.95); color: #10301d; border: 1px solid transparent; border-radius: 8px; padding: .55em .7em;
}
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: rgba(0,0,0,.25); flex-wrap: wrap; }
/* Installed app: keep the header clear of the notch in landscape. */
.top { padding-top: max(10px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.brand { color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: .02em; }
.roomcode { display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.roomcode b { letter-spacing: .08em; }
.status { margin-left: auto; font-size: .8rem; color: var(--muted); }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #777; vertical-align: middle; }
.status.s-online::before { background: #4ade80; }
.status.s-local::before { background: #93c5fd; }
.status.s-idle::before { display: none; }
.status.s-connecting::before, .status.s-waiting::before, .status.s-reconnecting::before { background: var(--yellow); }
.status.s-offline::before, .status.s-taken::before, .status.s-nopeer::before { background: var(--away); }
main { max-width: 860px; margin: 0 auto; padding: 12px 16px 40px; display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.hero { margin-top: 6vh; max-width: 520px; align-self: center; width: 100%; }
.hero h1 { margin: 0 0 6px; font-size: 1.9rem; }
.hero h1 span { color: var(--yellow); }
.lead { color: var(--muted); margin: 0 0 16px; }
.hint { color: var(--muted); font-size: .85rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: .9rem; color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.row.join input { flex: 1; min-width: 0; text-transform: uppercase; }
.scoreboard { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.side { border-radius: var(--radius); padding: 8px 12px; background: var(--panel); border: 2px solid transparent; }
.side.t-H { border-left: 6px solid var(--home); }
.side.t-A { border-left: 6px solid var(--away); }
.side.active.t-H { border-color: var(--home); box-shadow: 0 0 0 2px var(--home-soft); }
.side.active.t-A { border-color: var(--away); box-shadow: 0 0 0 2px var(--away-soft); }
.tname { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.left { color: var(--muted); font-size: .9rem; }
.left b { color: var(--text); font-size: 1.3rem; }
.yc { display: inline-block; width: 10px; height: 14px; background: var(--yellow); border-radius: 2px; }
.banner { text-align: center; padding: 10px 12px; border-radius: var(--radius); background: var(--panel); font-weight: 500; }
.banner.t-H { box-shadow: inset 0 -3px 0 var(--home); }
.banner.t-A { box-shadow: inset 0 -3px 0 var(--away); }
.banner .clue { font-size: 1.4rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; margin-right: 8px; }
.banner .gl, .banner .poss { color: var(--muted); font-size: .9rem; }
.banner .poss { display: block; }
.banner.over { font-size: 1.15rem; font-weight: 700; background: var(--card); color: var(--card-text); }
.banner.over.t-H { background: var(--home); color: #fff; }
.banner.over.t-A { background: var(--away); color: #fff; }
.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.card {
  position: relative; aspect-ratio: 1.45; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--card); color: var(--card-text); border: 2px solid transparent; border-radius: 8px; padding: 4px;
  font-weight: 700; text-align: center; line-height: 1.1; cursor: default; overflow: hidden;
  font-size: clamp(.62rem, 2.6vw, 1.05rem); box-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.card:hover:not(:disabled) { background: var(--card); }
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-1px); box-shadow: 0 4px 0 rgba(0,0,0,.3); background: #fffaf0; }
.card .word { overflow-wrap: anywhere; hyphens: auto; }
.card.mid .word { font-size: .88em; }
.card.long .word { font-size: .76em; }
.card .tag { font-size: .62em; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-top: 3px; opacity: .85; }
.card .tag.faint { opacity: .7; }
.card.k-H { background: #dbe6fb; border-color: var(--home); }
.card.k-A { background: #f9dcdc; border-color: var(--away); }
.card.k-N { background: #efe3cc; border-color: var(--wood); }
.card.k-X { background: #2b2b2b; color: #fff; border-color: #000; }
.card.revealed { color: #fff; box-shadow: none; }
.card.revealed .word { text-decoration: line-through; text-decoration-thickness: 1px; opacity: .9; }
.board.manager .card.revealed { opacity: .55; }
.card.r-H { background: var(--home); }
.card.r-A { background: var(--away); }
.card.r-N { background: var(--wood); color: #3a2a10; }
.card.r-X { background: var(--red); }
.card.r-X::after { content: ""; position: absolute; top: 6px; right: 6px; width: 10px; height: 14px; background: var(--away); border-radius: 2px; }
.card.proposed { outline: 3px solid var(--yellow); outline-offset: 1px; }
.card .prop { position: absolute; top: 2px; left: 4px; font-size: .55em; font-weight: 600; color: #6b5200; }
.card .cap { position: absolute; top: 3px; right: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--yellow); color: #222; font-size: 10px; line-height: 16px; }
.controls p { margin: 0 0 8px; }
.clueform { display: flex; gap: 8px; flex-wrap: wrap; }
.clueform input { flex: 1; min-width: 140px; }
.clash { color: var(--yellow); font-size: .85rem; min-height: 1.2em; margin: 4px 0 8px; }
.note { background: rgba(244,196,48,.12); border: 1px solid rgba(244,196,48,.4); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; font-size: .9rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seatrow { display: flex; gap: 6px; flex-wrap: wrap; }
.seat { font-size: .85rem; padding: .4em .7em; }
.seat.t-H.on { background: var(--home); border-color: var(--home); }
.seat.t-A.on { background: var(--away); border-color: var(--away); }
.seat.on:not(.t-H):not(.t-A) { background: var(--card); color: var(--card-text); }
.rosters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.rosters ul { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.rosters li { padding: 2px 0; }
.rosters li.h { font-weight: 700; }
.rosters ul.t-H li.h { color: #8fb3f5; }
.rosters ul.t-A li.h { color: #f19a9d; }
.rosters li.away { opacity: .5; }
.rosters .x, .watchers .x { padding: 0 .4em; font-size: .8rem; }
.watchers { list-style: none; margin: 8px 0 0; padding: 0; font-size: .9rem; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.watchers li.h { font-weight: 700; opacity: .8; }
.watchers li.away { opacity: .5; }
.log h3 { margin: 0 0 6px; font-size: .95rem; }
.log ol { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; font-size: .88rem; }
.log li { padding: 3px 0 3px 8px; border-left: 3px solid transparent; }
.log li.t-H { border-left-color: var(--home); }
.log li.t-A { border-left-color: var(--away); }
.log li.l-clue { font-weight: 700; }
.log li.l-end { font-weight: 700; color: var(--yellow); }
.log li.l-yellow { color: var(--yellow); }
.settings summary { cursor: pointer; font-weight: 600; }
.cb { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: #111; color: #fff; padding: 10px 16px; border-radius: 8px; transition: .2s; max-width: calc(100% - 32px); z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
dialog { max-width: 600px; width: calc(100% - 32px); border: none; border-radius: 12px; padding: 20px 22px; background: #f8f5ec; color: #1b241e; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin-top: 0; }
dialog h3 { margin-bottom: 4px; font-size: 1rem; }
dialog .close { float: right; background: none; border: none; color: #444; font-size: 1.5rem; padding: 0 6px; }
dialog .home { color: var(--home); } dialog .away { color: var(--away); }
dialog .hint { color: #4d5e52; }
body.tv .top, body.tv .footer { display: none; }
body.tv main { max-width: 1400px; padding-top: 16px; }
body.tv .card { font-size: clamp(.8rem, 2.4vw, 2rem); }
body.tv .banner .clue { font-size: 2.2rem; }
.exit-tv { align-self: center; opacity: .5; }
@media (max-width: 520px) {
  main { padding: 10px 10px 32px; gap: 10px; }
  .board { gap: 4px; }
  .card { aspect-ratio: 1.05; border-radius: 6px; padding: 2px; }
  .card .tag { display: none; }
  .hero { margin-top: 2vh; }
}
body.tv .board { width: 100%; max-width: calc((100vh - 190px) * 1.45); margin: 0 auto; }
body.tv .banner { font-size: 1.3rem; }
body.tv .scoreboard .left b { font-size: 1.8rem; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 12px; }
.modes button { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; padding: .7em .9em; }
.modes button small { font-weight: 400; font-size: .78rem; opacity: .75; }
.card.k-G { background: #d9f2dc; border-color: #2e9e4f; }
.card.r-G { background: #2e9e4f; }
.side.t-G { border-left: 6px solid #2e9e4f; }
.side.t-N { border-left: 6px solid var(--wood); }
.banner.over.t-G { background: #2e9e4f; color: #fff; }
.card .tans { position: absolute; top: 3px; right: 4px; display: flex; gap: 2px; }
.card .tan { font-size: 9px; line-height: 1; padding: 2px 3px; border-radius: 3px; background: var(--wood); color: #3a2a10; }

/* Live rooms on the homepage */
.rooms h3 { margin: 0 0 8px; }
.roomlist { list-style: none; margin: 0; padding: 0; }
.roomlist li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.roomlist li:first-child { border-top: none; }
.roomlist .ri { min-width: 0; }
.roomlist .ri .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roomlist .ra { display: flex; gap: 6px; flex-shrink: 0; }
.badge { display: inline-block; font-size: .75rem; padding: 1px 7px; border-radius: 99px; background: rgba(255,255,255,.12); color: var(--muted); margin-left: 4px; }
.badge.full { background: var(--away-soft); color: #f19a9d; }
.install { margin-top: 8px; }
