:root {
  color-scheme: dark;
  --ink: #071c2b;
  --ink-soft: #0d293a;
  --panel: #102f40;
  --line: rgba(231,244,239,.14);
  --cream: #fff7e8;
  --muted: #aac1c6;
  --gold: #ffb454;
  --coral: #ff6b4a;
  --mint: #75e0c1;
  --shadow: 0 28px 70px rgba(0,10,18,.34);
  font-family: "Avenir Next", Avenir, "Noto Sans Khmer", "Khmer Sangam MN", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--ink);
  color: var(--cream);
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 10% 0%, rgba(48,145,139,.22), transparent 34rem),
    radial-gradient(circle at 100% 42%, rgba(255,107,74,.12), transparent 30rem),
    var(--ink);
}
button, input { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
fieldset { min-width: 0; }
[hidden] { display: none !important; }

.site-header {
  width: min(1120px, calc(100% - 32px));
  min-height: 76px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--cream); text-decoration: none; font-weight: 800; letter-spacing: -.02em; }
.brand img { width: 38px; height: 38px; }
.brand > span { display: grid; gap: 1px; line-height: 1.05; }
.brand small { color: var(--muted); font-size: .64em; font-weight: 650; letter-spacing: 0; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.privacy-chip { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .75rem; }
.language-toggle { min-width: 46px; min-height: 38px; padding: 7px 11px; border: 1px solid rgba(255,180,84,.45); border-radius: 999px; color: var(--gold); background: rgba(255,180,84,.08); font-size: .78rem; font-weight: 850; cursor: pointer; }

.stepper {
  width: min(700px, calc(100% - 32px));
  margin: 8px auto 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(5,24,36,.7);
  overflow: hidden;
}
.stepper button { min-width: 0; min-height: 54px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-right: 1px solid var(--line); color: var(--muted); background: transparent; cursor: pointer; }
.stepper button:last-child { border-right: 0; }
.stepper button:disabled { cursor: default; opacity: .55; }
.stepper button.is-active { color: var(--ink); background: var(--cream); }
.stepper button.is-complete { color: var(--mint); }
.stepper span { width: 22px; height: 22px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: .7rem; font-weight: 850; }
.stepper strong { font-size: .78rem; }

.flow-shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.flow-screen { min-height: calc(100svh - 172px); padding: 44px 0 64px; }
.flow-screen[data-step-panel="1"] { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, .7fr); align-items: center; gap: clamp(36px, 7vw, 90px); }
.screen-copy { max-width: 630px; }
.eyebrow { margin: 0 0 14px; color: var(--gold); font-size: .78rem; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(2.45rem, 5vw, 4.8rem); line-height: .98; letter-spacing: -.06em; }
.lede { max-width: 620px; margin: 20px 0 0; color: var(--muted); font-size: 1.05rem; line-height: 1.6; }

.subject-choice { margin: 28px 0 12px; padding: 0; border: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.subject-choice legend { grid-column: 1 / -1; padding: 0 0 7px; color: var(--muted); font-size: .84rem; font-weight: 750; }
.choice-card { position: relative; min-height: 76px; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.035); cursor: pointer; }
.choice-card.is-selected { border-color: rgba(255,180,84,.72); background: rgba(255,180,84,.09); }
.choice-card input { position: absolute; opacity: 0; pointer-events: none; }
.choice-card > span:last-child { display: grid; gap: 3px; }
.choice-card strong { font-size: .9rem; }
.choice-card small { color: var(--muted); font-size: .74rem; line-height: 1.35; }
.choice-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; color: var(--gold); background: rgba(255,180,84,.12); font-weight: 850; }

