:root {
  --paper: #e1e8d5;
  --floor: #f6f8f0;
  --panel: #f0f3ea;
  --panel-2: #e5eadd;
  --field: #ffffff;
  --ink: #2f3337;
  --ink-2: #5a6157;
  --ink-3: #82897e;
  --rule: #cbd2c1;
  --rule-strong: #aab2a0;
  --blue: #2a80c2;
  --blue-soft: #d7e9f7;
  --red: #c7382c;
  --red-ink: #8e2219;
  --red-soft: #f7e3df;
  --ok: #3d7638;
  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-tight: 'Barlow Semi Condensed', 'Barlow', 'Arial Narrow', system-ui, sans-serif;
  --r: 6px;
  --left: 264px;
  --right: 276px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  height: 100dvh;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr);
  overflow: hidden;
  font: 14px/1.45 var(--font);
  color: var(--ink);
  background: var(--panel);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.icon { width: 18px; height: 18px; flex: none; }

/* ---- Top bar ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 10px 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 600 17px/1 var(--font-tight);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.plan-name {
  width: 220px;
  min-width: 0;
  padding: 5px 8px;
  font-weight: 500;
  font-size: 15px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
}
.plan-name:hover { border-color: var(--rule); }
.plan-name:focus { outline: none; background: var(--field); border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }

.modes {
  display: inline-flex;
  margin: 0 auto;
  padding: 3px;
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-radius: 9px;
}
.modes button {
  padding: 5px 18px;
  font: 600 14px/1.2 var(--font-tight);
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.modes button:hover { color: var(--ink); }
.modes button[aria-checked='true'] { color: var(--floor); background: var(--ink); }

.topbar-end { display: flex; align-items: center; gap: 4px; }

/* ---- Controls ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  font-weight: 500;
  font-size: 13.5px;
  white-space: nowrap;
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--rule-strong); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-block { width: 100%; justify-content: center; }
.btn-primary { color: var(--floor); background: var(--ink); border-color: var(--ink); }
.btn-danger { color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red-soft); border-color: var(--red); }

.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  font-weight: 600;
  font-size: 16px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
}
.btn-icon:hover:not(:disabled) { background: var(--panel-2); }
.btn-icon:disabled { opacity: 0.35; cursor: default; }

.link {
  padding: 2px 0;
  font-weight: 500;
  font-size: 13px;
  color: var(--blue);
  background: none;
  border: 0;
  cursor: pointer;
}
.link:hover { text-decoration: underline; }

.input {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 9px;
  font-weight: 500;
  font-size: 14px;
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--r);
}
.input:hover { border-color: var(--rule-strong); }
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
select.input { padding-right: 4px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0 12px;
  font-size: 13.5px;
  cursor: pointer;
}
.check input { flex: none; width: 15px; height: 15px; margin: 3px 0 0; accent-color: var(--ink); }
.check small { display: block; font-size: 12.5px; color: var(--ink-3); }

kbd {
  padding: 0 5px;
  font: 600 12px/1.5 var(--font-tight);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

/* ---- Layout ---- */

.workspace {
  display: grid;
  grid-template-columns: var(--left) minmax(0, 1fr) var(--right);
  min-height: 0;
}

.panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.panel-left { border-right: 1px solid var(--rule); }
.panel-right { border-left: 1px solid var(--rule); }
.panel-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 14px 28px; }
.panel-search { padding: 12px 14px 0; }

.group + .group { margin-top: 22px; }
.group h2,
.insp-head h2 { margin: 0 0 6px; font: 600 15px/1.25 var(--font-tight); letter-spacing: 0.01em; }
h3 { margin: 16px 0 6px; font: 600 14px/1.25 var(--font-tight); }
.help { max-width: 60ch; margin: 0 0 10px; font-size: 13px; color: var(--ink-2); }

.tips { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); }
.tips li + li { margin-top: 4px; }
.tips b { color: var(--ink); }

.steps { margin: 0 0 12px; padding-left: 20px; font-size: 13.5px; }
.steps li + li { margin-top: 6px; }

/* ---- Library ---- */

.shapes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; margin: 4px 0 10px; }
.shape {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 2px 6px;
  font: 500 12.5px/1.2 var(--font-tight);
  text-align: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
}
.shape:hover { background: var(--panel-2); border-color: var(--rule); }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; }
.tile {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 1px;
  padding: 8px 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.tile:hover { background: var(--panel-2); border-color: var(--rule); }
.tile-art { display: grid; place-items: center; height: 58px; }
.tile-art svg { overflow: visible; filter: drop-shadow(0.6px 1.3px 0.6px rgba(29, 42, 23, 0.3)); }
.tile-name { font: 600 13px/1.2 var(--font-tight); text-align: center; }
.tile-size { font: 500 12px/1.3 var(--font-tight); color: var(--ink-3); }

/* ---- Canvas ---- */

.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--paper); }

#canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#canvas.is-pan-ready { cursor: grab; }
#canvas.is-panning,
#canvas.is-panning * { cursor: grabbing !important; }
body[data-tool='draw'] #canvas { cursor: crosshair; }

.hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 7px 14px;
  font: 500 13px/1.5 var(--font-tight);
  color: var(--floor);
  background: var(--ink);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(29, 42, 23, 0.2);
  pointer-events: none;
}

.length-entry {
  position: absolute;
  z-index: 5;
  width: 160px;
  font: 600 15px var(--font-tight);
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft), 0 4px 12px rgba(29, 42, 23, 0.18);
}

.layouts {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: calc(100% - 270px);
  padding: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 12px;
  font: 600 13px/1 var(--font-tight);
  color: var(--ink-2);
  white-space: nowrap;
  background: rgba(240, 243, 234, 0.94);
  border: 1px solid var(--rule-strong);
  border-radius: 7px;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); background: var(--floor); border-color: var(--ink); }
.tab .icon { width: 15px; height: 15px; }
.tab-icon { padding: 0 8px; }
.tab-input { width: 140px; cursor: text; color: var(--ink); background: var(--field); border-color: var(--blue); outline: none; }

.titleblock {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 6px;
  min-width: 220px;
  max-width: 280px;
  padding: 8px 6px 4px 10px;
  background: var(--floor);
  border: 1.5px solid var(--ink);
  border-radius: 3px;
}
.tb-text { display: grid; padding: 0 4px 6px 0; line-height: 1.25; border-bottom: 1px solid var(--rule); }
.tb-text strong { overflow: hidden; font: 600 14.5px/1.3 var(--font-tight); white-space: nowrap; text-overflow: ellipsis; }
.tb-text span { font: 500 12.5px/1.3 var(--font-tight); color: var(--ink-2); }
.tb-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.scalebar { display: flex; align-items: center; gap: 6px; font: 600 12px var(--font-tight); color: var(--ink-2); white-space: nowrap; }
.zoom { display: flex; }
.zoom .btn-icon { width: 28px; height: 28px; }

/* ---- Inspector ---- */

.insp-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 8px; margin-bottom: 10px; }
.insp-title {
  width: calc(100% + 6px);
  margin-left: -6px;
  padding: 3px 6px;
  font: 600 19px/1.25 var(--font-tight);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
}
.insp-title:hover { border-color: var(--rule); }
.insp-title:focus { outline: none; background: var(--field); border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.insp-sub { font: 500 13px var(--font-tight); color: var(--ink-3); }

.field { display: grid; gap: 4px; min-width: 0; margin-bottom: 12px; }
.field-label { font: 500 12.5px/1.2 var(--font-tight); color: var(--ink-2); }

.size-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 4px; }
.size-row.pair { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.size-row > .btn-icon { margin-bottom: 12px; }
.rot-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: end; gap: 4px; }
.rot-row > .btn-icon { margin-bottom: 12px; background: var(--field); border-color: var(--rule); }

.swatches { display: flex; flex-wrap: wrap; gap: 7px; padding: 2px 0 4px; }
.swatch {
  position: relative;
  width: 26px;
  height: 26px;
  padding: 0;
  background: var(--swatch);
  border: 1px solid rgba(29, 42, 23, 0.22);
  border-radius: 50%;
  cursor: pointer;
}
.swatch[aria-pressed='true'] { box-shadow: 0 0 0 2px var(--panel), 0 0 0 3.5px var(--ink); }
.swatch-custom { overflow: hidden; background: conic-gradient(#eaa59c, #e7bd58, #95b27c, #94aed2, #b9a8da, #eaa59c); }
.swatch-custom input { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; opacity: 0; cursor: pointer; }
.swatch-custom:focus-within { outline: 2px solid var(--blue); outline-offset: 2px; }

.insp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 4px; }

.issues {
  margin: 0 0 14px;
  padding: 8px 10px 8px 12px;
  list-style: none;
  font-size: 13px;
  color: var(--red-ink);
  background: var(--red-soft);
  border-left: 3px solid var(--red);
  border-radius: 0 var(--r) var(--r) 0;
}
.issue-list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.issue-list button {
  position: relative;
  width: 100%;
  padding: 6px 8px 6px 24px;
  font-weight: 500;
  font-size: 13.5px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--r);
  cursor: pointer;
}
.issue-list button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 9px;
  width: 7px;
  height: 7px;
  background: var(--red);
  border-radius: 50%;
  transform: translateY(-50%);
}
.issue-list button:hover { background: var(--red-soft); }
.ok { margin: 4px 0; font-size: 13.5px; color: var(--ok); }
.warn { margin: 0 0 12px; padding: 8px 10px; font-size: 13px; color: var(--red-ink); background: var(--red-soft); border-radius: var(--r); }

.stats { margin: 6px 0 14px; }
.stats div { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--rule); }
.stats div:first-child { border-top: 1px solid var(--rule); }
.stats dt { font-size: 13px; color: var(--ink-2); }
.stats dd { margin: 0; font: 600 14.5px var(--font-tight); }

