:root {
  --ink: #171816;
  --muted: #686a64;
  --paper: #f2efe6;
  --surface: #fbfbf8;
  --line: #d8d9d2;
  --accent: #244cff;
  --danger: #b52d21;
  --radius: 22px;
}

* { box-sizing: border-box; }
html { background: var(--surface); color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 92% 8%, rgba(36,76,255,.06), transparent 24rem), var(--surface); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
.hidden { display: none !important; }

.topbar { height: 76px; padding: max(18px, env(safe-area-inset-top)) 22px 14px; display: flex; align-items: flex-end; justify-content: space-between; border-bottom: 1px solid rgba(23,24,22,.1); position: sticky; top: 0; z-index: 20; background: rgba(251,251,248,.9); backdrop-filter: blur(18px); }
.wordmark { color: var(--ink); text-decoration: none; font-size: 11px; font-weight: 800; letter-spacing: .16em; line-height: 1.05; display: flex; flex-direction: column; }
.wordmark span:last-child { color: var(--accent); }
.text-button { border: 0; background: none; padding: 8px 0 3px 16px; font-weight: 650; cursor: pointer; }
.topbar-actions { display: flex; align-items: flex-end; gap: 14px; }
.text-link { color: var(--ink); text-decoration: none; font-weight: 650; font-size: 13px; padding-bottom: 3px; }
.account-button { max-width: 105px; border: 0; background: none; padding: 0; text-align: right; cursor: pointer; }
.account-button span, .account-button small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.account-button span { font-size: 11px; font-weight: 700; }
.account-button small { color: var(--muted); font-size: 8px; }

main { width: min(100%, 760px); margin: 0 auto; padding: 0 20px 80px; }
.intro { padding: 68px 2px 46px; }
.eyebrow { margin: 0 0 15px; color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; font-weight: 750; letter-spacing: .18em; }
.intro h1 { margin: 0; font-family: "Songti SC", "STSong", Georgia, serif; font-size: clamp(42px, 12vw, 70px); line-height: .98; letter-spacing: -.055em; font-weight: 620; }
.intro-copy { margin: 24px 0 0; max-width: 31rem; color: var(--muted); font-size: 15px; line-height: 1.75; }

.studio, .result-view, .history-view { border-top: 1px solid var(--ink); padding-top: 25px; }
.section-heading { display: grid; grid-template-columns: 46px 1fr; gap: 12px; align-items: start; margin-bottom: 22px; }
.section-number { color: var(--accent); font: 700 10px/1.4 ui-monospace, SFMono-Regular, monospace; letter-spacing: .08em; padding-top: 5px; }
.section-heading h2 { margin: 0 0 5px; font-size: 18px; letter-spacing: -.02em; }
.section-heading p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.upload-stage { position: relative; display: grid; place-items: center; min-height: 360px; aspect-ratio: 3 / 4; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); cursor: pointer; transition: border-color .2s, transform .2s; }
.upload-stage:active { transform: scale(.995); }
.upload-stage input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; }
.upload-stage > img { width: 100%; height: 100%; object-fit: cover; display: none; }
.upload-stage.has-photo > img { display: block; }
.upload-stage.has-photo .upload-empty { display: none; }
.upload-empty { display: flex; flex-direction: column; align-items: center; gap: 9px; text-align: center; }
.upload-empty strong { font-size: 16px; }
.upload-empty > span:last-child { color: var(--muted); font-size: 12px; }
.upload-mark { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); margin-bottom: 6px; }
.upload-mark svg { width: 24px; stroke: white; stroke-width: 1.5; fill: none; }
.replace-photo { display: none; position: absolute; right: 14px; bottom: 14px; border: 0; border-radius: 99px; padding: 9px 13px; color: white; background: rgba(23,24,22,.78); backdrop-filter: blur(8px); font-size: 12px; }
.upload-stage.has-photo .replace-photo { display: block; }

