/* Ruang - drafting-table identity. Tokens mirror design.md. */
:root {
  --paper: #f4f1ea;
  --sheet: #fbfaf6;
  --ink: #1e2328;
  --muted: #565d64;
  --line: #d9d3c7;
  --line-strong: #b9b1a2;
  --accent: #a84b25;
  --accent-ink: #ffffff;
  --ok: #2f7a52;
  --warn: #9a6a10;
  --bad: #a3321f;
  --lens: #285a86;
  --grid: rgba(30, 35, 40, 0.045);
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, 'Noto Serif', serif;
  --sans: 'Segoe UI', system-ui, -apple-system, 'Noto Sans', 'Helvetica Neue', Arial, 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  --r: 4px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --bar-h: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15181b; --sheet: #1c2024; --ink: #ece8e0; --muted: #a9afb4; --line: #30363c; --line-strong: #4a525a;
    --accent: #e0814f; --accent-ink: #1a0f08; --grid: rgba(236, 232, 224, 0.04); --ok: #6cc596; --warn: #e2b04a; --bad: #f08a72; --lens: #8ab8e0;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 15px/1.45 var(--sans); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* top bar */
.bar { height: var(--bar-h); display: flex; align-items: center; gap: var(--s4); padding: 0 var(--s4); border-bottom: 1px solid var(--line); background: var(--sheet); }
.brand { display: flex; align-items: center; gap: var(--s2); color: var(--ink); text-decoration: none; }
.mark { width: 26px; height: 26px; color: var(--accent); }
.word { font: 600 22px/1 var(--serif); letter-spacing: 0.01em; }
.tag { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-actions { margin-left: auto; display: flex; gap: var(--s2); }

/* buttons */
.btn { border: 1px solid var(--line-strong); background: var(--sheet); border-radius: var(--r); padding: 7px 12px; cursor: pointer; min-height: 36px; line-height: 1.2; }
.btn:hover { border-color: var(--ink); }
.btn:focus-visible, .chip:focus-visible, .step:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 30px; padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.row { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }

/* layout */
.work { display: grid; grid-template-columns: 76px 1fr 380px; height: calc(100vh - var(--bar-h)); height: calc(100dvh - var(--bar-h)); }
.steps { border-right: 1px solid var(--line); background: var(--sheet); display: flex; flex-direction: column; padding: var(--s2) 0; }
.step { border: 0; background: none; padding: var(--s3) var(--s1); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); border-left: 3px solid transparent; }
.step b { font: 600 13px var(--mono); color: var(--ink); opacity: 0.55; }
.step span { font-size: 11.5px; text-align: center; line-height: 1.15; }
.step[aria-current='step'] { color: var(--ink); border-left-color: var(--accent); background: var(--paper); }
.step[aria-current='step'] b { opacity: 1; color: var(--accent); }
.stage { position: relative; overflow: hidden; background: var(--paper); }
.view, .photo-ed { position: absolute; inset: 0; }
.view canvas { display: block; touch-action: none; }
.panel { border-left: 1px solid var(--line); background: var(--sheet); overflow-y: auto; padding: var(--s4) var(--s4) var(--s6); }

/* panel content */
.panel h2 { font: 600 22px/1.2 var(--serif); margin: 0 0 var(--s2); }
.sec { margin: var(--s5) 0 var(--s2); display: flex; align-items: center; gap: var(--s2); font: 600 12px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.sec::before, .sec::after { content: ''; height: 1px; background: var(--line-strong); }
.sec::before { width: 10px; }
.sec::after { flex: 1; }
.panel p { margin: var(--s2) 0; }
.field { display: grid; grid-template-columns: 1fr 120px; gap: var(--s2); align-items: center; margin: 6px 0; }
.field input, .field select, .dlg select, textarea, .num { border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--paper); padding: 6px 8px; min-height: 34px; width: 100%; }
.num { font-family: var(--mono); text-align: right; }
textarea { min-height: 72px; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line-strong); border-radius: 999px; padding: 5px 11px; background: var(--paper); cursor: pointer; font-size: 13.5px; min-height: 32px; }
.chip[aria-pressed='true'] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r); overflow: hidden; }
.seg button { border: 0; background: var(--sheet); padding: 6px 10px; cursor: pointer; min-height: 32px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button[aria-pressed='true'] { background: var(--ink); color: var(--paper); }

/* style picker: a sheet of small specimen tiles */
.styles { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s2); }
.stile { border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--paper); padding: 0; cursor: pointer; text-align: left; overflow: hidden; }
.stile img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: var(--line); }
.stile span { display: block; padding: 6px 8px; font-size: 13.5px; }
.stile[aria-pressed='true'] { outline: 2px solid var(--accent); outline-offset: -2px; }

