/* Black and yellow, high contrast: yellow on black ≈ 15:1, white on black 21:1. Touch targets ≥ 56 px. */
:root {
  --bg: #000; --fg: #fff; --accent: #ffd600; --accent-2: #ffb800; --muted: #c9c9c9;
  --good: #3ddc84; --bad: #ff5a4f; --warn: #ff9f1a;
  --glass: rgba(14, 14, 16, .72); --line: rgba(255, 255, 255, .14);
  --radius: 24px; --gutter: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 4px solid var(--fg); outline-offset: 3px; }

#app { position: relative; height: 100dvh; max-width: 560px; margin: 0 auto; overflow: hidden; background: #0b0b0b; }

/* ---------- Camera, full bleed under everything ---------- */
#viewport { position: absolute; inset: 0; background: radial-gradient(120% 80% at 50% 30%, #1d1d20, #000); }
#cam, #demoImg { width: 100%; height: 100%; display: block; }
#cam { object-fit: cover; }
#demoImg { object-fit: contain; }
#cam[hidden], #demoImg[hidden] { display: none; }
#viewport::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,.7) 0, rgba(0,0,0,0) 24%, rgba(0,0,0,0) 42%, rgba(0,0,0,.6) 66%); }

/* Viewfinder: yellow while aiming, green when light/sharpness/glare are fine, red when not */
.frame { --c: var(--accent); position: absolute; left: 10%; right: 10%; top: 20%; bottom: 42%; pointer-events: none; }
[data-quality="good"] .frame { --c: var(--good); }
[data-quality="bad"] .frame { --c: var(--bad); }
.frame i { position: absolute; width: 44px; height: 44px; border: 0 solid var(--c);
  filter: drop-shadow(0 0 6px rgba(0,0,0,.6)); transition: border-color .25s ease; }
.frame i:nth-child(1) { top: 0; left: 0; border-top-width: 6px; border-left-width: 6px; border-top-left-radius: 18px; }
.frame i:nth-child(2) { top: 0; right: 0; border-top-width: 6px; border-right-width: 6px; border-top-right-radius: 18px; }
.frame i:nth-child(3) { bottom: 0; left: 0; border-bottom-width: 6px; border-left-width: 6px; border-bottom-left-radius: 18px; }
.frame i:nth-child(4) { bottom: 0; right: 0; border-bottom-width: 6px; border-right-width: 6px; border-bottom-right-radius: 18px; }
.scan { position: absolute; left: 10%; right: 10%; top: 20%; height: 4px; border-radius: 4px; opacity: 0; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--accent), transparent); box-shadow: 0 0 22px 6px rgba(255,214,0,.45); }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.is-thinking .scan { opacity: 1; animation: scan 1.3s ease-in-out infinite alternate; }
.is-thinking .frame { --c: var(--accent); animation: breathe 1.3s ease-in-out infinite alternate; }
.is-shot .flash { animation: flash .35s ease-out; }
@keyframes scan { from { transform: translateY(0); } to { transform: translateY(calc(38dvh - 4px)); } }
@keyframes breathe { from { transform: scale(1); } to { transform: scale(.97); } }
@keyframes flash { from { opacity: .6; } to { opacity: 0; } }

/* ---------- Top bar ---------- */
#topbar { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter) 0; }
.brand { display: flex; align-items: center; gap: 8px; height: 52px; padding: 0 16px 0 12px; border-radius: 999px;
  background: var(--glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border: 1px solid var(--line);
  color: var(--accent); font-weight: 800; font-size: 22px; letter-spacing: .3px; }
.langs { display: flex; margin-left: auto; padding: 4px; border-radius: 999px; background: var(--glass);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border: 1px solid var(--line); }
.langs button { min-width: 50px; min-height: 52px; padding: 0 8px; border: 0; border-radius: 999px; background: transparent;
  color: var(--fg); font-size: 16px; font-weight: 800; letter-spacing: .3px; transition: background .2s ease, color .2s ease; }
.langs button[aria-pressed="true"] { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #000;
  box-shadow: 0 4px 14px rgba(255,200,0,.35); }
.round { width: 60px; height: 60px; flex: none; display: grid; place-items: center; padding: 0; border-radius: 50%;
  background: var(--glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); color: var(--accent);
  border: 2px solid rgba(255,214,0,.8); }

/* ---------- Frame check list ---------- */
#quality { position: absolute; left: 0; right: 0; top: calc(max(12px, env(safe-area-inset-top)) + 66px);
  display: flex; justify-content: center; gap: 8px; pointer-events: none; }
