[hidden] { display: none !important; }
:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --fg: #16202c;
  --muted: #5b6573;
  --line: #dcd9d0;
  --accent: #1d4f91;
  --accent-fg: #ffffff;
  --gold: #c98a00;
  --box: #ffffff;
  --box-line: #16202c;
  --box-cur: #ffe7a3;
  --key: #ffffff;
  --key-fg: #16202c;
  --dock: #e6e4dd;
  --note-bg: #fff6e0;
  --radius: 12px;
  --dock-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --card: #18202a;
    --fg: #eef1f5;
    --muted: #a3adbb;
    --line: #2b3542;
    --accent: #8db8f2;
    --accent-fg: #0f141b;
    --gold: #f2b33d;
    --box: #0f141b;
    --box-line: #c9d3df;
    --box-cur: #4a3d12;
    --key: #2a3442;
    --key-fg: #eef1f5;
    --dock: #141b24;
    --note-bg: #2c2512;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom) + 16px);
}
body.kb-open { padding-bottom: calc(var(--dock-h) + 230px + env(safe-area-inset-bottom)); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.tiny { font-size: 0.78rem; }
.center { text-align: center; }
.pad { padding: 16px; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; min-width: 0; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; max-width: 760px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--fg); text-decoration: none; font-size: 1.1rem; }
.brand b { color: var(--accent); }
.who { color: var(--muted); font-size: 0.875rem; }
.main { max-width: 760px; margin: 0 auto; padding: 0 12px; display: grid; gap: 12px; }
.main > * { min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.sticky-top { position: sticky; top: 0; z-index: 5; box-shadow: 0 4px 12px rgb(0 0 0 / 0.06); }
.note { background: var(--note-bg); border-radius: 8px; padding: 10px 12px; margin: 8px 0; font-size: 0.9rem; }
.sec { margin: 12px 4px 6px; font-size: 0.95rem; }
.version { text-align: center; color: var(--muted); font-size: 0.75rem; padding: 16px; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--fg); border-radius: 10px; padding: 8px 14px; cursor: pointer; min-height: 40px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 0.875rem; }
.btn.round { flex-shrink: 0; width: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 1.3rem; line-height: 1; }
.btn.ai { width: 100%; margin: 8px 0; font-weight: 600; }

select, input[type='search'] { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 40px; }
.spoiler { flex-shrink: 0; font-size: 0.875rem; }
.theme-select { flex: 1; min-width: 0; }
.clue-input { width: 100%; font-size: 1.05rem; }
.len-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.len-label { font-weight: 600; min-width: 6.5em; text-align: center; }

