:root {
  --purple: #887BA6;
  --violet: #7D79D9;
  --deep: #5857A7;
  --olive: #69731F;
  --cream: #F2D6B3;
  --ink: #28243A;
  --muted: #706B7C;
  --line: #E8E3ED;
  --paper: #FFFCF8;
  --white: #FFFFFF;
  --danger: #A74444;
  --shadow: 0 16px 50px rgba(88, 87, 167, .12);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #C7CAE5; }
body { position: relative; margin: 0; color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: transparent; min-height: 100vh; min-height: 100dvh; }
body::before { content: ""; position: fixed; z-index: -2; inset: 0; width: 100%; height: 100%; background: #C7CAE5 url("app-background.jpg") 58% center / cover no-repeat; filter: saturate(.6) brightness(1.08); }
body::after { content: ""; position: fixed; z-index: -1; inset: 0; pointer-events: none; background: linear-gradient(135deg, rgba(242,246,255,.12), rgba(88,87,167,.08)); }
button, input, select, textarea { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.app-shell { max-width: 980px; min-height: 100vh; min-height: 100dvh; margin: 0 auto; background: rgba(255,252,248,.84); box-shadow: 0 0 80px rgba(35,35,70,.18); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.topbar { position: sticky; z-index: 20; top: 0; min-height: 68px; padding: max(12px, env(safe-area-inset-top)) 22px 12px; display: flex; align-items: center; justify-content: space-between; gap: 14px; background: rgba(255,252,248,.82); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-bottom: 1px solid rgba(136,123,166,.18); }
.brand, .history-link { border: 0; background: transparent; color: var(--ink); display: inline-flex; align-items: center; gap: 9px; padding: 6px; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; color: var(--white); background: var(--deep); border-radius: 11px 11px 11px 4px; }
.history-link { color: var(--deep); font-size: 14px; }
.screen { display: none; padding: 26px 24px max(32px, env(safe-area-inset-bottom)); }
.screen.active { display: block; animation: enter .28s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(28px, 6vw, 44px); line-height: 1.2; letter-spacing: -.03em; margin-bottom: 12px; }
h2 { font-size: 20px; margin-bottom: 5px; }
.eyebrow, .section-kicker { color: var(--olive); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.welcome { max-width: 620px; padding: 48px 0 28px; }
.welcome > p:last-child { color: var(--muted); line-height: 1.7; }
.upload-card { border: 2px dashed rgba(125,121,217,.38); min-height: 390px; border-radius: 30px; padding: 44px 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: linear-gradient(145deg, rgba(242,214,179,.32), rgba(136,123,166,.08)); transition: .2s ease; }
.upload-card.dragging { transform: scale(.995); border-color: var(--deep); background: rgba(125,121,217,.09); }
.upload-card > p { color: var(--muted); }
.upload-illustration { display: grid; grid-template-columns: repeat(3, 17px); gap: 5px; transform: rotate(-6deg); margin-bottom: 26px; }
.upload-illustration span { width: 17px; height: 17px; border-radius: 50%; background: var(--violet); box-shadow: inset -2px -2px 4px rgba(49,39,94,.22); }
.upload-illustration span:nth-child(2n) { background: var(--cream); }
.upload-illustration span:nth-child(4n) { background: var(--olive); }
.upload-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.primary-button, .secondary-button { min-height: 50px; border: 0; border-radius: 15px; padding: 0 20px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; font-weight: 800; text-decoration: none; }
.primary-button { color: var(--white); background: var(--deep); box-shadow: 0 8px 22px rgba(88,87,167,.24); }
.secondary-button { color: var(--deep); background: var(--white); box-shadow: inset 0 0 0 1px rgba(88,87,167,.22); }
.full-button { width: 100%; }
.privacy-note { color: var(--muted); font-size: 13px; display: flex; gap: 8px; justify-content: center; align-items: center; padding: 20px; }
.privacy-note svg { width: 16px; }
.install-panel { width: min(100%, 520px); margin: 0 auto 18px; display: grid; gap: 8px; text-align: center; }
.install-panel small { color: var(--muted); font-size: 11px; line-height: 1.5; }
@media (display-mode: standalone), (display-mode: fullscreen) { .install-panel { display: none; } }
.compact-panel { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 18px; background: rgba(242,214,179,.34); margin-bottom: 20px; }
.compact-panel img { width: 58px; height: 58px; border-radius: 12px; object-fit: cover; background: var(--line); }
.compact-panel > div { min-width: 0; flex: 1; }
.compact-panel strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }
.text-button { border: 0; color: var(--deep); background: transparent; font-weight: 700; }
#setup-screen.active { min-height: calc(100dvh - 69px); display: grid; grid-template-rows: minmax(220px, 3fr) auto minmax(420px, 6fr); gap: 18px; }
#setup-screen > * { min-width: 0; }
.history-reference { height: min(30vh, 280px); min-height: 220px; display: flex; flex-direction: column; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; gap: 14px; align-items: end; margin-bottom: 14px; }
.section-heading h2 { margin: 4px 0 0; }
.scroll-hint, .required-tip { color: var(--muted); font-size: 12px; }
.history-strip { display: flex; gap: 12px; overflow-x: auto; padding: 1px 2px 10px; scroll-snap-type: x mandatory; }
.reference-card { flex: 0 0 min(310px, 82vw); scroll-snap-align: start; background: var(--white); border: 1px solid var(--line); border-radius: 18px; padding: 14px; box-shadow: 0 6px 20px rgba(72,53,99,.06); }
.reference-card[data-record-id], .history-item[data-record-id] { cursor: pointer; touch-action: pan-y; }
.reference-card.sorting, .history-item.sorting { border-color: var(--olive); box-shadow: 0 0 0 3px rgba(105,115,31,.13); }
.reference-card.dragging, .history-item.dragging { opacity: .78; transform: scale(.985); z-index: 5; }
body.reordering-history { user-select: none; }
.record-card-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.record-card-actions button { min-height: 32px; border: 0; border-radius: 9px; padding: 0 10px; color: var(--deep); background: rgba(125,121,217,.10); font-size: 11px; font-weight: 800; }
.record-card-actions .delete-record { margin-left: auto; color: var(--danger); background: rgba(167,68,68,.08); }
.version-tag { color: var(--olive); font-size: 10px; font-weight: 800; }
.reference-card.current { background: linear-gradient(140deg, rgba(242,214,179,.54), rgba(125,121,217,.13)); border-color: rgba(88,87,167,.28); }
.reference-badge { display: inline-block; margin-bottom: 6px; color: var(--olive); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.reference-card .replace-reference { margin-left: auto; border: 0; color: var(--deep); background: transparent; font-size: 12px; font-weight: 800; }
.reference-card header { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.reference-card img { width: 46px; height: 46px; object-fit: cover; border-radius: 10px; }
.reference-card header div { min-width: 0; }
.reference-card strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reference-card time { color: var(--muted); font-size: 12px; }
.focus-values, .key-values { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.focus-values span, .key-values span { border-radius: 9px; background: rgba(125,121,217,.09); padding: 7px 5px; text-align: center; font-size: 11px; color: var(--muted); }
.focus-values b, .key-values b { display: block; color: var(--deep); font-size: 13px; margin-top: 3px; }
.empty-state { width: 100%; min-height: 110px; border-radius: 17px; display: grid; place-items: center; text-align: center; padding: 16px; color: var(--muted); background: rgba(136,123,166,.07); }
.preheat-area { padding: 14px 16px 16px; border-radius: 18px; background: rgba(242,214,179,.20); border: 1px solid rgba(105,115,31,.15); }
.preheat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.preheat-grid .field { min-width: 0; }
.preheat-grid .field > span { font-size: 12px; }
.preheat-grid select { min-width: 0; max-width: 100%; padding: 10px 11px; font-size: 13px; }
.custom-input { width: 100%; min-width: 0; color: var(--ink); background: var(--white); border: 1px solid var(--violet); border-radius: 12px; padding: 10px 11px; font-size: 13px; outline: none; }
.custom-input:focus { box-shadow: 0 0 0 3px rgba(125,121,217,.13); }
.custom-input[hidden] { display: none; }
.preheat-grid small { color: var(--olive); font-size: 10px; line-height: 1.35; }
.setup-form-area { padding-top: 24px; }
.parameter-list { display: grid; gap: 12px; }
.focus-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.field { display: grid; gap: 7px; }
.field > span { font-size: 13px; font-weight: 700; }
.field b { color: var(--olive); font-size: 10px; margin-left: 5px; }
select, textarea { width: 100%; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: 13px; padding: 13px 14px; outline: none; }
select:focus, textarea:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(125,121,217,.13); }
.focus-field select { border-color: rgba(105,115,31,.34); background: rgba(242,214,179,.16); }
.form-error { min-height: 18px; margin: 0; color: var(--danger); font-size: 13px; }
.locked-summary { position: sticky; z-index: 12; top: 69px; display: grid; grid-template-columns: 72px 1fr auto; gap: 14px; align-items: center; padding: 14px; border-radius: 20px; background: var(--deep); color: var(--white); box-shadow: var(--shadow); }
.locked-summary img { width: 72px; height: 72px; object-fit: cover; border-radius: 13px; }
.locked-content { min-width: 0; }
.locked-content .section-kicker { color: var(--cream); }
.locked-content > strong { display: block; margin: 5px 0 9px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.key-values span { background: rgba(255,255,255,.13); color: rgba(255,255,255,.7); }
.key-values b { color: var(--white); }
.overall-time { text-align: center; padding: 0 9px; }
.locked-summary .overall-time span { display: block; color: rgba(255,255,255,.72); font-size: 11px; }
.overall-time strong { display: block; margin-top: 5px; font-variant-numeric: tabular-nums; font-size: 22px; }
.steps-area { padding-top: 30px; }
.formal-area { min-height: 0; padding-top: 4px; }
.formal-tools { display: flex; align-items: center; gap: 12px; }
.formal-tools .overall-time { min-width: 86px; padding: 7px 10px; color: var(--white); background: var(--deep); border-radius: 12px; }
.formal-tools .overall-time span { display: block; color: rgba(255,255,255,.72); font-size: 10px; }
.formal-tools .overall-time strong { margin-top: 2px; font-size: 17px; }
.row-controls { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.row-controls button { width: 34px; height: 34px; border: 0; border-radius: 10px; color: var(--deep); background: rgba(125,121,217,.11); font-size: 20px; }
.gesture-tip { color: var(--muted); font-size: 12px; line-height: 1.6; background: rgba(242,214,179,.25); border-radius: 12px; padding: 9px 12px; }
.step-list { display: grid; gap: 11px; margin: 16px 0; }
.step-row { display: grid; grid-template-columns: 34px repeat(4, minmax(0, 1fr)); gap: 8px; align-items: end; padding: 13px; background: var(--white); border: 1px solid var(--line); border-radius: 16px; transition: .2s; }
.step-row.active { border-color: var(--violet); box-shadow: 0 7px 25px rgba(88,87,167,.1); }
.step-row.done { background: rgba(105,115,31,.06); border-color: rgba(105,115,31,.25); }
.step-index { grid-row: 1 / span 2; align-self: center; font-weight: 800; color: var(--deep); }
.step-row label { display: grid; gap: 4px; min-width: 0; }
.step-row label span { color: var(--muted); font-size: 10px; }
.step-row select { min-width: 0; width: 100%; padding: 10px 8px; font-size: 13px; }
.step-custom { width: 100%; min-width: 0; color: var(--ink); background: var(--white); border: 1px solid var(--violet); border-radius: 10px; padding: 9px 8px; font-size: 12px; outline: none; }
.step-custom[hidden] { display: none; }
.step-result { align-self: center; text-align: center; }
.checkmark { width: 28px; height: 28px; display: grid; place-items: center; margin: auto; border: 2px solid #C7C2CF; border-radius: 50%; color: transparent; }
.done .checkmark { color: var(--white); border-color: var(--olive); background: var(--olive); }
.step-time { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.45; font-variant-numeric: tabular-nums; }
.session-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.session-actions.hidden { display: none; }
.start-button, .finish-button { min-height: 92px; border: 0; border-radius: 20px; padding: 16px; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--white); touch-action: manipulation; user-select: none; }
.start-button { background: var(--violet); }
.start-button.paused { background: var(--purple); }
.finish-button { background: var(--olive); }
.complete-session-button { grid-column: 1 / -1; min-height: 66px; border: 0; border-radius: 18px; padding: 13px 18px; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--white); background: var(--deep); }
.complete-session-button span { text-align: left; }
.complete-session-button strong, .complete-session-button small { display: block; }
.complete-session-button small { margin-top: 3px; opacity: .72; }
.complete-session-button:disabled, .start-button:disabled, .finish-button:disabled { cursor: not-allowed; opacity: .42; }
.start-button svg, .finish-button svg { width: 28px; height: 28px; }
.start-button span, .finish-button span { text-align: left; }
.start-button strong, .finish-button strong { display: block; font-size: 17px; }
.start-button small, .finish-button small { display: block; opacity: .72; margin-top: 3px; }
.holdable.holding { animation: holdPulse .75s ease-in-out infinite alternate; }
@keyframes holdPulse { to { filter: brightness(.82); transform: scale(.985); } }
.hold-status { min-height: 20px; text-align: center; color: var(--danger); font-size: 13px; margin: 10px 0 0; }
.history-page-heading { display: flex; justify-content: space-between; align-items: end; padding: 25px 0 20px; border-bottom: 1px solid var(--line); }
.history-page-heading h1 { margin-bottom: 0; }
.history-page-heading > span { color: var(--deep); font-weight: 700; }
.history-heading-actions { display: flex; align-items: center; gap: 12px; color: var(--deep); font-weight: 700; }
.history-heading-actions .secondary-button { min-height: 40px; padding: 0 14px; }
.history-list { display: grid; gap: 14px; padding-top: 20px; }
.history-item { display: grid; grid-template-columns: 86px 1fr; gap: 15px; padding: 14px; border-radius: 19px; background: var(--white); border: 1px solid var(--line); }
.history-item img { width: 86px; height: 86px; object-fit: cover; border-radius: 13px; }
.history-item header { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.history-item header div { min-width: 0; }
.history-item header strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.history-item time, .history-item .duration { color: var(--muted); font-size: 12px; }
.history-item .all-params { margin: 11px 0 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.record-state { display: inline-block; margin-left: 6px; color: var(--olive); font-size: 10px; font-style: normal; }
.record-state.unfinished { color: var(--danger); }
.record-timing { display: grid; gap: 4px; text-align: right; color: var(--muted); font-size: 11px; font-weight: 400; }
.record-timing b { color: var(--deep); font-size: 12px; }
.record-timing small { font-size: 10px; }
.step-history { margin-top: 10px; color: var(--muted); font-size: 12px; }
.step-history summary { cursor: pointer; color: var(--deep); font-weight: 700; }
.step-history-entry { display: grid; gap: 4px; padding: 9px 0; border-top: 1px solid var(--line); line-height: 1.55; }
.step-history-entry:first-of-type { margin-top: 8px; }
.version-history { margin-top: 10px; color: var(--muted); font-size: 12px; }
.version-history summary { cursor: pointer; color: var(--deep); font-weight: 700; }
.version-entry { padding: 10px 0; border-top: 1px solid var(--line); }
.version-entry:first-of-type { margin-top: 8px; }
.version-entry > span { display: block; margin-bottom: 6px; }
.edit-dialog { width: min(720px, calc(100% - 24px)); max-height: min(88vh, 900px); overflow-y: auto; text-align: left; }
.edit-dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.edit-dialog-heading h2 { margin-top: 4px; }
.edit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.edit-grid input { width: 100%; min-width: 0; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; outline: none; }
.edit-grid input:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(125,121,217,.13); }
.edit-note { margin: 16px 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.edit-subheading { margin: 22px 0 10px; font-size: 15px; }
.edit-step-list { display: grid; gap: 10px; }
.edit-step-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 11px; border-radius: 14px; background: rgba(125,121,217,.07); }
.edit-step-row strong { grid-column: 1 / -1; color: var(--deep); font-size: 12px; }
.edit-step-row label { display: grid; gap: 4px; min-width: 0; color: var(--muted); font-size: 10px; }
.edit-step-row input { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 9px; padding: 8px; color: var(--ink); background: var(--white); font-size: 12px; }
.completion-dialog { width: min(720px, calc(100% - 24px)); max-height: min(90vh, 920px); overflow-y: auto; text-align: left; }
.completion-summary { display: grid; gap: 12px; }
.completion-summary-block { padding: 12px; border-radius: 14px; background: rgba(125,121,217,.07); }
.completion-summary-block h3 { margin: 0 0 8px; font-size: 14px; }
.completion-summary-block p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.finished-upload { margin: 16px 0; padding: 16px; border: 1px dashed rgba(88,87,167,.35); border-radius: 16px; text-align: center; }
.finished-upload > p { margin-bottom: 10px; font-weight: 800; }
.finished-upload .upload-actions { margin-top: 0; }
#finished-preview { width: min(100%, 320px); max-height: 260px; margin: 14px auto 0; display: block; object-fit: contain; border-radius: 14px; background: var(--line); }
#finished-preview[hidden] { display: none; }
.history-images { display: grid; gap: 7px; align-content: start; }
.history-images img { width: 86px; height: 74px; object-fit: cover; border-radius: 12px; }
.history-images small { color: var(--muted); font-size: 9px; text-align: center; }
dialog { width: min(420px, calc(100% - 32px)); border: 0; border-radius: 26px; padding: 30px; text-align: center; color: var(--ink); box-shadow: 0 25px 80px rgba(36,29,53,.26); }
dialog::backdrop { background: rgba(30,23,42,.45); backdrop-filter: blur(5px); }
.dialog-icon { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 18px; color: var(--white); background: var(--olive); border-radius: 50%; font-size: 27px; }
dialog p { color: var(--muted); line-height: 1.6; }

@media (max-width: 700px) {
  body::before { background-position: right center; background-size: auto 100%; }
  body::after { background: linear-gradient(180deg, rgba(244,247,255,.10), rgba(88,87,167,.11)); }
  .app-shell { background: rgba(255,252,248,.80); }
  .topbar { background: rgba(255,252,248,.78); }
  .screen { padding-left: 16px; padding-right: 16px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .history-link { font-size: 12px; gap: 5px; }
  .history-link svg { width: 18px; }
  .welcome { padding-top: 28px; }
  .upload-card { min-height: 340px; padding: 34px 18px; }
  .locked-summary { top: 65px; grid-template-columns: 54px 1fr; }
  .locked-summary img { width: 54px; height: 54px; }
  .locked-summary .overall-time { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 8px 5px 0; border-top: 1px solid rgba(255,255,255,.17); }
  .overall-time strong { font-size: 18px; }
  #setup-screen.active { grid-template-rows: minmax(220px, 3fr) auto minmax(500px, 6fr); }
  .preheat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .formal-tools { align-items: flex-end; flex-direction: column; gap: 7px; }
  .formal-tools .overall-time { align-self: stretch; display: flex; align-items: center; justify-content: space-between; }
  .step-row { grid-template-columns: 28px 1fr 1fr; }
  .step-index { grid-row: 1 / span 5; }
  .step-result { grid-column: 2 / -1; grid-row: auto; }
  .session-actions { position: sticky; z-index: 10; bottom: max(10px, env(safe-area-inset-bottom)); }
  .start-button, .finish-button { min-height: 80px; padding: 12px 8px; }
  .history-item { grid-template-columns: 68px 1fr; }
  .history-item img { width: 68px; height: 68px; }
  .history-images img { width: 68px; height: 62px; }
  .edit-grid { grid-template-columns: 1fr; }
  .edit-step-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .brand > span:last-child { display: none; }
  .focus-grid { grid-template-columns: 1fr; }
  .preheat-grid { grid-template-columns: 1fr 1fr; }
  .focus-values, .key-values { grid-template-columns: repeat(2, 1fr); }
  .section-heading { align-items: start; }
  .required-tip, .scroll-hint { max-width: 100px; text-align: right; }
}
