/* 木与竹: warm wood, bamboo green, paper-white blueprint grid. */
:root {
  color-scheme: light dark;
  --paper: #fbf8f0;
  --paper-2: #f3ecdc;
  --sheet: #fffdf8;
  --grid-minor: rgba(74, 124, 89, 0.11);
  --grid-major: rgba(74, 124, 89, 0.22);
  --ink: #2c2218;
  --ink-soft: #6a5a48;
  --wood: #8a5a2e;
  --wood-dark: #5b3a1d;
  --wood-light: #c9a173;
  --bamboo: #4a7c59;
  --bamboo-dark: #2f5a3e;
  --bamboo-pale: #dfeadb;
  --good: #3f7a50;
  --warn: #a2512b;
  --line: #d9ccb4;
  --focus: #1f6f8b;
  --radius: 10px;
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", Georgia, serif;
  --sans: "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --t-bedroom: #e8d3b5; --t-living: #dbe6cf; --t-kitchen: #f0dcc0; --t-bathroom: #cfe1e0;
  --t-study: #d9d3e6; --t-dining: #ecdcc6; --t-balcony: #e1ecd2; --t-storage: #e4dccf;
  --t-entrance: #efe3c4; --t-other: #e6e0d4;
}
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1f1a14; --paper-2: #2a2319; --sheet: #28211a;
    --grid-minor: rgba(143, 188, 150, 0.09); --grid-major: rgba(143, 188, 150, 0.18);
    --ink: #f1e8d8; --ink-soft: #b9a98f; --line: #4a3d2c;
    --wood: #d09a5f; --wood-dark: #e3b883; --wood-light: #7a5630;
    --bamboo: #8cc29a; --bamboo-dark: #a9d6b4; --bamboo-pale: #26382b;
    --good: #8cc29a; --warn: #e49a72; --focus: #6cc0dc;
    --t-bedroom: #4a3b29; --t-living: #2f4232; --t-kitchen: #4d3b27; --t-bathroom: #2c4343;
    --t-study: #3d3750; --t-dining: #4b3c2b; --t-balcony: #354629; --t-storage: #403829;
    --t-entrance: #4b4128; --t-other: #3a352b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  line-height: 1.6;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid-minor) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  padding: 0 16px 48px;
}
h1, h2, h3 { font-family: var(--serif); letter-spacing: 0.04em; margin: 0; }
h3 { font-size: 1.05rem; margin: 20px 0 8px; color: var(--wood-dark); }
code { font-family: ui-monospace, Menlo, monospace; font-size: 0.9em; background: var(--paper-2); padding: 0 4px; border-radius: 3px; }

.masthead {
  max-width: 1180px; margin: 0 auto; padding: 22px 0 10px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.7rem; color: var(--wood-dark); line-height: 1.1; }
.tagline { margin: 2px 0 0; color: var(--ink-soft); font-size: 0.92rem; }
.brand-mark { width: 46px; height: 46px; }
.bm-frame { fill: var(--sheet); stroke: var(--wood); stroke-width: 2; }
.bm-stalk { fill: none; stroke: var(--bamboo); stroke-width: 2.6; stroke-linecap: round; }
.local-badge {
  margin: 0; display: inline-flex; align-items: center; gap: 8px; font-size: 0.85rem;
  padding: 5px 12px; border: 1px solid var(--bamboo); color: var(--bamboo-dark);
  background: var(--bamboo-pale); border-radius: 999px;
}
.local-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bamboo); }

.notice {
  max-width: 1180px; margin: 6px auto 18px; padding: 10px 14px; font-size: 0.9rem;
  border-left: 4px solid var(--wood); background: var(--paper-2); color: var(--ink); border-radius: 0 var(--radius) var(--radius) 0;
}

.workbench {
  max-width: 1180px; margin: 0 auto;
  display: grid; gap: 18px; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  grid-template-areas: "editor compass" "results results";
}
.editor { grid-area: editor; }
.compass-panel { grid-area: compass; }
.results { grid-area: results; }

