:root {
  --bg: #0b1a2b;
  --bg2: #11263d;
  --card: #ffffff;
  --ink: #0f2236;
  --muted: #5d7085;
  --text: #eef5ff;
  --text-dim: #9fb4cc;
  --accent: #ff5a5f;
  --accent-dark: #c63a40;
  --teal: #19c3a6;
  --yellow: #ffc93c;
  --line: rgba(255, 255, 255, 0.12);
  --panel: rgba(255, 255, 255, 0.06);
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --display: 'Space Grotesk', 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 650px at 0% -10%, #17406a 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 0%, #0f4b52 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }

#app { max-width: 820px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 56px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; font-size: 14px; color: var(--text-dim); }
.brand { font-family: var(--display); font-weight: 700; font-size: 22px; color: var(--text); letter-spacing: -0.02em; white-space: nowrap; }
.brand span { color: var(--teal); }
.meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; background: rgba(255,255,255,0.08); font-weight: 600; font-size: 13px; color: var(--text); white-space: nowrap; }
.linkish { background: none; border: 0; color: var(--text-dim); cursor: pointer; padding: 4px; text-decoration: underline; font-size: 13px; }
.linkish:hover { color: var(--text); }

/* ---------- home ---------- */
.hero { text-align: center; padding: 30px 0 14px; }
.globe { font-size: 64px; display: block; animation: spinslow 18s linear infinite; }
.logo { font-family: var(--display); font-weight: 700; font-size: clamp(56px, 15vw, 104px); line-height: 0.95; letter-spacing: -0.045em; margin: 6px 0 0; }
.logo span { color: var(--teal); }
.tagline { color: var(--text-dim); font-size: 17px; margin: 12px auto 0; max-width: 480px; line-height: 1.5; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-top: 16px; }
.panel h2 { font-family: var(--display); font-size: 20px; margin: 0 0 12px; letter-spacing: -0.01em; }
.panel h2 small { font-family: 'Inter', sans-serif; font-weight: 500; font-size: 13px; color: var(--text-dim); margin-left: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.label { font-size: 12px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.07em; }
input[type=text] { width: 100%; padding: 14px 16px; border-radius: 12px; border: 2px solid transparent; background: #fff; color: var(--ink); font-size: 18px; outline: none; }
input[type=text]:focus { border-color: var(--teal); }
input.code { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; text-align: center; }
.or { text-align: center; color: var(--text-dim); margin: 6px 0 14px; font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 20px; border-radius: 14px; border: 0; cursor: pointer;
  font-weight: 700; font-size: 17px; background: var(--accent); color: #fff;
  box-shadow: 0 4px 0 var(--accent-dark); transition: transform .08s, box-shadow .08s, opacity .2s; width: 100%;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--ink); box-shadow: 0 4px 0 #9fb0c4; }
.btn.teal { background: var(--teal); color: #052a24; box-shadow: 0 4px 0 #0e8a75; }
.btn.ghost { background: rgba(255,255,255,0.1); color: var(--text); box-shadow: none; }
.btn.small { padding: 9px 14px; font-size: 14px; width: auto; border-radius: 10px; }

.how { color: var(--text-dim); font-size: 15px; line-height: 1.6; margin: 0; padding-left: 20px; }
.how b { color: var(--text); }

/* ---------- lobby ---------- */
.room-code { text-align: center; padding: 18px; border-radius: var(--radius); background: var(--yellow); color: var(--ink); box-shadow: var(--shadow); }
.room-code small { display: block; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; font-size: 12px; opacity: .7; }
.room-code strong { font-family: var(--display); font-size: 64px; letter-spacing: .14em; line-height: 1.1; }
.room-code .share button { margin-top: 6px; background: rgba(0,0,0,.08); color: var(--ink); border: 0; border-radius: 999px; padding: 7px 14px; font-weight: 600; cursor: pointer; font-size: 14px; }

.players { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.players li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,0.08); font-weight: 600; min-width: 0; }
.players li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.players li.off { opacity: .45; }
.players li.me { outline: 2px solid var(--teal); }
.avatar { width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; }
.kick { background: none; border: 0; color: var(--text-dim); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 4px; }
.kick:hover { color: var(--accent); }

.set-row { margin-bottom: 18px; }
.set-row:last-child { margin-bottom: 0; }
.set-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.set-head .note { font-size: 13px; color: var(--text-dim); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  border: 2px solid var(--line); background: transparent; color: var(--text-dim); font-weight: 700; font-size: 15px;
  padding: 8px 14px; border-radius: 12px; cursor: pointer; min-width: 54px; transition: background .15s, color .15s, border-color .15s;
}
.seg button.on { background: rgba(25,195,166,0.16); border-color: var(--teal); color: var(--text); }
.seg button:disabled { cursor: default; }
.seg button:not(.on):disabled { opacity: .6; }
.seg.wide button { flex: 1 1 auto; }
.ladder { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.ladder span { text-align: center; padding: 6px 0; border-radius: 8px; background: rgba(255,255,255,0.07); font-size: 12px; font-weight: 700; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.ladder span b { display: block; font-size: 10px; font-weight: 600; opacity: .7; }
.hint { color: var(--text-dim); font-size: 14px; text-align: center; margin: 12px 0 0; }
.actions { display: grid; gap: 10px; margin-top: 18px; }

/* ---------- play ---------- */
.play-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.worth { flex: 1; min-width: 0; }
.worth .big { font-family: var(--display); font-weight: 700; font-size: 30px; line-height: 1; color: var(--yellow); font-variant-numeric: tabular-nums; }
.worth .small { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.clock { flex: none; font-family: var(--display); font-weight: 700; font-size: 28px; font-variant-numeric: tabular-nums; padding: 6px 12px; border-radius: 12px; background: rgba(255,255,255,0.08); min-width: 86px; text-align: center; }
.clock.low { background: var(--accent); color: #fff; animation: pulse 1s ease infinite; }

.timer { height: 6px; border-radius: 99px; background: rgba(255,255,255,0.12); overflow: hidden; margin: 0 0 14px; }
.timer > i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--yellow)); width: 100%; transition: width .25s linear; }
.timer.low > i { background: var(--accent); }

.pips { display: flex; gap: 4px; margin-bottom: 12px; }
.pips i { flex: 1; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.13); }
.pips i.on { background: var(--teal); }

.tips { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.tip {
  display: grid; grid-template-columns: 38px 1fr; gap: 12px; align-items: start;
  background: var(--card); color: var(--ink); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow);
}
.tip.new { animation: slideIn .45s cubic-bezier(.2,.9,.3,1.2); }
.tip .num { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 18px; background: #e8f1fa; color: var(--ink); }
.tip .cat { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 3px; }
.tip .txt { font-size: 18px; line-height: 1.4; font-weight: 600; overflow-wrap: anywhere; }
.tip img { display: block; margin-top: 6px; max-width: 100%; border-radius: 10px; }
.tip img.flag { width: 220px; max-width: 100%; aspect-ratio: 4 / 3; object-fit: cover; box-shadow: 0 0 0 1px rgba(0,0,0,.12); }
.tip img.shape { width: 220px; aspect-ratio: 1; background: #eef4fa; padding: 6px; }
.tip img.map { width: 100%; aspect-ratio: 1000 / 520; background: #dfe9f5; }
.redact { display: inline-block; background: var(--ink); color: transparent; border-radius: 4px; padding: 0 .35em; line-height: 1.15; user-select: none; }
.redact::before { content: 'hidden'; }

#me-zone { position: sticky; bottom: 0; z-index: 5; }
.guess-box { margin-top: 14px; padding: 14px 0 max(10px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(11,26,43,0) 0%, rgba(11,26,43,.96) 18%); }
.guess-form { display: flex; gap: 8px; position: relative; }
.guess-form .inp { position: relative; flex: 1; min-width: 0; }
.guess-form .btn { width: auto; flex: none; }
.suggest { position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); background: #fff; color: var(--ink); border-radius: 12px; box-shadow: var(--shadow); list-style: none; margin: 0; padding: 6px; max-height: 280px; overflow-y: auto; z-index: 6; }
.suggest:empty { display: none; }
.suggest li { padding: 10px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.suggest li small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.suggest li.on, .suggest li:hover { background: #e6f7f3; }
.guess-tools { display: flex; gap: 8px; margin-top: 8px; }
.guess-tools .btn { flex: 1; }
.wrongs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.wrongs span { padding: 5px 10px; border-radius: 999px; background: rgba(255,90,95,0.18); color: #ffb3b5; font-size: 13px; font-weight: 600; text-decoration: line-through; }

.done-card { text-align: center; padding: 20px; border-radius: var(--radius); margin-top: 14px; }
.done-card.win { background: var(--teal); color: #052a24; }
.done-card.lose { background: rgba(255,255,255,0.08); }
.done-card h3 { font-family: var(--display); font-size: 26px; margin: 0; }
.done-card p { margin: 6px 0 0; font-weight: 600; }

.status { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; justify-content: center; }
.chip { padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: rgba(255,255,255,0.08); color: var(--text-dim); }
.chip.solved { background: var(--teal); color: #052a24; }
.chip.out { background: rgba(255,90,95,0.25); color: #ffd0d1; }
.chip.off { opacity: .45; }
.host-bar { display: flex; justify-content: center; margin-top: 14px; }

/* ---------- reveal ---------- */
.answer-card { background: var(--card); color: var(--ink); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); display: grid; grid-template-columns: 150px 1fr; gap: 18px; align-items: center; animation: slideIn .5s cubic-bezier(.2,.9,.3,1.2); }
.answer-card img { width: 150px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; box-shadow: 0 0 0 1px rgba(0,0,0,.12); }
.answer-card .was { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.answer-card h2 { font-family: var(--display); font-size: clamp(30px, 7vw, 44px); margin: 2px 0 4px; line-height: 1.05; letter-spacing: -0.02em; }
.answer-card p { margin: 0; color: var(--muted); font-weight: 600; }
.results { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.results li { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 14px; background: rgba(255,255,255,0.07); animation: slideIn .4s ease both; }
.results li.me { outline: 2px solid var(--teal); }
.results .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .how-it { display: block; font-size: 13px; font-weight: 500; color: var(--text-dim); white-space: normal; }
.results .pts { font-family: var(--display); font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
.results .pts.zero { color: var(--text-dim); }
details.all-tips { margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; }
details.all-tips summary { cursor: pointer; font-weight: 700; }
details.all-tips ol { margin: 10px 0 0; padding-left: 22px; color: var(--text-dim); line-height: 1.55; }
details.all-tips ol li b { color: var(--text); font-weight: 600; }

/* ---------- scores ---------- */
.board { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 8px; }
.board li { display: grid; grid-template-columns: 34px 34px 1fr auto; align-items: center; gap: 10px; background: rgba(255,255,255,0.08); padding: 10px 14px; border-radius: 14px; animation: slideIn .4s ease both; }
.board li.me { outline: 2px solid var(--teal); }
.board .rank { font-family: var(--display); font-weight: 700; font-size: 20px; color: var(--text-dim); text-align: center; }
.board .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-family: var(--display); font-weight: 700; font-size: 22px; font-variant-numeric: tabular-nums; text-align: right; }
.board .plus { display: block; font-size: 13px; color: var(--teal); font-weight: 700; font-family: 'Inter', sans-serif; }
.section-title { font-family: var(--display); font-size: 18px; margin: 22px 0 0; color: var(--text-dim); font-weight: 600; }

h1.title { font-family: var(--display); font-weight: 700; font-size: clamp(30px, 7vw, 44px); margin: 0; text-align: center; letter-spacing: -0.02em; }
.sub-title { text-align: center; color: var(--text-dim); margin: 6px 0 0; }
.winner { text-align: center; padding: 10px 0 4px; }
.winner .crown { font-size: 64px; display: block; animation: bounce 1.6s ease infinite; }
.winner .who { font-family: var(--display); font-size: clamp(34px, 9vw, 56px); font-weight: 700; color: var(--yellow); line-height: 1.05; overflow-wrap: anywhere; }

.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255,255,255,.15); border-top-color: var(--teal); animation: spin 0.9s linear infinite; margin: 30px auto 14px; }

#toast {
  position: fixed; left: 50%; top: max(16px, env(safe-area-inset-top)); transform: translate(-50%, calc(-100% - 40px));
  background: #fff; color: var(--ink); padding: 12px 18px; border-radius: 12px; font-weight: 600;
  box-shadow: var(--shadow); transition: transform .3s ease, visibility .3s; max-width: calc(100% - 32px); z-index: 20; text-align: center; visibility: hidden;
}
#toast.show { transform: translate(-50%, 0); visibility: visible; }
#toast.err { background: var(--accent); color: #fff; }

@keyframes slideIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spinslow { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.shake { animation: shake .4s ease; }

@media (max-width: 520px) {
  .room-code strong { font-size: 52px; }
  .tip { grid-template-columns: 30px 1fr; gap: 10px; padding: 12px 14px; }
  .tip .num { width: 30px; height: 30px; font-size: 15px; border-radius: 9px; }
  .tip .txt { font-size: 16px; }
  .answer-card { grid-template-columns: 1fr; text-align: center; }
  .answer-card img { margin: 0 auto; }
  .ladder span { font-size: 11px; }
  .worth .big { font-size: 24px; }
  .clock { font-size: 22px; min-width: 70px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
