/* ============================================================
   Sokhapheap (សុខភាព) — Design System
   "Deliver Wellness, Deliver Dignity"
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Kantumruy+Pro:wght@300;400;500;600;700&family=Hanken+Grotesk:wght@400;500;600;700;800&display=swap');

:root {
  /* — Brand — */
  --royal:        oklch(0.43 0.13 264);
  --royal-deep:   oklch(0.32 0.11 265);
  --royal-bright: oklch(0.56 0.15 264);
  --royal-tint:   oklch(0.95 0.028 264);
  --royal-tint-2: oklch(0.91 0.045 264);

  --gold:         oklch(0.74 0.085 78);
  --gold-deep:    oklch(0.60 0.085 68);
  --gold-tint:    oklch(0.95 0.038 85);

  /* — Neutrals (cool paper) — */
  --bg:        oklch(0.975 0.007 258);
  --surface:   oklch(1 0 0);
  --surface-2: oklch(0.965 0.009 258);
  --line:      oklch(0.91 0.01 258);
  --line-soft: oklch(0.94 0.008 258);

  --ink:       oklch(0.27 0.025 264);
  --ink-soft:  oklch(0.46 0.022 264);
  --ink-faint: oklch(0.62 0.016 264);

  /* — Signals — */
  --safe:       oklch(0.58 0.10 158);
  --safe-tint:  oklch(0.95 0.04 158);
  --warn:       oklch(0.70 0.12 66);
  --warn-tint:  oklch(0.96 0.045 78);
  --danger:     oklch(0.57 0.19 26);
  --danger-tint:oklch(0.95 0.045 26);

  /* — Radii — */
  --r-xl: 30px;
  --r-lg: 24px;
  --r:    18px;
  --r-sm: 13px;

  --khmer: 'Kantumruy Pro', system-ui, sans-serif;
  --latin: 'Hanken Grotesk', system-ui, sans-serif;

  --shadow-card: 0 1px 2px oklch(0.4 0.05 264 / 0.04), 0 8px 24px oklch(0.4 0.05 264 / 0.06);
  --shadow-pop:  0 8px 24px oklch(0.3 0.06 264 / 0.12), 0 24px 60px oklch(0.3 0.06 264 / 0.16);

  --scale: 1;  /* text-size accessibility multiplier */
}

.dark {
  --royal:        oklch(0.62 0.14 264);
  --royal-deep:   oklch(0.30 0.09 265);
  --royal-bright: oklch(0.70 0.14 264);
  --royal-tint:   oklch(0.30 0.05 264);
  --royal-tint-2: oklch(0.36 0.07 264);

  --gold:         oklch(0.80 0.09 80);
  --gold-deep:    oklch(0.70 0.09 74);
  --gold-tint:    oklch(0.30 0.04 80);

  --bg:        oklch(0.18 0.012 264);
  --surface:   oklch(0.23 0.016 264);
  --surface-2: oklch(0.27 0.018 264);
  --line:      oklch(0.34 0.02 264);
  --line-soft: oklch(0.30 0.018 264);

  --ink:       oklch(0.96 0.006 264);
  --ink-soft:  oklch(0.78 0.012 264);
  --ink-faint: oklch(0.62 0.014 264);

  --safe-tint:  oklch(0.30 0.05 158);
  --warn-tint:  oklch(0.32 0.05 78);
  --danger-tint:oklch(0.30 0.06 26);

  --shadow-card: 0 1px 2px rgba(0,0,0,0.4), 0 10px 28px rgba(0,0,0,0.4);
  --shadow-pop:  0 12px 40px rgba(0,0,0,0.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: var(--latin);
  background:
    radial-gradient(1200px 700px at 50% -10%, oklch(0.93 0.03 264), transparent 60%),
    oklch(0.91 0.012 258);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.km { font-family: var(--khmer); line-height: 1.75; }
.en { font-family: var(--latin); }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { max-width: 100%; display: block; }

/* ── App stage / phone frame ───────────────────────────── */
.stage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 32px 16px 48px;
}

.frame {
  position: relative;
  width: min(390px, 100%);
  max-width: 390px;
  height: 844px;
  border-radius: 52px;
  background: #0b0d12;
  padding: 12px;
  box-shadow:
    0 50px 100px oklch(0.3 0.06 264 / 0.30),
    0 0 0 2px oklch(0.3 0.04 264 / 0.20),
    inset 0 0 0 2px rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.screen-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 42px;
  overflow: hidden;
  background: var(--bg);
}
/* dynamic island */
.island {
  position: absolute;
  top: 11px; left: 50%; transform: translateX(-50%);
  width: 118px; height: 34px; border-radius: 22px;
  background: #000; z-index: 200;
  pointer-events: none;
}
/* status bar */
.statusbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 150;
  height: 54px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 30px 0;
  font-family: var(--latin); font-weight: 700; font-size: 15px;
  letter-spacing: 0.2px;
  pointer-events: none;
}
.statusbar .sb-icons { display: flex; gap: 7px; align-items: center; }
.home-indicator {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  width: 134px; height: 5px; border-radius: 99px; z-index: 220;
  pointer-events: none;
}

