:root {
  --bg: #ffffff;
  --bar: rgba(246, 246, 248, 0.94);
  --bar-line: #d9d9de;
  --text: #111114;
  --muted: #8a8a8f;
  --them: #e9e9eb;
  --them-text: #111114;
  --me: #e5484d;
  --me-text: #ffffff;
  --riddle: #fff4e5;
  --riddle-line: #f3c98b;
  --field: #ffffff;
  --field-line: #cfcfd4;
  --chip: #f1f1f4;
  --yes: #1f9d55;
  --no: #d93036;
  --soft: #c47f00;
  --meh: #6e6e73;
  --sheet: #ffffff;
  --shade: rgba(0, 0, 0, 0.35);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bar: rgba(22, 22, 24, 0.94);
    --bar-line: #2c2c2e;
    --text: #f2f2f7;
    --muted: #8e8e93;
    --them: #26262a;
    --them-text: #f2f2f7;
    --me: #e5484d;
    --riddle: #2f2414;
    --riddle-line: #6b4e1f;
    --field: #1c1c1e;
    --field-line: #3a3a3c;
    --chip: #1c1c1e;
    --yes: #34c759;
    --no: #ff6961;
    --soft: #ffb340;
    --meh: #a1a1a6;
    --sheet: #1c1c1e;
    --shade: rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  position: relative;
}

/* ---------- header ---------- */
.top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: var(--bar);
  border-bottom: 1px solid var(--bar-line);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  z-index: 2;
}
.contact { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; }
.contact-text { text-align: center; line-height: 1.15; }
.contact-name { font-size: 13px; font-weight: 600; }
.contact-sub { font-size: 11px; color: var(--muted); }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--me);
}
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.icon-btn:active { background: var(--chip); }
.icon-btn[hidden] { visibility: hidden; }