.chip { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px 0 6px; border-radius: 999px;
  background: var(--glass); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border: 1px solid var(--line);
  font-size: 15px; font-weight: 700; color: var(--muted); transition: color .2s ease, border-color .2s ease; }
.chip i { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-style: normal;
  font-size: 13px; font-weight: 900; background: rgba(255,255,255,.18); color: #000; }
.chip.ok { color: var(--fg); border-color: rgba(61,220,132,.5); }
.chip.ok i { background: var(--good); }
.chip.ok i::before { content: "✓"; }
.chip.bad { color: var(--fg); border-color: rgba(255,90,79,.7); }
.chip.bad i { background: var(--bad); color: #fff; }
.chip.bad i::before { content: "✕"; }

/* ---------- Bottom sheet ---------- */
#panel { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; gap: 12px;
  padding: 8px var(--gutter) calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(22,22,24,.9), rgba(6,6,8,.97));
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-top-left-radius: 30px; border-top-right-radius: 30px; border-top: 1px solid var(--line);
  box-shadow: 0 -12px 40px rgba(0,0,0,.5); }
.grip { width: 44px; height: 5px; margin: 0 auto 2px; border-radius: 3px; background: rgba(255,255,255,.25); }
#statusRow { display: flex; align-items: center; gap: 10px; min-height: 30px; }
.dot { width: 12px; height: 12px; flex: none; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
[data-quality="good"] .dot { background: var(--good); box-shadow: 0 0 10px var(--good); }
[data-quality="bad"] .dot { background: var(--bad); box-shadow: 0 0 10px var(--bad); }
.is-thinking .dot, .is-listening .dot { animation: pulse 1s ease-in-out infinite; }
.is-thinking .dot { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.is-listening .dot { background: var(--bad); box-shadow: 0 0 10px var(--bad); }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.6); opacity: .55; } }
#status { margin: 0; font-size: 21px; font-weight: 700; color: var(--accent); }

/* Answer card: colour follows the verdict */
#card { --edge: var(--accent); display: none; max-height: 30dvh; overflow-y: auto; padding: 14px 16px; border-radius: 20px;
  background: linear-gradient(180deg, #1a1a1c, #121214); border: 1px solid var(--line); border-left: 6px solid var(--edge);
  animation: rise .25s ease-out; }
#card.has-text { display: block; }
/* The answer is spoken; the card stays only for screen readers so the camera view is not covered. */
#card, #card.has-text { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0; animation: none; }
#card[data-verdict="expired"] { --edge: var(--bad); background: linear-gradient(180deg, #2a1210, #160a09); }
#card[data-verdict="valid"] { --edge: var(--good); }
#card[data-verdict="retake"], #card[data-verdict="unreadable"], #card[data-verdict="unsure"] { --edge: var(--warn); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
#heard { margin: 0 0 6px; font-size: 19px; line-height: 1.3; color: var(--muted); font-style: italic; }
#heard:empty { display: none; }
#answer { margin: 0; font-size: 27px; line-height: 1.3; font-weight: 650; }

/* Main button */
#askBtn { position: relative; display: flex; align-items: center; justify-content: center; gap: 14px; min-height: 108px; padding: 0 20px;
  border: 0; border-radius: var(--radius); color: #000; font-size: clamp(26px, 8vw, 36px); font-weight: 900; line-height: 1.1;
  background: linear-gradient(180deg, #ffe34d 0%, var(--accent) 45%, var(--accent-2) 100%);
  box-shadow: 0 10px 30px rgba(255,200,0,.3), inset 0 2px 0 rgba(255,255,255,.55), inset 0 -3px 0 rgba(0,0,0,.12);
  transition: transform .08s ease, filter .08s ease; }