.options { margin: 28px 0 24px; }
.option-block { padding: 21px 0; border-bottom: 1px solid var(--line); }
.option-title { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 13px; }
.option-title span { font-size: 14px; font-weight: 700; }
.option-title small { color: var(--muted); font-size: 11px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 5px; padding: 4px; background: #ebece7; border-radius: 13px; }
.segmented button { min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 7px rgba(23,24,22,.09); font-weight: 700; }
.micro-input { width: 100%; margin-top: 11px; border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; background: transparent; outline: none; font-size: 13px; }
.micro-input:focus { border-color: var(--accent); }
.micro-input:disabled { opacity: .38; }
.color-options { display: flex; gap: 12px; flex-wrap: wrap; }
.color-options button { width: 34px; height: 34px; border: 2px solid transparent; border-radius: 50%; padding: 3px; background: content-box var(--swatch, transparent); box-shadow: inset 0 0 0 3px var(--surface); cursor: pointer; }
.color-options button.active { border-color: var(--ink); }
.color-options .auto-color { width: 52px; border-radius: 99px; background: repeating-linear-gradient(135deg,#244cff 0 8px,#f0442e 8px 16px,#f4d62a 16px 24px); color: white; text-shadow: 0 1px 2px #000; font-size: 8px; font-weight: 800; letter-spacing: .08em; }
.swatch-cobalt { --swatch: #244cff; }
.swatch-tomato { --swatch: #f0442e; }
.swatch-lemon { --swatch: #f4d62a; }
.swatch-magenta { --swatch: #e636a2; }
.swatch-pear { --swatch: #80cf34; }

.primary-action { width: 100%; min-height: 58px; padding: 0 20px; border: 0; border-radius: 15px; background: var(--ink); color: white; display: flex; align-items: center; justify-content: space-between; text-decoration: none; font-weight: 700; cursor: pointer; transition: opacity .2s, transform .2s; }
.primary-action:active { transform: scale(.99); }
.primary-action:disabled { opacity: .28; cursor: not-allowed; }
.privacy-note { margin: 13px 0 0; text-align: center; color: var(--muted); font-size: 10px; }

.progress-view { min-height: 72vh; padding: 88px 4px 60px; text-align: center; }
.paper-loader { width: 90px; height: 112px; margin: 0 auto 36px; position: relative; }
.paper-loader span { position: absolute; inset: 0; border: 1px solid rgba(23,24,22,.25); background: var(--paper); transform-origin: bottom center; animation: gather 2.2s ease-in-out infinite; }
.paper-loader span:nth-child(2) { animation-delay: .15s; background: #e7e8e2; }
.paper-loader span:nth-child(3) { animation-delay: .3s; background: #fff; }
@keyframes gather { 0%,100% { transform: rotate(-5deg) translateX(-7px); } 50% { transform: rotate(5deg) translateX(7px); } }
.progress-view h2 { margin: 0 0 24px; font-family: "Songti SC", Georgia, serif; font-size: 28px; }
.progress-track { height: 3px; background: var(--line); overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .5s ease; }
#progressPercent { margin: 9px 0 28px; text-align: right; color: var(--muted); font: 10px ui-monospace, monospace; }
.stage-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4,1fr); color: #adafa9; font-size: 10px; }
.stage-list li.done { color: var(--ink); font-weight: 700; }
.progress-hint { max-width: 280px; margin: 42px auto 0; color: var(--muted); font-size: 11px; line-height: 1.65; }

.result-view, .history-view { margin-top: 44px; }
.result-heading { margin-bottom: 25px; }
.result-paper { margin: 0; padding: 12px; background: #e8e8e2; border-radius: 18px; box-shadow: 0 28px 70px rgba(23,24,22,.14); }
.result-paper img { width: 100%; display: block; border-radius: 7px; background: var(--paper); }
.result-paper.landscape { padding: 10px; }
.result-meta { margin: 12px 0 0; color: var(--muted); text-align: center; font: 10px ui-monospace, SFMono-Regular, monospace; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 24px; }
.result-actions .primary-action { grid-column: 1 / -1; }
.secondary-action { min-height: 48px; border: 1px solid var(--line); border-radius: 13px; background: transparent; font-weight: 650; cursor: pointer; }
.secondary-action.full { width: 100%; margin-top: 24px; }
.delete-action { grid-column: 1/-1; min-height: 42px; border: 0; background: transparent; color: var(--muted); font-size: 11px; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }

.history-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.history-card { border: 0; padding: 0; background: none; text-align: left; cursor: pointer; }
.history-card img, .history-placeholder { width: 100%; aspect-ratio: 3/5; object-fit: cover; border-radius: 12px; background: var(--paper); }
.history-card.landscape img, .history-card.landscape .history-placeholder { aspect-ratio: 5/3; }
.history-placeholder { display: grid; place-items: center; color: var(--muted); font-size: 11px; padding: 15px; text-align: center; }
.history-card p { margin: 7px 2px 0; font-size: 11px; font-weight: 650; }
.history-card small { display: block; margin: 3px 2px 0; color: var(--muted); font-size: 9px; }
.empty-history { grid-column: 1/-1; color: var(--muted); padding: 50px 0; text-align: center; font-size: 13px; }

footer { width: min(100%,760px); margin: 0 auto; border-top: 1px solid var(--line); padding: 24px 20px calc(28px + env(safe-area-inset-bottom)); display: flex; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 9px; letter-spacing: .04em; }

.login-dialog { width: min(calc(100% - 30px), 420px); border: 0; border-radius: 24px; padding: 0; background: var(--surface); box-shadow: 0 30px 100px rgba(0,0,0,.28); }
.login-dialog::backdrop { background: rgba(23,24,22,.72); backdrop-filter: blur(8px); }
.login-dialog form { padding: 34px 26px 27px; }
.login-dialog h2 { margin: 0 0 9px; font-family: "Songti SC", Georgia, serif; font-size: 30px; }
.login-dialog p:not(.eyebrow,.form-error) { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 0 0 24px; }
.login-dialog label span { display: block; margin: 0 0 7px; font-size: 11px; font-weight: 700; }
.login-dialog input { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 14px; outline: none; letter-spacing: .12em; }
.login-dialog input:focus { border-color: var(--accent); }
.login-dialog .primary-action { margin-top: 17px; }
.form-error { min-height: 18px; margin: 7px 0 0; color: var(--danger); font-size: 11px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 50; transform: translate(-50%,20px); opacity: 0; pointer-events: none; background: var(--ink); color: white; padding: 11px 15px; border-radius: 99px; font-size: 11px; transition: .25s; }
.toast.show { transform: translate(-50%,0); opacity: 1; }

@media (min-width: 700px) {
  .topbar { padding-inline: max(24px, calc((100vw - 900px)/2)); }
  .upload-stage { min-height: 500px; }
  .studio { display: grid; grid-template-columns: 1.08fr .92fr; gap: 0 32px; }
  .studio .section-heading { grid-column: 1/-1; }
  .upload-stage { grid-row: span 4; }
  .options { margin-top: 0; }
  .privacy-note { grid-column: 2; }
}

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