:root {
  color-scheme: light;
  font-family: Geist, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: #172923;
  background: #f5f6f3;
  font-size: 16px;
  line-height: 1.5;
  --ink: #172923;
  --brand: #153b32;
  --primary: #216753;
  --primary-hover: #174d3e;
  --muted: #536560;
  --paper: #fff;
  --panel: #f5f6f3;
  --border: #dbe3dd;
  --selected: #e8f3ed;
  --danger: #9a362d;
  --round: 8px;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 300px; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.25; text-wrap: balance; }
p { text-wrap: pretty; }
h1 { font-size: 1.75rem; font-weight: 650; }
h2 { font-size: 1.125rem; font-weight: 650; }
h3 { font-size: 1.125rem; }
small { font-size: .8125rem; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .52; }
:focus-visible { outline: 2px solid #318266; outline-offset: 3px; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.sr-only { position: absolute; overflow: hidden; clip-path: inset(50%); width: 1px; height: 1px; white-space: nowrap; }
.splash, .blank-panel, .home-empty { display: grid; justify-items: center; align-content: center; gap: 12px; text-align: center; padding: 32px; }
.splash { min-height: 65vh; }
.blank-panel { min-height: 300px; padding: 40px 16px; }
.blank-panel p, .home-empty p { max-width: 440px; }
.home-empty { align-self: stretch; min-height: min(68vh, 600px); }
.home-empty .button, .blank-panel .button { margin-top: 8px; }

.button, .icon-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 12px; color: var(--ink); background: var(--paper);
  border: 1px solid var(--border); border-radius: var(--round);
  font-size: .875rem; font-weight: 560; line-height: 1.35; text-decoration: none; white-space: nowrap;
  transition: background-color 200ms cubic-bezier(.22,1,.36,1), color 200ms cubic-bezier(.22,1,.36,1);
}
.button:hover:not(:disabled), .icon-button:hover { background: #f0f5f1; }
.button.primary { color: #fff; background: var(--primary); border-color: var(--primary); font-size: .9375rem; font-weight: 650; }
.button.primary:hover:not(:disabled) { background: var(--primary-hover); }
.button.subtle { background: transparent; border-color: transparent; color: var(--muted); }
.button.subtle:hover:not(:disabled) { background: var(--selected); color: var(--ink); }
.button.danger { color: var(--danger); }
.button.compact { min-height: 34px; padding: 4px 8px; }
.icon-button { min-width: 36px; min-height: 36px; padding: 4px; flex: none; font-size: 1.25rem; }
.actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.wrap { flex-wrap: wrap; }

label { display: grid; gap: 4px; font-size: .875rem; font-weight: 550; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; min-width: 0; min-height: 38px; padding: 8px 10px; color: var(--ink);
  border: 1px solid #cbd8d0; background: var(--paper); border-radius: 6px; font-size: .875rem;
}
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; flex: none; }
::placeholder { color: #65756e; opacity: 1; }
.stack { display: grid; gap: 16px; }
.stack.slim { gap: 8px; }
.stack.slim small { font-weight: 400; }
.inline-error { color: var(--danger); font-size: .875rem; }
.toggle-line { display: flex; align-items: center; gap: 8px; min-height: 28px; }

.brand { display: flex; align-items: center; gap: 11px; font-weight: 650; font-size: 1.375rem; letter-spacing: -.025em; white-space: nowrap; }
.mark {
  position: relative; width: 34px; height: 34px; flex: none; border-radius: 8px;
  background: #cee7a9; color: #173c32;
}
.mark::before, .mark::after { content: ""; position: absolute; background: currentColor; transform: rotate(-48deg); }
.mark::before { width: 21px; height: 6px; top: 13px; left: 7px; clip-path: polygon(0 0, 70% 0, 100% 50%, 70% 100%, 0 100%); }
.mark::after { width: 4px; height: 11px; top: 18px; left: 9px; }

.entry { min-height: 100svh; display: grid; grid-template-columns: minmax(360px, 1.05fr) minmax(330px, .95fr); }
.entry-identity {
  min-height: 100%; display: grid; grid-template-rows: min-content 1fr; position: relative; overflow: hidden;
  isolation: isolate; gap: 48px; padding: clamp(28px, 5vw, 72px); background: var(--brand); color: #f1f7ef;
}
.entry-copy { align-self: center; padding: 28px 0 min(23vh, 180px); z-index: 1; }
.entry-copy h1 { font-size: clamp(3rem, 5.5vw, 5rem); line-height: 1.12; font-weight: 650; letter-spacing: -.08em; margin: 12px 0 20px; }
.entry-copy p { max-width: 345px; color: #dae8d9; }
.entry-copy p:first-child { color: #cee7a9; font-size: .875rem; letter-spacing: .08em; }
.entry-graphic { position: absolute; width: clamp(210px, 32vw, 480px); height: clamp(180px, 25vw, 340px); right: -5%; bottom: -5%; transform: rotate(-12deg); opacity: .7; z-index: -1; }
.sheet { position: absolute; width: 62%; height: 100%; border-radius: 16px; border: 1px solid #a3c2ae; padding: 29% 12% 12%; background: #275648; }
.sheet-back { left: 27%; bottom: 14%; }
.sheet-front { left: 4%; bottom: 0; background: #183e34; }
.sheet i { display: block; height: 7px; width: 80%; margin: 18px 0; background: #628878; border-radius: 3px; }
.sheet i:nth-child(2) { width: 60%; }
.sheet i:nth-child(3) { width: 42%; background: #a4be84; }
.entry-form { align-self: center; width: min(100%, 510px); padding: 48px clamp(24px, 6vw, 76px); justify-self: center; }
.entry-form h2 { font-size: 2rem; margin-bottom: 8px; }
.entry-form form { margin-top: 28px; }
.entry-form input, .entry-form button { min-height: 46px; }

.topbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 24px; color: #f5faf6; background: var(--brand); }
.brand-divider { height: 19px; width: 1px; background: #6a8d7f; margin-left: 4px; }
.brand-label { font-size: .875rem; font-weight: 500; color: #d0e0d7; letter-spacing: 0; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.user-name { font-size: .875rem; padding: 5px 8px; color: #deebdf; overflow-wrap: anywhere; }
.button.top-action { color: #f5faf6; min-height: 36px; border-color: transparent; background: transparent; padding: 6px 8px; }
.button.top-action:hover { background: #295346; }
.topbar button:focus-visible { outline-color: #cee7a9; }

.workspace { display: grid; grid-template-columns: minmax(175px, 210px) minmax(0, 1fr); min-height: calc(100svh - 64px); }
.sidebar { display: flex; flex-direction: column; gap: 16px; border-right: 1px solid var(--border); background: #f0f3ef; padding: 20px 12px; }
.section-heading, .pane-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-heading { padding: 0 4px; }
.section-heading h2, .pane-header h2 { font-size: .875rem; }
.project-list { display: grid; align-content: start; gap: 4px; }
.project-link, .layer-item {
  display: flex; align-items: center; width: 100%; min-width: 0; gap: 10px;
  border: 1px solid transparent; border-radius: 6px; padding: 8px; color: var(--ink); background: transparent; text-align: left;
}
.project-link:hover, .layer-item:hover { background: #f3f6f2; }
.project-link.current, .layer-item.active { background: var(--selected); border-color: #bbd8c9; }
.project-link strong, .layer-item strong { display: block; overflow-wrap: anywhere; font-size: .875rem; font-weight: 650; }
.project-link small, .layer-item small { display: block; color: var(--muted); font-size: .75rem; }
.project-glyph, .large-glyph { position: relative; display: block; flex: none; width: 20px; height: 15px; border: 1.5px solid #568171; border-radius: 2px; }
.project-glyph::after, .large-glyph::after { content: ""; position: absolute; inset: -4px 3px 2px -4px; border: inherit; border-radius: 2px; }
.large-glyph { width: 48px; height: 37px; margin: 8px 0; border-radius: 4px; background: var(--selected); }
.large-glyph::after { inset: -6px 4px 4px -6px; border-radius: 4px; }
.sidebar-empty { padding: 4px; font-size: .875rem; }

.project { min-width: 0; }
.project-head { min-height: 86px; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 24px; background: var(--paper); }
.title-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.title-block h1 { overflow-wrap: anywhere; }
.save-state { font-size: .8125rem; white-space: nowrap; margin-right: 4px; }
.tabs { display: flex; gap: 20px; padding: 0 24px; background: var(--paper); border-bottom: 1px solid var(--border); }
.tabs button { padding: 9px 0 8px; background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent; font-size: .9375rem; }
.tabs button.active { border-color: var(--primary); color: var(--primary-hover); font-weight: 650; }
.tabs button:hover { color: var(--primary-hover); }
.template-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--border); }
.template-list { display: flex; flex-wrap: wrap; gap: 6px; }
.template-chip { border: 1px solid var(--border); color: var(--ink); padding: 6px 10px; min-height: 36px; border-radius: 6px; background: #fafbf9; text-align: left; font-size: .875rem; }
.template-chip.active { background: var(--selected); border-color: #a9ccba; }

.editor { display: grid; grid-template-columns: minmax(150px, 205px) minmax(210px, 1fr) minmax(220px, 268px); min-height: 590px; }
.layer-pane, .properties { min-width: 0; background: var(--paper); }
.layer-pane { border-right: 1px solid var(--border); }
.properties { border-left: 1px solid var(--border); }
.pane-header { min-height: 52px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.layer-list { display: grid; gap: 3px; padding: 8px; max-height: 665px; overflow: auto; }
.layer-item { min-height: 43px; }
.layer-icon { display: grid; place-items: center; width: 25px; height: 25px; flex: none; color: #306852; background: #e5eee7; border-radius: 5px; font-size: .875rem; }
.layer-meta { min-width: 0; flex: 1; }
.layer-item.is-hidden .layer-meta { opacity: .72; }
.layer-visibility { font-size: .75rem; color: var(--muted); }
.empty-layers { margin: 12px; font-size: .875rem; }
.ocr-tools { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px; border-bottom: 1px solid var(--border); }
.ocr-tools select { min-height: 34px; padding: 4px 8px; }

.preview-pane { min-width: 0; display: flex; flex-direction: column; }
.preview-header { background: #fafbf9; }
.preview-row { min-width: 0; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.preview-row select { min-height: 34px; width: clamp(118px, 16vw, 260px); padding: 4px 6px; }
.preview-board { display: grid; align-content: start; justify-items: center; gap: 12px; flex: 1; min-height: 330px; padding: clamp(12px, 2vw, 28px); background: #e7ece8; }
.artboard {
  position: relative; width: min(100%, var(--preview-width)); aspect-ratio: var(--ratio); overflow: clip;
  align-self: start; background-color: #f8f9f7; outline: 1px solid #b8c6bd;
}
.artboard.drawing { touch-action: none; cursor: crosshair; }
#art-image { position: absolute; inset: 0; }
.artboard canvas { width: 100%; height: 100%; display: block; }
#selection-box { position: absolute; border: 1px solid #116cd4; background: #66b2f31c; pointer-events: none; }
.artboard:not(.drawing) #selection-box {
  border: 2px solid #ffda45;
  background: transparent;
  box-shadow: 0 0 0 1px #182332, inset 0 0 0 1px #182332;
}
@media (prefers-reduced-motion: no-preference) {
  .artboard:not(.drawing) #selection-box { animation: selection-signal 2.1s cubic-bezier(.22, 1, .36, 1) both; }
}
@keyframes selection-signal {
  0%, 100% { border-color: #ffda45; }
  33% { border-color: #ff4d91; }
  67% { border-color: #49e7f4; }
}
#preview-status { font-size: .875rem; }
.selection-help { padding: 6px 12px; font-size: .875rem; background: #e2f2e8; color: #224d3d; }
.preview-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 8px 12px; color: var(--muted); background: #fafbf9; font-size: .8125rem; }
.property-body { padding: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.property-body details { border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.property-body summary { cursor: pointer; font-size: .875rem; }
.property-body details[open] summary { margin-bottom: 8px; }
.property-body details label + label, .property-body details .form-grid + label { margin-top: 8px; }
.layer-actions { display: flex; flex-wrap: wrap; gap: 4px; }

.table-section { padding: 20px 24px 32px; }
.table-toolbar { display: flex; flex-wrap: wrap; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.table-toolbar p { margin-top: 4px; font-size: .875rem; }
.table-scroll { overflow: auto; max-height: 68vh; border: 1px solid var(--border); border-radius: var(--round); background: #fff; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .875rem; text-align: left; }
th, td { min-width: 98px; border-bottom: 1px solid var(--border); padding: 8px 12px; vertical-align: middle; }
thead th { position: sticky; top: 0; z-index: 1; background: #ecf3ee; color: #29463a; white-space: nowrap; }
thead th small { margin-left: 8px; font-weight: normal; color: var(--muted); }
tbody tr:last-child > * { border-bottom: 0; }
.param-table td { padding: 0; border-right: 1px solid var(--border); min-width: 105px; }
.param-table td input { padding: 8px; border: 0; border-radius: 0; }
.param-table td input:focus-visible { outline-offset: -2px; }
.param-table .row-number { min-width: 66px; text-align: center; width: 66px; color: var(--muted); }
.param-table tbody .row-number { background: #f4f7f4; padding: 2px 6px; }
.row-number-content, .field-heading, .field-actions { display: flex; align-items: center; gap: 4px; }
.row-number-content { justify-content: flex-end; }
.field-actions { margin-left: auto; }
.table-icon { display: inline-grid; place-items: center; flex: none; width: 30px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--primary); }
.table-icon:hover:not(:disabled) { border-color: var(--border); background: var(--paper); }
.table-icon.danger { color: var(--danger); }
.param-table .row-actions { min-width: 65px; padding: 2px 8px; white-space: nowrap; }
.table-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: .875rem; }
.table-empty { padding: 16px; }
.pagination { display: flex; align-items: center; gap: 8px; }
.mini { max-height: 250px; }
.mini td { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 62px; max-width: 210px; }
.history-table td { min-width: 70px; }
.run-status { display: inline-block; color: #3b5148; background: #eaf0ec; padding: 2px 8px; border-radius: 5px; font-size: .8125rem; white-space: nowrap; }
.run-status.complete { color: #1b583e; background: #e1f2e6; }
.run-status.failed, .run-status.interrupted { color: #852821; background: #fcebe7; }
.run-error { display: block; margin-top: 4px; overflow-wrap: anywhere; }

dialog { width: min(calc(100% - 28px), 615px); max-height: 90dvh; padding: 0; color: var(--ink); background: var(--paper); border: 1px solid var(--border); border-radius: 12px; }
dialog::backdrop { background: #10282099; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.dialog-body { padding: 16px 20px 20px; }
.dialog-actions { display: flex; align-items: center; justify-content: end; gap: 8px; flex-wrap: wrap; }
.dialog-body fieldset { border: 1px solid var(--border); border-radius: 6px; min-width: 0; max-height: 250px; overflow: auto; }
.dialog-body legend { font-weight: 600; font-size: .875rem; }
.dialog-body p, .review-issues { font-size: .9375rem; }
.review-issues { max-height: 235px; overflow: auto; margin: 0; padding: 8px 12px 8px 28px; color: #8b3229; background: #fcf0eb; border-radius: 6px; }
#generation-issues:empty { display: none; }
progress { width: 100%; height: 14px; accent-color: var(--primary); }
.accounts { list-style: none; padding: 0; margin: 0; max-height: 180px; overflow: auto; }
.accounts li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.accounts span { font-size: .875rem; color: var(--muted); }
#notice { position: fixed; z-index: 3; right: 16px; bottom: 16px; max-width: min(490px, calc(100% - 32px)); padding: 12px 16px; color: #fff; background: var(--brand); border-radius: var(--round); }
#notice[data-error=true] { background: #943c33; }

@media (max-width: 1060px) {
  .workspace { grid-template-columns: 165px minmax(0, 1fr); }
  .editor { grid-template-columns: 140px minmax(160px, 1fr) 205px; }
  .project-head, .tabs, .template-bar, .table-section { padding-inline: 16px; }
  .save-state { display: none; }
}
@media (max-width: 850px) {
  .editor { grid-template-columns: 145px minmax(0, 1fr); }
  .properties { grid-column: 1 / -1; border-top: 1px solid var(--border); border-left: 0; }
  .property-body { max-width: 560px; }
  .project-head, .title-block { flex-wrap: wrap; }
}
@media (max-width: 625px) {
  .entry { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .entry-identity { padding: 20px; gap: 8px; }
  .entry-copy { padding: 16px 0 8px; }
  .entry-copy h1 { font-size: 2.75rem; }
  .entry-form { padding: 28px 20px; }
  .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 3px; }
  .topbar-actions { flex-wrap: wrap; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); padding: 8px 12px; gap: 4px; }
  .project-list { display: flex; gap: 4px; overflow: auto; }
  .project-link { width: auto; flex: none; }
  .editor { display: flex; flex-direction: column; }
  .preview-pane { order: -1; }
  .preview-board { min-height: 185px; }
  .layer-pane { border-top: 1px solid var(--border); border-right: 0; }
  .layer-list { max-height: 260px; }
  .project-head, .tabs, .template-bar, .table-section { padding-inline: 12px; }
  .template-bar { align-items: start; }
  .template-chip { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
