:root {
  color-scheme: light;
  --ink: #1c1915;
  --muted: #5e584e;
  --line: #d5cfc3;
  --paper: #f4f1ea;
  --panel: #fbf9f5;
  --green: #0f6b3c;
  --green-soft: #e5f3eb;
  --red: #8c2f2f;
  --amber: #6a4b12;
  --blue: #1557b0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.4 "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

button, input, textarea, select { font: inherit; color: inherit; }

button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}

button.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

button:disabled { opacity: 0.45; cursor: default; }

button[aria-pressed="true"] {
  border-color: var(--green);
  background: var(--green-soft);
}

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.consent {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(28, 25, 21, 0.45);
}

.consent[hidden] { display: none; }

.consent-card {
  width: min(440px, 100%);
  max-height: min(90vh, 640px);
  overflow: auto;
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  border: 1px solid var(--line);
  box-shadow: 0 16px 48px rgba(20, 16, 10, 0.22);
  padding: 18px 18px 16px;
}

.consent-card h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  text-transform: none;
  letter-spacing: 0;
}

.consent-card p { margin: 0 0 10px; font-size: 14px; line-height: 1.45; }
.consent-card ul {
  margin: 0 0 12px;
  padding-left: 1.15em;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}
.consent-card li { margin: 0.4em 0; }
.consent-card li strong { color: var(--ink); }
.consent-card code {
  font-size: 0.9em;
  background: var(--paper);
  padding: 0 4px;
  border-radius: 3px;
}
.consent-note {
  color: var(--muted);
  font-size: 13px !important;
}
.consent-card .primary {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
}

body.consent-pending #app,
body.consent-pending #poster {
  pointer-events: none;
  user-select: none;
}

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.edit-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  flex: 0 0 auto;
}

.edit-bar .tool { width: auto; }

.edit-bar button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.edit-bar .icon-rotate {
  display: block;
  flex: 0 0 auto;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
}

.lede {
  margin: 2px 0 0;
  font-size: 13px;
}

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

.top h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}

#save-state, #pay-state, .fine, .hint {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 320px;
  min-height: 0;
}

.tools, .facts {
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  padding: 12px;
}

.tools { border-right: 1px solid var(--line); }
.facts { border-left: 1px solid var(--line); }

h2 {
  margin: 14px 0 8px;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tools h2:first-of-type { margin-top: 14px; }
.facts h2:first-child,
.check-wrap h2 { margin-top: 0; }

.edit-actions { display: grid; gap: 6px; margin-bottom: 4px; }
.edit-actions button { width: 100%; }

.tool-col, .fields { display: grid; gap: 6px; }

.tool {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
}

#btn-finish { width: 100%; margin-top: 6px; }

.canvas-wrap {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 8px;
  align-items: stretch;
}

.canvas-wrap .edit-bar {
  align-self: flex-start;
}

svg.plan {
  width: min(100%, calc((100% - 0px)));
  max-width: 100%;
  height: auto;
  max-height: 100%;
  aspect-ratio: 1000 / 700;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(40, 30, 10, 0.08);
  touch-action: none;
}

svg.plan.a4 { max-width: min(100%, 900px); }
svg.plan.portrait { max-width: min(100%, 640px); }
svg.plan.a4.portrait { max-width: min(100%, 520px); }

svg.plan[data-tool="room"],
svg.plan[data-tool="route"],
svg.plan[data-tool="place"] { cursor: crosshair; }

svg.plan text { font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif; }

.hint { margin: 0; }

.facts section + section { margin-top: 8px; }

label { display: grid; gap: 4px; font-size: 13px; }

label.checkline {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  grid-template-columns: none;
}

label.checkline input { width: auto; margin-top: 2px; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
}

textarea { min-height: 4.5em; resize: vertical; }

.check-wrap {
  position: sticky;
  top: -12px;
  z-index: 1;
  background: var(--panel);
  padding-bottom: 8px;
}

#check-sum { margin: 0 0 6px; font-weight: 650; }

#checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 3px;
}

