/* Empira — Scan prototype (S5)
   Follows HOME_DESIGN_RULES.md (locked) + EMPIRA_DESIGN_SYSTEM.md. Prototype only, not production code. */

:root {
  --blue-500: #3B4CFF;  --blue-600: #2F3DE0;  --blue-700: #2632C2;
  --blue-100: #DDE1FF;  --blue-50:  #EEF0FF;
  --amber-500: #FFB21E;
  --coral-500: #FF6A4D; --coral-700: #B93A25;
  --ink-900: #0B1026;  --ink-700: #3A4166;  --ink-500: #5A6285;
  --line: #D9DCE8;  --mist: #EEF0F5;  --paper: #F6F7FB;  --white: #FFFFFF;

  --font: "Sora", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
  --s6: 32px; --s7: 48px; --s8: 64px;

  --r-s: 8px; --r-m: 12px; --r-l: 20px; --r-full: 999px;
  --ease: cubic-bezier(.2,.8,.2,1); --t-fast: 150ms;

  --page-margin: var(--s4);
  --topbar-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  background: var(--paper); color: var(--ink-900);
  font-family: var(--font); font-size: 16px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; font: inherit; }
ol, ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Top bar (same as inner pages, without the Scan button) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  height: 100%;
  max-width: calc(960px + 2 * var(--page-margin));
  margin: 0 auto; padding: 0 var(--page-margin);
  display: flex; align-items: center; gap: var(--s2);
}
.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; margin-left: -10px;
  border-radius: var(--r-m); color: var(--ink-900);
  transition: background var(--t-fast) var(--ease);
}
.icon-btn .icon { width: 24px; height: 24px; }
.logo { display: inline-flex; align-items: center; height: 44px; border-radius: var(--r-s); }
.logo svg { height: 28px; width: auto; display: block; }
.logo .logo__full { display: none; }

.scan-btn {
  margin-left: auto;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  width: 44px; height: 44px;
  background: var(--white); color: var(--ink-900);
  border: 1px solid var(--line); border-radius: var(--r-m);
  font-size: 16px; font-weight: 600;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.scan-btn__label { display: none; }

/* ---------- Page ---------- */
.page {
  max-width: calc(960px + 2 * var(--page-margin));
  margin: 0 auto;
  padding: var(--s5) var(--page-margin) calc(var(--s7) + env(safe-area-inset-bottom));
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Narrow, focused column (design system: Scan max 640 px) */
.page { max-width: calc(640px + 2 * var(--page-margin)); }

/* ---------- States: one view at a time ---------- */
.view { display: none; }
[data-state="idle"] .view--capture,
[data-state="camera"] .view--capture,
[data-state="processing"] .view--processing,
[data-state="result"] .view--result,
[data-state="notfound"] .view--notfound { display: block; }

/* ---------- Type ---------- */
.title {
  font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em;
  text-wrap: balance;
}
.title:focus { outline: none; }
.hint { margin-top: var(--s1); font-size: 14px; line-height: 1.45; font-weight: 500; color: var(--ink-500); }

/* ---------- The dominant scan tile ---------- */
.drop {
  position: relative;
  margin-top: var(--s5);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s3);
  height: clamp(260px, 52vh, 400px);
  padding: var(--s5);
  background: var(--white);
  border: 1px solid var(--line); border-radius: var(--r-l);
  text-align: center;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.drop[hidden] { display: none; }
.drop__chip {
  display: grid; place-items: center;
  width: 56px; height: 56px; border-radius: var(--r-l);
  background: var(--blue-500); color: var(--white);
  transition: background var(--t-fast) var(--ease);
}
.drop__chip .icon { width: 28px; height: 28px; stroke-width: 2; }
.drop__label { font-size: 22px; line-height: 1.2; font-weight: 600; letter-spacing: -0.015em; transition: color var(--t-fast) var(--ease); }
.drop__note { font-size: 14px; line-height: 1.4; font-weight: 500; color: var(--ink-500); }
.drop:focus-within { outline: 2px solid var(--blue-500); outline-offset: 2px; }

/* Camera is primary on every device; only the one-line note differs (phone camera app vs. laptop webcam). */
.drop { width: 100%; font: inherit; color: inherit; }
.drop__note--desk { display: none; }
@media (hover: hover) and (pointer: fine) {
  .drop__note--desk { display: block; }
}

/* ---------- Live camera (desktop) ---------- */
.camera { margin-top: var(--s5); }
.camera__video {
  display: block; width: 100%;
  height: clamp(260px, 52vh, 400px); object-fit: cover;
  background: var(--mist);
  border: 1px solid var(--line); border-radius: var(--r-l);
}
.camera__actions { margin-top: var(--s3); display: flex; justify-content: flex-end; gap: var(--s3); }
[data-state="camera"] .alt { display: none; }

/* ---------- Secondary way in ---------- */
.alt { margin-top: var(--s3); }
.alt .btn { width: 100%; }

/* ---------- Presenter mode only (?taqdimot=1): never shown to teachers ---------- */
.presenter { margin-top: var(--s5); padding-top: var(--s4); border-top: 1px dashed var(--line); }
.presenter__label { font-size: 13px; line-height: 1.3; font-weight: 600; color: var(--ink-500); }
.presenter__chips { margin-top: var(--s2); display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  display: inline-flex; align-items: center; gap: var(--s2);
  height: 36px; padding: 0 var(--s3);
  background: var(--white); border: 1px solid var(--line); border-radius: var(--r-s);
  font: 600 14px/1 var(--font); color: var(--ink-700); cursor: pointer;
}
.chip__key {
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 6px;
  background: var(--mist); color: var(--ink-500); font-size: 12px;
}
.chip[aria-checked="true"] { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-500); box-shadow: inset 0 0 0 1px var(--blue-500); }
.chip[aria-checked="true"] .chip__key { background: var(--blue-500); color: var(--white); }

/* ---------- Alert (coral = alerts only) ---------- */
.alert {
  margin-top: var(--s3);
  display: flex; align-items: center; gap: var(--s2);
  font-size: 14px; line-height: 1.4; font-weight: 500; color: var(--coral-700);
}
.alert[hidden] { display: none; }
.alert .icon { color: var(--coral-500); }

/* ---------- Processing ---------- */
.preview {
  position: relative;
  margin-top: var(--s5);
  height: clamp(260px, 52vh, 400px);
  background: var(--mist);
  border: 1px solid var(--line); border-radius: var(--r-l);
  overflow: hidden;
}
.preview__img { display: block; width: 100%; height: 100%; object-fit: cover; }
.preview__img:not([src]) { display: none; }
.preview__veil { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(246, 247, 251, .55); }
.spinner {
  width: 40px; height: 40px; border-radius: var(--r-full);
  border: 3px solid var(--blue-100); border-top-color: var(--blue-500);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Result ---------- */
.found { display: flex; align-items: center; gap: var(--s3); }
.found .dot { width: 10px; height: 10px; border-radius: var(--r-full); background: var(--amber-500); flex: none; }
.result {
  margin-top: var(--s5);
  padding: var(--s1) 20px 20px;
  background: var(--white);
  border: 1px solid var(--line); border-radius: var(--r-l);
}
.facts { margin: 0; }
.fact {
  display: grid; grid-template-columns: 1fr; row-gap: 2px;
  padding: 14px 0;
  border-bottom: 1px solid var(--mist);
}
.fact dt { font-size: 14px; line-height: 1.4; font-weight: 500; color: var(--ink-500); }
.fact dd { margin: 0; font-size: 18px; line-height: 1.35; font-weight: 600; letter-spacing: -0.01em; color: var(--ink-900); }
.result__cta { margin-top: 20px; width: 100%; }
.result__build { margin-top: var(--s2); width: 100%; }

.quiet-actions {
  margin-top: var(--s4); margin-left: calc(-1 * var(--s3));
  display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2);
}
.text-btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  height: 44px; padding: 0 var(--s3);
  border-radius: var(--r-m);
  font-size: 16px; font-weight: 600; color: var(--blue-500);
  transition: background var(--t-fast) var(--ease);
}

