/* scan.chonrieng.com — same look as the Chốn Riêng homepage: a desk lamp in a dark room,
   one accent (lamp yellow), League Spartan for display, Be Vietnam Pro for text. */
:root {
  --ink: #0f0e0c;
  --ink-2: #171512;
  --ink-3: #211e1a;
  --paper: #f2ede3;
  --muted: #a59d8f;
  --line: rgba(242, 237, 227, 0.12);
  --lamp: #f2c14e;
  --lamp-ink: #1b1508;
  --bad: #ff7a6b;
  --r: 14px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --display: "League Spartan", "Be Vietnam Pro", system-ui, sans-serif;
  --body: "Be Vietnam Pro", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 30% -10%, rgba(242, 193, 78, 0.1), transparent 60%),
    var(--ink);
  color: var(--paper);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.is-editing, body.is-sheet { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--lamp); outline-offset: 3px; border-radius: 8px; }

.ico { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- top ---------- */
.top {
  display: flex; align-items: center; gap: 10px;
  max-width: 640px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 6px;
}
.brand {
  font-family: var(--display); font-weight: 700; font-size: 1.32rem;
  letter-spacing: -0.03em; text-decoration: none;
}
.brand-tag {
  font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--lamp-ink); background: var(--lamp);
  padding: 3px 9px 2px; border-radius: 999px; font-weight: 600;
}

.wrap { max-width: 640px; margin: 0 auto; padding: 0 20px 140px; }

/* ---------- home ---------- */
.hero { padding-top: 8px; }
.cat-scene { display: block; width: min(100%, 360px); margin: 6px auto 4px; overflow: visible; }
.cat-scene .eye, .cat-scene .pupil, .cat-scene .glint { transform-box: fill-box; transform-origin: center; animation: blink 5.5s infinite; }
.cat-scene .scan-line { opacity: 0; }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 95.5% { transform: scaleY(0.08); } }

.title {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(2.6rem, 11vw, 3.6rem); line-height: 0.96; letter-spacing: -0.03em;
  margin: 8px 0 14px;
}
.lamp-word { color: var(--lamp); }
.lead { color: #d8d1c4; margin: 0 0 22px; max-width: 34em; }

.cta { display: grid; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.55em;
  min-height: 52px; padding: 0.85em 1.4em;
  border: 1px solid transparent; border-radius: 999px;
  font-weight: 600; white-space: nowrap;
  transition: background 0.3s var(--ease), border-color 0.3s var(--ease), transform 0.15s var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn--lamp { background: var(--lamp); color: var(--lamp-ink); box-shadow: 0 8px 30px -10px rgba(242, 193, 78, 0.55); }
.btn--lamp:hover { background: #ffd56e; }
.btn--ghost { background: var(--ink-2); border-color: var(--line); }
.btn--ghost:hover { border-color: rgba(242, 237, 227, 0.3); }
.btn--wide { width: 100%; }
.btn--sm { min-height: 44px; padding: 0.55em 1.05em; font-size: 0.94rem; }

.tips { list-style: none; margin: 28px 0 0; padding: 0; display: grid; gap: 10px; }
.tips li {
  position: relative; padding: 12px 14px 12px 40px;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--r);
  color: #cfc8ba; font-size: 0.94rem;
}
.tips li::before {
  content: ""; position: absolute; left: 15px; top: 19px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--lamp); box-shadow: 0 0 12px 3px rgba(242, 193, 78, 0.45);
}
.tips b { color: var(--paper); font-weight: 600; }

.privacy {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 26px 0 0; color: var(--muted); font-size: 0.86rem;
}
.privacy .ico { margin-top: 2px; color: var(--lamp); }

/* ---------- pages ---------- */
.pages { padding-top: 10px; }
.pages-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.pages-title { font-family: var(--display); font-size: 2rem; letter-spacing: -0.02em; margin: 6px 0 12px; }
.link-btn { background: none; border: 0; padding: 8px 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.link-btn[data-armed] { color: var(--bad); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 10px; }
.chips button {
  flex: 1 1 auto; min-height: 40px; padding: 0 10px; border-radius: 999px; white-space: nowrap;
  background: var(--ink-2); border: 1px solid var(--line); color: #d8d1c4; font-size: 0.86rem;
}
.chips button[aria-checked="true"] { background: var(--paper); color: var(--ink); border-color: var(--paper); font-weight: 600; }

.page-grid { list-style: none; margin: 6px 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (min-width: 560px) { .page-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.page-card { position: relative; background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--r); padding: 8px; }
.page-thumb {
  position: relative; display: grid; place-items: center; width: 100%; aspect-ratio: 3 / 4;
  padding: 0; border: 0; border-radius: 8px; background: var(--ink-3); overflow: hidden;
}
.page-thumb img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45); }
.page-thumb img:not([src]) { display: none; }
.page-card.is-loading .page-thumb::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; border-radius: 3px;
  background: var(--lamp); box-shadow: 0 0 14px 2px rgba(242, 193, 78, 0.6);
  animation: sweep 1.2s ease-in-out infinite alternate;
}
@keyframes sweep { to { top: calc(100% - 3px); } }
.page-no {
  position: absolute; top: 14px; left: 14px; min-width: 26px; height: 26px; padding: 0 7px;
  display: grid; place-items: center; border-radius: 999px;
  background: var(--lamp); color: var(--lamp-ink); font-weight: 700; font-size: 0.82rem;
}
.page-tools { display: flex; justify-content: space-between; margin-top: 6px; }
.page-tools button {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 10px; color: #d8d1c4;
}
.page-tools button:hover { background: var(--ink-3); }
.page-tools button:disabled { opacity: 0.25; cursor: default; }
.page-tools svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.hint-small { color: var(--muted); font-size: 0.86rem; margin: 12px 0 0; }