/* The actual scrolling viewport of the app */
.viewport {
  position: absolute; inset: 0;
  border-radius: 42px;
  overflow: hidden;
  display: flex; flex-direction: column;
}

/* ── Scroll body ───────────────────────────── */
.scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.scroll::-webkit-scrollbar { width: 0; }

/* ── App header ───────────────────────────── */
.appbar {
  background: linear-gradient(160deg, var(--royal) 0%, var(--royal-deep) 130%);
  color: #fff;
  padding: 60px 22px 22px;
  border-radius: 0 0 28px 28px;
  position: relative;
  z-index: 5;
  flex-shrink: 0;
}

/* ── Cards ───────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
}

/* ── Buttons ───────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 16px 20px;
  border-radius: var(--r);
  font-family: var(--khmer);
  font-weight: 700;
  font-size: calc(18px * var(--scale));
  line-height: 1.3;
  transition: transform .12s ease, filter .15s ease, background .2s ease;
}
.btn:active { transform: scale(0.975); }
.btn-primary { background: var(--royal); color: #fff; box-shadow: 0 6px 16px oklch(0.43 0.13 264 / 0.28); }
.btn-primary:active { filter: brightness(1.05); }
.btn-gold { background: var(--gold); color: oklch(0.30 0.05 70); box-shadow: 0 6px 16px oklch(0.74 0.085 78 / 0.30); }
.btn-soft { background: var(--royal-tint); color: var(--royal); }
.btn-ghost { background: var(--surface-2); color: var(--ink-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-safe { background: var(--safe); color: #fff; }
.btn-lg { min-height: 66px; font-size: calc(20px * var(--scale)); }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 99px;
  font-family: var(--khmer); font-weight: 600;
  font-size: calc(13px * var(--scale));
}

.prototype-disclaimer {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 14px 15px;
  border-radius: var(--r-sm);
  background: var(--warn-tint);
  color: var(--ink);
  border: 1px solid color-mix(in oklch, var(--gold-deep) 28%, transparent);
  box-shadow: none;
}
.prototype-disclaimer > svg {
  flex-shrink: 0;
  color: var(--gold-deep);
  margin-top: 2px;
}
.prototype-disclaimer .t-label {
  color: var(--gold-deep);
  margin-bottom: 4px;
}
.prototype-disclaimer.compact {
  padding: 11px 12px;
}
.prototype-disclaimer.compact .t-body-en {
  font-size: calc(12px * var(--scale));
}

/* ── Tab bar ───────────────────────────── */
.tabbar {
  flex-shrink: 0;
  display: flex;
  padding: 10px 16px 30px;
  gap: 4px;
  background: color-mix(in oklch, var(--surface) 86%, transparent);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-top: 1px solid var(--line-soft);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px;
  border-radius: 16px;
  color: var(--ink-faint);
  font-family: var(--khmer); font-weight: 600;
  font-size: calc(11px * var(--scale));
  transition: color .2s ease;
}
.tab.active { color: var(--royal); }
.tab.fab-tab { flex: 0 0 auto; }