.upload-card { min-height: 88px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 14px; border: 1px dashed rgba(255,180,84,.5); border-radius: 18px; background: rgba(255,247,232,.045); cursor: pointer; }
.upload-card:hover { border-color: var(--gold); background: rgba(255,180,84,.08); }
.upload-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; color: var(--gold); background: rgba(255,180,84,.13); font-size: 1.35rem; font-weight: 800; }
.upload-card > span:nth-child(2) { display: grid; gap: 3px; }
.upload-card small { color: var(--muted); font-size: .78rem; }
.upload-action { padding: 9px 14px; border-radius: 999px; color: var(--ink); background: var(--cream); font-size: .8rem; font-weight: 850; }
.privacy-note { margin-top: 13px; display: flex; gap: 9px; color: var(--muted); font-size: .78rem; line-height: 1.45; }
.privacy-note strong { color: var(--mint); white-space: nowrap; }
.message { min-height: 1.3em; margin: 10px 2px 0; color: var(--muted); font-size: .8rem; line-height: 1.45; }
.message.is-error { color: #ffad9a; }
.message.is-success { color: var(--mint); }

.destination-peek, .canvas-card, .adjust-card, .preview-side, .done-copy, .download-card {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(160deg, rgba(19,54,70,.95), rgba(8,29,42,.93));
  box-shadow: var(--shadow);
}
.destination-peek { position: relative; padding: 13px; }
.destination-peek canvas { width: 100%; display: block; aspect-ratio: 4 / 5; border-radius: 16px; }
.destination-peek > div { display: grid; gap: 2px; padding: 12px 4px 2px; }
.destination-peek span { color: var(--gold); font-size: .74rem; }
.destination-peek strong { font-size: .9rem; }
.slide-button { position: absolute; top: 43%; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.22); border-radius: 50%; color: var(--cream); background: rgba(7,28,43,.72); backdrop-filter: blur(10px); font-size: 1.45rem; cursor: pointer; }
.slide-button.is-previous { left: 22px; }
.slide-button.is-next { right: 22px; }

.mobile-screen-head { max-width: 780px; margin: 0 auto 28px; text-align: center; }
.mobile-screen-head h1 { font-size: clamp(2.25rem, 4.5vw, 4.1rem); }
.mobile-screen-head .lede { margin-left: auto; margin-right: auto; }
.editor-layout, .preview-layout { display: grid; grid-template-columns: minmax(360px, .92fr) minmax(280px, .52fr); gap: 24px; align-items: start; max-width: 930px; margin: 0 auto; }
.canvas-card { padding: 13px; }
.canvas-topline { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 3px 10px; color: var(--muted); font-size: .76rem; }
.canvas-topline strong { max-width: 64%; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canvas-wrap { overflow: hidden; border-radius: 17px; background: #173244; }
.canvas-wrap canvas { width: 100%; display: block; aspect-ratio: 4 / 5; user-select: none; -webkit-user-select: none; cursor: grab; }
#position-canvas { touch-action: none; }
#preview-canvas, #welcome-canvas { touch-action: pan-y; cursor: default; }
.canvas-wrap canvas:active { cursor: grabbing; }
.adjust-card, .preview-side { padding: 20px; }
.adjust-card > div:first-child { display: grid; gap: 5px; }
.adjust-card > div:first-child span { color: var(--muted); font-size: .8rem; line-height: 1.45; }
.adjust-card label { display: flex; justify-content: space-between; margin: 24px 0 8px; color: var(--muted); font-size: .82rem; }
.adjust-card output { color: var(--cream); }
input[type="range"] { width: 100%; accent-color: var(--coral); }
.nudge-grid { margin-top: 18px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.nudge-grid button { min-height: 48px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.06); font-weight: 850; cursor: pointer; }
.nudge-grid button:hover { border-color: var(--gold); background: rgba(255,180,84,.1); }

.screen-actions { display: grid; grid-template-columns: 1fr 1.2fr; gap: 8px; margin-top: 20px; }
.button { min-height: 48px; border: 0; border-radius: 14px; padding: 10px 15px; font-weight: 850; cursor: pointer; }
.button:disabled { opacity: .55; cursor: wait; }
.button-primary { color: #15232a; background: linear-gradient(135deg, var(--gold), #ffd08d); box-shadow: 0 9px 28px rgba(255,180,84,.16); }
.button-quiet { color: var(--muted); background: rgba(255,255,255,.06); }
.button-wide { width: min(100%, 340px); }
.text-button { border: 0; padding: 10px; color: var(--gold); background: transparent; font-weight: 750; cursor: pointer; }

.result-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; max-height: 560px; overflow: auto; }
.result-card { min-width: 0; padding: 5px; border: 1px solid var(--line); border-radius: 13px; color: var(--muted); background: rgba(255,255,255,.035); cursor: pointer; text-align: left; }
.result-card.is-active { color: var(--cream); border-color: var(--gold); background: rgba(255,180,84,.09); }
.result-card canvas { width: 100%; display: block; border-radius: 9px; aspect-ratio: 4 / 5; }
.result-card span { display: block; overflow: hidden; padding: 6px 3px 2px; font-size: .72rem; font-weight: 750; white-space: nowrap; text-overflow: ellipsis; }

.done-screen { display: grid; gap: 22px; max-width: 1000px; margin: 0 auto; text-align: center; }
.done-copy { padding: 26px; }
.done-copy h1 { font-size: clamp(2.35rem, 4.5vw, 4rem); }
.done-mark { width: 56px; height: 56px; display: grid; place-items: center; margin-bottom: 22px; border-radius: 18px; color: var(--ink); background: var(--mint); font-size: 1.5rem; font-weight: 900; }
.done-mark { margin-left: auto; margin-right: auto; }
.running-gallery { width: 100%; overflow: hidden; padding: 8px 0 14px; mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent); }
.running-track { width: max-content; display: flex; gap: 12px; animation: photo-run 28s linear infinite; }
.running-track:hover { animation-play-state: paused; }
.running-photo { width: 150px; flex: 0 0 auto; margin: 0; }
.running-photo canvas { width: 100%; display: block; border: 1px solid var(--line); border-radius: 17px; aspect-ratio: 4 / 5; box-shadow: var(--shadow); }
.running-photo figcaption { overflow: hidden; padding: 7px 4px 0; color: var(--muted); font-size: .72rem; white-space: nowrap; text-overflow: ellipsis; }
.done-actions { display: grid; justify-items: center; gap: 9px; }
.done-actions .button { margin: 0; }
@keyframes photo-run { to { transform: translateX(calc(-50% - 6px)); } }

.process-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 22px; background: rgba(3,20,31,.88); backdrop-filter: blur(14px); }
.process-card { width: min(390px,100%); display: grid; justify-items: center; padding: 28px; border: 1px solid var(--line); border-radius: 24px; background: var(--panel); text-align: center; box-shadow: var(--shadow); }
.process-card strong { margin-top: 15px; }
.process-card > span { margin-top: 5px; color: var(--muted); font-size: .82rem; }
.spinner { width: 42px; height: 42px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--gold); border-radius: 50%; animation: spin 850ms linear infinite; }
.progress-track { width: 100%; height: 5px; overflow: hidden; margin-top: 20px; border-radius: 99px; background: rgba(255,255,255,.12); }
.progress-track span { display: block; width: 8%; height: 100%; background: linear-gradient(90deg,var(--coral),var(--gold)); transition: width 220ms ease; }
@keyframes spin { to { transform: rotate(360deg); } }