/* catalog */
.catalog { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.cat { border: 1px solid var(--line); background: var(--paper); border-radius: var(--r); padding: 7px 9px; text-align: left; cursor: pointer; }
.cat:hover { border-color: var(--ink); }
.cat small { display: block; color: var(--muted); font: 11.5px var(--mono); }

/* templates */
.tpls { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s2); }
.tpl { border: 1px solid var(--line); background: var(--paper); border-radius: var(--r); padding: 0; cursor: pointer; text-align: left; overflow: hidden; }
.tpl .sw { display: flex; height: 26px; }
.tpl .sw i { flex: 1; }
.tpl .sw i:first-child { flex: 3; }
.tpl b { display: block; font-weight: 600; font-size: 13.5px; padding: 6px 8px 0; }
.tpl small { display: block; padding: 0 8px 7px; color: var(--muted); font: 11px var(--mono); }
.tpl[aria-pressed='true'] { outline: 2px solid var(--accent); outline-offset: -2px; }
.swatches { display: flex; gap: 4px; margin: var(--s2) 0; }
.swatches i { width: 34px; height: 34px; border-radius: var(--r); border: 1px solid var(--line); }

/* notes list */
.notes { list-style: none; padding: 0; margin: 0; }
.notes li { padding: 8px 0 8px 14px; border-bottom: 1px dashed var(--line); position: relative; }
.notes li::before { content: ''; position: absolute; left: 0; top: 14px; width: 6px; height: 6px; border: 1.5px solid var(--muted); }
.notes li.bad::before { background: var(--bad); border-color: var(--bad); }
.notes li.warn::before { border-color: var(--warn); background: transparent; transform: rotate(45deg); }
.notes li.good::before { border-color: var(--ok); border-radius: 50%; }
.notes li.lens::before { border-color: var(--lens); }
.notes li .btn { margin-top: 4px; }

/* cost table */
.cost { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.cost td { padding: 6px 2px; border-bottom: 1px solid var(--line); vertical-align: top; }
.cost td.amt { font-family: var(--mono); text-align: right; white-space: nowrap; }
.cost tr.off td { color: var(--muted); text-decoration: line-through; }
.cost tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--ink); }
.tagp { font: 10.5px var(--mono); border: 1px solid var(--line-strong); border-radius: 3px; padding: 0 4px; color: var(--muted); margin-left: 4px; }

/* viewbar: drafting toolbar over the stage */
.viewbar { position: absolute; top: var(--s3); left: var(--s3); right: var(--s3); display: flex; flex-wrap: wrap; gap: var(--s2); pointer-events: none; }
.viewbar > * { pointer-events: auto; }
.viewbar .seg { background: var(--sheet); box-shadow: 0 1px 0 var(--line); }
.viewbar .right { margin-left: auto; display: flex; gap: var(--s2); }

/* sun clock */
.sunbar { position: absolute; left: var(--s3); bottom: var(--s3); background: var(--sheet); border: 1px solid var(--line-strong); border-radius: var(--r); padding: 6px 10px; display: flex; gap: var(--s2); align-items: center; font-size: 13px; max-width: calc(100% - 300px); }
.sunbar input[type='range'] { width: 150px; accent-color: var(--accent); }
.sunbar select { border: 1px solid var(--line-strong); background: var(--paper); border-radius: var(--r); padding: 2px 4px; }
.sunbar .mono { min-width: 44px; }

