:root {
  --bg: #FAF7F2;
  --card: #FFFFFF;
  --ink: #2B2420;
  --muted: #7A6F66;
  --line: #ECE5DC;
  --soft: #F3EEE7;
  --accent: #D9653B;
  --accent-soft: #FBE7DD;
  --accent-ink: #FFFFFF;
  --ok: #3C8D5A;
  --ok-soft: #E2F2E7;
  --bad: #C2443A;
  --bad-soft: #F9E1DE;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(43, 36, 32, .06), 0 4px 16px rgba(43, 36, 32, .05);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1714;
    --card: #24201C;
    --ink: #F3EDE6;
    --muted: #A89C90;
    --line: #3A332C;
    --soft: #2E2924;
    --accent: #EE8458;
    --accent-soft: #3D2A20;
    --accent-ink: #1A1714;
    --ok: #6CC08A;
    --ok-soft: #1F3326;
    --bad: #F07A6E;
    --bad-soft: #3A2220;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 26px; letter-spacing: -.02em; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.shell { max-width: 720px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
}
.zone-select {
  flex: 1; min-width: 0;
  appearance: none; border: 0; background: var(--soft);
  padding: 9px 34px 9px 14px; border-radius: 999px; font-weight: 600;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 999px; border: 0;
  background: var(--soft); display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-inner { display: flex; width: 100%; max-width: 720px; }
.nav a {
  flex: 1; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--accent); }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-title a { font-size: 14px; text-decoration: none; font-weight: 600; }
.section-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; }
.section-label.bad { color: var(--bad); }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 54px; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { overflow-wrap: anywhere; }
.row .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.row.done .title { text-decoration: line-through; color: var(--muted); }
.row.clickable { cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty .big { font-size: 34px; margin-bottom: 6px; }

.check {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); background: transparent; cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.check svg { width: 14px; height: 14px; }
.del { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; }
.del:hover { color: var(--bad); background: var(--bad-soft); }
.del svg { width: 18px; height: 18px; display: block; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.input, .select, .textarea {
  width: 100%; border: 1.5px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 11px 13px; outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.textarea { min-height: 96px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 11px 18px; font-weight: 650; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--soft); color: var(--ink); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.add-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.add-bar .input { flex: 1; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 6px 0; }
.check-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }

.segmented { display: flex; background: var(--soft); border-radius: 12px; padding: 4px; margin-bottom: 14px; gap: 4px; }
.segmented button { flex: 1; border: 0; background: none; padding: 8px 6px; border-radius: 9px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted); }
.segmented button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: var(--soft); border: 0; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip .x { opacity: .55; font-size: 16px; line-height: 1; }

/* ---------- auth ---------- */
.auth { max-width: 420px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 16px 40px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand img { width: 52px; height: 52px; border-radius: 14px; }
.brand .name { font-weight: 800; font-size: 22px; }
.brand .tag { color: var(--muted); font-size: 14px; }
.error { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; }

/* ---------- home ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-decoration: none; color: inherit; display: block; }
.tile .emoji { font-size: 26px; }
.tile .num { font-size: 26px; font-weight: 800; margin-top: 4px; }
.tile .lbl { color: var(--muted); font-size: 13px; }

/* ---------- recipes ---------- */
.recipe-card { display: block; text-decoration: none; color: inherit; }
.bar { height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.ing { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.ing:last-child { border-bottom: 0; }
.ing .mark { width: 18px; flex: none; text-align: center; font-weight: 700; }
.ing.have .mark { color: var(--ok); }
.ing.miss .mark { color: var(--bad); }
.ing .opt { color: var(--muted); font-size: 12px; }
.steps { white-space: pre-wrap; line-height: 1.6; }

/* ---------- games ---------- */
.game-tile { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; }
.game-tile .ico { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 28px; background: var(--accent-soft); flex: none; }
.fw-wrap { max-width: 440px; margin: 0 auto; }
.fw-grid { display: grid; gap: 5px; touch-action: none; user-select: none; -webkit-user-select: none; margin: 10px 0 14px; }
.fw-cell {
  aspect-ratio: 1; border-radius: 10px; border: 0; background: var(--card); box-shadow: var(--shadow);
  font-weight: 750; text-transform: uppercase; display: grid; place-items: center; cursor: pointer;
  font-size: clamp(16px, 5.4vw, 24px); transition: background .12s, transform .12s; padding: 0;
}
.fw-cell.sel { background: var(--accent); color: var(--accent-ink); transform: scale(.94); }
.fw-cell.found { color: #2B2420; }
.fw-cell.hint { outline: 3px dashed var(--accent); outline-offset: -3px; }
.fw-stats { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; font-weight: 600; }
.fw-current { text-align: center; min-height: 30px; font-weight: 800; font-size: 20px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.story { white-space: pre-wrap; line-height: 1.6; }
.answer-btn { display: block; width: 100%; text-align: left; margin-bottom: 8px; padding: 13px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); cursor: pointer; font-weight: 550; }
.answer-btn:hover:not(:disabled) { border-color: var(--accent); }
.answer-btn.right { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.answer-btn.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.verdict { padding: 14px; border-radius: 12px; margin-top: 6px; }
.verdict.ok { background: var(--ok-soft); }
.verdict.bad { background: var(--bad-soft); }
.stars { color: var(--accent); letter-spacing: 1px; }
table.board { width: 100%; border-collapse: collapse; font-size: 14px; }
table.board th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 4px; }
table.board td { padding: 8px 4px; border-top: 1px solid var(--line); }
table.board td.num, table.board th.num { text-align: right; }

/* ---------- dialog & toast ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(520px, calc(100vw - 24px));
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgba(20, 15, 10, .45); }
dialog h2 { margin-bottom: 14px; }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.mt { margin-top: 12px; }
.code { font: 700 22px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; }

/* ---------- logic-grid mysteries ---------- */
.crime { border-left: 4px solid var(--accent); }
.crime p:first-child { font-weight: 650; font-size: 17px; }
.dossier { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.dossier-item { display: flex; gap: 10px; align-items: center; background: var(--soft); border-radius: 12px; padding: 8px 10px; }
.dossier-item .emo { font-size: 24px; line-height: 1; }
.dossier-item .nm { font-weight: 650; font-size: 14px; line-height: 1.25; }
.dossier-item .tg { font-size: 12px; color: var(--muted); }
.clues { margin: 0; padding-left: 22px; line-height: 1.55; }
.clues li { padding: 3px 0; }
.statement { background: var(--soft); border-radius: 12px; padding: 9px 12px; margin-bottom: 6px; font-size: 15px; }
.key-fact { margin-top: 14px; background: var(--accent-soft); color: var(--accent); font-weight: 700; padding: 10px 12px; border-radius: 12px; }
.lg-wrap { display: flex; flex-wrap: wrap; gap: 14px; }
.lg-box { flex: 1 1 260px; min-width: 0; }
.lg-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
table.lg { border-collapse: collapse; width: 100%; table-layout: fixed; }
table.lg th { font-weight: 600; font-size: 20px; padding: 4px 0; text-align: center; }
table.lg th.corner { font-size: 10px; color: var(--muted); width: 38%; text-align: left; font-weight: 600; }
table.lg th.rowh { font-size: 13px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 6px; }
table.lg td { border: 1.5px solid var(--line); height: 38px; text-align: center; font-weight: 800; font-size: 18px; cursor: pointer; user-select: none; -webkit-user-select: none; }
table.lg td.yes { background: var(--ok-soft); color: var(--ok); }
table.lg td.no { color: var(--bad); opacity: .75; }
table.board tr.culprit td { background: var(--bad-soft); font-weight: 700; }