footer { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 20px 0 32px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 14px; color: rgba(170,193,198,.62); font-size: .73rem; }

@media (max-width: 820px) {
  .privacy-chip { display: none; }
  .site-header { min-height: 64px; }
  .brand img { width: 34px; height: 34px; }
  .stepper { position: sticky; top: 8px; z-index: 20; margin-top: 0; box-shadow: 0 10px 28px rgba(0,10,18,.24); backdrop-filter: blur(16px); }
  .stepper button { min-height: 50px; flex-direction: column; gap: 2px; }
  .stepper strong { font-size: .64rem; }
  .stepper span { width: 20px; height: 20px; }
  .flow-screen { min-height: calc(100svh - 130px); padding: 20px 0 38px; }
  .flow-screen[data-step-panel="1"], .editor-layout, .preview-layout, .done-screen { grid-template-columns: 1fr; }
  .screen-copy { max-width: none; }
  h1 { font-size: clamp(2.15rem, 9.5vw, 3.25rem); }
  .destination-peek { width: min(58vw, 240px); margin: 18px auto 0; padding: 9px; }
  .destination-peek > div { padding-top: 8px; text-align: left; }
  .slide-button { top: 42%; width: 34px; height: 34px; }
  .slide-button.is-previous { left: 15px; }
  .slide-button.is-next { right: 15px; }
  .mobile-screen-head { text-align: left; margin-bottom: 13px; }
  .mobile-screen-head h1 { font-size: clamp(2rem, 8.8vw, 2.8rem); }
  .mobile-screen-head .lede { margin-left: 0; }
  .mobile-screen-head .lede { margin-top: 10px; font-size: .95rem; line-height: 1.45; }
  .mobile-screen-head .eyebrow { margin-bottom: 8px; }
  .editor-layout, .preview-layout { gap: 14px; }
  .canvas-card { padding: 10px; }
  .editor-layout > .canvas-card { width: min(60vw, 240px); margin: 0 auto; }
  .preview-layout > .canvas-card { width: min(68vw, 270px); margin: 0 auto; }
  .adjust-card, .preview-side { padding: 16px; }
  .adjust-card label { margin-top: 14px; }
  .nudge-grid { margin-top: 10px; }
  .screen-actions { margin-top: 12px; }
  .result-gallery { display: flex; max-height: none; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x mandatory; }
  .result-card { flex: 0 0 104px; scroll-snap-align: start; }
  .done-copy { padding: 22px; }
  .running-photo { width: 126px; }
}

