/* 豆格的视觉语言来自透明拼豆板、方格纸和实体色号标签。 */
:root {
  color-scheme: light;
  --paper: #f4f7f6;
  --surface: #ffffff;
  --surface-muted: #edf3f1;
  --ink: #1c2827;
  --muted: #687774;
  --line: #d8e2df;
  --line-strong: #a8bab5;
  --accent: #19756b;
  --accent-dark: #105950;
  --accent-soft: #dceeea;
  --warm: #f1b84b;
  --danger: #b64b45;
  --shadow: 0 12px 36px rgba(30, 54, 50, 0.1);
  --header-height: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body { min-height: 100dvh; background: var(--paper); color: var(--ink); overflow-x: hidden; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(25, 117, 107, 0.24); outline-offset: 2px; }
[hidden] { display: none !important; }

/* 顶部栏 */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: calc(var(--header-height) + var(--safe-top));
  display: grid;
  grid-template-columns: 248px minmax(180px, 1fr) auto;
  align-items: center;
  gap: 20px;
  padding: var(--safe-top) 18px 0;
  background: rgba(250, 252, 251, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand > span:last-child { display: grid; gap: 1px; }
.brand strong { font-size: 18px; line-height: 1; }
.brand small { color: var(--muted); font-size: 10px; font-weight: 700; }
.brand-mark { width: 30px; height: 30px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 3px; transform: rotate(3deg); }
.brand-mark i { border-radius: 3px; background: var(--accent); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: var(--warm); }
.project-title-wrap { min-width: 0; display: flex; align-items: center; gap: 12px; }
.project-title { min-width: 0; width: min(440px, 58vw); border: 1px solid transparent; background: transparent; padding: 8px 10px; font-weight: 750; color: var(--ink); }
.project-title:not(:disabled):hover, .project-title:not(:disabled):focus { background: var(--surface); border-color: var(--line); }
.project-title:disabled { opacity: 0.54; }
.save-state { color: var(--muted); font-size: 12px; white-space: nowrap; }
.header-actions { display: flex; gap: 8px; }
.pwa-install-button { white-space: nowrap; }

/* 通用按钮 */
.button, .icon-button, .tool-button, .segmented button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}
.button { padding: 0 16px; font-weight: 700; }
.button.primary { color: #fff; background: var(--accent); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: var(--surface); border-color: var(--line); }
.button.secondary:hover, .button.ghost:hover { background: var(--surface-muted); border-color: var(--line-strong); }
.button.ghost { background: transparent; border-color: transparent; }
.button.danger { color: #fff; background: var(--danger); }
.button.full { width: 100%; }
.button:disabled, .icon-button:disabled, .tool-button:disabled { cursor: not-allowed; opacity: 0.42; }
.icon-button { width: 38px; padding: 0; background: transparent; font-size: 20px; }
.icon-button:hover:not(:disabled) { background: var(--surface-muted); }

/* 三栏应用结构 */
.app-shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: calc(100dvh - var(--header-height) - var(--safe-top)); }
.project-sidebar { position: sticky; top: calc(var(--header-height) + var(--safe-top)); height: calc(100dvh - var(--header-height) - var(--safe-top)); padding: 22px 14px calc(22px + var(--safe-bottom)); background: #edf2f0; border-right: 1px solid var(--line); overflow-y: auto; }
.sidebar-heading, .section-heading, .palette-heading, .dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.eyebrow { color: var(--accent); font-size: 10px; font-weight: 800; text-transform: uppercase; }
h2 { margin: 4px 0 0; font-size: 17px; letter-spacing: 0; }
.project-list { display: grid; gap: 7px; margin-top: 22px; }
.project-item { display: grid; grid-template-columns: 50px minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; }
.project-item:hover { background: rgba(255,255,255,0.68); }
.project-item.active { background: var(--surface); border-color: #c7d7d3; box-shadow: 0 2px 10px rgba(35,60,56,.06); }
.project-thumb { width: 50px; height: 50px; border: 1px solid var(--line); border-radius: 5px; object-fit: cover; image-rendering: pixelated; background: #fff; }
.project-copy { min-width: 0; display: grid; gap: 4px; }
.project-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.project-copy small { color: var(--muted); font-size: 11px; }
.project-actions { display: grid; gap: 2px; opacity: 0; }
.project-item:hover .project-actions, .project-item:focus-within .project-actions { opacity: 1; }
.project-actions button { width: 28px; height: 26px; border: 0; border-radius: 4px; background: transparent; cursor: pointer; }
.project-actions button:hover { background: var(--surface-muted); }
.sidebar-empty { margin-top: 34px; color: var(--muted); font-size: 12px; text-align: center; }
.main-workspace { min-width: 0; }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) 288px; min-height: calc(100dvh - var(--header-height) - var(--safe-top)); }
.canvas-column { min-width: 0; display: flex; flex-direction: column; }

/* 画布区域 */
.canvas-toolbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.tool-group, .zoom-group { display: flex; align-items: center; gap: 4px; }
.tool-button { min-width: 54px; padding: 0 10px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.tool-button:hover { background: var(--surface-muted); color: var(--ink); }
.tool-button.active { background: var(--accent-soft); color: var(--accent-dark); border-color: #b6d9d2; }
.zoom-group output { width: 48px; color: var(--muted); font-size: 12px; text-align: center; }
.canvas-viewport { position: relative; min-height: 590px; height: calc(100dvh - var(--header-height) - var(--safe-top) - 58px); overflow: auto; background-color: #e8eeec; background-image: linear-gradient(#dfe7e4 1px, transparent 1px), linear-gradient(90deg, #dfe7e4 1px, transparent 1px); background-size: 24px 24px; }
.board-wrap { width: max-content; min-width: 100%; min-height: 100%; padding: 34px; display: grid; place-items: center; }
#boardCanvas { display: block; background: #fff; box-shadow: var(--shadow); touch-action: none; }
.canvas-viewport[data-tool="pan"] #boardCanvas { cursor: grab; }
.canvas-viewport[data-tool="pan"].dragging #boardCanvas { cursor: grabbing; }
.canvas-viewport[data-tool="pencil"] #boardCanvas, .canvas-viewport[data-tool="eraser"] #boardCanvas, .canvas-viewport[data-tool="picker"] #boardCanvas { cursor: crosshair; }
.empty-state { min-height: 100%; display: grid; place-content: center; justify-items: center; gap: 28px; padding: 36px; }
.drop-zone { width: min(520px, 78vw); min-height: 268px; display: grid; place-items: center; align-content: center; gap: 12px; padding: 32px; background: rgba(255,255,255,.82); border: 1.5px dashed #9cb7b1; border-radius: 8px; cursor: pointer; box-shadow: 0 16px 40px rgba(38, 67, 61, .08); }
.drop-zone:hover, .drop-zone.dragover { background: #fff; border-color: var(--accent); transform: translateY(-2px); }
.drop-zone strong { margin-top: 4px; font-size: 20px; }
.drop-zone > span:last-child { color: var(--muted); font-size: 13px; }
.drop-visual { width: 90px; display: grid; grid-template-columns: repeat(3, 24px); gap: 5px; transform: rotate(-2deg); }
.drop-visual i { width: 24px; aspect-ratio: 1; border-radius: 5px; background: var(--c); box-shadow: inset 0 0 0 3px rgba(255,255,255,.24); }
.board-measure { display: flex; align-items: baseline; gap: 10px; color: var(--muted); }
.board-measure span { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 24px; font-weight: 800; }
.processing-overlay { position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; justify-items: center; gap: 12px; background: rgba(239,245,243,.9); backdrop-filter: blur(4px); }
.processing-meter { width: min(320px, 60vw); height: 5px; overflow: hidden; background: #ccd9d5; border-radius: 3px; }
.processing-meter span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 120ms linear; }
.processing-overlay strong { font-size: 14px; }
.processing-overlay output { color: var(--muted); font-variant-numeric: tabular-nums; }

/* 右侧检查器 */
.inspector { position: sticky; top: calc(var(--header-height) + var(--safe-top)); height: calc(100dvh - var(--header-height) - var(--safe-top)); padding-bottom: var(--safe-bottom); overflow-y: auto; background: var(--surface); border-left: 1px solid var(--line); }
.inspector-section { padding: 22px 18px; border-bottom: 1px solid var(--line); }
.dimension-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; margin: 20px 0 14px; }
.preset-field { margin-top: 16px; }
.dimension-row label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.dimension-row input, .search-input, .option-field select { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: #fbfdfc; color: var(--ink); }
.dimension-row > span { padding-bottom: 10px; color: var(--muted); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; margin-bottom: 12px; padding: 3px; background: var(--surface-muted); border-radius: 7px; }
.generation-modes { grid-template-columns: repeat(3, 1fr); margin-top: 12px; }
.segmented button { min-height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.segmented button.active { background: var(--surface); color: var(--accent-dark); box-shadow: 0 1px 4px rgba(29,54,50,.1); }
.outline-confirm-button { margin-top: 8px; }
.generation-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.option-field { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.option-field select { padding-right: 6px; cursor: pointer; }
.toggle-option { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding: 0 10px; background: #f7faf9; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; }
.toggle-option input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.revision-field { display: grid; gap: 7px; margin: 16px 0 10px; color: var(--muted); font-size: 11px; font-weight: 700; }
.revision-field textarea { width: 100%; min-height: 84px; padding: 10px; resize: vertical; border: 1px solid var(--line); border-radius: 5px; background: #fbfdfc; color: var(--ink); line-height: 1.55; }
.palette-heading output { min-width: 40px; padding: 5px 7px; background: var(--ink); border-radius: 4px; color: #fff; font-size: 11px; text-align: center; }
.search-input { margin: 16px 0 12px; }
.palette-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; max-height: 390px; overflow-y: auto; padding-right: 3px; }
.palette-swatch { position: relative; aspect-ratio: 1; min-width: 0; border: 1px solid rgba(31,47,45,.14); border-radius: 4px; background: var(--swatch); cursor: pointer; }
.palette-swatch:hover { transform: scale(.92); }
.palette-swatch.active { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.palette-swatch span { position: absolute; inset: auto 2px 2px; padding: 1px; border-radius: 2px; background: rgba(255,255,255,.82); color: #172321; font-size: 7px; font-weight: 800; text-align: center; }

/* 色号统计 */
.color-section { padding: 24px; background: var(--surface); border-top: 1px solid var(--line); }
.summary-line { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 12px; }
.summary-line strong { color: var(--ink); }
.color-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; margin-top: 18px; }
.color-card { min-height: 62px; display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 9px; padding: 8px; background: #f8faf9; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; text-align: left; }
.color-card:hover { border-color: var(--line-strong); background: var(--surface); }
.color-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.color-card.dimmed { opacity: .34; }
.color-chip { width: 34px; height: 34px; border: 1px solid rgba(21,31,30,.16); border-radius: 5px; background: var(--chip); }
.color-card-copy { display: grid; gap: 2px; }
.color-card-copy strong { font-size: 13px; }
.color-card-copy small { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.color-card > strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* 对话框与反馈 */
dialog { max-height: calc(96dvh - var(--safe-top) - var(--safe-bottom)); padding: 0; border: 0; border-radius: 8px; color: var(--ink); box-shadow: 0 24px 72px rgba(14, 31, 28, .28); }
dialog::backdrop { background: rgba(18,31,29,.54); backdrop-filter: blur(3px); }
.dialog-shell { width: min(720px, 92vw); max-width: 100%; padding: 22px; background: var(--surface); }
.dialog-shell.compact { width: min(420px, 90vw); }
.dialog-shell.compact p { color: var(--muted); line-height: 1.65; }
.activation-field { display: grid; gap: 7px; margin-top: 18px; color: var(--muted); font-size: 11px; font-weight: 700; }
.activation-field input { width: 100%; height: 42px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: #fbfdfc; color: var(--ink); }
.crop-stage { width: 100%; margin: 20px 0 14px; padding: 18px; background: #dfe7e4; overflow: hidden; }
#cropCanvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 46vh; margin: 0 auto; touch-action: none; cursor: grab; }
#cropCanvas.dragging { cursor: grabbing; }
#cropCanvas.guide-marking { cursor: crosshair; }
.portrait-guide-controls { display: grid; grid-template-columns: auto minmax(280px, 1fr) auto; align-items: center; gap: 12px; margin-bottom: 12px; color: var(--muted); font-size: 12px; font-weight: 700; }
.crop-guide-modes { grid-template-columns: repeat(4, 1fr); margin: 0; }
.crop-guide-modes button.complete { color: var(--accent-dark); box-shadow: inset 0 -2px var(--accent); }
.crop-controls { display: grid; grid-template-columns: auto minmax(120px, 1fr) 52px auto; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.ai-request-status { display: block; min-height: 18px; margin-top: 14px; color: var(--accent-dark); font-size: 12px; font-weight: 700; text-align: right; }
.beautify-shell { width: min(920px, 94vw); max-height: 94vh; overflow-y: auto; }
.beautify-comparison { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 20px; }
.beautify-preview { min-width: 0; margin: 0; }
.beautify-preview figcaption { margin-bottom: 8px; color: var(--muted); font-size: 11px; font-weight: 700; }
.beautify-preview > div { display: grid; place-items: center; height: min(54vh, 520px); overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: #e8eeec; }
.beautify-preview img { display: block; width: 100%; height: 100%; object-fit: contain; }
.beautify-revision { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; margin-top: 14px; }
.beautify-revision .revision-field { margin: 0; }
.beautify-revision .button { min-height: 84px; }
.line-preview-shell { width: min(820px, 94vw); }
.line-preview-meta { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 18px; color: var(--muted); font-size: 12px; font-weight: 700; }
.line-preview-modes { width: 190px; grid-template-columns: repeat(2, 1fr); margin: 0; }
.line-structure-level { grid-template-columns: repeat(3, 1fr); margin: 10px 0 0; }
.line-preview-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; color: var(--muted); font-size: 11px; font-weight: 700; }
.line-preview-legend span { display: inline-flex; align-items: center; gap: 5px; }
.line-preview-legend i { width: 12px; height: 12px; border: 1px solid rgba(30, 55, 51, .16); }
.line-preview-legend .confirmed { background: #202b2a; }
.line-preview-legend .candidate { background: #aab9b5; }
.line-preview-legend .boundary { background: #e0ebe8; }
.line-preview-legend .removed { background: #f2b4ae; }
.line-preview-stage { width: 100%; max-height: 48vh; margin-top: 10px; overflow: auto; background: #e8eeec; border: 1px solid var(--line); }
#linePreviewCanvas { display: block; max-width: 100%; height: auto; margin: 0 auto; background: #fff; image-rendering: pixelated; cursor: crosshair; touch-action: none; }
#linePreviewCanvas.region-mode { cursor: crosshair; }
#linePreviewCanvas.cells-mode { cursor: cell; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.toast-region { position: fixed; z-index: 80; right: 18px; bottom: calc(18px + var(--safe-bottom)); display: grid; gap: 8px; }
.toast { min-width: 240px; max-width: 360px; padding: 12px 14px; background: #20312f; border-radius: 6px; color: #fff; box-shadow: var(--shadow); font-size: 12px; animation: toast-in 180ms ease both; }
.toast.error { background: #8f3e39; }
.sidebar-scrim, .mobile-only { display: none; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; } }

/* 平板把参数区放到画布下方，保留完整工作流。 */
@media (max-width: 1100px) {
  .app-header { grid-template-columns: 220px minmax(140px, 1fr) auto; }
  .app-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); }
  .inspector { position: static; height: auto; display: grid; grid-template-columns: 1fr 1fr; border-left: 0; border-top: 1px solid var(--line); }
  .canvas-viewport { height: 600px; }
  .palette-grid { max-height: 260px; }
}

/* 手机端图纸列表使用抽屉，工具与参数纵向排列。 */
@media (max-width: 760px) {
  :root { --header-height: 58px; }
  .app-header { grid-template-columns: 38px auto minmax(0, 1fr) auto; gap: 8px; padding: var(--safe-top) 9px 0; }
  .mobile-only { display: block; }
  .brand small, .save-state { display: none; }
  .brand-mark { width: 26px; height: 26px; }
  .project-title-wrap { min-width: 0; }
  .project-title { width: 100%; padding-inline: 4px; font-size: 13px; }
  .header-actions .secondary { display: none; }
  .header-actions .pwa-install-button { display: block; }
  .header-actions .button { padding: 0 11px; font-size: 12px; }
  .app-shell { display: block; }
  .project-sidebar { position: fixed; z-index: 60; top: 0; left: 0; width: min(310px, 86vw); height: 100dvh; padding-top: calc(22px + var(--safe-top)); transform: translateX(-105%); transition: transform 180ms ease; box-shadow: var(--shadow); }
  .project-sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; z-index: 55; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(18,31,29,.42); }
  .sidebar-scrim.open { display: block; }
  .canvas-toolbar { align-items: flex-start; overflow-x: auto; padding: 8px; }
  .canvas-toolbar > .tool-group:nth-child(2) { display: none; }
  .tool-button { min-width: 48px; padding-inline: 7px; }
  .canvas-viewport { min-height: 440px; height: 62vh; }
  .board-wrap { padding: 20px; }
  .empty-state { padding: 18px; }
  .drop-zone { width: 88vw; min-height: 240px; }
  .inspector { grid-template-columns: 1fr; }
  .color-section { padding: 20px 14px; }
  .section-heading { align-items: flex-start; }
  .summary-line { display: grid; gap: 3px; text-align: right; }
  .color-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crop-controls { grid-template-columns: auto 1fr 48px; }
  .crop-controls .button { grid-column: 1 / -1; }
  .portrait-guide-controls { grid-template-columns: 1fr; }
  .portrait-guide-controls > span { display: none; }
  .portrait-guide-controls .button { width: 100%; }
  .beautify-shell { width: 94vw; padding: 16px; }
  .beautify-comparison { grid-template-columns: 1fr; }
  .beautify-preview > div { height: min(31vh, 300px); }
  .beautify-revision { grid-template-columns: 1fr; }
  .beautify-revision .button { min-height: 40px; }
  .beautify-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .beautify-actions .button { min-width: 0; padding-inline: 10px; }
  .beautify-actions .primary { grid-column: 1 / -1; }
  .line-preview-shell { width: 94vw; padding: 18px; }
  .line-preview-meta { align-items: stretch; flex-direction: column; gap: 8px; }
  .line-preview-modes { width: 100%; }
  .line-preview-dialog .dialog-actions { flex-wrap: wrap; }
  .line-preview-dialog .dialog-actions .button { flex: 1 1 auto; padding-inline: 10px; }
}