/* title block: the signature element */
.titleblock { position: absolute; right: var(--s3); bottom: var(--s3); background: var(--sheet); border: 1.5px solid var(--ink); display: grid; grid-template-columns: auto auto; font: 11px var(--mono); min-width: 230px; }
.titleblock div { padding: 3px 7px; border-right: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.titleblock div:nth-child(2n) { border-right: 0; }
.titleblock div:nth-last-child(-n + 2) { border-bottom: 0; }
.titleblock .k { color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.titleblock .name { font: 600 15px var(--serif); grid-column: span 2; border-right: 0; }

.split-handle { position: absolute; top: 0; bottom: 0; width: 28px; margin-left: -14px; cursor: ew-resize; display: flex; justify-content: center; touch-action: none; }
.split-handle span { width: 2px; background: var(--accent); height: 100%; position: relative; }
.split-handle span::after { content: '\2194'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--accent); color: var(--accent-ink); border-radius: 50%; width: 30px; height: 30px; display: grid; place-items: center; font-size: 16px; }
.walkpad { position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%); background: var(--sheet); border: 1px solid var(--line-strong); border-radius: var(--r); padding: 6px 10px; display: flex; gap: var(--s2); align-items: center; }
.toast { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: var(--r); font-size: 13.5px; opacity: 0; transition: opacity 0.2s; pointer-events: none; max-width: 90%; }
.toast.show { opacity: 1; }

/* photo editor */
.photo-ed { background: #2a2c2e; display: grid; place-items: center; }
.photo-ed canvas { max-width: 100%; max-height: 100%; touch-action: none; cursor: crosshair; }
.pick-pop { position: absolute; background: var(--sheet); border: 1px solid var(--ink); border-radius: var(--r); padding: 6px; display: flex; flex-wrap: wrap; gap: 4px; max-width: 290px; z-index: 5; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumb { position: relative; width: 86px; height: 64px; border: 1px solid var(--line-strong); border-radius: var(--r); overflow: hidden; padding: 0; cursor: pointer; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb b { position: absolute; left: 3px; top: 3px; background: var(--ink); color: var(--paper); font: 11px var(--mono); padding: 0 4px; }
.thumb[aria-pressed='true'] { outline: 2px solid var(--accent); }
.wallpick svg { width: 74px; height: 74px; }
.drop { border: 1.5px dashed var(--line-strong); border-radius: var(--r); padding: var(--s4); text-align: center; background: var(--paper); }

.dlg { border: 1.5px solid var(--ink); border-radius: var(--r); background: var(--sheet); color: var(--ink); padding: var(--s5); width: min(440px, 92vw); }
.dlg::backdrop { background: rgba(20, 22, 24, 0.55); }
.dlg h2 { font: 600 24px var(--serif); margin: 0 0 var(--s4); }
.dlg label { display: grid; gap: 4px; margin-bottom: var(--s3); font-weight: 600; font-size: 13.5px; }
.score { font: 600 30px var(--mono); }
.big { font: 600 20px var(--mono); }

/* phone */
@media (max-width: 860px) {
  body { overflow: auto; }
  .tag { display: none; }
  .work { grid-template-columns: 1fr; grid-template-rows: 52svh auto; height: auto; padding-bottom: 64px; }
  .stage { height: 52svh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .steps { position: fixed; left: 0; right: 0; bottom: 0; height: 60px; flex-direction: row; z-index: 20; border-right: 0; border-top: 1px solid var(--line); padding: 0; overflow-x: auto; }
  .step { flex: 1; min-width: 58px; border-left: 0; border-top: 3px solid transparent; padding: 6px 2px; }
  .step[aria-current='step'] { border-top-color: var(--accent); }
  .titleblock { display: none; }
  .sunbar { right: var(--s3); max-width: none; }
  .sunbar input[type='range'] { width: 100%; flex: 1; }
  .viewbar .right { margin-left: 0; }
  .bar-actions .btn { padding: 6px 8px; font-size: 13px; }
}

/* architect fixes: every catch carries its fix and its cost */
.fixrow { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s1); }
.fixcost { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); border-left: 2px solid var(--accent); padding: 2px 0 2px var(--s2); margin: var(--s2) 0; }

/* drafting paper: faint 1 cm-style grid behind the sheet */
body {
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}