.fab {
  width: 64px; height: 64px; border-radius: 22px;
  background: linear-gradient(150deg, var(--royal-bright), var(--royal-deep));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px oklch(0.43 0.13 264 / 0.4);
  margin-top: -26px;
  transition: transform .14s ease;
}
.fab:active { transform: scale(0.94); }

/* ── Overlays ───────────────────────────── */
.overlay {
  position: absolute; inset: 0; z-index: 100;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.sheet {
  position: absolute; inset: 0; z-index: 120;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.sheet-scrim { position: absolute; inset: 0; background: oklch(0.2 0.04 264 / 0.45); }
.sheet-card {
  position: relative;
  background: var(--surface);
  border-radius: 30px 30px 0 0;
  max-height: 86%;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-pop);
  animation: sheetUp .34s cubic-bezier(.2,.9,.3,1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Entrance animations are PROGRESSIVE ENHANCEMENT only.
   Base state is fully visible; the .is-anim class (added by JS via
   requestAnimationFrame) opts an element into the animation. If the
   render loop is ever stalled, content stays visible — never blank. */
.is-anim.fade-in { animation: fadeIn .4s ease backwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.is-anim.rise > * { animation: riseItem .5s cubic-bezier(.2,.85,.3,1) backwards; }
.is-anim.rise > *:nth-child(1){ animation-delay: .04s; }
.is-anim.rise > *:nth-child(2){ animation-delay: .12s; }
.is-anim.rise > *:nth-child(3){ animation-delay: .20s; }
.is-anim.rise > *:nth-child(4){ animation-delay: .28s; }
.is-anim.rise > *:nth-child(5){ animation-delay: .36s; }
.is-anim.rise > *:nth-child(6){ animation-delay: .44s; }
.is-anim.rise > *:nth-child(7){ animation-delay: .52s; }
@keyframes riseItem { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

/* ── Text helpers ───────────────────────────── */
.t-display { font-family: var(--khmer); font-weight: 700; font-size: calc(30px * var(--scale)); line-height: 1.5; }
.t-title   { font-family: var(--khmer); font-weight: 700; font-size: calc(23px * var(--scale)); line-height: 1.85; }
.t-h       { font-family: var(--khmer); font-weight: 700; font-size: calc(19px * var(--scale)); line-height: 1.82; }
.t-body    { font-family: var(--khmer); font-weight: 400; font-size: calc(17px * var(--scale)); line-height: 1.9; }
.t-body-en { font-family: var(--latin); font-weight: 500; font-size: calc(14px * var(--scale)); line-height: 1.55; }
.t-sm      { font-family: var(--khmer); font-weight: 500; font-size: calc(14px * var(--scale)); line-height: 1.78; }
.t-label   { font-family: var(--latin); font-weight: 700; font-size: calc(11px * var(--scale)); letter-spacing: 0.10em; text-transform: uppercase; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
/* Khmer headings bleed descenders — always give the following English gloss room */
.t-display + .t-body-en, .t-title + .t-body-en, .t-h + .t-body-en,
.t-sm + .t-body-en, .t-body + .t-body-en { margin-top: 6px; }

/* ── Sreymom avatar ───────────────────────────── */
.srey {
  border-radius: 50%;
  background: radial-gradient(120% 120% at 30% 25%, var(--gold-tint), var(--royal-tint-2));
  display: flex; align-items: center; justify-content: center;
  position: relative; flex-shrink: 0;
  box-shadow: inset 0 0 0 2px oklch(1 0 0 / 0.5);
}
.srey .ring {
  position: absolute; inset: -5px; border-radius: 50%;
  border: 2px solid var(--gold); opacity: 0.5;
}
.srey-pulse::after {
  content: ''; position: absolute; inset: -5px; border-radius: 50%;
  border: 2px solid var(--royal-bright);
  animation: pulseRing 1.6s ease-out infinite;
}
@keyframes pulseRing {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* ── Waveform ───────────────────────────── */
.wave { display: flex; align-items: center; gap: 3px; height: 34px; }
.wave i {
  width: 3px; border-radius: 3px; background: currentColor;
  height: 30%;
}
.wave.playing i { animation: bar .9s ease-in-out infinite; }
.wave i:nth-child(odd) { animation-delay: .15s; }
.wave i:nth-child(3n) { animation-delay: .3s; }
.wave i:nth-child(4n) { animation-delay: .45s; }
@keyframes bar { 0%,100% { height: 22%; } 50% { height: 92%; } }

/* ── Document facsimile ───────────────────────────── */
.facsimile {
  background: #fdfdfb;
  color: #2a2a28;
  font-family: var(--latin);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.05);
  position: relative;
}
.dark .facsimile { filter: brightness(0.96); }

/* scan grid / viewfinder */
.viewfinder {
  position: relative;
  background:
    repeating-linear-gradient(0deg, oklch(0.22 0.02 264) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(90deg, oklch(0.22 0.02 264) 0 1px, transparent 1px 28px),
    radial-gradient(120% 90% at 50% 0%, oklch(0.32 0.03 264), oklch(0.18 0.02 264));
  overflow: hidden;
}
.scanline {
  position: absolute; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  box-shadow: 0 0 18px 4px var(--gold);
  animation: scanmove 2.4s ease-in-out infinite;
}
@keyframes scanmove { 0%,100% { top: 8%; } 50% { top: 88%; } }

.corner { position: absolute; width: 30px; height: 30px; border: 3px solid var(--gold); }
.corner.tl { top: 18px; left: 18px; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.corner.tr { top: 18px; right: 18px; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.corner.bl { bottom: 18px; left: 18px; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
.corner.br { bottom: 18px; right: 18px; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }

/* spinner dots */
.dots { display: flex; gap: 8px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--royal); animation: dotb 1.1s ease-in-out infinite; }
.dots i:nth-child(2){ animation-delay: .15s; }
.dots i:nth-child(3){ animation-delay: .3s; }
@keyframes dotb { 0%,100%{ transform: translateY(0); opacity: .4; } 50%{ transform: translateY(-8px); opacity: 1; } }

/* divider */
.hr { height: 1px; background: var(--line); border: 0; margin: 0; }

/* page caption under phone */
.stage-caption {
  text-align: center; max-width: 440px;
  font-family: var(--latin); color: oklch(0.42 0.03 264);
}
.stage-caption b { color: oklch(0.32 0.06 264); }

/* evaluator button on the stage */
.eval-btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 11px 18px; border-radius: 99px;
  background: oklch(1 0 0 / 0.7); backdrop-filter: blur(8px);
  box-shadow: var(--shadow-card);
  font-family: var(--latin); font-weight: 700; font-size: 13px;
  color: var(--royal-deep);
  border: 1px solid oklch(1 0 0 / 0.8);
}

.list-row {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px;
}
.list-row + .list-row { border-top: 1px solid var(--line-soft); }

.icon-tile {
  width: 46px; height: 46px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── Giant scan button ───────────────────────────── */
.scan-hero {
  flex-direction: column;
  gap: 12px;
  min-height: 152px;
  font-family: var(--khmer);
  font-weight: 700;
  font-size: calc(22px * var(--scale));
  border-radius: var(--r-lg);
  box-shadow: 0 12px 30px oklch(0.43 0.13 264 / 0.34);
}

/* ── Elder Mode: hide bilingual glosses, enlarge, calm ───── */
.gloss { } /* visible by default */
.elder .gloss { display: none !important; }
.elder .btn { min-height: 66px; }
.elder .btn-lg { min-height: 78px; }
.elder .scan-hero { min-height: 172px; font-size: calc(25px * var(--scale)); }
.elder .t-body { font-size: calc(18.5px * var(--scale)); }
.elder .list-row { padding: 18px; }
.elder .tab { font-size: calc(12px * var(--scale)); }
