:root {
  --paper: #f3efe6;
  --paper-deep: #e7e0d3;
  --card: #fffdf8;
  --ink: #1c1712;
  --ink-soft: #5e574e;
  --ink-faint: #8a8278;
  --line: #e4dcd0;
  --line-strong: #d3cab9;
  --chop: #b42318;
  --chop-ink: #8b1a12;
  --chop-soft: #f8e8e4;
  --ok: #0f6b4c;
  --ok-soft: #e3f3ec;
  --warn: #8a5a12;
  --warn-soft: #f8efda;
  --shadow: 0 1px 2px rgba(28, 23, 18, 0.05), 0 10px 28px rgba(28, 23, 18, 0.07);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --font: "PingFang TC", "Hiragino Sans CNS", "Noto Sans CJK HK", "Noto Sans CJK TC",
    -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
  font-size: 16px;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
img { max-width: 100%; display: block; }

.app {
  width: min(430px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

.view {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding: calc(14px + var(--safe-top)) 20px calc(24px + var(--safe-bot));
}
.view.active { display: flex; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 18px;
}
.topbar h1, .topbar .view-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0;
  flex: 1;
  text-align: center;
}
.topbar .side {
  width: 72px;
  flex: 0 0 72px;
}
.topbar .side.right { text-align: right; }

.back, .text-btn {
  color: var(--ink-soft);
  font-size: 15px;
  padding: 8px 0;
  min-height: 44px;
}
.back:active, .text-btn:active { opacity: 0.55; }

/* Home */
.brand { padding: 8px 2px 22px; }
.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.chop {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: var(--chop);
  color: #fffaf5;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0;
  box-shadow: 0 6px 16px rgba(180, 35, 24, 0.22);
  flex: 0 0 52px;
}
.brand h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: 0.08em;
  line-height: 1.15;
}
.brand .en {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}
.lede {
  margin: 16px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.55;
}

.section-label {
  margin: 8px 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 96px;
  padding: 16px 14px 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.12s ease, background 0.12s ease;
}
.tile:active { transform: scale(0.98); background: #faf6ef; }
.tile .glyph {
  width: 28px;
  height: 28px;
  color: var(--chop);
  margin-bottom: 16px;
}
.tile .zh { display: block; font-weight: 600; font-size: 16px; }
.tile .en { display: block; font-size: 12px; color: var(--ink-faint); margin-top: 2px; }

.sample-list, .history-list { display: flex; flex-direction: column; gap: 10px; }
.sample-card, .history-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 14px;
  text-align: left;
  width: 100%;
}
.sample-card:active, .history-card:active { background: #faf6ef; }
.kicker {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--chop);
  font-weight: 600;
  margin: 0 0 4px;
}
.sample-card .zh, .history-card .zh {
  font-weight: 600;
  font-size: 16px;
  margin: 0;
}
.sample-card .en, .history-card .meta {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--chop-soft);
  color: var(--chop-ink);
  font-weight: 500;
}
.chip.quiet { background: var(--paper-deep); color: var(--ink-soft); }