.wall-list { display: grid; gap: 3px; margin: 4px 0 14px; padding: 0; list-style: none; }
.wall-list li { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: center; gap: 6px; padding: 2px; border-radius: var(--r); }
.wall-list li:hover { background: var(--panel-2); }
.wall-num {
  justify-self: center;
  width: 22px;
  height: 22px;
  padding: 0;
  font: 600 11.5px/1 var(--font-tight);
  color: var(--ink-2);
  background: var(--floor);
  border: 1px solid var(--ink-3);
  border-radius: 50%;
  cursor: pointer;
}
.wall-list li:hover .wall-num { color: #fff; background: var(--blue); border-color: var(--blue); }

.segmented { display: flex; gap: 2px; margin-bottom: 12px; padding: 3px; background: var(--panel-2); border: 1px solid var(--rule); border-radius: 8px; }
.segmented button {
  flex: 1;
  padding: 5px 4px;
  font: 600 13px/1.2 var(--font-tight);
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}
.segmented button[aria-pressed='true'] { color: var(--ink); background: var(--field); box-shadow: 0 1px 2px rgba(29, 42, 23, 0.16); }

.sheet-close { display: none; }

/* ---- Menus, dialog, toast ---- */

.menu {
  position: fixed;
  inset: auto;
  width: 290px;
  margin: 0;
  padding: 10px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(29, 42, 23, 0.2);
}
@supports not selector(:popover-open) {
  .menu { display: none; z-index: 40; }
  .menu.is-open { display: block; }
}
.menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  font-weight: 500;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--r);
  cursor: pointer;
}
.menu-item:hover { background: var(--panel-2); }
.menu-note { margin: 8px 10px 2px; padding-top: 8px; font-size: 12.5px; color: var(--ink-2); border-top: 1px solid var(--rule); }
.menu-field { display: grid; gap: 4px; margin-bottom: 10px; font: 500 12.5px var(--font-tight); color: var(--ink-2); }
.menu .check { margin: 10px 0; }

dialog#help {
  width: min(780px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 18px 22px 22px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--rule-strong);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(29, 42, 23, 0.25);
}
dialog::backdrop { background: rgba(29, 42, 23, 0.35); }
.help-head { display: flex; align-items: center; justify-content: space-between; }
.help-head h2 { margin: 0; font: 600 21px var(--font-tight); }
.help-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 28px; }
.keys { margin: 0; }
.keys div { display: grid; grid-template-columns: 140px 1fr; gap: 10px; padding: 5px 0; font-size: 13.5px; border-bottom: 1px solid var(--rule); }
.keys dt { font: 600 13px/1.5 var(--font-tight); }
.keys dd { margin: 0; color: var(--ink-2); }
.keys kbd, .help kbd { color: var(--ink); background: var(--field); border-color: var(--rule-strong); }
#help .help { margin-top: 10px; }

.ghost { position: fixed; top: 0; left: 0; z-index: 50; margin: -28px 0 0 -48px; pointer-events: none; filter: drop-shadow(0 6px 10px rgba(29, 42, 23, 0.25)); }
body.is-dragging,
body.is-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 120px;
  z-index: 60;
  max-width: min(92vw, 520px);
  padding: 10px 16px;
  font-weight: 500;
  color: var(--floor);
  background: var(--ink);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(29, 42, 23, 0.22);
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--red-ink); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* ---- Smaller screens ---- */

@media (max-width: 1100px) {
  :root { --left: 224px; --right: 252px; }
  .plan-name { width: 160px; }
}

@media (max-width: 860px) {
  body { grid-template-rows: auto minmax(0, 1fr); }
  .topbar { flex-wrap: wrap; gap: 6px 8px; padding: 8px 10px; }
  .brand-name { display: none; }
  .plan-name { flex: 1; width: auto; }
  .modes { order: 4; width: 100%; margin: 0; }
  .modes button { flex: 1; }

  .workspace { position: relative; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .panel-left { grid-row: 2; max-height: 36dvh; border-top: 1px solid var(--rule); border-right: 0; }
  .panel-left .panel-scroll { padding-top: 10px; }
  .panel-right {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    display: none;
    max-height: 55dvh;
    border-top: 1px solid var(--rule-strong);
    border-left: 0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 28px rgba(29, 42, 23, 0.16);
  }
  body.has-selection .panel-right,
  body[data-tool='draw'] .panel-right { display: flex; }
  .sheet-close { display: block; margin-left: auto; }

  .tiles { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .shapes { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
  .titleblock { min-width: 0; padding: 4px; }
  .tb-text, .scalebar { display: none; }
  .layouts { max-width: calc(100% - 130px); }
  .tab-add span { display: none; }
  .toast { bottom: calc(36dvh + 64px); }
}

/* ---- Wall list extras ---- */

.wall-list li { grid-template-columns: 28px minmax(0, 1fr) 32px; }
.wall-del { color: var(--ink-3); }
.wall-del:hover:not(:disabled) { color: var(--red); background: var(--red-soft); }
.wall-del:disabled { opacity: 0.25; }

.notice {
  display: grid;
  justify-items: start;
  gap: 8px;
  margin: 0 0 12px;
  padding: 10px 12px;
  font-size: 13px;
  background: var(--blue-soft);
  border-radius: var(--r);
}
.notice p { margin: 0; }
