:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #ebe8e2;
  --text: #1d1f22;
  --muted: #62666d;
  --border: #d6d2ca;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --accent-soft: #fde5d6;
  --good: #1f8a4c;
  --good-soft: #dcf3e5;
  --bad: #c92a2a;
  --bad-soft: #fbe2e2;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517;
    --surface: #1e2023;
    --surface-2: #272a2e;
    --text: #eceae6;
    --muted: #9a9ea6;
    --border: #34373c;
    --accent: #ff7a33;
    --accent-ink: #1a0d05;
    --accent-soft: #3a2316;
    --good: #4cc47e;
    --good-soft: #17301f;
    --bad: #ff6b6b;
    --bad-soft: #3a1a1a;
    --warn: #e3a948;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 18px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--accent-soft); color: var(--accent); }

main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 24px 16px 40px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }

h1 { font-size: 28px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-play { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 760px) { .grid-2, .grid-play { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text);
  transition: transform .05s, background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { padding: 14px 22px; font-size: 16px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }

input[type=text], select {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); min-width: 0;
}
input[type=text]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
label.field input { color: var(--text); font-weight: 400; font-size: 15px; }

/* Home */
.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }
.lede { font-size: 17px; color: var(--muted); }
.mode { display: flex; flex-direction: column; gap: 10px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; font-family: var(--mono); letter-spacing: .15em; }
.rules { margin: 0; padding-left: 18px; color: var(--muted); }
.rules li { margin-bottom: 6px; }
.rules b { color: var(--text); }
.divider { height: 1px; background: var(--border); margin: 4px 0; }

/* Target */
.target { display: flex; flex-direction: column; gap: 14px; }
.target-img {
  position: relative; background: #fff; border-radius: 10px; border: 1px solid var(--border);
  aspect-ratio: 4 / 3; display: grid; place-items: center; overflow: hidden;
}
.target-img img { max-width: 92%; max-height: 92%; object-fit: contain; }
.target-img.hidden img { filter: blur(24px) grayscale(1); opacity: .35; }
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 96px; font-weight: 800; color: var(--accent); font-family: var(--mono);
  text-shadow: 0 2px 12px rgba(0,0,0,.15);
}
.target-title { font-size: 20px; font-weight: 700; line-height: 1.3; }

.timer { font-family: var(--mono); font-size: 52px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.timer.done { color: var(--good); }
.timer.low { color: var(--bad); }
.status-line { min-height: 22px; font-size: 14px; }
.status-line.bad { color: var(--bad); }
.status-line.good { color: var(--good); }

.banner { padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.good { background: var(--good-soft); color: var(--good); }
.banner.info { background: var(--surface-2); color: var(--muted); }
.banner.warn { background: var(--accent-soft); color: var(--accent); }

.manual { display: flex; gap: 8px; }
.manual input { flex: 1; }

/* Results */
.result-time { font-family: var(--mono); font-size: 56px; font-weight: 800; color: var(--good); line-height: 1; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.kpi .v { font-family: var(--mono); font-size: 22px; font-weight: 700; }
.kpi .l { font-size: 12px; color: var(--muted); }
.hist { width: 100%; height: 120px; display: block; }
.hist .bar { fill: var(--border); }
.hist .bar.you { fill: var(--accent); }
.hist text { fill: var(--muted); font-size: 10px; font-family: var(--mono); }

table.board { width: 100%; border-collapse: collapse; font-size: 14px; }
table.board th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.board td { padding: 8px; border-bottom: 1px solid var(--border); }
table.board tr.you td { background: var(--accent-soft); }
table.board td.num { font-family: var(--mono); text-align: right; white-space: nowrap; }
table.board th.num { text-align: right; }

/* Room */
.room-code { font-family: var(--mono); font-size: 28px; font-weight: 800; letter-spacing: .2em; }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.players li.me { outline: 2px solid var(--accent); outline-offset: -2px; }
.players .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .score { font-family: var(--mono); font-weight: 700; }
.players .tag { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--surface); color: var(--muted); }
.players .tag.found { background: var(--good-soft); color: var(--good); }
.players .tag.bad { background: var(--bad-soft); color: var(--bad); }
.players .off { opacity: .5; }
.players .kick { padding: 2px 8px; font-size: 12px; }

.reveal { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.reveal .pn { font-family: var(--mono); font-weight: 700; font-size: 18px; }

.ext-card ol { margin: 0; padding-left: 20px; color: var(--muted); }
.ext-card li { margin-bottom: 4px; }
code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 50; max-width: calc(100% - 32px);
}