/* ---------- Not found ---------- */
.missing {
  display: flex; align-items: center; gap: var(--s2);
  margin-bottom: var(--s2);
  font-size: 14px; line-height: 1.4; font-weight: 600; color: var(--coral-700);
}
.missing .icon { color: var(--coral-500); }
.nf-actions { margin-top: var(--s5); display: flex; flex-direction: column; gap: var(--s3); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 48px; padding: 0 20px;
  border-radius: var(--r-m);
  font-size: 16px; font-weight: 600; line-height: 1; white-space: nowrap;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn--large { height: 56px; padding: 0 var(--s5); }
.btn--primary { background: var(--blue-500); color: var(--white); }
.btn--secondary { background: var(--white); color: var(--ink-900); border: 1px solid var(--line); }
.btn:focus-within { outline: 2px solid var(--blue-500); outline-offset: 2px; }

/* ---------- Interaction states (HOME_DESIGN_RULES §4) ---------- */
@media (hover: hover) {
  .drop:hover { background: var(--blue-50); border-color: var(--blue-500); }
  .drop:hover .drop__label { color: var(--blue-500); }
  .drop:hover .drop__chip { background: var(--blue-600); }
  .btn--primary:hover { background: var(--blue-600); }
  .btn--secondary:hover { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-500); }
  .text-btn:hover, .icon-btn:hover { background: var(--blue-50); }
  .icon-btn:hover { color: var(--blue-500); }
}
.drop.is-over { background: var(--blue-50); border-color: var(--blue-500); box-shadow: inset 0 0 0 1px var(--blue-500); }
.drop.is-over .drop__label { color: var(--blue-500); }
.drop:active { background: var(--blue-50); border-color: var(--blue-600); }
.btn--primary:active { background: var(--blue-700); }
.btn--secondary:active { background: var(--blue-50); border-color: var(--blue-600); }
.text-btn:active, .icon-btn:active { background: var(--blue-50); }

/* ---------- Tablet ≥ 640 ---------- */
@media (min-width: 640px) {
  :root { --page-margin: var(--s5); }
  .page { padding-top: var(--s7); }
  .logo .logo__full { display: block; }
  .logo .logo__symbol { display: none; }
  .title { font-size: 32px; }
  .fact { grid-template-columns: 184px minmax(0, 1fr); align-items: baseline; column-gap: var(--s4); }
  .result { padding: var(--s1) var(--s5) var(--s5); }
  .nf-actions { flex-direction: row; }
  .nf-actions .btn { flex: 1; }
}

/* ---------- Desktop ≥ 1024 ---------- */
@media (min-width: 1024px) {
  :root { --page-margin: var(--s6); --topbar-h: 64px; }
  .title { font-size: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .spinner { animation-duration: 3s; }
}
