:root {
  color-scheme: light;
  --paper: #f4efe4;
  --ink: #30352f;
  --muted: #77796f;
  --sage: #687564;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); scroll-behavior: smooth; }
body {
  min-height: 100vh; margin: 0; color: var(--ink);
  background: radial-gradient(ellipse at 8% 0%, rgba(255,255,255,.76), transparent 38%), radial-gradient(ellipse at 100% 22%, rgba(205,195,171,.26), transparent 33%), linear-gradient(155deg,#eee9de,#e4dfd4 58%,#ebe5d9);
  font-family: "PingFang SC","Microsoft YaHei",-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; }
.grain {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .14;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.18'/%3E%3C/svg%3E");
}
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; height: 72px; align-items: center; justify-content: space-between;
  padding: 0 max(22px, calc((100vw - 1060px) / 2)); border-bottom: 1px solid rgba(65,67,58,.09);
  background: rgba(241,237,228,.82); backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 36px; height: 36px; overflow: hidden; border-radius: 12px; }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-copy strong, .brand-copy small { display: block; }
.brand-copy strong { font-size: 14px; letter-spacing: .4px; }
.brand-copy small { margin-top: 2px; color: #8d9085; font: 8px ui-monospace,monospace; letter-spacing: 1.4px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.token-chip { color: #81745e; font-size: 12px; white-space: nowrap; }
.login-button, .account-button { min-height: 38px; padding: 0 15px; border: 1px solid rgba(54,59,48,.12); border-radius: 999px; background: rgba(255,255,255,.66); color: var(--ink); font-size: 12px; }
.account-button[hidden], .login-button[hidden], .token-chip[hidden] { display: none; }
.page { width: min(920px, calc(100% - 36px)); margin: 0 auto; padding: 48px 0 58px; }
.intro { margin: 0 auto 27px; text-align: center; }
.eyebrow { display: inline-flex; align-items: center; gap: 9px; margin: 0; color: #9a7553; font: 700 10px ui-monospace,monospace; letter-spacing: 3px; }
.eyebrow::before, .eyebrow::after { width: 20px; height: 1px; background: currentColor; content: ""; opacity: .48; }
h1 { margin: 13px 0 8px; font-family: "Songti SC","Noto Serif SC",serif; font-size: clamp(30px, 5vw, 43px); font-weight: 600; letter-spacing: -.8px; }
.lead { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.workshop { width: min(100%, 730px); margin: 0 auto; }
.upload-stage {
  position: relative; display: grid; min-height: clamp(250px, 53vw, 410px); place-items: center; overflow: hidden;
  border: 1px solid rgba(74,77,65,.12); border-radius: 24px; background: linear-gradient(142deg,#dfe2d7,#c6cdbf 57%,#c7bca8);
  box-shadow: 0 22px 56px rgba(67,66,54,.14), inset 0 1px rgba(255,255,255,.6); cursor: pointer; isolation: isolate;
}
.upload-stage::before { position: absolute; inset: 0; z-index: -1; background: radial-gradient(ellipse at 50% 100%,rgba(255,255,255,.42),transparent 53%); content: ""; }
.upload-stage input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.ticket-placeholder {
  display: flex; width: min(72%, 470px); min-height: 190px; align-items: center; justify-content: center;
  border: 1px solid rgba(73,73,61,.13); border-radius: 12px; background: rgba(249,246,238,.78);
  box-shadow: 0 17px 35px rgba(66,64,51,.14); transition: transform .25s ease, opacity .25s ease;
}
.ticket-placeholder::before { width: 8px; height: 8px; margin-right: 14px; border: 1px solid #9a9c8e; border-radius: 50%; content: ""; }
.ticket-placeholder-copy { padding: 22px 16px; text-align: left; }
.ticket-placeholder-copy small { display: block; color: #97896f; font: 9px ui-monospace,monospace; letter-spacing: 2px; }
.ticket-placeholder-copy strong { display: block; margin-top: 9px; color: #4d534a; font-family: "Songti SC",serif; font-size: 22px; font-weight: 600; }
.ticket-placeholder-copy span { display: block; margin-top: 8px; color: #929286; font-size: 11px; }
.upload-stage.has-image { display: block; background: #d8d3c9; }
.upload-preview { display: block; width: 100%; height: 100%; min-height: inherit; object-fit: contain; }
.upload-action { position: absolute; right: 14px; bottom: 14px; padding: 9px 14px; border: 1px solid rgba(255,255,255,.18); border-radius: 99px; background: rgba(33,37,33,.72); color: #fff; font-size: 11px; }
.upload-preview[hidden], .upload-action[hidden], .ticket-placeholder[hidden] { display: none; }
.stage-hint { position: absolute; bottom: 18px; left: 20px; color: rgba(52,57,48,.66); font-size: 11px; }
.fields { display: grid; grid-template-columns: 1.3fr .7fr; gap: 12px; margin-top: 15px; }
.field { display: flex; min-width: 0; min-height: 52px; align-items: center; justify-content: space-between; gap: 12px; padding: 0 15px; border: 1px solid rgba(68,70,59,.08); border-radius: 14px; background: rgba(255,255,255,.58); }
.field label { flex: 0 0 auto; color: #65675e; font-size: 11px; font-weight: 650; }
.field small { margin-left: 4px; color: #9b998e; font-size: 10px; font-weight: 400; }
.field input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 12px; text-align: right; }
.field input::placeholder { color: #aaa99f; }
.submit-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 15px; }
.usage { color: #858476; font-size: 11px; line-height: 1.6; }
.usage strong { display: block; color: #59604f; font-size: 12px; font-weight: 650; }
.generate { min-width: 184px; min-height: 50px; padding: 0 21px; border: 0; border-radius: 16px; background: linear-gradient(110deg,#394238,#677461 62%,#9a785a); box-shadow: 0 10px 24px rgba(69,80,63,.2); color: #fff; font-size: 13px; font-weight: 700; transition: transform .2s, opacity .2s; }
.generate:hover { transform: translateY(-1px); }
.generate:disabled { opacity: .52; cursor: not-allowed; transform: none; }
.progress { margin-top: 14px; padding: 14px 16px; border: 1px solid rgba(70,74,63,.08); border-radius: 14px; background: rgba(255,255,255,.54); }
.progress[hidden], .result[hidden], .login[hidden], .login-error[hidden] { display: none; }
.progress-meta { display: flex; justify-content: space-between; color: #666b60; font-size: 11px; }
.progress-track { height: 6px; margin-top: 10px; overflow: hidden; border-radius: 99px; background: #e1ded5; }
.progress-bar { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg,#71806b,#bb906a); transition: width .3s ease; }
.result { margin-top: 22px; padding: 13px; border: 1px solid rgba(75,77,67,.12); border-radius: 19px; background: rgba(249,246,239,.8); box-shadow: 0 14px 38px rgba(67,66,54,.1); }
.result img { display: block; width: 100%; border-radius: 11px; background: #e4dfd5; }
.result-actions { display: flex; justify-content: flex-end; padding-top: 12px; }
.result-actions button { min-height: 39px; padding: 0 17px; border: 1px solid rgba(59,64,54,.14); border-radius: 999px; background: #fffdf7; color: #444a40; font-size: 11px; }
.rules { display: grid; grid-template-columns: 100px 1fr; gap: 16px; width: min(100%, 730px); margin: 28px auto 0; padding: 19px 3px 0; border-top: 1px solid rgba(63,66,56,.13); }
.rules strong { color: #555b50; font-family: "Songti SC",serif; font-size: 15px; font-weight: 600; }
.rules p { margin: 0 0 6px; color: #858579; font-size: 11px; line-height: 1.65; }
.status { min-height: 18px; margin: 9px 2px 0; color: #7c7e72; font-size: 11px; }
.status.error { color: #a95043; }
.toast { position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; z-index: 50; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 99px; background: rgba(42,45,39,.92); color: white; font-size: 12px; opacity: 0; pointer-events: none; transform: translate(-50%, 8px); transition: .2s; }
.toast.visible { opacity: 1; transform: translate(-50%,0); }
.login { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(36,39,33,.4); backdrop-filter: blur(8px); }
.login-card { position: relative; width: min(100%, 380px); padding: 27px; border: 1px solid rgba(255,255,255,.76); border-radius: 23px; background: #faf8f1; box-shadow: 0 28px 70px rgba(35,36,31,.24); }
.login-card h2 { margin: 0; font-family: "Songti SC",serif; font-size: 25px; }
.login-card > p:not(.login-error) { margin: 8px 0 20px; color: #858579; font-size: 12px; line-height: 1.6; }
.login-card label { display: grid; gap: 7px; margin-top: 12px; color: #66675d; font-size: 11px; }
.login-card input { min-height: 42px; padding: 0 12px; border: 1px solid rgba(57,61,51,.12); border-radius: 11px; background: white; color: var(--ink); }
.login-card button[type=submit] { width: 100%; min-height: 44px; margin-top: 18px; border: 0; border-radius: 12px; background: #4f5b4d; color: white; font-size: 13px; font-weight: 700; }
.login-close { position: absolute; top: 12px; right: 14px; width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; color: #77796f; font-size: 23px; }
.login-error { color: #a95043 !important; }
footer { padding: 18px; color: #9b998e; font: 9px ui-monospace,monospace; letter-spacing: 1px; text-align: center; }
@media(max-width:620px) {
  .topbar { height: 60px; padding: 0 16px; }
  .brand-copy small { display: none; }
  .token-chip { max-width: 110px; overflow: hidden; font-size: 10px; text-overflow: ellipsis; }
  .page { width: calc(100% - 26px); padding-top: 31px; }
  .upload-stage { min-height: 290px; border-radius: 19px; }
  .upload-preview { min-height: 290px; }
  .ticket-placeholder { width: 82%; min-height: 165px; }
  .ticket-placeholder-copy strong { font-size: 19px; }
  .fields { gap: 8px; }
  .field { min-height: 48px; padding: 0 10px; gap: 6px; }
  .field label { font-size: 10px; }
  .field input { font-size: 11px; }
  .field small { display: none; }
  .submit-row { align-items: flex-start; flex-direction: column; }
  .generate { width: 100%; }
  .rules { grid-template-columns: 74px 1fr; gap: 10px; }
}

.history-jump, .history-refresh, .history-more, .history-save {
  border: 1px solid rgba(64,70,59,.15); border-radius: 999px;
  background: rgba(255,255,255,.7); color: #56604f; font-weight: 650;
}
.history-jump { display: inline-flex; align-items: center; gap: 9px; margin-top: 17px; padding: 10px 16px; font-size: 11px; box-shadow: 0 6px 18px rgba(67,66,54,.07); }
.history-jump[hidden], .history-more[hidden] { display: none; }
.history-section { width: min(100%,730px); margin: 48px auto 0; padding: 23px; scroll-margin-top: 90px; border: 1px solid rgba(74,77,65,.11); border-radius: 22px; background: rgba(250,248,241,.68); box-shadow: 0 16px 42px rgba(67,66,54,.07); }
.history-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.history-heading h2 { margin: 7px 0 0; color: var(--ink); font-family: "Songti SC",serif; font-size: 22px; font-weight: 600; }
.history-caption { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.history-refresh, .history-more { min-height: 34px; padding: 0 13px; font-size: 10px; white-space: nowrap; }
.history-state { margin: 18px 0 0; color: #858579; font-size: 11px; line-height: 1.6; }
.history-state.is-error { color: #a95043; }
.history-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; margin-top: 16px; }
.history-item { min-width: 0; overflow: hidden; padding: 8px; border: 1px solid rgba(75,77,67,.1); border-radius: 15px; background: rgba(255,255,255,.62); }
.history-item img { display: block; width: 100%; aspect-ratio: 1.28; object-fit: cover; border-radius: 10px; background: #e4dfd5; }
.history-item-footer { display: flex; align-items: center; justify-content: space-between; gap: 7px; padding: 9px 2px 1px; }
.history-item time { overflow: hidden; color: #858579; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.history-save { min-height: 28px; flex: 0 0 auto; padding: 0 9px; font-size: 9px; }
.history-more { display: block; margin: 18px auto 0; }
@media(max-width:620px) {
  .history-section { margin-top: 35px; padding: 17px; border-radius: 18px; }
  .history-heading h2 { font-size: 19px; }
  .history-caption { max-width: 230px; line-height: 1.6; }
  .history-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .history-item { padding: 6px; border-radius: 12px; }
  .history-item img { border-radius: 8px; }
  .history-item-footer { align-items: flex-start; flex-direction: column; gap: 6px; padding-top: 7px; }
  .history-save { min-height: 26px; }
}
