:root {
  --paper: #f2ead3;
  --paper-2: #f9f4e5;
  --paper-3: #efe6cc;
  --grid: rgba(70, 95, 60, 0.06);
  --grid-strong: rgba(70, 95, 60, 0.11);
  --ink: #1d241e;
  --text: #1d241e;
  --text-2: #4c5447;
  --text-3: #868a7b;
  --green: #2e7d4f;
  --green-2: #3b9461;
  --green-soft: #d6e7cb;
  --gold: #d9a93f;
  --danger: #b4392e;
  --danger-soft: #f3d9cf;
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", Menlo, Consolas, "PingFang SC", "Microsoft YaHei", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --paper: #171c18;
  --paper-2: #1f2620;
  --paper-3: #252d26;
  --grid: rgba(190, 215, 185, 0.04);
  --grid-strong: rgba(190, 215, 185, 0.07);
  --ink: #3a5242;
  --text: #e8e3d2;
  --text-2: #b6b5a4;
  --text-3: #7d8275;
  --green: #4fae78;
  --green-2: #5fc08a;
  --green-soft: #24402e;
  --danger: #f08a7c;
  --danger-soft: #3d2420;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

[hidden] { display: none !important; }

body {
  font-family: var(--sans);
  color: var(--text);
  line-height: 1.7;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 80px 80px, 80px 80px, 16px 16px, 16px 16px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--green); }

button { font: inherit; color: inherit; cursor: pointer; }

svg { flex-shrink: 0; }

.container { width: min(1200px, 100% - 48px); margin: 0 auto; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 2px solid var(--ink);
}
[data-theme="dark"] .site-header { border-bottom-color: #3d5745; }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-logo { width: 28px; height: 28px; }
.brand-name { font-family: var(--mono); font-size: 21px; font-weight: 800; letter-spacing: 2px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.quota-badge {
  display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 12px;
  font-family: var(--mono); font-size: 13px; color: var(--ink);
  background: var(--green-soft); border: 2px solid var(--ink); border-radius: 999px; box-shadow: 2px 2px 0 var(--ink);
}
[data-theme="dark"] .quota-badge { color: var(--text); }
.quota-badge svg { width: 14px; height: 14px; color: var(--green); }
.quota-badge b { font-weight: 800; }
.quota-badge.is-empty { background: var(--danger-soft); }
.quota-badge.is-empty svg { color: var(--danger); }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 0; background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--green-soft); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* Hero */
.hero { padding: 48px 0 40px; }
.hero-inner {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px);
  align-items: center; gap: 32px; padding: 0 40px 0 72px;
}
.hero-title { width: fit-content; margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; font-family: var(--mono); }
.hero-brand { position: relative; padding-bottom: 10px; font-size: 48px; font-weight: 800; letter-spacing: 4px; line-height: 1.2; }
.hero-brand::after {
  content: ""; position: absolute; left: 50%; bottom: 0; width: 120%; height: 7px; transform: translateX(-50%) rotate(-2deg);
  border-radius: 50%; background: var(--green); opacity: .85;
}
.sparkle { position: absolute; top: -14px; right: -38px; width: 30px; height: 30px; color: var(--gold); }
.hero-slogan { font-size: 42px; font-weight: 800; letter-spacing: 3px; line-height: 1.35; }
.hero-highlight { position: relative; display: inline-block; isolation: isolate; font-style: normal; color: var(--green); }
.hero-highlight::after {
  content: ""; position: absolute; left: -4%; right: -10%; bottom: 2px; height: 12px; z-index: -1;
  transform: rotate(-1.5deg); background: var(--green-soft);
}
.hero-desc { margin: 22px 0 0; color: var(--text-2); font-size: 15px; line-height: 1.9; }
.hero-tags { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; padding: 0; margin: 26px 0 0; }
.hero-tags li {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 14px 4px 4px; font-size: 13px; font-weight: 500; color: var(--text);
  background: var(--paper-2); border: 2px solid var(--ink); border-radius: 999px; box-shadow: var(--shadow-sm);
}
.tag-icon {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--green); color: #f9f4e5; border: 1.5px solid var(--ink);
}
.tag-icon svg { width: 14px; height: 14px; }