.sheet {
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px 20px; position: relative; overflow: hidden;
  box-shadow: 0 1px 0 var(--line), 0 8px 20px -14px rgba(60, 40, 15, 0.45);
}
.sheet::before { /* wood-grain rail */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 6px;
  background: repeating-linear-gradient(90deg, var(--wood) 0 14px, var(--wood-dark) 14px 17px, var(--wood) 17px 40px, var(--wood-light) 40px 43px);
  opacity: 0.85;
}
.sheet-head { margin: 4px 0 12px; }
.sheet-head h2 { font-size: 1.2rem; color: var(--wood-dark); display: flex; align-items: center; gap: 10px; }
.step {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px;
  background: var(--bamboo); color: #fff; font-size: 0.95rem; font-family: var(--serif);
}
:root:not([data-theme="light"]) .step { color: #12200f; }
.hint { margin: 6px 0 0; color: var(--ink-soft); font-size: 0.9rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 10px; }
.tool-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
button { font: inherit; cursor: pointer; }
.tool, .ghost, .small-btn {
  border: 1px solid var(--wood); background: transparent; color: var(--wood-dark);
  padding: 6px 14px; border-radius: 7px; min-height: 36px;
}
.tool.is-on { background: var(--wood); color: #fff; }
:root:not([data-theme="light"]) .tool.is-on { color: #1b1209; }
.ghost { border-color: var(--bamboo); color: var(--bamboo-dark); }
.ghost:hover, .tool:hover, .small-btn:hover { background: var(--paper-2); }
.tool.is-on:hover { background: var(--wood-dark); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.field-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 0.92rem; }
select, input[type="number"], input[type="text"] {
  font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; min-height: 36px;
}

.canvas-wrap {
  border: 2px solid var(--wood); border-radius: 6px; background: var(--paper); overflow: hidden;
  touch-action: none; line-height: 0;
}
#plan { width: 100%; height: auto; display: block; cursor: crosshair; user-select: none; -webkit-user-select: none; }
#plan.tool-door { cursor: copy; }
#plan.tool-erase { cursor: not-allowed; }
.canvas-help { margin: 8px 0 0; font-size: 0.85rem; color: var(--ink-soft); }

.g-minor { stroke: var(--grid-major); stroke-width: 0.6; }
.g-major { stroke: var(--bamboo); stroke-opacity: 0.45; stroke-width: 1; }
.room rect { stroke: var(--wood-dark); stroke-width: 1.2; }
.room text { font-family: var(--sans); fill: var(--ink); pointer-events: none; }
.room .r-label { font-size: 13px; font-weight: 600; }
.room .r-star { font-size: 12px; }
.star-auspicious { fill: var(--good) !important; }
.star-inauspicious { fill: var(--warn) !important; }
.t-bedroom rect { fill: var(--t-bedroom); } .t-living rect { fill: var(--t-living); } .t-kitchen rect { fill: var(--t-kitchen); }
.t-bathroom rect { fill: var(--t-bathroom); } .t-study rect { fill: var(--t-study); } .t-dining rect { fill: var(--t-dining); }
.t-balcony rect { fill: var(--t-balcony); } .t-storage rect { fill: var(--t-storage); } .t-entrance rect { fill: var(--t-entrance); }
.t-other rect { fill: var(--t-other); }
.outline { fill: none; stroke: var(--wood-dark); stroke-width: 3.5; stroke-linejoin: round; pointer-events: none; }
.preview { fill: var(--bamboo); fill-opacity: 0.25; stroke: var(--bamboo-dark); stroke-width: 2; stroke-dasharray: 5 4; }
.preview.bad { fill: var(--warn); stroke: var(--warn); }
.door-mark { fill: var(--bamboo-dark); stroke: var(--sheet); stroke-width: 2; }
.door-arrow { stroke: var(--bamboo-dark); stroke-width: 3; fill: none; stroke-linecap: round; }
.door-text { font-size: 12px; fill: var(--bamboo-dark); font-weight: 700; font-family: var(--sans); }
.north-arrow path { fill: var(--wood-dark); }
.north-arrow text { font-size: 13px; fill: var(--wood-dark); font-weight: 700; font-family: var(--serif); text-anchor: middle; }
.north-arrow circle { fill: var(--sheet); stroke: var(--wood); stroke-width: 1.5; }

.rose-wrap { display: grid; justify-items: center; gap: 6px; margin: 4px 0 8px; }
#rose { width: min(100%, 300px); height: auto; cursor: grab; touch-action: none; border-radius: 50%; }
#rose.dragging { cursor: grabbing; }
#rose.disabled { cursor: not-allowed; opacity: 0.55; }
.rose-disc { fill: var(--paper); stroke: var(--wood); stroke-width: 3; }
.rose-ring { fill: none; stroke: var(--wood-light); stroke-width: 1; }
.rose-tick { stroke: var(--wood); stroke-width: 1; }
.rose-tick.major { stroke-width: 2; }
.rose-dir { font-family: var(--serif); font-size: 13px; fill: var(--wood-dark); text-anchor: middle; dominant-baseline: central; }
.rose-tri { font-size: 9px; fill: var(--ink-soft); text-anchor: middle; dominant-baseline: central; }
.rose-north { fill: var(--warn); }
.rose-face { stroke: var(--bamboo-dark); stroke-width: 4; stroke-linecap: round; }
.rose-face-head { fill: var(--bamboo-dark); }
.rose-hub { fill: var(--wood-dark); }
.rose-center-text { font-size: 12px; fill: var(--ink); text-anchor: middle; font-family: var(--sans); font-weight: 700; }
.rose-note { margin: 0; font-size: 0.85rem; color: var(--ink-soft); text-align: center; min-height: 1.4em; }

.form-grid { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; font-size: 0.92rem; }
.field input[type="number"] { max-width: 140px; }
fieldset.refs { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0; display: grid; gap: 4px; }
fieldset.refs legend { padding: 0 6px; color: var(--ink-soft); }
.refs label, .check { display: flex; align-items: center; gap: 8px; }
input[type="radio"], input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--bamboo); }
.check { padding: 8px 12px; border: 1px dashed var(--bamboo); border-radius: 8px; background: var(--bamboo-pale); }

.list-h { margin-top: 18px; }
.roster { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.roster li { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; }
.roster .swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--wood-dark); }
.roster input[type="text"] { width: 100%; min-height: 32px; padding: 3px 8px; }
.roster .rtype { font-size: 0.8rem; color: var(--ink-soft); }
.small-btn { padding: 2px 10px; min-height: 30px; font-size: 0.85rem; }
.empty { color: var(--ink-soft); font-size: 0.9rem; margin: 4px 0 0; }

