:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --surface-2: #f5ede0;
  --ink: #2a211a;
  --muted: #6b5e52;
  --line: #e6dccd;
  --primary: #c93a25;
  --on-primary: #ffffff;
  --primary-soft: #fce8e2;
  --accent: #14747a;
  --paper: #fffdf8;
  --shadow: 0 8px 28px rgba(60, 40, 20, .14);
  --r: 16px;
  --dock-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17130f; --surface: #221c17; --surface-2: #2c241d; --ink: #f4ece2; --muted: #b8aa9a;
    --line: #3a3028; --primary: #ff7a5f; --on-primary: #1a0e0a; --primary-soft: #3b2119;
    --accent: #4cc2c7; --paper: #2a231d; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden; overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
svg.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }

#app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; position: relative; }

/* top bar */
.bar { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 10px) 16px 8px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: .5px; flex: 1; }
.logo i { width: 28px; height: 28px; border-radius: 9px; background: var(--primary); display: grid; grid-template: repeat(3,1fr)/repeat(3,1fr); gap: 2px; padding: 5px; }
.logo i b { background: var(--on-primary); border-radius: 50%; opacity: .95; }
.logo i b:nth-child(even) { opacity: .45; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; color: var(--ink); transition: background .15s; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* empty state */
.empty { flex: 1; overflow: auto; padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 18px; }
.hero h1 { font-size: 30px; line-height: 1.2; margin: 8px 0 8px; letter-spacing: .5px; }
.hero p { margin: 0; color: var(--muted); }
.drop {
  border: 2px dashed var(--line); border-radius: 24px; background: var(--surface);
  padding: 28px 20px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
.drop .big { width: 64px; height: 64px; border-radius: 20px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.drop .big svg { width: 30px; height: 30px; }
.drop strong { font-size: 18px; }
.drop small { color: var(--muted); }
.btn {
  min-height: 48px; padding: 0 22px; border-radius: 14px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--primary); color: var(--on-primary); transition: filter .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.line { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn.sm { min-height: 40px; padding: 0 14px; border-radius: 12px; font-size: 14px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.feat { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.feat div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.feat svg { color: var(--accent); margin-top: 1px; }
.feat b { display: block; font-size: 15px; }
.feat span { color: var(--muted); font-size: 13px; line-height: 1.4; display: block; }
.credit { color: var(--muted); font-size: 12px; text-align: center; }

/* stage */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.viewport { position: relative; flex: 1; min-height: 0; margin: 0 12px; border-radius: 20px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.viewport canvas.main { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.chip {
  position: absolute; left: 12px; top: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px 6px 8px; display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; box-shadow: var(--shadow); pointer-events: none;
}
.chip i { width: 20px; height: 20px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); }
.chip small { font-weight: 500; color: var(--muted); }
.info { position: absolute; right: 12px; top: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--muted); pointer-events: none; }
.zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.zoom button { width: 44px; height: 44px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; box-shadow: var(--shadow); }
.loupe { position: absolute; width: 132px; height: 132px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: var(--shadow); pointer-events: none; background: var(--paper); }
.loupe::after { content: ""; position: absolute; inset: 50% auto auto 50%; width: 14px; height: 14px; margin: -7px; border: 2px solid var(--primary); border-radius: 3px; }

.tools { display: flex; align-items: center; gap: 4px; padding: 10px 12px 6px; overflow-x: auto; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.tool { min-width: 46px; height: 52px; padding: 4px 4px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 11px; font-weight: 600; color: var(--muted); flex: none; }
.tool[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); }
.tool.focus { margin-left: auto; background: var(--ink); color: var(--bg); padding: 4px 12px; flex-direction: row; gap: 6px; font-size: 13px; min-width: 0; }
.strip { display: flex; gap: 8px; padding: 0 12px 6px; overflow-x: auto; scrollbar-width: none; align-items: center; }
.strip::-webkit-scrollbar { display: none; }
.sw { flex: none; width: 44px; height: 44px; border-radius: 12px; border: 2px solid transparent; position: relative; display: grid; place-items: end center; font-size: 10px; font-weight: 700; padding-bottom: 2px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.sw[aria-pressed="true"] { border-color: var(--ink); outline: 2px solid var(--surface); outline-offset: -4px; }
.sw span { background: rgba(255,255,255,.82); color: #222; border-radius: 4px; padding: 0 3px; line-height: 14px; }
.strip .more { flex: none; width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; }

/* dock */
.dock { display: grid; grid-template-columns: repeat(4, 1fr); padding: 6px 8px calc(var(--safe-b) + 6px); background: var(--surface); border-top: 1px solid var(--line); }
.dock button { min-height: 52px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); }
.dock button[aria-pressed="true"] { color: var(--primary); }
.dock button[aria-pressed="true"] svg { stroke-width: 2.5; }

/* sheet */
.backdrop { position: fixed; inset: 0; background: rgba(20, 12, 6, .45); z-index: 30; animation: fade .2s; }
.backdrop.modeless { background: transparent; pointer-events: none; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; max-width: 720px; margin: 0 auto; background: var(--surface);
  border-radius: 24px 24px 0 0; box-shadow: 0 -10px 40px rgba(40, 24, 10, .22); max-height: 88dvh; display: flex; flex-direction: column;
  padding-bottom: var(--safe-b); animation: up .25s cubic-bezier(.2,.8,.2,1);
}
.sheet.peek { max-height: 42dvh; }
.sheet.tall { height: 88dvh; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet header { display: flex; align-items: center; padding: 6px 8px 6px 20px; flex: none; }
.sheet header h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet .body { overflow: auto; padding: 4px 20px 20px; display: flex; flex-direction: column; gap: 18px; overscroll-behavior: contain; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.field label, .lbl { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.lbl em { font-style: normal; font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 13px; margin: 2px 0 0; line-height: 1.45; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); font-size: 22px; font-weight: 700; flex: none; }
input[type=range] { flex: 1; height: 44px; accent-color: var(--primary); margin: 0; min-width: 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { min-height: 40px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); font-weight: 600; font-size: 14px; }
.chip-btn[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.switch b { display: block; font-size: 15px; }
.switch span { color: var(--muted); font-size: 13px; }
.switch input { appearance: none; width: 52px; height: 32px; border-radius: 16px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .2s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(20px); }
.input, textarea.input { width: 100%; min-height: 46px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); padding: 10px 12px; }
textarea.input { min-height: 96px; resize: vertical; }
.list { display: flex; flex-direction: column; }
.stat { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 4px 0; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.stat .dot { width: 32px; height: 32px; border-radius: 10px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); flex: none; }
.stat b { width: 54px; font-variant-numeric: tabular-nums; }
.stat .bar2 { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.stat .bar2 i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.stat .n { width: 48px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.stat.off { opacity: .45; }
.stat.off b, .stat.off .n { text-decoration: line-through; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary div { background: var(--surface-2); border-radius: 14px; padding: 10px; text-align: center; }
.summary b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.summary span { font-size: 12px; color: var(--muted); }
.grid-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 8px; }
.grid-pick .sw { width: auto; height: 56px; }
.series { font-weight: 800; font-size: 13px; color: var(--muted); margin: 6px 0 -6px; display: flex; align-items: center; gap: 10px; }
.series button { margin-left: auto; font-size: 13px; color: var(--accent); font-weight: 700; min-height: 32px; padding: 0 6px; }
.sw.off { opacity: .28; }
.sw.on::before { content: ""; position: absolute; top: 3px; right: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--ink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/10px no-repeat; }
.sticky { position: sticky; bottom: -20px; background: var(--surface); padding: 10px 0 4px; display: flex; gap: 10px; }
.sticky .btn { flex: 1; }
.progress { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .3s; }
.preview-img { width: 100%; max-height: 40dvh; object-fit: contain; border-radius: 14px; background: var(--surface-2); image-rendering: auto; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--dock-h) + var(--safe-b) + 24px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 80; max-width: 88vw; text-align: center; animation: fade .2s; pointer-events: none; }

/* cropper + focus overlays */
.overlay { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
.overlay > header { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 8px) 12px 8px; }
.overlay > header h2 { flex: 1; margin: 0; font-size: 17px; }
.crop-stage { flex: 1; min-height: 0; position: relative; margin: 0 12px; background: #1b1511; border-radius: 16px; overflow: hidden; touch-action: none; user-select: none; }
.crop-stage img { position: absolute; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.crop-box { position: absolute; box-shadow: 0 0 0 9999px rgba(0,0,0,.55); border: 2px solid #fff; cursor: move; touch-action: none;
  background-image: linear-gradient(rgba(255,255,255,.35) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.35) 1px, transparent 1px);
  background-size: 33.333% 33.333%; }
.crop-box .h { position: absolute; width: 44px; height: 44px; touch-action: none; }
.crop-box .h::after { content: ""; position: absolute; width: 22px; height: 22px; background: #fff; border-radius: 6px; box-shadow: 0 1px 6px rgba(0,0,0,.5); }
.crop-box .h.nw { left: -22px; top: -22px; } .crop-box .h.nw::after { left: 11px; top: 11px; }
.crop-box .h.ne { right: -22px; top: -22px; } .crop-box .h.ne::after { right: 11px; top: 11px; }
.crop-box .h.sw { left: -22px; bottom: -22px; } .crop-box .h.sw::after { left: 11px; bottom: 11px; }
.crop-box .h.se { right: -22px; bottom: -22px; } .crop-box .h.se::after { right: 11px; bottom: 11px; }
.overlay .foot { padding: 12px 12px calc(var(--safe-b) + 12px); display: flex; flex-direction: column; gap: 10px; }
.focus-view { flex: 1; min-height: 0; position: relative; margin: 0 12px; border-radius: 20px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.focus-view canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.focus-stat { padding: 10px 16px 4px; display: flex; align-items: center; gap: 12px; }
.focus-stat .progress { flex: 1; }
.focus-stat b { font-variant-numeric: tabular-nums; font-size: 14px; }
.sw small { position: absolute; top: -2px; right: -2px; background: var(--ink); color: var(--bg); border-radius: 9px; min-width: 18px; padding: 0 4px; font-size: 10px; line-height: 18px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (min-width: 720px) { .viewport { margin: 0 16px; } }

/* lock screen + landing badge */
.lock { flex: 1; display: grid; place-items: center; padding: 16px; }
.lock form { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 28px 22px; display: flex; flex-direction: column; gap: 14px; align-items: stretch; text-align: center; box-shadow: var(--shadow); }
.lock h1 { margin: 0; font-size: 20px; }
.lock .big { width: 56px; height: 56px; border-radius: 18px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; margin: 0 auto; }
.lock .input { text-align: center; font-size: 17px; letter-spacing: 2px; }
.hint.err { color: var(--primary); font-weight: 600; margin: -4px 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lockpill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; }
.lockpill svg { width: 14px; height: 14px; }
