:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #e9f1ef;
  --text: #15201f;
  --muted: #5a6b68;
  --line: #d3dedb;
  --primary: #0b7a75;
  --primary-strong: #075c58;
  --on-primary: #ffffff;
  --accent: #d98a12;
  --accent-soft: #fff1d8;
  --danger: #b4232c;
  --danger-soft: #fde3e5;
  --ok: #1d7a3b;
  --ok-soft: #dff3e4;
  --focus: #1f6fe0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(10, 30, 28, 0.06), 0 8px 24px rgba(10, 30, 28, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1716;
    --surface: #182322;
    --surface-2: #203030;
    --text: #e8f0ee;
    --muted: #9fb3af;
    --line: #2d3f3d;
    --primary: #3fb8b1;
    --primary-strong: #67cfc8;
    --on-primary: #06201e;
    --accent: #f0b04a;
    --accent-soft: #3a2d14;
    --danger: #ff7b84;
    --danger-soft: #3b1a1d;
    --ok: #6fd48d;
    --ok-soft: #173424;
    --focus: #7fb2ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.9rem; }
a { color: var(--primary-strong); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 8px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--primary-strong); font-size: 1.1rem; }
.brand-mark { width: 28px; height: 28px; }
.topnav a { text-decoration: none; font-weight: 600; padding: 8px 10px; border-radius: 8px; }
.topnav a:hover { background: var(--surface-2); }

.page { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 16px; }
.page:focus { outline: none; }
.footer { margin-top: auto; display: flex; gap: 18px; justify-content: center; padding: 18px 16px 24px; color: var(--muted); font-size: 0.9rem; }
.footer a { color: var(--muted); }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card.center { text-align: center; }
.hero h1 { font-size: 1.7rem; }
.lead { font-size: 1.05rem; color: var(--muted); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; background: var(--surface-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--accent-soft); color: var(--accent); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #1d1300; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary-strong); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 1.1rem; }
.btn svg { width: 22px; height: 22px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; }
.input, textarea, select {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
textarea { min-height: 110px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span { display: inline-block; min-height: 44px; line-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.chip input:checked + span { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 6px 0 14px; }
.progress > div { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.3s ease; }

.question h2 { font-size: 1.35rem; margin-bottom: 18px; }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.actions .btn { flex: 1; }

/* Choice list (radio) */
.choices { display: grid; gap: 10px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.choice span { display: block; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.choice input:checked + span { border-color: var(--primary); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--primary); font-weight: 600; }
.choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Segmented control */
.segmented { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.segmented .choice { flex: 1; }
.segmented .choice span { border: 0; border-radius: 0; text-align: center; padding: 14px 6px; font-size: 0.95rem; }
.segmented .choice + .choice span { border-left: 1px solid var(--line); }
.segmented .choice input:checked + span { background: var(--primary); color: var(--on-primary); box-shadow: none; }

/* Stars and smileys */
.scale { display: flex; justify-content: space-between; gap: 6px; }
.scale button { flex: 1; min-height: 64px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: grid; place-items: center; padding: 6px 2px; color: var(--muted); }
.scale button svg { width: 34px; height: 34px; }
.scale button[aria-pressed="true"], .scale.stars button.lit { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.scale.smileys button[aria-pressed="true"] { color: var(--primary-strong); border-color: var(--primary); background: var(--surface-2); }
.scale-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.85rem; margin-top: 6px; }
.scale-value { text-align: center; font-weight: 600; margin-top: 8px; min-height: 1.4em; }

/* Sliders */
.slider-wrap { padding: 8px 2px; }
input[type="range"] { width: 100%; height: 44px; accent-color: var(--primary); }
.face-big { display: block; width: 120px; height: 120px; margin: 0 auto 8px; color: var(--primary-strong); }

/* Thumbs */
.thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.thumbs button { min-height: 96px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: grid; place-items: center; gap: 6px; font-weight: 600; }
.thumbs button svg { width: 40px; height: 40px; }
.thumbs button[aria-pressed="true"] { border-color: var(--primary); background: var(--surface-2); color: var(--primary-strong); }

/* Ranking */
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rank-item { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.rank-item .pos { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 700; font-size: 0.9rem; flex: none; }
.rank-item .label { flex: 1; }
.rank-item button { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; }
.rank-item button[disabled] { opacity: 0.35; cursor: default; }

.counter { text-align: right; color: var(--muted); font-size: 0.85rem; }

/* Coupon */
.coupon { text-align: center; }
.coupon .qr { display: inline-block; padding: 12px; background: #fff; border-radius: 12px; border: 1px solid var(--line); }
.coupon .qr svg { display: block; width: 220px; height: 220px; }
.coupon .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.15rem; letter-spacing: 0.08em; margin: 10px 0 4px; }
.coupon .reward { font-size: 1.35rem; font-weight: 700; color: var(--accent); }
.coupon.used { opacity: 0.6; }

.reward-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.reward-list li { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); display: flex; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer; background: var(--surface); }

.venue-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.venue-list a { display: flex; justify-content: space-between; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); text-decoration: none; color: inherit; background: var(--surface); }

.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 14px; }
.notice.ok { background: var(--ok-soft); }
.notice.warn { background: var(--accent-soft); }
.notice.danger { background: var(--danger-soft); }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Scanner */
.scanner { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 3 / 4; max-height: 60vh; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; inset: 12%; border: 3px solid rgba(255,255,255,0.9); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,0.35); pointer-events: none; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; }
}

/* Admin and staff pages */
.wide { max-width: 1080px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 800px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.table td.q-text { min-width: 260px; }
.table td.q-cond { max-width: 260px; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.78rem; }
.kpi { padding: 14px; border-radius: var(--radius-sm); background: var(--surface-2); }
.kpi .n { font-size: 1.6rem; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: 0.85rem; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: minmax(90px, 32%) 1fr 40px; align-items: center; gap: 8px; font-size: 0.9rem; }
.bar .track { height: 14px; background: var(--surface-2); border-radius: 7px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--primary); border-radius: 7px; }
.bar .n { text-align: right; color: var(--muted); }
.result-big { padding: 28px; border-radius: var(--radius); text-align: center; font-size: 1.3rem; font-weight: 700; }
.result-big.ok { background: var(--ok-soft); color: var(--ok); }
.result-big.bad { background: var(--danger-soft); color: var(--danger); }
.poster { text-align: center; padding: 32px; }
.poster .qr svg { width: 320px; height: 320px; }
@media print {
  .topbar, .footer, .no-print, .toast { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