.menu {
  position: absolute;
  top: calc(100% - 4px);
  right: 10px;
  min-width: 240px;
  background: var(--bar);
  border: 1px solid var(--bar-line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.menu[hidden] { display: none; }
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 0;
  border-bottom: 1px solid var(--bar-line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 13px 16px;
  cursor: pointer;
}
.menu button:last-child { border-bottom: 0; }
.solved-banner .actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.pill.secondary { background: var(--chip); color: var(--me); }
.menu button:active { background: var(--chip); }

/* ---------- screens ---------- */
.screen { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.screen[hidden] { display: none; }
.top-actions { display: flex; }
.icon-spacer { width: 44px; height: 44px; flex: 0 0 44px; }
.play .top .contact { position: absolute; left: 50%; transform: translateX(-50%); }

/* ---------- dashboard ---------- */
.home-top { justify-content: space-between; }
.home-brand { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.home-brand h1 { margin: 0; font-size: 17px; font-weight: 700; }
.home-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px max(24px, env(safe-area-inset-bottom));
}
.home-intro { margin: 0 4px 16px; color: var(--muted); font-size: 15px; line-height: 1.4; }
.levels { display: flex; flex-direction: column; gap: 12px; }
.level-card {
  appearance: none;
  border: 1px solid var(--bar-line);
  background: var(--chip);
  color: var(--text);
  font: inherit;
  text-align: left;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 14px 18px 18px;
  border-radius: 18px;
  cursor: pointer;
  border-left: 6px solid var(--muted);
}
.level-card.level-easy { border-left-color: var(--yes); }
.level-card.level-moderate { border-left-color: var(--soft); }
.level-card.level-difficult { border-left-color: var(--no); }
.level-card.soon { cursor: default; opacity: 0.55; }
.level-card:active:not(.soon) { opacity: 0.75; }
.level-text { flex: 1; min-width: 0; }
.level-name { font-size: 20px; font-weight: 700; }
.level-sub { margin-top: 2px; color: var(--muted); font-size: 14px; }
.level-count { text-align: right; font-weight: 600; font-size: 15px; white-space: nowrap; }
.level-count span { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.chev { width: 22px; height: 22px; fill: var(--muted); flex: 0 0 22px; }

.riddle-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--bar-line);
  border-radius: 16px;
  overflow: hidden;
  background: var(--chip);
}
.riddle-list li + li { border-top: 1px solid var(--bar-line); }
.riddle-row {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 12px 15px 16px;
  text-align: left;
  cursor: pointer;
}
.riddle-row:active { background: var(--bar-line); }
.riddle-name { flex: 1; min-width: 0; font-size: 17px; }
.riddle-status { display: flex; align-items: center; }
.riddle-status .tag { color: var(--muted); font-size: 13px; }
.riddle-status .check { width: 24px; height: 24px; fill: var(--yes); }
.solved-banner .link {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--me);
  font: inherit;
  font-size: 15px;
  padding: 6px 10px;
  cursor: pointer;
}

/* ---------- thread ---------- */
.thread {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
}

.stamp {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin: 10px 0 8px;
}
.stamp b { font-weight: 600; }

.row { display: flex; }
.row.me { justify-content: flex-end; }
.row + .row.gap { margin-top: 8px; }

.bubble {
  max-width: 78%;
  padding: 8px 13px;
  border-radius: 19px;
  line-height: 1.32;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: pop 0.18s ease-out;
}
.them .bubble { background: var(--them); color: var(--them-text); border-bottom-left-radius: 6px; }
.me .bubble { background: var(--me); color: var(--me-text); border-bottom-right-radius: 6px; }
.row.cont .bubble { border-radius: 19px; }
.them.cont .bubble { border-top-left-radius: 6px; }
.me.cont .bubble { border-top-right-radius: 6px; }

.bubble .verdict { font-weight: 700; }
.v-yes .verdict { color: var(--yes); }
.v-no .verdict { color: var(--no); }
.v-close .verdict, .v-partly .verdict { color: var(--soft); }
.v-irrelevant .verdict, .v-mixed .verdict { color: var(--meh); }

.bubble.riddle {
  background: var(--riddle);
  border: 1px solid var(--riddle-line);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.35;
}
.bubble.solution {
  background: var(--riddle);
  border: 1px solid var(--riddle-line);
}
.bubble.solution .title { display: block; font-weight: 700; margin-bottom: 4px; }

.solved-banner {
  align-self: center;
  margin: 14px 0 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.solved-banner .big { font-size: 40px; line-height: 1; }
.solved-banner p { margin: 0; color: var(--muted); font-size: 14px; }
.pill {
  appearance: none;
  border: 0;
  background: var(--me);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  padding: 11px 22px;
  border-radius: 999px;
  cursor: pointer;
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--them);
  border-radius: 19px;
  border-bottom-left-radius: 6px;
}
.typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes blink { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- chips + composer ---------- */
.chips {
  display: flex;
  gap: 8px;
  padding: 6px 12px 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  appearance: none;
  border: 1px solid var(--field-line);
  background: var(--chip);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.chip:active { opacity: 0.7; }

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  background: var(--bar);
  border-top: 1px solid var(--bar-line);
}
.composer input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 20px;
  padding: 9px 14px;
  outline: none;
}
.composer input:focus { border-color: var(--me); }
.send {
  appearance: none;
  border: 0;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 50%;
  background: var(--me);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.send svg { width: 20px; height: 20px; fill: currentColor; }
.send:disabled { opacity: 0.35; cursor: default; }

/* ---------- online: dashboard card, lists, account ---------- */
.level-card.together { border-left-color: var(--me); margin-bottom: 20px; }
.together-icon { width: 30px; height: 30px; flex: 0 0 30px; fill: var(--me); }

.section-title {
  margin: 24px 4px 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.empty { margin: 4px; color: var(--muted); font-size: 15px; line-height: 1.4; }
.empty .link, .room-note .link {
  appearance: none; border: 0; background: transparent; color: var(--me);
  font: inherit; padding: 0; cursor: pointer;
}
.room-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.room-meta { color: var(--muted); font-size: 13px; }
.pill.wide { display: block; width: 100%; }
.pill:disabled { opacity: 0.5; cursor: default; }
.pill[hidden] { display: none; }
.level-card:disabled { opacity: 0.55; cursor: default; }

.signin-card {
  background: var(--chip);
  border: 1px solid var(--bar-line);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
}
.signin-card p { margin: 0 0 12px; font-size: 15px; line-height: 1.4; }

.account { display: flex; flex-direction: column; gap: 14px; }
.account .home-intro { margin-bottom: 0; }
.pill.google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--field-line);
}
.g-logo { width: 18px; height: 18px; flex: 0 0 18px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--bar-line); }
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 13px; color: var(--muted); padding-left: 4px; }
.field input, .field textarea {
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 12px;
  padding: 10px 13px;
  outline: none;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 64px; font-size: 16px; }