.checklist { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.checklist li { display: flex; gap: 10px; align-items: baseline; }
.checklist .mark { width: 1.4em; font-weight: 700; color: var(--ink-soft); }
.checklist .ok .mark { color: var(--good); }
.callout { padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--warn); background: var(--paper-2); }
.callout.good { border-color: var(--bamboo); background: var(--bamboo-pale); }
.verdict { margin-bottom: 14px; display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: baseline; }
.verdict .big { font-family: var(--serif); font-size: 1.9rem; color: var(--wood-dark); }
.verdict .sub { color: var(--ink-soft); }

.results-grid { display: grid; gap: 22px; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); align-items: start; }
.bagua { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-width: 460px; }
.bagua .cell {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 6px; text-align: center; background: var(--paper);
  min-height: 92px; display: grid; align-content: center; gap: 2px;
}
.bagua .cell.auspicious { border-color: var(--good); background: var(--bamboo-pale); }
.bagua .cell.inauspicious { border-color: var(--warn); }
.bagua .cell.center { background: var(--paper-2); border-style: dashed; }
.bagua .dir { font-size: 0.78rem; color: var(--ink-soft); }
.bagua .star { font-family: var(--serif); font-size: 1.25rem; }
.bagua .auspicious .star { color: var(--good); } .bagua .inauspicious .star { color: var(--warn); }
.bagua .rooms { font-size: 0.78rem; color: var(--ink); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-family: var(--serif); color: var(--wood-dark); border-bottom: 2px solid var(--wood-light); white-space: nowrap; }
td.star-auspicious, td.star-inauspicious { font-weight: 700; white-space: nowrap; }
td ul { margin: 0; padding-left: 1.1em; }
td li { margin-bottom: 4px; }
.facts { margin: 0 0 10px; }
.facts p { margin: 2px 0; color: var(--ink-soft); font-size: 0.9rem; }
.tag { display: inline-block; font-size: 0.75rem; padding: 0 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-soft); margin-left: 6px; white-space: nowrap; }

.colophon { max-width: 1180px; margin: 26px auto 0; color: var(--ink-soft); font-size: 0.85rem; border-top: 1px solid var(--line); padding-top: 12px; }
.colophon p { margin: 4px 0; }

@media (max-width: 920px) {
  .workbench { grid-template-columns: minmax(0, 1fr); grid-template-areas: "editor" "compass" "results"; }
  .results-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .sheet { padding: 14px 12px 18px; }
  .bagua .cell { min-height: 80px; padding: 6px 2px; }
}
@media print {
  body { background: #fff; color: #000; }
  .toolbar, .compass-panel, .canvas-help { display: none; }
  .workbench { display: block; }
  .sheet { box-shadow: none; break-inside: avoid; }
}
@media (prefers-reduced-motion: no-preference) {
  .tool, .ghost, .small-btn { transition: background-color 0.15s; }
}