/* ---------- dock ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 14px 20px calc(14px + var(--safe-b));
  background: linear-gradient(to top, var(--ink) 55%, rgba(15, 14, 12, 0));
}
.dock .btn { max-width: 600px; margin: 0 auto; display: flex; }

.foot { max-width: 640px; margin: 0 auto; padding: 0 20px calc(110px + var(--safe-b)); color: var(--muted); font-size: 0.84rem; }
.foot a { color: var(--paper); }

/* ---------- editor ---------- */
.editor {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column;
  background: #070706;
  padding: env(safe-area-inset-top, 0px) 0 var(--safe-b);
}
.editor-hint { margin: 0; padding: 14px 20px 10px; text-align: center; color: #d8d1c4; font-size: 0.94rem; }
.editor-stage { position: relative; flex: 1; margin: 0 14px; touch-action: none; user-select: none; -webkit-user-select: none; }
.editor-img { position: absolute; display: block; pointer-events: none; -webkit-user-drag: none; }
.editor-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.editor-shade { fill: rgba(7, 7, 6, 0.55); }
.editor-quad { fill: rgba(242, 193, 78, 0.08); stroke: var(--lamp); stroke-width: 2; stroke-linejoin: round; }
.editor-quad.is-bad { stroke: var(--bad); fill: rgba(255, 122, 107, 0.1); }
.editor-handle-hit { fill: transparent; }
.editor-handle-dot { fill: var(--lamp); stroke: #070706; stroke-width: 2.5; transition: r 0.15s var(--ease); }
.editor-handle.is-active .editor-handle-dot { r: 13; }
.editor-loupe {
  position: absolute; width: 140px; height: 140px; border-radius: 50%;
  border: 2px solid var(--lamp); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6); pointer-events: none;
}
.editor-bar { display: flex; gap: 8px; align-items: center; padding: 12px 14px; }
.editor-gap { flex: 1; }

/* ---------- sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.sheet-panel {
  position: relative; width: 100%; max-width: 560px;
  background: var(--ink-2); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(18px + var(--safe-b));
  display: grid; gap: 12px;
  animation: rise 0.35s var(--ease);
}
.sheet-panel > div { display: grid; gap: 12px; }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
.sheet-title { font-family: var(--display); font-size: 1.7rem; letter-spacing: -0.02em; margin: 0 0 4px; }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; }
.field-label { color: var(--muted); font-size: 0.86rem; }
.field-row { display: flex; align-items: center; background: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; }
.field-row:focus-within { border-color: var(--lamp); }
.field-input { flex: 1; min-width: 0; min-height: 48px; background: none; border: 0; outline: 0; color: var(--paper); font: inherit; font-size: 16px; }
.field-suffix { color: var(--muted); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--ink); border: 1px solid var(--line); border-radius: 14px; padding: 4px; }
.seg button { min-height: 42px; border: 0; border-radius: 10px; background: none; color: #d8d1c4; font-size: 0.94rem; }
.seg button[aria-checked="true"] { background: var(--paper); color: var(--ink); font-weight: 600; }
.sheet-later { justify-self: center; }
.sheet-result { margin: 0 0 6px; color: #d8d1c4; word-break: break-all; }
.sheet-working { justify-items: center; padding: 26px 0 30px; }
.sheet-progress { margin: 0; color: #d8d1c4; }

/* small "cat scanning" loader used while busy */
.mini-cat { position: relative; width: 64px; height: 48px; }
.mini-cat::before {
  content: ""; position: absolute; left: 8px; right: 8px; top: 10px; bottom: 0; border-radius: 4px; background: var(--paper);
}
.mini-cat::after {
  content: ""; position: absolute; left: 4px; right: 4px; top: 10px; height: 3px; border-radius: 3px;
  background: var(--lamp); box-shadow: 0 0 12px 2px rgba(242, 193, 78, 0.7);
  animation: mini-scan 1s ease-in-out infinite alternate;
}
.mini-cat span {
  position: absolute; left: 50%; top: 0; width: 26px; height: 16px; margin-left: -13px;
  background: #1d1a17; border-radius: 13px 13px 4px 4px;
}
@keyframes mini-scan { to { transform: translateY(34px); } }

.busy {
  position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: rgba(7, 7, 6, 0.78); color: #d8d1c4;
}
.busy p { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); z-index: 60;
  transform: translateX(-50%); width: min(92vw, 520px);
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 14px;
  background: var(--paper); color: var(--ink); font-size: 0.92rem;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
}
.toast-action { margin-left: auto; background: none; border: 0; color: var(--ink); font-weight: 700; text-decoration: underline; padding: 6px 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
