:root {
  --bg: #0f1118;
  --bg-2: #161926;
  --panel: #1c2030;
  --panel-2: #232841;
  --line: #2e3450;
  --text: #eef0f6;
  --muted: #9aa1b8;
  --accent: #f2c94c;
  --accent-2: #4fd1c5;
  --danger: #ff6b6b;
  --ok: #46c46d;
  --rail: 160px;
  --rail-gap: 24px;
  --topbar: 58px;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: "Pretendard Variable", Pretendard, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, #232a45 0%, var(--bg) 60%);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}
a { color: inherit; }
button { font-family: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: rgba(15, 17, 24, .85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.fw-link {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; letter-spacing: .02em;
}
.fw-link:hover { color: var(--text); }
.fw-link .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.sep { width: 1px; height: 22px; background: var(--line); }
.brand { display: inline-flex; align-items: center; text-decoration: none; }
.brand img { height: 36px; width: auto; display: block; object-fit: contain; }
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.topnav button {
  background: transparent; border: 0; color: var(--muted); font-size: 14px; font-weight: 600;
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
}
.topnav button:hover { color: var(--text); background: rgba(255,255,255,.05); }
.topnav button.is-active { color: var(--text); background: var(--panel-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.account { display: flex; align-items: center; gap: 10px; }
.account .avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #ff9f43); color: #1a1a1a; font-weight: 800; font-size: 14px;
}
.account .who { display: flex; flex-direction: column; line-height: 1.15; }
.account .who b { font-size: 14px; }
.account .who small { color: var(--muted); font-size: 11px; }
.account .level-chip {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--accent); font-weight: 800; font-size: 11px;
  padding: 3px 8px; border-radius: 999px; letter-spacing: .04em;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: #3f4766; background: #2a3050; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn-primary { background: linear-gradient(180deg, #ffd765, var(--accent)); color: #1a1405; border-color: #c9a53a; }
.btn-primary:hover { background: linear-gradient(180deg, #ffe08a, #f5d060); border-color: #d9b545; }
.btn-ghost { background: transparent; }
.btn-lg { padding: 14px 24px; font-size: 16px; border-radius: 12px; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-icon { width: 38px; height: 38px; padding: 0; font-size: 16px; }

/* ---------- ad rails ---------- */
.ad-rail {
  display: none;
  position: fixed; top: 50%; transform: translateY(-50%); z-index: 40;
  width: var(--rail); height: 600px;
}
.ad-rail.left { left: var(--rail-gap); }
.ad-rail.right { right: var(--rail-gap); }
.ad-rail .ad-box {
  width: 160px; height: 600px; display: grid; place-items: center;
  border: 1px dashed rgba(255,255,255,.18); border-radius: 8px;
  background: rgba(255,255,255,.03); color: rgba(255,255,255,.35);
  font-size: 11px; letter-spacing: .12em; text-align: center; line-height: 1.8;
}
.ad-rail ins.adsbygoogle { display: inline-block; width: 160px; height: 600px; }
@media (min-width: 1320px) and (min-height: 700px) {
  .ad-rail { display: block; }
}
.ad-mobile { display: none; justify-content: center; padding: 10px 16px 0; }
.ad-mobile .ad-box {
  width: 320px; height: 100px; display: grid; place-items: center;
  border: 1px dashed rgba(255,255,255,.18); border-radius: 8px; background: rgba(255,255,255,.03);
  color: rgba(255,255,255,.35); font-size: 11px; letter-spacing: .12em;
}
.ad-mobile ins.adsbygoogle { display: inline-block; width: 320px; height: 100px; }
@media (max-width: 820px) { .ad-mobile { display: flex; } }

/* ---------- layout ---------- */
#app { max-width: 980px; margin: 0 auto; padding: 24px 20px 40px; }
.screen { display: none; animation: fade .25s ease-out; }
.screen.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0; }
.panel-head h2 { margin: 0; font-size: 16px; letter-spacing: .02em; }
.panel-body { padding: 14px 18px 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- lobby ---------- */
.lobby { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
.hero {
  position: relative; overflow: hidden; min-height: 420px;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 14px; padding: 26px;
  background: linear-gradient(180deg, rgba(28,32,48,.2), rgba(15,17,24,.92) 70%), var(--panel);
}
.hero canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; object-fit: cover; object-position: center 35%; z-index: 0; opacity: .75; }
.hero::after { content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(15,17,24,.1) 0%, rgba(15,17,24,.45) 40%, rgba(15,17,24,.96) 100%); }
.hero > * { position: relative; z-index: 1; }
.hero .logo-big img { display: block; width: min(420px, 100%); height: auto; filter: drop-shadow(0 6px 18px rgba(0,0,0,.5)); }
.hero .tagline { color: var(--accent); font-weight: 800; letter-spacing: .28em; font-size: 13px; }
.hero p { margin: 0; color: var(--muted); max-width: 520px; line-height: 1.6; }
.hero .cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.side { display: flex; flex-direction: column; gap: 20px; }

.profile { display: flex; flex-direction: column; gap: 12px; }
.profile .row { display: flex; align-items: center; gap: 12px; }
.profile .avatar-lg {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #ff9f43); color: #1a1a1a; font-weight: 900; font-size: 20px;
}
.profile .name { font-size: 16px; font-weight: 800; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; }
.stat .v { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 11px; color: var(--muted); letter-spacing: .05em; }
.exp-bar { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.exp-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); width: 0; transition: width .4s ease; }

.rank-mini { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rank-mini li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); font-size: 13px; }
.rank-mini li.me { outline: 1px solid var(--accent); }
.rank-mini .r { width: 22px; font-weight: 800; color: var(--accent); text-align: center; }
.rank-mini .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-mini .e { color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 13px; padding: 10px 0; text-align: center; }

/* ---------- stages ---------- */
.stage-grid { display: flex; flex-direction: column; gap: 12px; }
.stage-grid-inner { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; padding-top: 12px; }
details.chapter { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
details.chapter summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
details.chapter summary::-webkit-details-marker { display: none; }
details.chapter summary::before { content: '▸'; color: var(--muted); margin-right: 8px; }
details.chapter[open] summary::before { content: '▾'; }
.ch-name { font-weight: 800; font-size: 16px; }
.ch-meta { color: var(--muted); font-size: 12px; text-align: right; }
.game-top .title .credit { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 6px; }
.stage-card {
  position: relative; text-align: left; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; color: var(--text);
  transition: transform .08s ease, border-color .15s ease;
}
.stage-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.stage-card:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.stage-card .num { font-size: 11px; color: var(--muted); letter-spacing: .12em; }
.stage-card .name { font-size: 16px; font-weight: 800; margin: 2px 0 8px; }
.stage-card .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.stage-card .meta b { color: var(--text); }
.stage-card .badge { position: absolute; top: 10px; right: 10px; font-size: 12px; }
.stage-card.cleared .badge { color: var(--ok); }

/* ---------- ranking ---------- */
.tabs { display: flex; gap: 6px; }
.tabs button { background: transparent; border: 1px solid transparent; color: var(--muted); padding: 8px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.tabs button.is-active { background: var(--panel-2); border-color: var(--line); color: var(--text); }
table.rank { width: 100%; border-collapse: collapse; font-size: 14px; }
table.rank th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.rank td { padding: 10px; border-bottom: 1px solid rgba(255,255,255,.04); font-variant-numeric: tabular-nums; }
table.rank tr.me td { background: rgba(242,201,76,.08); }
table.rank td.r { font-weight: 800; color: var(--accent); width: 48px; }
table.rank td.num { text-align: right; }
table.rank th.num { text-align: right; }
.rank-tools { display: flex; align-items: center; gap: 10px; }
select.sel {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13px; font-family: inherit;
}

/* ---------- game ---------- */
.game-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.game-top .title { font-weight: 800; font-size: 16px; }
.game-top .title small { color: var(--muted); font-weight: 600; margin-right: 8px; letter-spacing: .1em; }
.game-top .actions { margin-left: auto; display: flex; gap: 6px; }

.counters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.counter { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.counter .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--panel-2); font-size: 18px; }
.counter .k { font-size: 11px; color: var(--muted); letter-spacing: .06em; }
.counter .v { font-size: 20px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.counter .v small { font-size: 12px; color: var(--muted); font-weight: 600; }

.board-wrap { position: relative; padding: 14px; display: flex; justify-content: center; overflow: hidden; }
.board-wrap canvas { display: block; max-width: 100%; height: auto; }
.ready { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 6px;
  background: rgba(15,17,24,.45); z-index: 5; pointer-events: none; text-align: center; }
.ready.show { display: flex; }
.ready .stage { font-size: 13px; letter-spacing: .3em; color: var(--accent); font-weight: 800; animation: ready-in .4s ease-out both; }
.ready .name { font-size: 22px; font-weight: 800; animation: ready-in .4s .05s ease-out both; }
.ready .word { font-size: clamp(40px, 9vw, 72px); font-weight: 900; letter-spacing: .08em; margin-top: 10px;
  color: #fff; -webkit-text-stroke: 2px #23272f; text-shadow: 0 6px 0 #23272f, 0 10px 30px rgba(0,0,0,.6); animation: ready-pop .5s cubic-bezier(.2,1.4,.4,1) both; }
.ready .word.go { color: var(--accent); }
@keyframes ready-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes ready-pop { from { opacity: 0; transform: scale(2.2); } to { opacity: 1; transform: scale(1); } }
.board-wrap .toast {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: rgba(15,17,24,.9); border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px; font-size: 13px;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.board-wrap .toast.show { opacity: 1; }

.pad { display: none; grid-template-columns: repeat(3, 68px); grid-template-rows: repeat(3, 68px); gap: 8px; margin: 14px auto 0; width: max-content; }
.pad button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; color: var(--text); font-size: 24px; cursor: pointer; touch-action: manipulation; }
.pad button:active { background: #353c5e; }
.pad .up { grid-column: 2; grid-row: 1; } .pad .left { grid-column: 1; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; } .pad .down { grid-column: 2; grid-row: 3; }
.pad .undo { grid-column: 1; grid-row: 1; font-size: 18px; } .pad .reset { grid-column: 3; grid-row: 1; font-size: 18px; }
.pad .mid { grid-column: 2; grid-row: 2; background: transparent; border: 0; }
.help { color: var(--muted); font-size: 12px; text-align: center; margin: 14px 0 0; line-height: 1.8; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-family: inherit; font-size: 11px; }
@media (pointer: coarse), (max-width: 820px) {
  .pad { display: grid; }
  .help { display: none; }
}

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: 20px;
  background: rgba(8, 9, 14, .7); backdrop-filter: blur(4px); }
.modal.show { display: flex; }
.modal .card { width: min(440px, 100%); padding: 26px; animation: pop .22s ease-out; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h2 { margin: 0 0 6px; font-size: 24px; }
.modal h2.accent { color: var(--accent); }
.modal p { margin: 6px 0; color: var(--muted); line-height: 1.6; }
.modal p b { color: var(--text); }
.modal .btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.form label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.form input {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 14px; font-family: inherit;
}
.form input:focus { outline: none; border-color: var(--accent); }
.form .err { color: var(--danger); font-size: 13px; min-height: 18px; }
.score-big { text-align: center; margin: 10px 0 4px; }
.score-big .v { font-size: 44px; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
.score-big .v small { font-size: 14px; color: var(--muted); font-weight: 600; }
.score-big .k { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat .v small { font-size: 11px; color: var(--muted); font-weight: 600; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.exp-gain { color: var(--accent-2); font-weight: 800; }

/* ---------- versus ---------- */
.btn-vs { background: linear-gradient(180deg, #ff8a8a, #ff5e5e); color: #2a0b0b; border-color: #d94c4c; }
.btn-vs:hover { background: linear-gradient(180deg, #ffa0a0, #ff7272); }
.vs-top { display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: start; }
.vs-mecard { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: center; }
.vs-mecard .k { font-size: 11px; color: var(--muted); letter-spacing: .08em; }
.vs-mecard .v { font-size: 30px; font-weight: 900; color: var(--accent); }
.vs-actions { display: flex; flex-direction: column; gap: 10px; }
.vs-create, .vs-join { display: flex; gap: 8px; align-items: center; }
.vs-create .sel { flex: 1; min-width: 0; }
.code-input { width: 110px; text-transform: uppercase; letter-spacing: .3em; font-weight: 800; text-align: center;
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-size: 15px; font-family: inherit; }
.room-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.room-row { display: grid; grid-template-columns: 70px 1fr auto auto; gap: 12px; align-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.room-row.playing { opacity: .6; }
.room-code { font-weight: 900; letter-spacing: .2em; color: var(--accent); }
.room-state { font-size: 12px; color: var(--muted); }
.code-chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px; letter-spacing: .25em; color: var(--accent); font-size: 15px; margin-left: 6px; }
.room-body { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; }
.room-players { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.player-card { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.player-card.empty-slot { border-style: dashed; opacity: .8; }
.player-card .name { font-weight: 800; }
.vs-mark { font-weight: 900; color: var(--danger); font-size: 18px; letter-spacing: .1em; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #555c74; margin-right: 4px; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.room-stage-row { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.room-stage-row .sel { max-width: 320px; }
.room-actions { margin-top: 16px; display: flex; align-items: center; gap: 12px; }
.room-right { display: flex; align-items: center; justify-content: center; background: #121317; border-radius: 12px; min-height: 200px; padding: 10px; }
.room-right canvas { max-width: 100%; height: auto; }

.vs-panel { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; padding: 10px 14px; margin-bottom: 12px; }
.vs-panel .k { font-size: 11px; color: var(--muted); letter-spacing: .06em; }
.vs-panel .v { font-size: 14px; font-weight: 700; }
.vs-side.vs-opp { display: flex; align-items: center; justify-content: flex-end; gap: 12px; text-align: right; }
.vs-side.vs-opp canvas { border-radius: 8px; background: #121317; }
.vs-center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.vs-timer { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: .05em; }
.vs-timer.low { color: var(--danger); animation: blink 1s steps(2) infinite; }
@keyframes blink { to { opacity: .35; } }
.vsr-title { margin: 0 0 6px; font-size: 30px; }
.vsr-title.win { color: var(--accent); } .vsr-title.lose { color: var(--danger); } .vsr-title.draw { color: var(--muted); }
.vsr-rows { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 6px; }
.vsr-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
#vsr-rating .up { color: var(--ok); } #vsr-rating .down { color: var(--danger); }

/* ---------- chat dock ---------- */
body.chat-open { padding-bottom: 280px; }
body { padding-bottom: 56px; }
.chat-dock { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(980px, calc(100% - 40px)); z-index: 60;
  background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: 12px 12px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.35); display: flex; flex-direction: column; }
.chat-bar { display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer; user-select: none; }
.chat-bar .chat-title { font-weight: 700; font-size: 13px; white-space: nowrap; }
.chat-bar .chat-preview { flex: 1; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-badge { background: var(--danger); color: #fff; font-size: 11px; font-weight: 800; border-radius: 999px; padding: 1px 7px; }
.chat-caret { color: var(--muted); transition: transform .2s; }
.chat-dock.open .chat-caret { transform: rotate(180deg); }
.chat-body { display: none; flex-direction: column; height: 240px; border-top: 1px solid var(--line); }
.chat-dock.open .chat-body { display: flex; }
.chat-head { display: none; }
.chat-list { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.chat-msg { display: flex; gap: 8px; align-items: baseline; }
.chat-msg .who { color: var(--accent-2); font-weight: 700; white-space: nowrap; }
.chat-msg.me .who { color: var(--accent); }
.chat-msg .txt { word-break: break-word; }
.chat-msg .when { color: var(--muted); font-size: 11px; margin-left: auto; white-space: nowrap; }
.chat-sys { color: var(--muted); font-size: 12px; text-align: center; padding: 2px 0; }
.chat-form { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; font-size: 14px; font-family: inherit; }
.chat-form input:focus { outline: none; border-color: var(--accent); }
.chat-form input:disabled { opacity: .6; }

@media (max-width: 820px), (pointer: coarse) {
  body, body.chat-open { padding-bottom: 52px; }
  .chat-dock { width: 100%; left: 0; transform: none; border-radius: 0; border-left: 0; border-right: 0; }
  .chat-dock.open { height: 60vh; height: 60dvh; max-height: 420px; border-radius: 16px 16px 0 0; }
  .chat-dock.open .chat-bar { display: none; }
  .chat-dock.open .chat-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 8px 16px; font-weight: 700; }
  .chat-body { height: auto; flex: 1; min-height: 0; border-top: 0; }
  .chat-form { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .chat-form input { font-size: 16px; } /* prevents iOS zoom on focus */
  .vs-top { grid-template-columns: 1fr; }
  .room-body { grid-template-columns: 1fr; }
  .room-players { grid-template-columns: 1fr; }
  .vs-mark { text-align: center; }
  .vs-panel { grid-template-columns: 1fr 1fr; }
  .vs-center { grid-column: 1 / -1; order: -1; flex-direction: row; justify-content: center; gap: 12px; }
  .room-row { grid-template-columns: 60px 1fr auto; }
  .room-row .room-state { display: none; }
}

/* ---------- footer ---------- */
footer { max-width: 980px; margin: 0 auto; padding: 0 20px 30px; color: var(--muted); font-size: 12px; text-align: center; line-height: 1.8; }
footer a { color: var(--muted); }

@media (max-width: 860px) {
  .lobby { grid-template-columns: 1fr; }
  .hero { min-height: 340px; }
  .counters { grid-template-columns: repeat(2, 1fr); }
  .topnav { display: none; }
  #app { padding: 16px 12px 30px; }
  .account .who small { display: none; }
  .topbar { padding: 0 12px; gap: 10px; }
  .fw-link .label { display: none; }
  .brand img { height: 30px; }
  .topbar-right .btn { white-space: nowrap; padding: 6px 10px; font-size: 12px; }
  .account .who { display: none; }
}
