:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #6f6a62;
  --line: #e3ddd3;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --chip: #efe9df;
  --good: #2e7d4f;
  --bad: #b3412e;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #212127;
    --text: #ece9e4;
    --muted: #9c978f;
    --line: #34343c;
    --accent: #6fb39c;
    --accent-text: #0f1a16;
    --chip: #2b2b33;
    --good: #6fcf97;
    --bad: #ef7d68;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  min-height: 44px;
  padding: 0 16px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn.small { min-height: 40px; min-width: 40px; padding: 0 10px; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 4px; cursor: pointer; }

.levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--chip);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.level {
  border: 0;
  background: transparent;
  border-radius: 9px;
  min-height: 40px;
  cursor: pointer;
  touch-action: manipulation;
  color: var(--muted);
  font-weight: 600;
}
.level[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }

.controls { display: flex; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.seed { flex: 1; min-width: 200px; }
.label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stepper { display: flex; align-items: center; gap: 8px; }
#count { min-width: 1.5em; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.seedrow { display: flex; gap: 6px; }
.seedrow input { flex: 1; min-width: 0; }

input[type="text"] {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  min-height: 40px;
  padding: 0 12px;
  font-size: 16px; /* prevents iOS zoom */
}
input:focus-visible, .btn:focus-visible, .level:focus-visible, .word:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.meta { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); margin-bottom: 10px; gap: 8px; }
.words { display: flex; flex-wrap: wrap; gap: 10px; }
.word {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
  padding: 10px 14px 8px;
  border-radius: 12px;
  background: var(--chip);
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}
.word .w { font-size: 1.35rem; font-weight: 600; }
.word .d {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  min-height: 1.3em;
  letter-spacing: 0.08em;
}
.word .d.hidden { color: transparent; }
.word .d.hidden::before { content: "·"; color: var(--muted); }
.word .n { font-size: 0.72rem; color: var(--muted); text-align: center; max-width: 9em; }

.guess { display: flex; gap: 8px; }
.guess input {
  flex: 1;
  min-width: 0;
  min-height: 52px;
  font-size: 1.4rem;
  letter-spacing: 0.1em;
  font-variant-numeric: tabular-nums;
}
.guess .btn { min-height: 52px; }
.guess input.good { border-color: var(--good); }
.guess input.bad { border-color: var(--bad); animation: shake 0.3s; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.feedback { min-height: 1.5em; margin: -4px 0 0; font-weight: 600; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 0; }

.sheet {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 16px;
}
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { margin: 0; font-size: 1.2rem; }
.sheet h3 { margin: 14px 0 4px; font-size: 1rem; }
.keytable { width: 100%; border-collapse: collapse; }
.keytable td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.keytable td:first-child { font-weight: 700; color: var(--accent); width: 2.4em; font-size: 1.1rem; }
.keytable td:last-child { color: var(--muted); text-align: right; }
.rules { padding-left: 18px; margin: 0; }
.rules li { margin: 6px 0; }
.btn.toggle[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }

.words.pao { flex-direction: column; }
.scene { display: flex; gap: 8px; width: 100%; }
.scene .word { flex: 1; min-width: 0; padding: 8px 6px; }
.scene .word .w { font-size: 1.05rem; overflow-wrap: anywhere; text-align: center; }
.word .r { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.scene-text { font-size: 0.85rem; color: var(--muted); text-align: center; margin: -2px 0 4px; }
.keytable.pao td:last-child { text-align: left; color: var(--text); }
.keytable.pao tr:first-child td { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.tiny { font-size: 0.8rem; color: var(--muted); margin-bottom: 0; }

[hidden] { display: none !important; }