/* Hero illustration */
.hero-art { width: 100%; height: auto; overflow: visible; }
.ha-glow { fill: var(--green-soft); opacity: .55; }
.ha-shadow { fill: var(--ink); }
.ha-sheet { stroke: var(--ink); stroke-width: 2; }
.ha-draft .ha-sheet { fill: var(--paper-3); }
.ha-good .ha-sheet { fill: var(--paper-2); }
.ha-draft-label { fill: #8e9182; }
.ha-draft text { fill: #f9f4e5; font-family: var(--mono); font-size: 12px; font-weight: 700; }
.ha-draft-lines rect { fill: #a9ab9c; }
.ha-scribble { fill: none; stroke: #8e9182; stroke-width: 2; stroke-linecap: round; }
.ha-arrow { fill: none; stroke: var(--green); stroke-width: 8; stroke-linecap: round; }
.ha-arrow-head { fill: var(--green); }
.ha-good-label { fill: var(--green); stroke: var(--ink); stroke-width: 1.5; }
.ha-good text { fill: #f9f4e5; font-family: var(--mono); font-size: 13px; font-weight: 700; letter-spacing: 1px; }
.ha-good-lines rect { fill: var(--green-soft); }
[data-theme="dark"] .ha-good-lines rect { fill: #3a5e46; }
.ha-pen { stroke: var(--ink); stroke-width: 1; }
.ha-star-main { fill: var(--gold); stroke: var(--ink); stroke-width: 1.5; stroke-linejoin: round; }
.ha-star { fill: var(--green); }

/* Cards */
.workspace { display: grid; gap: 24px; }
.card { padding: 20px; background: var(--paper-2); border: 2px solid var(--ink); box-shadow: var(--shadow); }

.card-title { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-family: var(--mono); font-size: 15px; font-weight: 700; }
.card-title label { cursor: text; }
.card-icon { display: inline-grid; place-items: center; width: 28px; height: 28px; background: var(--green-soft); border: 1.5px solid var(--ink); }
.card-icon svg { width: 16px; height: 16px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[data-theme="dark"] .card-icon svg { stroke: var(--text); }

.textarea-wrap { position: relative; }
#draft {
  display: block; width: 100%; min-height: 180px; max-height: 60vh; resize: vertical;
  padding: 12px 14px 30px; font: inherit; font-size: 14.5px; line-height: 1.85; color: var(--text);
  background: var(--paper); border: 2px solid var(--ink); border-radius: 0; outline: none;
  background-image: linear-gradient(transparent calc(1.85em - 1px), var(--grid-strong) 0);
  background-size: 100% 1.85em; background-attachment: local; background-position: 0 12px;
}
#draft::placeholder { color: var(--text-3); }
#draft:focus { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
.counter { position: absolute; right: 14px; bottom: 8px; font-family: var(--mono); font-size: 12px; color: var(--text-3); pointer-events: none; }
.counter.over { color: var(--danger); }

.editor-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px;
  font-family: var(--mono); font-size: 12.5px; color: var(--text-2);
  background: var(--paper); border: 1.5px dashed var(--text-3);
}
.chip-btn:hover { border-style: solid; border-color: var(--ink); background: var(--green-soft); color: var(--text); }
.chip-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chip-btn .chev { width: 14px; height: 14px; }
.rule-mode.custom { color: var(--green); font-weight: 700; }

.primary-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 124px; height: 42px; padding: 0 22px;
  font-family: var(--mono); font-size: 14px; font-weight: 700; color: #f9f4e5;
  background: var(--green); border: 2px solid var(--ink); border-radius: 0; box-shadow: var(--shadow);
  transition: transform .08s, box-shadow .08s, background .15s;
}
.primary-btn:hover { background: var(--green-2); }
.primary-btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.primary-btn:disabled { cursor: not-allowed; opacity: .75; transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.primary-btn svg { width: 16px; height: 16px; }
.primary-btn.small { min-width: 80px; height: 36px; padding: 0 16px; box-shadow: var(--shadow-sm); }
.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  font-family: var(--mono); font-size: 13px; color: var(--text);
  background: var(--paper); border: 2px solid var(--ink); border-radius: 0; box-shadow: var(--shadow-sm);
}
.ghost-btn:hover { background: var(--green-soft); }
.ghost-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.ghost-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; }
.ghost-btn.copied { background: var(--green-soft); color: var(--green); }

/* Result */
.result-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.result-head .card-title { margin: 0; }
.result-card { scroll-margin-top: 80px; }
.result-actions { display: flex; align-items: center; gap: 10px; }
.history-badge {
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 2px;
  font-size: 11px; font-weight: 700; line-height: 15px; text-align: center;
  color: #f9f4e5; background: var(--green); border: 1.5px solid var(--ink); border-radius: 999px;
}
.result-body { min-height: 300px; background: var(--paper); border: 2px solid var(--ink); }
.result-body .empty { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 296px; padding: 30px 16px; text-align: center; }
.empty-art { position: relative; width: 120px; height: 96px; margin-bottom: 14px; }
.doc-mini {
  position: absolute; left: 24px; top: 8px; width: 70px; height: 80px; padding: 14px 11px;
  display: flex; flex-direction: column; gap: 8px; transform: rotate(-6deg);
  background: var(--paper-2); border: 2px solid var(--ink); box-shadow: var(--shadow-sm);
}
.doc-mini i { display: block; height: 6px; background: var(--green-soft); }
.doc-mini i:nth-child(2) { width: 80%; }
.doc-mini i:nth-child(3) { width: 60%; }
.empty-star { position: absolute; right: 8px; top: 0; width: 26px; height: 26px; fill: var(--gold); stroke: var(--ink); stroke-width: 1.2; }
.empty-title { margin: 0; font-family: var(--mono); font-size: 15px; font-weight: 700; }
.empty-desc { margin: 6px 0 0; font-size: 13px; color: var(--text-3); }

.result-body .loading { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 296px; padding: 32px 16px; text-align: center; }
.loading-art { position: relative; width: 140px; height: 110px; margin-bottom: 18px; }
.loading-paper {
  position: absolute; left: 22px; top: 6px; width: 84px; height: 98px; padding: 16px 12px;
  display: flex; flex-direction: column; gap: 9px; transform: rotate(-4deg);
  background: var(--paper-2); border: 2px solid var(--ink); box-shadow: var(--shadow-sm);
}
.loading-paper i { display: block; height: 6px; width: 0; background: var(--green); animation: write 3s ease-in-out infinite; }
.loading-paper i:nth-child(1) { --w: 100%; animation-delay: 0s; }
.loading-paper i:nth-child(2) { --w: 80%; animation-delay: .35s; }
.loading-paper i:nth-child(3) { --w: 92%; animation-delay: .7s; }
.loading-paper i:nth-child(4) { --w: 66%; animation-delay: 1.05s; }
.loading-paper i:nth-child(5) { --w: 48%; animation-delay: 1.4s; }
.loading-pen {
  position: absolute; left: 70px; top: 18px; width: 40px; height: 40px;
  fill: var(--green); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round;
  animation: pen 3s ease-in-out infinite;
}
.loading-pen path:last-child { fill: none; }
.loading-title { margin: 0; font-family: var(--mono); font-size: 15px; font-weight: 700; }
.loading-title::after { content: ""; display: inline-block; width: 1.5em; text-align: left; animation: dots 1.2s steps(4) infinite; }
.loading-steps { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0 0; padding: 0; list-style: none; }
.loading-steps li {
  padding: 3px 10px; font-family: var(--mono); font-size: 12px; color: var(--text-3);
  border: 1.5px dashed var(--text-3);
}
.loading-steps li.done { color: var(--green); border-style: solid; border-color: var(--green); }
.loading-steps li.done::before { content: "✓ "; }
.loading-steps li.active { color: #f9f4e5; background: var(--green); border: 1.5px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.loading-desc { margin: 14px 0 0; font-size: 12.5px; color: var(--text-3); }
.loading-desc b { font-family: var(--mono); color: var(--text-2); }

.result-body .status {
  display: flex; align-items: center; gap: 10px; margin: 0; padding: 12px 18px;
  font-family: var(--mono); font-size: 13px; color: var(--text-2); border-bottom: 1.5px dashed var(--text-3);
}
.result-body .status.error { color: var(--danger); background: var(--danger-soft); }
.result-body .status .dot { width: 8px; height: 8px; background: var(--green); animation: blink 1s steps(1) infinite; }
.result-body .status .retry { margin-left: auto; height: 28px; }

.result-body .output {
  padding: 24px 28px; white-space: pre-wrap; word-break: break-word;
  font-size: 15.5px; line-height: 2; color: var(--text);
}
.result-body .output.streaming::after { content: "▌"; color: var(--green); animation: blink 1s steps(1) infinite; }

/* FAQ */
.faq { margin-top: 48px; }
.faq h2 { margin: 0 0 16px; font-family: var(--mono); font-size: 20px; }
.faq-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.faq details { padding: 14px 18px; background: var(--paper-2); border: 2px solid var(--ink); box-shadow: var(--shadow-sm); }
.faq summary { cursor: pointer; font-family: var(--mono); font-weight: 700; font-size: 14px; }
.faq summary::marker { color: var(--green); }
.faq details p { margin: 10px 0 0; font-size: 13.5px; color: var(--text-2); }

/* Footer */
.site-footer { margin-top: 32px; padding-bottom: 32px; }
.notes {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px;
  margin: 0; padding: 14px 20px; list-style: none; border: 1.5px dashed var(--text-3);
  background: color-mix(in srgb, var(--paper-2) 60%, transparent);
}
.notes li { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.notes svg { width: 16px; height: 16px; margin-top: 2px; fill: var(--green); stroke: var(--paper-2); stroke-width: 2; stroke-linecap: round; }
.copyright { margin: 16px 0 0; text-align: center; font-family: var(--mono); font-size: 12px; color: var(--text-3); }

/* Modal */
.modal {
  width: min(720px, 100% - 32px); padding: 0; color: var(--text);
  background: var(--paper-2); border: 2px solid var(--ink); border-radius: 0; box-shadow: 6px 6px 0 var(--ink);
}
.modal::backdrop { background: rgba(20, 28, 22, 0.45); }
.modal-inner { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-family: var(--mono); font-size: 17px; }
.modal-tip { margin: 0; font-size: 13px; color: var(--text-3); }
#promptInput {
  width: 100%; height: min(52vh, 440px); resize: vertical; padding: 12px 14px;
  font-family: var(--mono); font-size: 13px; line-height: 1.8; color: var(--text);
  background: var(--paper); border: 2px solid var(--ink); border-radius: 0; outline: none;
}
#promptInput:focus { border-color: var(--green); }
.modal-foot { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.ghost-btn.small { height: 28px; padding: 0 10px; font-size: 12px; box-shadow: 2px 2px 0 var(--ink); }
.ghost-btn.danger { color: var(--danger); }
.ghost-btn.danger:hover { background: var(--danger-soft); }
.ghost-btn:disabled { opacity: .45; cursor: not-allowed; }

/* History */
.history-modal { width: min(1040px, 100% - 32px); }
.history-list { display: flex; flex-direction: column; gap: 10px; max-height: min(62vh, 560px); overflow-y: auto; padding: 2px 6px 6px 2px; }
.history-item {
  display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 12px 14px; text-align: left;
  background: var(--paper); border: 2px solid var(--ink); box-shadow: var(--shadow-sm);
}
.history-item:hover { background: var(--green-soft); }
.history-item:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.hi-head { display: flex; justify-content: space-between; gap: 12px; font-family: var(--mono); font-size: 12px; color: var(--text-3); }
.hi-title { font-size: 15px; font-weight: 600; color: var(--text); }
.hi-snippet { font-size: 13px; color: var(--text-2); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.history-empty { padding: 48px 16px; text-align: center; border: 1.5px dashed var(--text-3); }

.detail-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-time { font-family: var(--mono); font-size: 12.5px; color: var(--text-3); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 14px; }
.detail-pane { display: flex; flex-direction: column; min-width: 0; background: var(--paper); border: 2px solid var(--ink); }
.pane-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 2px solid var(--ink); background: var(--paper-3); }
.pane-head h3 { margin: 0; font-family: var(--mono); font-size: 13px; }
.pane-head h3 span { margin-left: 6px; font-weight: 400; color: var(--text-3); }
.pane-text {
  height: min(52vh, 480px); overflow-y: auto; padding: 14px 16px;
  white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.9; color: var(--text);
}

.toast {
  position: fixed; left: 50%; bottom: 32px; z-index: 100; transform: translate(-50%, 20px);
  padding: 10px 18px; font-family: var(--mono); font-size: 13px; color: #f9f4e5;
  background: #213428; border: 2px solid var(--ink); box-shadow: var(--shadow-sm);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Privacy page */
.prose { max-width: 760px; margin: 40px auto; padding: 28px 32px; background: var(--paper-2); border: 2px solid var(--ink); box-shadow: var(--shadow); }
.prose h1 { margin-top: 0; font-family: var(--mono); font-size: 26px; }
.prose h2 { font-family: var(--mono); font-size: 16px; margin-top: 28px; }
.prose p, .prose li { color: var(--text-2); font-size: 15px; }

@keyframes write {
  0% { width: 0; }
  40%, 80% { width: var(--w); }
  100% { width: var(--w); opacity: 0; }
}
@keyframes pen {
  0%, 100% { transform: translate(-30px, 0) rotate(0); }
  20% { transform: translate(0, 6px) rotate(-6deg); }
  40% { transform: translate(-24px, 22px) rotate(0); }
  60% { transform: translate(-6px, 30px) rotate(-6deg); }
  80% { transform: translate(-36px, 44px) rotate(0); }
}
@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75%, 100% { content: "..."; }
}
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 960px) {
  .hero-inner { grid-template-columns: 1fr; padding: 0; }
  .hero-art { display: none; }
  .notes { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .container { width: calc(100% - 28px); }
  .hero { padding-top: 30px; }
  .hero-brand { font-size: 38px; }
  .hero-slogan { font-size: 28px; }
  .hero-desc br { display: none; }
  .hero-tags li { padding-right: 14px; }
  .faq-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .pane-text { height: 32vh; }
  .result-head { flex-wrap: wrap; gap: 10px; }
  .editor-actions .primary-btn { flex: 1; }
  .result-body .output { padding: 16px; }
  .prose { padding: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
