:root {
  --bg: #eef2f8;
  --card: #ffffff;
  --ink: #0b1220;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #2563eb;
  --blue-d: #1e40af;
  --in: #16a34a;
  --bo: #d97706;
  --bi: #2563eb;
  --out: #dc2626;
  --accent: #2563eb;
  --radius: 24px;
  --shadow: 0 24px 48px -24px rgba(15, 23, 42, .25), 0 2px 6px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #dbeafe 0%, transparent 60%), var(--bg);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
}
button { font: inherit; cursor: pointer; border: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
#app { height: 100%; }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; opacity: 0; transform: translateY(8px); transition: opacity .25s ease, transform .25s ease; }
.screen.active { display: flex; }
.screen.shown { opacity: 1; transform: none; }

/* splash */
#splash { align-items: center; justify-content: center; }
.splash-box { text-align: center; font-weight: 700; color: var(--muted); }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid #cbd5e1; border-top-color: var(--blue); margin: 0 auto 16px; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* home */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 22px 28px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo { width: 54px; height: 54px; border-radius: 16px; background: #fff; box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; overflow: hidden; font-weight: 800; color: var(--blue); flex: none; }
.logo img { width: 100%; height: 100%; object-fit: contain; }
.eyebrow { margin: 0; font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--blue); }
.brand h1 { margin: 2px 0 0; font-size: 22px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock { text-align: right; background: #0b1220; color: #fff; padding: 10px 18px; border-radius: 18px; box-shadow: var(--shadow); }
.clock p { margin: 0; }
#clockTime { font-size: 24px; font-weight: 800; letter-spacing: .02em; }
#clockDate { font-size: 12px; color: #94a3b8; }
.home-body { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 0 28px; max-width: 1100px; width: 100%; margin: 0 auto; }
.home-title { text-align: center; font-size: clamp(28px, 4vw, 44px); font-weight: 800; margin: 0 0 6px; letter-spacing: -.02em; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-top: 28px; }
.tile { border-radius: 28px; min-height: 190px; color: #fff; font-size: 22px; font-weight: 800; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; box-shadow: var(--shadow); transition: transform .15s ease, box-shadow .15s ease; }
.tile:active { transform: scale(.97); }
.tile-ic { width: 64px; height: 64px; border-radius: 20px; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; font-size: 30px; }
.tile.in { background: linear-gradient(140deg, #22c55e, #15803d); }
.tile.bo { background: linear-gradient(140deg, #f59e0b, #b45309); }
.tile.bi { background: linear-gradient(140deg, #3b82f6, #1d4ed8); }
.tile.out { background: linear-gradient(140deg, #ef4444, #b91c1c); }
.warn { margin: 22px auto 0; background: #fffbeb; color: #92400e; border: 1px solid #fde68a; padding: 12px 16px; border-radius: 16px; font-weight: 700; font-size: 14px; text-align: center; }
.foot { text-align: center; padding: 16px; font-size: 13px; font-weight: 600; }

/* chips */
.chip { display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 999px; font-size: 12px; font-weight: 800; letter-spacing: .1em; color: #fff; background: var(--accent); white-space: nowrap; }

/* session */
.session-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 22px; background: #0b1220; color: #fff; }
.session-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.session-left > div { min-width: 0; }
.sess-title { margin: 0; font-weight: 800; font-size: 18px; }
#sessBy { margin: 2px 0 0; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-right { display: flex; align-items: center; gap: 14px; }
.sess-clock { margin: 0; font-weight: 800; font-size: 20px; }
.session-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; padding: 18px 22px 22px; min-height: 0; }
.cam-card, .pad-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-height: 0; display: flex; flex-direction: column; }
.cam-wrap { position: relative; flex: 1; min-height: 240px; border-radius: 18px; overflow: hidden; background: #0f172a; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.cam-guide { position: absolute; left: 50%; top: 48%; width: min(46%, 300px); aspect-ratio: 3 / 4; transform: translate(-50%, -50%); border: 3px dashed rgba(255,255,255,.55); border-radius: 50% / 42%; pointer-events: none; }
.cam-msg { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); background: rgba(15,23,42,.72); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 15px; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; backdrop-filter: blur(6px); }
.countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: clamp(110px, 18vw, 200px); font-weight: 800; color: #fff; text-shadow: 0 10px 40px rgba(0,0,0,.45); }
.countdown.pop { animation: pop .9s ease; }
@keyframes pop { 0% { transform: scale(1.5); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(.85); opacity: .85; } }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .45s ease; }
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }
.result { position: absolute; left: 16px; right: 16px; bottom: 16px; display: flex; align-items: center; gap: 14px; background: #fff; border-radius: 18px; padding: 12px; box-shadow: 0 20px 40px -10px rgba(0,0,0,.4); animation: up .25s ease; }
.result img { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; flex: none; background: #e2e8f0; }
.result-name { margin: 0; font-weight: 800; font-size: 18px; }
.result-text { margin: 2px 0 0; font-weight: 700; font-size: 14px; color: var(--muted); }
.result.ok { border-left: 8px solid var(--in); }
.result.bad { border-left: 8px solid var(--out); }
.result.bad .result-text { color: #b91c1c; }
@keyframes up { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
#camHint { margin: 10px 0 0; }

.pad-label { margin: 0 0 8px; font-weight: 800; font-size: 15px; }
.id-display { height: 64px; border-radius: 18px; border: 2px solid var(--line); background: #f8fafc; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 800; letter-spacing: .2em; transition: border-color .15s ease; }
.id-display .ph { font-size: 17px; letter-spacing: 0; color: #94a3b8; font-weight: 700; }
.id-display.focus { border-color: var(--accent); background: #fff; }
.id-display.shake { animation: shake .35s ease; border-color: #ef4444; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.id-error { min-height: 20px; margin: 6px 0 4px; font-size: 13px; font-weight: 700; color: #dc2626; text-align: center; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button { height: 58px; border-radius: 16px; background: #f1f5f9; font-size: 24px; font-weight: 800; color: var(--ink); transition: background .1s ease, transform .1s ease; }
.keypad button:active { background: #dbeafe; transform: scale(.96); }
.keypad .k-alt { font-size: 16px; color: var(--muted); }
.btn { height: 50px; padding: 0 20px; border-radius: 16px; font-weight: 800; font-size: 15px; transition: transform .1s ease, opacity .15s ease; }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: #dc2626; color: #fff; }
.btn.ghost { background: rgba(148,163,184,.18); color: inherit; }
.session-bar .btn.ghost { background: rgba(255,255,255,.12); color: #fff; height: 42px; }
.btn.big { height: 60px; font-size: 18px; margin-top: 12px; width: 100%; }

.recent { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; min-height: 0; flex: 1; display: flex; flex-direction: column; }
.recent-head { display: flex; justify-content: space-between; font-weight: 800; font-size: 14px; margin-bottom: 6px; }
#recentList { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 60px; }
#recentList li { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
#recentList img { width: 34px; height: 34px; border-radius: 10px; object-fit: cover; flex: none; background: #e2e8f0; }
#recentList .r-main { flex: 1; min-width: 0; }
#recentList .r-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#recentList .r-sub { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 11px; font-weight: 800; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill.saving { background: #eff6ff; color: #1d4ed8; }
.pill.saved { background: #dcfce7; color: #166534; }
.pill.failed { background: #fee2e2; color: #991b1b; }
.retry { font-size: 12px; font-weight: 800; color: var(--blue); background: none; padding: 4px; }

/* sheets */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.55); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 30; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet { background: #fff; border-radius: 28px; padding: 24px; width: min(440px, 100%); box-shadow: 0 30px 60px -20px rgba(0,0,0,.45); animation: up .25s ease; max-height: 100%; overflow-y: auto; }
.sheet h3 { margin: 12px 0 4px; font-size: 22px; font-weight: 800; }
.sheet p { margin: 0 0 14px; font-size: 14px; }
.small-pad button { height: 52px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: #0b1220; color: #fff; padding: 12px 20px; border-radius: 16px; font-weight: 700; font-size: 14px; opacity: 0; transition: all .25s ease; z-index: 50; max-width: 90%; text-align: center; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* portrait tablets / phones */
@media (max-width: 900px), (orientation: portrait) {
  body { overflow: auto; }
  .screen { position: absolute; min-height: 100%; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile { min-height: 150px; font-size: 19px; }
  .session-body { grid-template-columns: minmax(0, 1fr); padding: 12px; gap: 12px; flex: none; }
  .cam-card, .pad-card { min-height: auto; }
  #sessBy { white-space: normal; }
  .cam-wrap { min-height: 0; height: 46vh; flex: none; }
  .recent { flex: none; }
  #recentList { max-height: 180px; }
}
@media (max-width: 560px) {
  .topbar { padding: 14px 16px; }
  .brand h1 { font-size: 17px; }
  .clock { padding: 8px 12px; }
  #clockTime { font-size: 18px; }
  .home-body { padding: 0 16px; }
  .tiles { gap: 12px; }
  .tile { min-height: 128px; border-radius: 22px; }
  .tile-ic { width: 50px; height: 50px; font-size: 24px; }
  .session-bar { padding: 10px 12px; }
  .sess-title { font-size: 15px; }
  .sess-clock { display: none; }
  .keypad button { height: 52px; }
}