/* Kirjainruudut: koko sovitetaan leveyteen, max 52 px. */
.boxes {
  display: grid;
  grid-template-columns: repeat(var(--n, 5), minmax(0, 52px));
  gap: 4px;
  justify-content: center;
  margin: 4px 0 6px;
}
.box {
  aspect-ratio: 1;
  border: 2px solid var(--box-line);
  background: var(--box);
  color: var(--fg);
  border-radius: 4px;
  font: 700 clamp(14px, 5vw, 26px) / 1 system-ui, sans-serif;
  padding: 0;
  cursor: pointer;
  min-width: 0;
}
.box.cur { background: var(--box-cur); outline: 3px solid var(--gold); outline-offset: 1px; }
.letters { width: 100%; min-height: 52px; font: 700 1.5rem/1.2 system-ui, sans-serif; letter-spacing: 0.2em; border: 2px solid var(--box-line); background: var(--box); color: var(--fg); border-radius: 8px; cursor: pointer; }
.letters.empty { font-weight: 400; font-size: 1rem; letter-spacing: normal; color: var(--muted); }
.letters.cur { outline: 3px solid var(--gold); }
.clue-boxes { margin-top: 8px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0; scrollbar-width: none; }
.chip { font: inherit; font-size: 0.875rem; white-space: nowrap; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.chip.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.switch { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; padding: 6px 0; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

.results { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.result { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.result:last-child { border-bottom: 0; }
.result-main { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 10px 12px; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.rword { font: 700 1.1rem/1.3 ui-monospace, 'SF Mono', Menlo, Consolas, monospace; letter-spacing: 0.12em; overflow-wrap: anywhere; }
.rword.masked { color: var(--muted); }
.rsub { color: var(--muted); font-size: 0.85rem; }
.rbadge { font-size: 0.72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }
.star { width: 48px; border: 0; background: none; color: var(--line); font-size: 1.3rem; cursor: pointer; }
.star.on { color: var(--gold); }

/* Alatelakka: näppäimistö + välilehdet peukaloalueella. */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--dock); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs { display: flex; max-width: 760px; margin: 0 auto; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: 0.72rem; }
.tab-icon { font-size: 1.3rem; line-height: 1; }
.tab.active { color: var(--fg); font-weight: 700; }
.keyboard { max-width: 640px; margin: 0 auto; padding: 6px 4px 2px; display: grid; gap: 6px; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.kb-row { display: flex; gap: 4px; justify-content: center; }
.kb-key { flex: 1 1 0; max-width: 54px; min-width: 0; height: 44px; border: 0; border-radius: 6px; background: var(--key); color: var(--key-fg); font: 600 1.1rem system-ui, sans-serif; box-shadow: 0 1px 0 rgb(0 0 0 / 0.25); cursor: pointer; padding: 0; }
.kb-key:active { filter: brightness(0.85); }
.kb-unknown { background: var(--gold); color: #1a1208; font-weight: 800; }
.kb-back { flex-grow: 1.5; max-width: 80px; }
.kb-tools { align-items: center; }
.kb-len { display: flex; align-items: center; gap: 4px; flex: 1.4; }
.kb-len .kb-key { max-width: 48px; }
.kb-len-label { font-size: 0.75rem; color: var(--muted); padding: 0 2px; }
.kb-wide { max-width: none; flex: 1; font-size: 0.9rem; }
.kb-done { background: var(--accent); color: var(--accent-fg); }

.dlg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--fg); width: min(560px, calc(100vw - 32px)); max-height: 80vh; padding: 18px; }
.dlg::backdrop { background: rgb(0 0 0 / 0.45); }
.dlg-actions { display: flex; gap: 8px; margin-top: 14px; position: sticky; bottom: -18px; background: var(--card); padding: 8px 0 0; }
.sense { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.sense ol { margin: 4px 0; padding-left: 1.3em; }

.update-banner { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 8px 16px; background: var(--accent); color: var(--accent-fg); }
.toast { position: fixed; left: 50%; bottom: calc(var(--dock-h) + 24px); transform: translateX(-50%) translateY(20px); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 30; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (min-width: 700px) {
  .kb-key { height: 48px; }
}

/* Kamera-suurennuslasi */
.row.wrap { flex-wrap: wrap; margin: 6px 0; }
.btn.big { font-weight: 700; }
.cam-status { font-size: 0.95rem; margin: 8px 0 0; }
.cam-stage { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; line-height: 0; }
.cam-media { width: 100%; height: auto; display: block; }
.cam-overlay { position: absolute; inset: 0; transition: opacity 0.25s; line-height: 1.25; }
.cam-overlay.faded { opacity: 0.15; }
.cam-box { position: absolute; border: 2px solid #f2b33d; border-radius: 3px; pointer-events: none; }
.cam-tag { position: absolute; transform: translateY(2px); background: #f2b33d; color: #1a1208; border: 0; border-radius: 6px; padding: 3px 7px; font: 700 15px/1.25 system-ui, sans-serif; text-align: left; box-shadow: 0 2px 6px rgb(0 0 0 / 0.4); cursor: pointer; overflow-wrap: anywhere; letter-spacing: 0.04em; }
.cam-tag.none { background: #ddd; color: #444; font-weight: 500; }
.cam-clue { flex-basis: 100%; font-size: 0.95rem; }
.cam-big { font: 700 1.6rem/1.3 ui-monospace, Menlo, monospace; letter-spacing: 0.1em; overflow-wrap: anywhere; }
.guide { margin: 8px 0; }
.guide summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.guide ol { padding-left: 1.3em; margin: 8px 0; }
.guide li { margin: 4px 0; }
.stack-sm { display: grid; gap: 8px; margin: 8px 0; }
.key-input { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 44px; }
.tab { font-size: 0.68rem; }
.cam-def { font-size: 1rem; line-height: 1.4; }
.cam-def.big { font-size: 1.15rem; }
.cam-tag { max-width: 70%; font-size: 14px; }