#checklist li { font-size: 13px; padding-left: 16px; position: relative; }
#checklist li::before { position: absolute; left: 0; }
#checklist li.ok::before { content: "✓"; color: var(--green); }
#checklist li.miss.ska::before { content: "•"; color: var(--red); }
#checklist li.miss.bor::before { content: "•"; color: var(--amber); }
#checklist li.ok { color: #245c3a; }
#checklist li.miss.ska { color: var(--red); }
#checklist li.miss.bor { color: var(--amber); }

#selection p { margin: 0 0 8px; }
#selection .row { display: flex; gap: 6px; margin-top: 8px; }

.rules { margin-top: 16px; font-size: 13px; }
.rules p { margin: 8px 0; }

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

#poster { display: none; }

body.previewing { overflow: auto; height: auto; background: #d9d3c5; }
body.previewing #app { display: none; }
body.previewing #poster { display: block; padding: 16px 16px 32px; }

.preview-bar {
  width: min(1120px, 100%);
  margin: 0 auto 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.preview-bar #paper-note {
  margin-left: auto;
}

.sheet {
  position: relative;
  width: min(1120px, 100%);
  aspect-ratio: 420 / 297;
  height: auto;
  max-height: none;
  margin: 0 auto;
  background: #fff;
  color: #111;
  border: 8px solid #01925F;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(40, 30, 10, 0.16);
}

/* A4 is ~71% of A3 (297/420), so preview size matches physical paper. */
.sheet.a4 {
  width: min(792px, 100%);
}

.sheet.portrait {
  width: min(820px, 100%);
  aspect-ratio: 297 / 420;
}

.sheet.a4.portrait {
  width: min(580px, 100%);
  aspect-ratio: 210 / 297;
}

.watermark {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

body.paid .watermark { display: none; }

.sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: stretch;
  background: #01925F;
  color: #fff;
  padding: 10px 16px;
}

.sheet-head h2 {
  margin: 0;
  color: #fff;
  font-size: 28px;
  letter-spacing: 0.04em;
  text-transform: none;
}

.sheet-head p { margin: 2px 0 0; font-size: 14px; }

#p-address {
  margin: 0;
  text-align: right;
  font-size: 16px;
  font-weight: 650;
  max-width: 42%;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.85fr 1fr;
}

.sheet.portrait .sheet-body {
  grid-template-columns: 1fr;
  grid-template-rows: 1.35fr 1fr;
}

.sheet-draw {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-right: 2px solid #111;
}

.sheet.portrait .sheet-draw {
  border-right: 0;
  border-bottom: 2px solid #111;
}

.sheet-draw svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#overview-svg {
  width: 100%;
  height: 78px;
  display: block;
}

.sheet-side {
  min-height: 0;
  overflow: hidden;
  padding: 8px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sheet-side h3 {
  margin: 0 0 2px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.prose, .assembly-name, #p-alarm-address {
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
}

.prose { white-space: pre-wrap; }
.assembly-name { font-weight: 700; }

#overview-svg {
  border: 1px solid #111;
  background: #f4f7f2;
}

#p-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 8px;
}

#p-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  min-width: 0;
}

.sheet-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid #111;
  padding: 4px 12px;
  font-size: 11px;
}

.sheet-foot p { margin: 0; }

dialog {
  border: none;
  border-radius: 10px;
  padding: 16px 18px;
  max-width: 380px;
}

#examples { max-width: 460px; }
#examples h2 { margin: 0 0 12px; font-size: 18px; }
#example-list {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin: 0 0 14px;
}
#example-list button { text-align: left; }
#example-list strong { display: block; }
#example-list span { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }

dialog::backdrop { background: rgba(20, 16, 10, 0.35); }
dialog p { margin: 0 0 14px; }
dialog div { display: flex; gap: 8px; justify-content: flex-end; }

@media (max-width: 980px) {
  body { height: auto; overflow: auto; }
  #app { height: auto; }
  .workspace { grid-template-columns: 1fr; }
  .tools, .facts { border: 0; overflow: visible; }
  .canvas-wrap { min-height: 420px; }
  svg.plan { max-height: none; height: 420px; }
  .check-wrap { position: static; }
}

#print-block { display: none; }

@media print {
  body > * { display: none !important; }
  #print-block {
    display: block !important;
    margin: 24mm;
    font: 16px/1.4 "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    color: #111;
  }
}