.privacy {
  margin: 28px 2px 8px;
  font-size: 12px;
  color: var(--ink-faint);
  line-height: 1.55;
}
.child-row {
  margin: 6px 0 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.child-row label { font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.child-row input {
  flex: 1;
  border: 0;
  background: transparent;
  outline: none;
  min-width: 0;
  font-size: 16px;
}

/* Forms */
.stack { display: flex; flex-direction: column; gap: 14px; flex: 1; }
.note, .hint {
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--warn-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  line-height: 1.55;
}
.hint.ok { background: var(--ok-soft); color: var(--ok); }
.hint.plain { background: var(--paper-deep); }

.textarea, .field input[type="text"], .field input[type="date"], .field input[type="time"] {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px; /* prevent iOS zoom */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.textarea:focus, .field input:focus {
  border-color: #b7aa96;
  box-shadow: 0 0 0 3px rgba(28, 23, 18, 0.06);
}
.textarea {
  min-height: 280px;
  resize: vertical;
  line-height: 1.6;
  letter-spacing: 0.01em;
}

.group {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.field {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  align-items: center;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  min-height: 52px;
}
.field:first-child { border-top: 0; }
.field.block {
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 6px;
}
.field label, .lbl {
  font-size: 13px;
  color: var(--ink-soft);
}
.field input, .field textarea {
  border: 0;
  background: transparent;
  padding: 4px 0;
  width: 100%;
  min-width: 0;
  outline: none;
  box-shadow: none;
}
.field textarea { min-height: 64px; resize: vertical; line-height: 1.5; }
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.switch {
  position: relative;
  width: 48px;
  height: 30px;
  border-radius: 999px;
  background: #d7d0c4;
  transition: background 0.15s ease;
  flex: 0 0 48px;
}
.switch[aria-checked="true"] { background: var(--ok); }
.switch i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.15s ease;
}
.switch[aria-checked="true"] i { transform: translateX(18px); }

.items { display: flex; flex-direction: column; gap: 8px; }
.item-row { display: flex; gap: 8px; align-items: center; }
.item-row input { flex: 1; border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; background: var(--card); font-size: 16px; }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--ink-soft);
  flex: 0 0 36px;
}
.icon-btn:active { background: var(--paper-deep); }
.linkish {
  color: var(--chop-ink);
  font-size: 14px;
  font-weight: 550;
  padding: 4px 0 0;
  text-align: left;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 18px -20px 0;
  padding: 16px 20px 8px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to bottom, rgba(243,239,230,0) 0, var(--paper) 14px, var(--paper) 100%);
  padding-bottom: calc(8px + var(--safe-bot));
}
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 16px;
  padding: 12px 16px;
  width: 100%;
}
.btn.primary { background: var(--ink); color: #faf6ef; }
.btn.primary:active { background: #2a241d; }
.btn.accent { background: var(--chop); color: #fffaf5; }
.btn.accent:active { background: var(--chop-ink); }
.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
}
.btn:disabled { opacity: 0.45; }
.btn.danger { color: var(--chop); }

/* Preview / progress */
.preview-frame {
  background: #1c1712;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 280px;
  display: grid;
  place-items: center;
}
.preview-frame img, .preview-frame canvas {
  max-height: 58dvh;
  width: 100%;
  object-fit: contain;
}
.progress-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: 24px 4px; }
.progress-label { text-align: center; color: var(--ink-soft); font-size: 15px; }
.bar {
  height: 6px;
  background: var(--paper-deep);
  border-radius: 99px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--chop);
  border-radius: 99px;
  transition: width 0.2s ease;
}

/* Done + history detail */
.stamp {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--ok-soft);
  color: var(--ok);
  display: grid;
  place-items: center;
  font-size: 30px;
  margin: 8px auto 16px;
}
.done-title { text-align: center; font-size: 22px; font-weight: 650; margin: 0 0 6px; }
.done-sub { text-align: center; color: var(--ink-soft); margin: 0 0 22px; font-size: 14px; }

.summary {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.summary h2 { margin: 0 0 8px; font-size: 18px; }
.summary dl { margin: 0; display: grid; grid-template-columns: 76px 1fr; gap: 6px 10px; font-size: 14px; }
.summary dt { color: var(--ink-faint); }
.summary dd { margin: 0; }

.empty {
  text-align: center;
  color: var(--ink-faint);
  font-size: 14px;
  padding: 12px 8px 4px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bot));
  transform: translateX(-50%) translateY(16px);
  background: var(--ink);
  color: #faf6ef;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: min(360px, calc(100% - 32px));
  z-index: 20;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.quote-preview {
  margin-top: 8px;
  padding: 10px 12px;
  border-left: 3px solid var(--chop);
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.55;
}

@media (prefers-reduced-motion: reduce) {
  .tile, .bar > i, .toast, .switch, .switch i { transition: none; }
}

.file-banner {
  margin: 16px 16px 0;
  padding: 14px 16px;
  background: var(--warn-soft);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  line-height: 1.5;
}
.file-banner[hidden] { display: none !important; }
.file-banner code {
  font-size: 0.92em;
  background: var(--paper-deep);
  padding: 0.1em 0.35em;
  border-radius: 6px;
}
