:root {
  --bg: #08202d; --bg2: #0d2b3b; --panel: #11364a; --panel2: #18455c; --line: #25607a;
  --text: #eef6f8; --muted: #9fbac6; --accent: #ff8c2e; --accent2: #ff5d3a; --good: #57c785; --bad: #ff6b6b;
  --radius: 12px; --shadow: 0 6px 24px rgba(0,0,0,.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; display: flex; flex-direction: column;
  background: radial-gradient(1200px 700px at 50% -10%, #145a78 0%, var(--bg) 65%); }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; background: rgba(0,0,0,.25);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; backdrop-filter: blur(6px); }
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-size: 1.15rem; letter-spacing: .3px; }
.logo b { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font-size: .85rem; cursor: pointer; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; width: 36px; height: 34px; cursor: pointer; font-size: 1rem; }
.icon-btn:hover { background: var(--panel2); }
.conn { width: 10px; height: 10px; border-radius: 50%; background: #c98a2a; box-shadow: 0 0 0 2px rgba(0,0,0,.3); }
.conn.on { background: var(--good); } .conn.off { background: var(--bad); }

main { flex: 1; width: 100%; max-width: 1500px; margin: 0 auto; padding: 14px; }
.foot { text-align: center; color: var(--muted); font-size: .75rem; padding: 14px; }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; cursor: pointer; transition: transform .08s, background .15s; }
.btn:hover:not(:disabled) { background: #1f5874; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #2a1405; border-color: #d96a14; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #ffa65a; }
.btn.danger { background: #7a2e2a; border-color: #a5443d; }
.btn.good { background: #2d7a50; border-color: #3d9c67; }
.btn.big { padding: 12px 22px; font-size: 1.05rem; }
.btn.sm { padding: 5px 9px; font-size: .85rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
input[type=text], input[type=number], input[type=password], input:not([type]), select { background: #071a24; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
h1, h2, h3 { margin: 0 0 10px; }

/* ------- home */
.home { max-width: 980px; margin: 0 auto; display: grid; gap: 18px; }
.hero { text-align: center; padding: 10px 0 4px; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
.hero p { color: var(--muted); margin: 0; }
.games { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.game-card { text-align: left; cursor: pointer; position: relative; overflow: hidden; border: 2px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 16px; }
.game-card.sel { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,140,46,.25); }
.game-card.soon { opacity: .55; cursor: default; }
.game-card .art { font-size: 2.2rem; text-align: center; line-height: 0; margin: 2px 0 8px; }
.game-card .art .tp-logo { max-width: 100%; height: auto; }
.games:has(.logo-only) { display: flex; flex-wrap: wrap; justify-content: center; gap: 26px; }
.game-card.logo-only .tp-logo { width: 180px; height: auto; display: block; }
@media (max-width: 520px) { .games:has(.logo-only) { gap: 14px; } .game-card.logo-only .tp-logo { width: calc((100vw - 60px) / 2); } }
/* the game's card is the button: no box around it; it lifts on hover and glows orange when picked */
.game-card.logo-only { background: none; border: 0; padding: 0; border-radius: 10px; overflow: visible; width: auto; transition: transform .15s ease; }
.game-card.logo-only .art { margin: 0; }
.game-card.logo-only:hover:not(:disabled) { transform: translateY(-4px); }
.game-card.logo-only.sel { box-shadow: none; }
.game-card.logo-only.sel .tp-logo { filter: drop-shadow(0 0 0 #ff8c2e) drop-shadow(0 0 3px #ff8c2e) drop-shadow(0 0 10px rgba(255,140,46,.8)); }
.game-card.logo-only:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.game-card h3 { margin: 6px 0 4px; }
.game-card p { margin: 0; color: var(--muted); font-size: .9rem; }
.badge { position: absolute; top: 10px; right: 10px; font-size: .7rem; background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 8px; }
.home-forms { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.home-forms label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.home-forms input { width: 100%; }
@media (max-width: 700px) { .home-forms { grid-template-columns: 1fr; } }

/* ------- lobby */
.lobby { max-width: 1000px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1.2fr; gap: 16px; }
@media (max-width: 820px) { .lobby { grid-template-columns: 1fr; } }
.invite { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.invite code { background: #071a24; padding: 6px 10px; border-radius: 8px; font-size: .9rem; word-break: break-all; }
.bigcode { font-size: 2rem; letter-spacing: 6px; font-weight: 800; color: var(--accent); }
.seat { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; background: var(--bg2); }
.seat .who { flex: 1; }
.seat .tag { font-size: .75rem; color: var(--muted); }
.seat:has(.dot.off) .tag { color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--good); }
.dot.off { background: var(--bad); }
.settings .field { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.settings .field .help { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); margin-top: -4px; }
.settings input[type=number] { width: 100px; }

/* ------- in-game chrome */
.bot-banner { background: linear-gradient(90deg, #3c2a6b, #263d6b); border-bottom: 1px solid #5c4aa0; padding: 8px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; position: sticky; top: 51px; z-index: 25; }
.bot-banner .feed { flex: 1; font-size: .85rem; color: #d9d2ff; min-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer-bar { height: 5px; background: rgba(255,255,255,.08); position: sticky; top: 51px; z-index: 24; }
.timer-bar > div { height: 100%; background: var(--accent); width: 100%; transition: width 1s linear, background .3s; }
.timer-bar.low > div { background: var(--bad); }

.pause-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(4,16,24,.75); backdrop-filter: blur(5px); display: grid; place-items: center; padding: 20px; }
.pause-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; max-width: 440px; text-align: center; box-shadow: var(--shadow); animation: pop .25s ease-out; }
.pause-icon { font-size: 3rem; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: min(560px, 100%); max-height: 92vh; overflow: auto; box-shadow: var(--shadow); animation: pop .18s ease-out; }
.modal-card .close { float: right; }

.popmenu { position: fixed; z-index: 55; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; box-shadow: var(--shadow); width: 290px; }
.popmenu label { display: flex; gap: 8px; align-items: center; padding: 6px 4px; cursor: pointer; }
.popmenu p { margin: 4px 0 8px; font-size: .8rem; color: var(--muted); }

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 70; width: min(440px, 92vw); pointer-events: none; }
.toast { background: #06171f; border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); animation: slideup .25s ease-out; font-size: .92rem; }
.toast.bad { border-left-color: var(--bad); }
.toast.bot { border-left-color: #8f7cf0; }
.toast.good { border-left-color: var(--good); }
@keyframes slideup { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

.game-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.game-bar .title { font-weight: 700; margin-right: auto; }
.chat { display: flex; gap: 6px; margin-top: 8px; }
.chat input { flex: 1; min-width: 0; }

.modal.see-map { background: rgba(0,0,0,.15); place-items: end end; }
.modal.see-map .modal-card { width: min(460px, 100%); max-height: 70vh; }
@media (max-width: 700px) { .modal.see-map { place-items: end center; } }

/* home: separate create / join, invite mode */
.invite-banner { background: linear-gradient(90deg, #ff8c2e33, #ff8c2e11); border: 1px solid var(--accent); border-radius: var(--radius); padding: 12px 16px; text-align: center; font-size: 1.02rem; }
.games.off, .create-card.off .create-body { opacity: .38; filter: grayscale(.7); pointer-events: none; }
.create-card.off { border-style: dashed; }
.off-note { background: rgba(0,0,0,.2); border-radius: 8px; padding: 8px 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.join-card.hot { border: 2px solid var(--accent); box-shadow: 0 0 0 4px rgba(255,140,46,.18), var(--shadow); }
.home-forms label { margin-top: 4px; }
@media (max-width: 700px) { .home.invited .join-card { order: -1; } .home.invited .home-forms { display: flex; flex-direction: column; } .home.invited .games { display: none; } }

.qr-box { display: grid; place-items: center; background: #fff; border-radius: 14px; padding: 10px; width: fit-content; margin: 6px auto 10px; }
.qr-box svg { display: block; width: min(240px, 70vw); height: auto; }

/* ---------- saved players, pieces, move codes */
.profile-card { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: start; }
.profile-card h3 { margin: 0 0 4px; }
.profile-card .row input { min-width: 0; }
.pc-who { display: flex; gap: 12px; align-items: center; }
.piece-btn { background: rgba(255,255,255,.08); border: 2px solid var(--line); border-radius: 50%; padding: 6px; cursor: pointer; line-height: 0; }
.piece-btn:hover { border-color: var(--accent); }
.my-games { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.move-box { border-left: 1px solid var(--line); padding-left: 16px; max-width: 260px; }
.move-box label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.move-box input { width: 110px; letter-spacing: 3px; font-size: 1.1rem; }
@media (max-width: 720px) { .profile-card { grid-template-columns: 1fr; } .move-box { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 12px; max-width: none; } }
.piece-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin: 8px 0 14px; }
.piece-pick { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: 12px; border: 2px solid var(--line); background: rgba(255,255,255,.06); color: inherit; cursor: pointer; font-size: .78rem; }
.piece-pick.sel { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,140,46,.25); }
.piece-pick:disabled { opacity: .35; cursor: not-allowed; }
.seat-piece { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: rgba(255,255,255,.08); flex: none; line-height: 0; }
.seat-piece.empty { border: 2px dashed var(--line); background: none; }
button.seat-piece { border: 2px solid var(--accent); cursor: pointer; padding: 0; }
table.stats { width: 100%; border-collapse: collapse; }
table.stats th, table.stats td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.move-code { margin-top: 12px; border-top: 1px solid rgba(0,0,0,.12); padding-top: 8px; }
.move-code .bigcode { letter-spacing: 6px; }

/* ---------- invisible watching + test server */
.watch-tag { display: inline-block; font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; padding: 2px 8px; border-radius: 999px; background: #6b4fbf; color: #fff; vertical-align: middle; }
.watch-tag.good { background: #2fbf71; color: #062b14; }
.test-banner { background: repeating-linear-gradient(45deg, #ffcc33, #ffcc33 12px, #1b1b1b 12px, #1b1b1b 24px); color: #000; text-align: center; font-weight: 900; padding: 4px; }
.test-banner span { background: #ffcc33; padding: 2px 10px; border-radius: 6px; }
.test-banner a { color: #000; }

/* ---------- suggestion chest */
.chest-btn { position: relative; display: inline-grid; place-items: center; padding: 0; }
.chest-btn:hover svg { transform: rotate(-8deg) scale(1.1); }
.chest-btn svg { transition: transform .15s; }
.chest-dot { position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 50%; background: #ff5d5d; }
.chest-title { display: flex; align-items: center; gap: 10px; }
.chest-big svg { width: 38px; height: 38px; }
.sugg-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.sugg-form textarea { background: #071a24; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; resize: vertical; }
.sugg-list { max-height: 40vh; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.sugg { display: grid; grid-template-columns: 104px 1fr; gap: 8px; align-items: start; background: rgba(255,255,255,.05); border-radius: 10px; padding: 8px; }
.sugg .st { font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #24435a; text-align: center; }
.sugg.add .st { background: #f2a03d; color: #2a1605; }
.sugg.done .st { background: #2fbf71; color: #062b14; }
.sugg.no .st { background: #3c4a57; opacity: .8; }
.start-choices { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.seat-opts { margin: 10px 0 4px; padding: 8px 10px; border: 1px dashed var(--line); border-radius: 10px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: .9rem; }
.seat-opts b { flex-basis: 100%; font-size: .85rem; color: var(--muted); }
.seat-opts label { display: inline-flex; gap: 6px; align-items: center; }
.lobby-h { display: flex; align-items: center; gap: 14px; }
.lobby-logo { line-height: 0; flex: none; filter: drop-shadow(0 4px 8px rgba(0,0,0,.4)); }
.game-card .art svg { filter: drop-shadow(0 3px 6px rgba(0,0,0,.35)); }

/* a message from the server owner (forced update countdown) */
.server-notice { position: fixed; left: 50%; top: 10px; transform: translateX(-50%); z-index: 9999; display: flex; gap: 12px; align-items: center; max-width: calc(100% - 24px);
  background: #5b2a86; color: #fff; border: 2px solid #ffd24a; border-radius: 16px; padding: 10px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); font-weight: 700; line-height: 1.3; }
.server-notice b { font: 900 1.3rem system-ui; color: #ffd24a; min-width: 3ch; text-align: center; }
.server-notice button { background: none; border: 0; color: #fff; font-size: 1.1rem; cursor: pointer; padding: 0 2px; }

/* rules window */
.modal-card.wide { width: min(780px, 100%); }
.rl-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; } .rl-h h2 { margin: 0; }
.rl-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.rl-tabs button { padding: 7px 12px; border-radius: 10px 10px 0 0; background: #0a2230; color: var(--muted); font-weight: 700; border: 0; cursor: pointer; font-size: .92rem; }
.rl-tabs button.sel { background: #16455c; color: #fff; }
.rl-body { padding: 14px 16px; background: #16455c; border-radius: 0 12px 12px 12px; line-height: 1.5; }
.rl-body h4 { margin: 14px 0 4px; color: #ffd166; } .rl-body h4:first-child { margin-top: 0; }
.rl-body ol, .rl-body ul { margin: 4px 0 8px; padding-left: 22px; } .rl-body li { margin: 3px 0; }
.rl-tip { background: #0d2b3b; border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 8px; margin: 10px 0 0; font-size: .92rem; }
.rl-card { display: inline-block; vertical-align: middle; margin: 0 2px; line-height: 0; } .rl-card svg { display: block; }
.rl-opts { width: 100%; border-collapse: collapse; } .rl-opts td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; } .rl-opts td:last-child { text-align: right; white-space: nowrap; padding-left: 10px; }
.rl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 8px; }
.rl-game { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: var(--text); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.rl-game:hover { border-color: var(--accent); } .rl-game .e { font-size: 2rem; }
.hero .btn { margin-top: 6px; }
.rl-body li > .rl-card:first-child { float: left; margin: 2px 10px 4px 0; }
.rl-body li { overflow: hidden; }
.rl-body ul:has(.rl-card) { list-style: none; padding-left: 0; }

/* ---------------------------------------------------------------- TV (big screen) */
body.tv-mode { overflow: hidden; background: radial-gradient(ellipse at 50% 40%, #0f4a63, #051a24 75%); }
body.tv-mode header.topbar, body.tv-mode .topbar, body.tv-mode .test-banner, body.tv-mode #toasts { display: none !important; }
body.tv-mode #app { padding: 0; max-width: none; margin: 0; }
#tvRoot { position: fixed; left: 0; top: 0; width: 1920px; height: 1080px; transform-origin: 0 0; }
.tvj, .tvl { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3.2vh; text-align: center; padding: 2vh 2vw; box-sizing: border-box; }
.tvj h1, .tvl h1 { font-size: 6.6vh; margin: 0; } .tvj h1 b { color: #ff8c2e; } .tvj p, .tvl p { font-size: 2.8vh; color: var(--muted); margin: 0; }
.tvj-code { display: flex; gap: 2vh; } .tvj-code span { width: 12vh; height: 14vh; border-radius: 2vh; background: #0b2a3a; border: .5vh solid #25607a; display: grid; place-items: center; font: 900 9vh ui-monospace, monospace; }
.tvj-code span.f { border-color: #ffd24a; box-shadow: 0 0 3vh rgba(255,210,74,.5); } .tvj-code span.e { color: #3d6a80; }
.tvj-keys { display: grid; grid-template-columns: repeat(11, 7.8vh); gap: 1.1vh; }
.tvk { height: 6.7vh; border-radius: 1.3vh; background: #123d52; color: var(--text); border: 0; font: 800 3.3vh system-ui; cursor: pointer; }
.tvk:focus, .tvk:hover { background: #ffd24a; color: #2a1605; outline: none; transform: scale(1.1); } .tvk.w { grid-column: span 2; font-size: 2.4vh; }
.tvj-hint { font-size: 2.2vh; color: var(--muted); }
.tvl-code { font-family: ui-monospace, monospace; letter-spacing: .4em; color: #fff; }
.tvl-seats { display: flex; flex-wrap: wrap; gap: 2vh; justify-content: center; max-width: 90vw; }
.tvl-seat { background: #0e3446; border: .4vh solid #25607a; border-radius: 2vh; padding: 2vh 2.4vh; display: flex; flex-direction: column; align-items: center; gap: .8vh; min-width: 16vh; }
.tvl-seat .av { width: 9vh; height: 9vh; border-radius: 50%; background: #fff; display: grid; place-items: center; font: 900 4vh system-ui; color: #3d6a80; line-height: 0; }
.tvl-seat .av svg { width: 7vh; height: 7vh; } .tvl-seat b { font-size: 2.6vh; } .tvl-seat small { font-size: 1.8vh; color: var(--muted); } .tvl-seat.open { opacity: .6; }
.tvl-logo svg { max-height: 26vh; width: auto; }
.tv-sound { position: fixed; right: 2vh; bottom: 2vh; z-index: 100; font: 700 2.4vh system-ui; background: #0b2a3a; color: #fff; border: .25vh solid #25607a; border-radius: 999px; padding: 1vh 1.8vh; cursor: pointer; }
.tv-sound.ask { background: #ff8c2e; color: #2a1605; border-color: #ffd24a; animation: hotpulse 1.4s ease-in-out infinite; }
.tv-hint { background: #0d2b3b; border-left: 4px solid #ff8c2e; padding: 8px 12px; border-radius: 8px; margin: 10px 0 0; } .tv-hint code { font-size: .95em; }
