:root {
  --ink: #173b32;
  --ink-2: #244c41;
  --paper: #f5f0e6;
  --card: #fffdf8;
  --line: #e5dccb;
  --seal: #a6533b;
  --muted: #75817c;
  --shadow: 0 20px 55px rgba(50, 43, 30, .09);
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  min-height: 100vh;
  margin: 0;
  color: #24342e;
  background:
    radial-gradient(circle at 6% 0%, rgba(166,83,59,.08), transparent 27rem),
    var(--paper);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 5px; color: var(--seal); font-size: 10px; font-weight: 800; letter-spacing: 2.4px; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 44px; border: 1px solid var(--line); border-radius: 30px; background: rgba(255,253,248,.93); box-shadow: var(--shadow); text-align: center; }
.seal-logo { width: 68px; height: 68px; margin: 0 auto 24px; display: grid; place-items: center; border: 4px double var(--seal); color: var(--seal); font: 36px "STKaiti","KaiTi",serif; transform: rotate(-4deg); }
.login-card h1 { margin: 4px 0 12px; color: var(--ink); font: 700 38px "STKaiti","KaiTi",serif; }
.login-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.7; }
.login-card form { margin-top: 28px; text-align: left; }

.topbar { height: 70px; padding: 0 28px; display: flex; align-items: center; gap: 20px; border-bottom: 1px solid rgba(23,59,50,.08); background: rgba(255,253,248,.88); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand span { width: 36px; height: 36px; display: grid; place-items: center; border: 2px solid var(--seal); color: var(--seal); font: 21px "STKaiti","KaiTi",serif; }
.brand strong { font: 700 22px "STKaiti","KaiTi",serif; white-space: nowrap; }
.status-pills { display: flex; gap: 8px; margin-left: auto; }
.status-pills span { padding: 7px 11px; border-radius: 999px; background: #e9eee9; color: #4d655b; font-size: 11px; }

.workspace { width: min(1500px, calc(100% - 36px)); margin: 24px auto 50px; display: grid; grid-template-columns: minmax(410px, 1.05fr) minmax(360px, .85fr) minmax(240px, .55fr); gap: 20px; align-items: start; }
.form-panel, .preview-panel, .orders-panel { padding: 26px; border: 1px solid var(--line); border-radius: 24px; background: rgba(255,253,248,.9); box-shadow: var(--shadow); }
.preview-panel { position: sticky; top: 94px; }
.orders-panel { min-height: 400px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.panel-heading h1, .panel-heading h2 { margin: 0; color: var(--ink); font: 700 27px "STKaiti","KaiTi",serif; }
.text-button { border: 0; background: transparent; color: var(--seal); font-size: 12px; font-weight: 700; }

form > label, .form-grid label { display: grid; gap: 7px; color: #52625b; font-size: 12px; font-weight: 700; }
input, textarea, select { width: 100%; border: 1px solid #ded6c8; border-radius: 12px; outline: 0; background: #fff; color: #263931; transition: .2s; }
input, select { height: 44px; padding: 0 13px; }
textarea { padding: 12px 13px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: #64877a; box-shadow: 0 0 0 3px rgba(36,76,65,.09); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 15px; }
form > label { margin-bottom: 15px; }

.rarity-block { margin: 20px 0; padding: 16px; border-radius: 15px; background: #f1ece2; }
.rarity-block > div:first-child { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.rarity-block strong { color: var(--ink); font-size: 13px; }
.rarity-block small { color: var(--muted); font-size: 10px; }
.range-row { margin-top: 13px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; color: var(--muted); font-size: 10px; }
input[type="range"] { height: auto; padding: 0; accent-color: var(--seal); }

.template-picker > strong { color: var(--ink); font-size: 13px; }
.template-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 10px; }
.template-options label input { position: absolute; opacity: 0; pointer-events: none; }
.template-card { min-height: 72px; display: flex; align-items: flex-end; padding: 10px; border: 2px solid transparent; border-radius: 13px; color: #fff; font-size: 11px; font-weight: 700; text-shadow: 0 1px 5px rgba(0,0,0,.35); transition: .2s; }
.template-options input:checked + .template-card { border-color: var(--seal); transform: translateY(-2px); }
.template-card.rain { background: linear-gradient(150deg,#7d9590,#223e39); }
.template-card.paper { color: var(--ink); text-shadow: none; background: linear-gradient(150deg,#fffdf7,#e7ddc9); }
.template-card.night { background: linear-gradient(150deg,#101c2a,#425c67); }
.template-card.plum { background: linear-gradient(150deg,#e7d7cf,#803d3b); }
.image-option { margin: 18px 0 0; padding: 14px 15px; display: flex; grid-template-columns: auto 1fr; align-items: center; gap: 11px; border: 1px solid #ded6c8; border-radius: 14px; background: #f7f3ea; }
.image-option input { width: 18px; height: 18px; padding: 0; accent-color: var(--seal); }
.image-option span { display: grid; gap: 3px; }
.image-option strong { color: var(--ink); font-size: 13px; }
.image-option small { color: var(--muted); font-size: 10px; font-weight: 400; }
.provider-select { margin-top: 12px; }
.reference-upload { margin-top: 16px; padding: 16px; display: grid; gap: 12px; border: 1px dashed #cfc4b2; border-radius: 15px; background: #faf7f0; }
.reference-upload > div:first-child { display: grid; gap: 4px; }
.reference-upload strong { color: var(--ink); font-size: 13px; }
.reference-upload small { color: var(--muted); font-size: 10px; line-height: 1.5; }
.upload-button { min-height: 42px; display: grid; place-items: center; border-radius: 12px; background: #e8eee9; color: var(--ink); font-size: 12px; font-weight: 800; cursor: pointer; }
.upload-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.reference-preview { width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; background: #e9e3d8; }

.primary, .ghost { border-radius: 13px; font-weight: 800; }
.primary { border: 0; background: var(--ink); color: #fff; }
.ghost { min-height: 40px; padding: 0 15px; border: 1px solid #d9d0c1; background: #fffdf8; color: var(--ink); }
.generate { width: 100%; min-height: 62px; margin-top: 23px; display: grid; place-items: center; }
.generate span { font-size: 15px; }.generate small { margin-top: -12px; color: rgba(255,255,255,.62); font-size: 9px; font-weight: 400; }
.primary:disabled { opacity: .45; cursor: not-allowed; }
.error { min-height: 18px; margin-top: 10px; color: #a33d2f; font-size: 12px; }

.size-tabs { display: flex; padding: 3px; border-radius: 10px; background: #eee8dd; }
.size-tabs button { padding: 7px 9px; border: 0; border-radius: 8px; background: transparent; color: #77837d; font-size: 10px; }
.size-tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.07); }
.canvas-stage { height: min(56vh, 590px); display: grid; place-items: center; padding: 13px; overflow: hidden; border-radius: 18px; background: #e9e3d8; }
#poetryCanvas { max-width: 100%; max-height: 100%; display: block; box-shadow: 0 14px 35px rgba(42,36,27,.2); }
.result-meta { margin-top: 14px; padding: 14px; border-left: 4px solid var(--seal); border-radius: 10px; background: #edf1ec; color: #506159; font-size: 12px; line-height: 1.65; }
.result-meta h3 { margin: 0 0 6px; color: var(--ink); font: 700 17px "STKaiti","KaiTi",serif; }
.result-meta p { margin: 0; }
.download-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 13px; }
.download-row button { min-height: 44px; }

.orders-list { display: grid; gap: 10px; }
.order-card { padding: 13px; border: 1px solid #e8e0d3; border-radius: 13px; background: #fff; }
.order-card strong { display: block; color: var(--ink); font: 700 15px "STKaiti","KaiTi",serif; }
.order-card span, .order-card small { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.muted { color: var(--muted); font-size: 12px; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 1fr 1fr; }
  .orders-panel { grid-column: 1 / -1; }
  .orders-list { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  .topbar { height: auto; min-height: 64px; padding: 10px 14px; flex-wrap: wrap; }
  .status-pills { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  .workspace { width: calc(100% - 20px); margin-top: 12px; grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .form-panel, .preview-panel, .orders-panel { padding: 18px; border-radius: 19px; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .template-options { grid-template-columns: 1fr 1fr; }
  .canvas-stage { height: 60vh; }
  .orders-panel { grid-column: auto; }
  .orders-list { grid-template-columns: 1fr; }
}
