:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #12201f;
  --muted: #5b6b69;
  --line: #d9e0de;
  --brand: #0f3d3e;
  --brand-ink: #ffffff;
  --ok: #157a4a;
  --ok-bg: #e6f4ec;
  --in: #157a4a;
  --out: #1d4f91;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --err: #b42318;
  --err-bg: #fdeceb;
  --key: #eef2f1;
  --radius: 18px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--brand);
  color: var(--brand-ink);
  padding-top: max(12px, env(safe-area-inset-top));
}
.brand { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.branch { font-weight: 700; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; width: fit-content; }
.badge.training { background: #ffd166; color: #3b2a00; }
.clock { text-align: center; }
.clock .time { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; line-height: 1; }
.clock .date { font-size: 14px; opacity: .85; margin-top: 4px; }
.net { justify-self: end; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.net .dot { width: 12px; height: 12px; border-radius: 50%; background: #9aa; }
.net.online .dot { background: #4ade80; }
.net.offline .dot { background: #f87171; animation: blink 1s infinite; }
.net.offline { font-weight: 700; }
@keyframes blink { 50% { opacity: .3; } }

main { flex: 1; overflow: auto; padding: 20px; display: flex; }
.screen { width: 100%; display: flex; flex-direction: column; align-items: center; }
.screen[hidden] { display: none; }

h1 { font-size: 26px; margin: 0 0 8px; text-align: center; }
.muted { color: var(--muted); margin: 0 0 12px; text-align: center; }
.center { text-align: center; }
.error { color: var(--err); min-height: 1.4em; font-weight: 600; text-align: center; margin: 10px 0 0; }

.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 720px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.card.narrow { max-width: 420px; }

.home-head { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.home-head h1 { margin: 0; text-align: left; }

.letters[hidden] { display: none; }
.letters { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; margin-bottom: 14px; }
.letters button {
  min-width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); font-size: 20px; font-weight: 700; color: var(--ink);
}
.letters button.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.people { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.person {
  min-height: 88px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel);
  font-size: 20px; font-weight: 700; color: var(--ink); text-align: left; padding: 14px 16px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.person .first { font-weight: 500; color: var(--muted); font-size: 17px; }
.person:active { transform: scale(.98); background: var(--key); }

.btn {
  border: 0; border-radius: 14px; padding: 16px 22px; font-size: 20px; font-weight: 700; cursor: pointer;
  background: var(--key); color: var(--ink); min-height: 60px;
}
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.wide { width: 100%; }
.btn.qr { display: flex; gap: 10px; align-items: center; background: var(--brand); color: var(--brand-ink); }
.btn.qr svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; }
.btn.huge { width: 100%; font-size: 30px; min-height: 96px; border-radius: 20px; color: #fff; background: var(--ok); }
.btn.huge.out { background: var(--out); }
.row { display: flex; gap: 12px; width: 100%; }
.row .btn { flex: 1; }
.link { background: none; border: 0; color: var(--warn); font-size: 16px; text-decoration: underline; padding: 14px; margin-top: 6px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; margin: 8px 0 14px; }
.keypad button {
  height: 72px; border-radius: 16px; border: 0; background: var(--key); font-size: 30px; font-weight: 700; color: var(--ink);
}
.keypad button:active { background: var(--line); }
.keypad .fn { font-size: 18px; color: var(--muted); }

.pin-dots { display: flex; gap: 14px; justify-content: center; min-height: 26px; margin: 6px 0; }
.pin-dots span { width: 20px; height: 20px; border-radius: 50%; background: var(--line); }
.pin-dots span.on { background: var(--brand); }
.code-display { font-size: 34px; font-weight: 800; letter-spacing: 6px; min-height: 44px; font-variant-numeric: tabular-nums; }

.confirm { gap: 12px; }
.greet { font-size: 22px; margin: 0; color: var(--muted); }
.action-label { font-size: 48px; font-weight: 900; letter-spacing: 1px; }
.action-label.in { color: var(--in); }
.action-label.out { color: var(--out); }
.action-time { font-size: 64px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; margin-bottom: 10px; }
.countdown { width: 100%; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.countdown .bar { height: 100%; background: var(--brand); width: 100%; transform-origin: left; }

.result { padding: 40px 24px; gap: 14px; }
.result-icon { width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center; font-size: 72px; font-weight: 900; }
.result.ok .result-icon { background: var(--ok-bg); color: var(--ok); }
.result.warn .result-icon { background: var(--warn-bg); color: var(--warn); }
.result.err .result-icon { background: var(--err-bg); color: var(--err); }
.result-msg { font-size: 28px; font-weight: 800; text-align: center; margin: 0; }

.video-wrap { position: relative; width: 100%; max-width: 520px; aspect-ratio: 4 / 3; background: #000; border-radius: 16px; overflow: hidden; }
.video-wrap video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.video-wrap .frame { position: absolute; inset: 18%; border: 4px solid rgba(255,255,255,.85); border-radius: 18px; }

.foot { padding: 6px 16px; font-size: 12px; color: var(--muted); text-align: right; padding-bottom: max(6px, env(safe-area-inset-bottom)); }

@media (max-width: 600px) {
  .top { grid-template-columns: 1fr auto; }
  .top .net { grid-column: 1 / -1; justify-self: start; }
  .clock .time { font-size: 34px; }
  .action-label { font-size: 36px; }
  .action-time { font-size: 48px; }
  .people { grid-template-columns: 1fr 1fr; }
  main { padding: 12px; }
}
