:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --text: #1d1b19;
  --muted: #6b6560;
  --border: #e2ddd7;
  --accent: #b3261e;
  --accent-text: #ffffff;
  --ok: #1f7a3d;
  --ok-bg: #e5f4ea;
  --bad: #b3261e;
  --bad-bg: #fbe7e5;
  --star: #c98a00;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --surface: #1f1d1b;
    --text: #f0ece8;
    --muted: #a39d97;
    --border: #36322e;
    --accent: #e0574d;
    --accent-text: #1a0806;
    --ok: #5fcf85;
    --ok-bg: #173323;
    --bad: #f07a70;
    --bad-bg: #3a1a17;
    --star: #f2b733;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
.view {
  max-width: 720px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 0; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1.4em; margin: 8px 0 0; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; margin-bottom: 12px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }

.btn {
  font: inherit; font-weight: 600;
  min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 44px; padding: 0 12px; font-size: .95rem; }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; }

input[type=text], input[type=password], input[type=search], input:not([type]) {
  font: inherit; width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
label { display: block; font-weight: 600; margin: 14px 0 6px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: 22px; height: 22px; }

.login { max-width: 360px; margin: 18vh auto 0; }
.login h1 { margin-bottom: 16px; font-size: 1.6rem; }
.login .btn { width: 100%; margin-top: 16px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--bg); border-radius: 12px; margin-bottom: 16px; }
.segmented button { font: inherit; font-weight: 600; min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.segmented button[aria-checked=true] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .15); }

.cat-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: .9rem; min-height: 40px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip small { opacity: .75; margin-left: 4px; }
#round-count { margin: 14px 0 10px; }
.row-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.score { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 24px 18px 12px; box-shadow: 0 6px 24px rgb(0 0 0 / .06);
}
.card-cat { margin: 0; color: var(--muted); font-size: .85rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.card-name { margin: 8px 0 22px; font-size: clamp(1.5rem, 6vw, 2.2rem); font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; min-height: 2.4em; }
.answer input { font-size: 1.8rem; min-height: 60px; text-align: center; letter-spacing: .12em; font-variant-numeric: tabular-nums; caret-color: transparent; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; max-width: 420px; margin-inline: auto; }
.keypad button {
  font: inherit; font-size: 1.6rem; font-weight: 700; min-height: 62px;
  border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  font-variant-numeric: tabular-nums;
}
.keypad button:active { background: var(--border); }
.keypad button:disabled { opacity: .4; }
.keypad .key-back { font-size: 1.4rem; color: var(--muted); }
.keypad .key-ok { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
@media (max-height: 700px) { .keypad button { min-height: 52px; } .card-name { margin-bottom: 14px; } }
.feedback { margin-top: 14px; padding: 14px; border-radius: 14px; text-align: center; }
.feedback.is-ok { background: var(--ok-bg); color: var(--ok); }
.feedback.is-bad { background: var(--bad-bg); color: var(--bad); }
.feedback p { margin: 0; font-weight: 600; }
.feedback-number { font-size: 2.4rem; font-weight: 800 !important; letter-spacing: .08em; margin: 4px 0 12px !important; font-variant-numeric: tabular-nums; }
.feedback .btn { margin-top: 4px; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 14px; border-top: 1px solid var(--border); padding-top: 8px; }
.tools .btn { font-size: .95rem; padding: 0 6px; }
#tool-star[aria-pressed=true] { color: var(--star); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-bottom: 18px; }
.stats strong { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stats span { font-size: .85rem; color: var(--muted); }

.search { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.search label.check { margin: 0; white-space: nowrap; }
.list { list-style: none; margin: 8px 0 16px; padding: 0; }
.list li { border-bottom: 1px solid var(--border); }
.list button {
  width: 100%; display: grid; grid-template-columns: 4.2em 1fr auto; gap: 10px; align-items: center;
  min-height: 52px; padding: 6px 4px; font: inherit; text-align: left; color: inherit; background: none; border: 0; cursor: pointer;
}
.list .num { font-weight: 700; font-variant-numeric: tabular-nums; }
.list .name small { display: block; color: var(--muted); font-size: .8rem; }
.list .star { color: var(--star); }

dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border: 1px solid var(--border); border-radius: 18px; padding: 18px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.dialog-actions .spacer { flex: 1; }

.scan-dialog { padding: 0; width: min(760px, calc(100vw - 16px)); height: calc(100dvh - 16px); max-height: none; overflow: hidden; }
.scan-dialog[open] { display: flex; flex-direction: column; }
.scan-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--border); }
.scan-body { flex: 1; overflow: auto; background: #fff; -webkit-overflow-scrolling: touch; }
.scan-wrap { position: relative; }
.scan-wrap img { display: block; width: 100%; height: auto; }
.scan-mark { position: absolute; left: 0; right: 0; border: 3px solid #e0201a; background: rgb(255 230 0 / .25); border-radius: 4px; pointer-events: none; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 10;
  max-width: calc(100vw - 32px);
}
@media (prefers-reduced-motion: reduce) { .btn:active { transform: none; } }