@media (max-width: 520px) {
  .site-header, .flow-shell, footer, .stepper { width: min(100% - 22px, 1120px); }
  .site-header { min-height: 56px; }
  .brand img { width: 30px; height: 30px; }
  .language-toggle { min-height: 34px; padding: 5px 10px; }
  .stepper { top: 5px; border-radius: 14px; }
  .stepper button { min-height: 45px; }
  .brand span { font-size: .86rem; }
  .upload-card { grid-template-columns: auto 1fr; }
  .upload-action { grid-column: 1 / -1; text-align: center; }
  .privacy-note { align-items: flex-start; flex-direction: column; gap: 2px; }
  .canvas-topline { font-size: .72rem; }
  .flow-screen { padding-top: 16px; }
  .lede { margin-top: 12px; font-size: .95rem; line-height: 1.5; }
  .flow-screen[data-step-panel="2"], .flow-screen[data-step-panel="3"] { padding-bottom: 108px; }
  .screen-actions { position: fixed; left: 11px; right: 11px; bottom: max(8px, env(safe-area-inset-bottom)); z-index: 30; padding: 8px; margin: 0; border: 1px solid var(--line); border-radius: 16px; background: rgba(7,28,43,.94); box-shadow: 0 14px 36px rgba(0,10,18,.38); backdrop-filter: blur(16px); }

  .flow-screen[data-step-panel="3"] {
    height: calc(100svh - 106px);
    min-height: 0;
    overflow: hidden;
    padding-top: 9px;
    padding-bottom: calc(82px + env(safe-area-inset-bottom));
  }
  .flow-screen[data-step-panel="3"] .mobile-screen-head { margin-bottom: 7px; text-align: center; }
  .flow-screen[data-step-panel="3"] .mobile-screen-head .eyebrow { display: none; }
  .flow-screen[data-step-panel="3"] .mobile-screen-head h1 { font-size: clamp(1.45rem, 6.5vw, 1.85rem); line-height: 1.06; letter-spacing: -.04em; }
  .flow-screen[data-step-panel="3"] .mobile-screen-head .lede { margin-top: 5px; font-size: .76rem; line-height: 1.3; }
  .flow-screen[data-step-panel="3"] .preview-layout { gap: 7px; }
  .flow-screen[data-step-panel="3"] .preview-layout > .canvas-card {
    width: min(44vw, 180px);
    padding: 6px;
    border-radius: 17px;
    place-self: center;
  }
  .flow-screen[data-step-panel="3"] .canvas-topline { min-height: 23px; padding: 0 2px 5px; font-size: .62rem; }
  .flow-screen[data-step-panel="3"] .canvas-wrap { border-radius: 11px; }
  .flow-screen[data-step-panel="3"] .preview-side {
    width: 100%;
    min-width: 0;
    margin: 0 auto;
    padding: 7px;
    border-radius: 15px;
  }
  .flow-screen[data-step-panel="3"] .result-gallery {
    width: 100%;
    gap: 6px;
    padding: 0 1px 2px;
    scrollbar-width: none;
  }
  .flow-screen[data-step-panel="3"] .result-gallery::-webkit-scrollbar { display: none; }
  .flow-screen[data-step-panel="3"] .result-card { flex-basis: 66px; padding: 3px; border-radius: 9px; }
  .flow-screen[data-step-panel="3"] .result-card canvas { border-radius: 6px; }
  .flow-screen[data-step-panel="3"] .result-card span { padding: 3px 2px 1px; font-size: .58rem; }
  .flow-screen[data-step-panel="3"] .screen-actions { grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); }
  .flow-screen[data-step-panel="3"] .screen-actions .button { min-height: 50px; }
  .brand small { display: block; font-size: .59em; }
  .running-photo { width: 112px; }
  footer { display: none; }
}

@media (max-width: 520px) and (max-height: 700px) {
  .flow-screen[data-step-panel="3"] .mobile-screen-head .lede { display: none; }
  .flow-screen[data-step-panel="3"] .preview-layout > .canvas-card { width: min(38vw, 145px); }
  .flow-screen[data-step-panel="3"] .result-card { flex-basis: 58px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