#askBtn:active { transform: scale(.98); filter: brightness(.94); }
.spinner { display: none; width: 40px; height: 40px; flex: none; border-radius: 50%; border: 5px solid rgba(0,0,0,.2);
  border-top-color: #000; animation: spin .8s linear infinite; }
.is-thinking #askBtn svg { display: none; }
.is-thinking .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Secondary buttons */
#row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#row button { min-height: 88px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border-radius: 20px; background: linear-gradient(180deg, #1b1b1d, #111113); color: var(--fg);
  border: 2px solid rgba(255,214,0,.75); font-size: 18px; font-weight: 800; transition: transform .08s ease; }
#row button svg { width: 40px; height: 40px; padding: 7px; border-radius: 50%; background: rgba(255,214,0,.14); color: var(--accent); }
#row button:active { transform: scale(.97); }
#micBtn[aria-pressed="true"] { background: linear-gradient(180deg, #ffe34d, var(--accent-2)); color: #000; border-color: var(--accent);
  animation: ring 1.2s ease-out infinite; }
#micBtn[aria-pressed="true"] svg { background: rgba(0,0,0,.12); color: #000; }
@keyframes ring { from { box-shadow: 0 0 0 0 rgba(255,214,0,.6); } to { box-shadow: 0 0 0 16px rgba(255,214,0,0); } }

/* ---------- Text question (fallback when there is no microphone) ---------- */
#askForm { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; flex-direction: column; gap: 12px;
  padding: 18px var(--gutter) calc(18px + env(safe-area-inset-bottom)); background: #0d0d0f;
  border-top: 3px solid var(--accent); border-top-left-radius: 30px; border-top-right-radius: 30px; }
#askForm[hidden] { display: none; }
#qLabel { font-size: 22px; color: var(--accent); font-weight: 800; }
#q { min-height: 64px; font-size: 26px; padding: 8px 14px; color: var(--fg); background: #18181a; border: 3px solid var(--fg);
  border-radius: 16px; -webkit-user-select: text; user-select: text; }
.formRow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.formRow button, #closeSettingsBtn { min-height: 64px; border-radius: 18px; background: #111113; color: var(--accent);
  border: 2px solid var(--accent); font-size: 22px; font-weight: 800; }
.formRow button[type=submit] { background: var(--accent); color: #000; }

/* ---------- Settings ---------- */
dialog { width: min(520px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 22px;
  background: #0d0d0f; color: var(--fg); border: 2px solid var(--accent); border-radius: 26px; }
dialog::backdrop { background: rgba(0, 0, 0, .85); }
dialog h2 { margin: 0 0 8px; font-size: 30px; color: var(--accent); }
dialog h3 { margin: 12px 0 6px; font-size: 19px; color: var(--muted); }
fieldset { margin: 0 0 8px; padding: 8px 0; border: 0; border-bottom: 1px solid var(--line); }
legend { font-size: 22px; font-weight: 800; color: var(--accent); padding: 0; margin-bottom: 4px; }
.opt { display: flex; align-items: center; gap: 14px; min-height: 56px; font-size: 24px; }
.opt input { width: 30px; height: 30px; accent-color: var(--accent); }
#closeSettingsBtn { width: 100%; margin-top: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Narrow phones: four language buttons need the room, the brand keeps only its eye icon */
@media (max-width: 430px) {
  .brand span { display: none; }
  .brand { padding: 0 12px; }
  #topbar { gap: 6px; }
}

/* 360 px Android phones and the 320 px iPhone SE: the header (eye, four languages, settings) needs ~366 px,
   so the decorative eye goes and the settings button stays on screen */
@media (max-width: 370px) {
  .brand { display: none; }
}