.field input:focus, .field textarea:focus { border-color: var(--me); }
.field input:disabled { opacity: 0.6; }
.form-msg { margin: 0; font-size: 14px; line-height: 1.4; color: var(--no); }
.form-msg.ok { color: var(--muted); }
.form-msg:empty { display: none; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.field-hint { font-size: 13px; color: var(--muted); padding-left: 4px; }
.account .link {
  appearance: none; border: 0; background: transparent; color: var(--me);
  font: inherit; font-size: 15px; padding: 2px 4px; cursor: pointer; align-self: flex-start;
}
.account .link:disabled { opacity: 0.6; cursor: default; }
.notice {
  background: var(--riddle);
  border: 1px solid var(--riddle-line);
  border-radius: 12px;
  padding: 10px 13px;
  font-size: 15px;
  line-height: 1.4;
}
.notice[hidden] { display: none; }

/* ---------- online: rooms ---------- */
.row.other .bubble {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--field-line);
}
.msg-col { display: flex; flex-direction: column; align-items: flex-start; max-width: 78%; min-width: 0; }
.msg-col .bubble { max-width: 100%; }
.sender { font-size: 11px; color: var(--muted); margin: 0 0 2px 12px; }
.row.pending .bubble { opacity: 0.6; }
.composer input:disabled { opacity: 0.6; }
.room-note {
  align-self: center;
  text-align: center;
  margin: 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.room-note p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.room-note .actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- online: wrong-answer reports ---------- */
.solved-banner .report-hint { font-size: 13px; }
.thread.reportable .row[data-ri] .bubble { cursor: pointer; }
.thread.reportable .row[data-ri] .bubble:active { opacity: 0.7; }
.row.reported .bubble { box-shadow: 0 0 0 2px var(--soft); }

/* ---------- sheet + toast ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--shade);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--sheet);
  color: var(--text);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: rise 0.2s ease-out;
}
@media (min-width: 720px) {
  .sheet-backdrop { align-items: center; }
  .sheet { max-width: 440px; border-radius: 18px; }
}
.sheet-title { margin: 0; font-size: 18px; font-weight: 700; }
.sheet-text, .sheet-label { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.4; }
.sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.gis-slot { display: flex; justify-content: center; min-height: 44px; }
.turnstile-slot { display: flex; justify-content: center; min-height: 65px; }
.report-qa {
  background: var(--chip);
  border: 1px solid var(--bar-line);
  border-radius: 12px;
  padding: 10px 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  line-height: 1.35;
}
.report-q { font-weight: 600; overflow-wrap: anywhere; }
.report-a { color: var(--muted); font-size: 15px; }
.report-a b { color: var(--text); }
.report-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip[aria-checked="true"] { background: var(--me); border-color: var(--me); color: #fff; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  max-width: calc(100% - 32px);
  width: max-content;
  background: rgba(30, 30, 32, 0.94);
  color: #fff;
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  padding: 10px 16px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  overflow-wrap: anywhere;
}
.toast[hidden] { display: none; }

@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .bubble, .typing span, .sheet { animation: none; }
}
