:root {
  --bg: #f6f4f0;
  --panel: #ffffff;
  --ink: #23262b;
  --muted: #6b6f76;
  --line: #e4e0d8;
  --accent: #e8742a;
  --accent-ink: #ffffff;
  --soft: #f1eee8;
  --danger: #b23b2c;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(30, 30, 30, 0.12);
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1d20; --panel: #24272b; --ink: #ecebe8; --muted: #a3a6ab; --line: #383c42; --soft: #2d3136;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1d20; --panel: #24272b; --ink: #ecebe8; --muted: #a3a6ab; --line: #383c42; --soft: #2d3136;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "side view";
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--soft); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: #c9c2b5; }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.primary.danger, .btns button.danger[value="ok"] { background: var(--danger); color: #fff; border-color: var(--danger); }
button.link { background: none; border: 0; padding: 4px 0; color: var(--accent); text-decoration: underline; }
button.icon { padding: 4px 9px; font-size: 16px; line-height: 1.2; }
#undo .long, #redo .long { font-size: 13px; }
button.wide { width: 100%; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%;
}
input[type="color"] { padding: 2px; height: 34px; width: 46px; flex: none; }
input[type="checkbox"], input[type="radio"] { width: auto; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h3 { margin: 4px 0 8px; font-size: 16px; }

/* top bar */
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 5;
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.logo { background: var(--accent); color: #fff; border-radius: 6px; width: 24px; height: 24px; display: grid; place-items: center; font-size: 15px; }
.look-box { display: flex; gap: 6px; align-items: center; }
.look-box select { width: 220px; }
.look-menu { position: relative; }
.menu {
  position: absolute; top: 110%; left: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; display: flex; flex-direction: column; min-width: 190px; z-index: 20;
}
.menu[hidden] { display: none; }
.menu button { background: none; border: 0; text-align: left; padding: 8px 10px; }
.menu button:hover { background: var(--soft); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--panel); padding: 6px 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--ink); color: var(--panel); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.spacer { flex: 1; }
.status { color: var(--muted); font-size: 12px; min-width: 110px; text-align: right; }

/* sidebar */
.sidebar { grid-area: side; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-radius: 0; background: none; padding: 10px 4px; font-size: 12px; font-weight: 500; color: var(--muted); white-space: normal; }
.tabs button.on { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.panel { padding: 12px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.cat { margin-top: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.cat-item { display: flex; justify-content: space-between; background: none; border: 1px solid transparent; text-align: left; }
.cat-item:hover { background: var(--soft); }
.cat-item small { color: var(--muted); }
.room-row { display: flex; gap: 10px; align-items: center; text-align: left; background: none; }
.room-row:hover { background: var(--soft); }
.room-row small { display: block; color: var(--muted); font-size: 12px; white-space: normal; }
.chip { width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(0, 0, 0, 0.12); flex: none; display: inline-block; }
.chip.big { width: 44px; height: 44px; border-radius: 10px; }
.total { display: flex; justify-content: space-between; align-items: baseline; font-size: 18px; }
.shop-row { display: flex; gap: 8px; align-items: center; padding: 6px; border-radius: 8px; cursor: pointer; }
.shop-row:hover { background: var(--soft); }
.shop-row img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.shop-row .grow { flex: 1; }
.shop-row a { color: var(--accent); font-size: 12px; }
.help { padding-left: 18px; line-height: 1.5; margin: 0; }
.help li { margin-bottom: 6px; }

/* 3-D view */
#viewport { grid-area: view; position: relative; min-height: 0; overflow: hidden; background: #dfe8ee; touch-action: none; }
#viewport canvas { display: block; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.room-label { background: rgba(255, 255, 255, 0.86); color: #23262b; border-radius: 6px; padding: 3px 7px; font-size: 11px; text-align: center; line-height: 1.25; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.room-label b { display: block; font-weight: 600; }
.size-tag { background: #e8742a; color: #fff; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 10px; white-space: nowrap; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; font-size: 16px; color: #555; }
.walk-pad, .walk-hint { display: none; }
body.walking .walk-pad {
  display: grid; grid-template-columns: repeat(3, 48px); gap: 6px; position: absolute; left: 16px; bottom: 16px;
}
.walk-pad button { height: 48px; font-size: 18px; background: rgba(255, 255, 255, 0.85); color: #23262b; touch-action: none; user-select: none; }
body.walking .walk-hint {
  display: block; position: absolute; left: 50%; transform: translateX(-50%); top: 10px; background: rgba(0, 0, 0, 0.55); color: #fff;
  padding: 5px 12px; border-radius: 14px; font-size: 12px; pointer-events: none; white-space: nowrap;
}

/* inspector */
.inspector {
  position: fixed; right: 12px; top: 64px; bottom: 12px; width: 320px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); padding: 14px; overflow-y: auto; z-index: 6; display: flex; flex-direction: column; gap: 6px;
}
.inspector[hidden] { display: none; }
.inspector > *, .panel > * { flex-shrink: 0; }
.insp-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.insp-head h3 { margin: 0; }
.title-input { font-weight: 600; font-size: 16px; border-color: transparent; padding-left: 4px; }
.title-input:hover, .title-input:focus { border-color: var(--line); }
.item-photo { width: 100%; max-height: 170px; object-fit: contain; background: #fff; border-radius: 8px; border: 1px solid var(--line); }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row3 label, .store-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.row3 small { display: none; }
.lbl { font-size: 12px; color: var(--muted); margin-top: 6px; }
.inline { display: flex; gap: 6px; align-items: center; }
.inline .btn { text-decoration: none; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; color: inherit; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btns.end { justify-content: flex-end; margin-top: 8px; }
.swatches { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.sw { width: 26px; height: 26px; padding: 0; border-radius: 7px; border: 1px solid rgba(0, 0, 0, 0.15); }
.current { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.palette { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.brand { font-size: 11px; font-weight: 600; color: var(--muted); margin: 6px 2px 4px; }
.pgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.pc { display: flex; flex-direction: column; align-items: stretch; gap: 3px; padding: 4px; font-size: 10.5px; background: none; white-space: normal; text-align: left; line-height: 1.15; }
.pc span { height: 30px; border-radius: 6px; border: 1px solid rgba(0, 0, 0, 0.1); }
.pc.our { position: relative; }
.pc-x { position: absolute; top: 1px; right: 1px; font-style: normal; font-size: 10px; line-height: 1; padding: 3px 4px; border-radius: 6px; background: rgba(20, 20, 20, 0.6); color: #fff; opacity: 0; }
.pc.our:hover .pc-x, .pc.our:focus-within .pc-x { opacity: 1; }
@media (hover: none) { .pc-x { opacity: 0.85; } }
.room-size fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; margin: 0; }
.room-size legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
.room-size .inline input[type=number] { width: 70px; }
.room-size label.check { font-size: 13px; gap: 6px; align-items: center; }
.size-preview { background: var(--soft); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.size-preview ul { margin: 4px 0 0; padding-left: 18px; }
.add-color { display: flex; flex-direction: column; gap: 8px; }
.add-color label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.add-color .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.add-color input[type=color] { width: 44px; flex: 0 0 44px; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.thumbs img { width: 100%; aspect-ratio: 16/10; object-fit: cover; border-radius: 6px; cursor: zoom-in; }
details summary { cursor: pointer; font-size: 13px; padding: 4px 0; }
.seg + .current { margin-top: 4px; }
.inspector .seg { width: 100%; }
.inspector .seg button { flex: 1; }

/* dialogs */
dialog { border: 0; border-radius: 16px; padding: 18px; width: min(460px, calc(100vw - 32px)); box-shadow: var(--shadow); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(20, 20, 20, 0.45); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
dialog label.check { flex-direction: row; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center; cursor: pointer; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.drop.over { border-color: var(--accent); background: var(--soft); }
.drop img { max-height: 140px; max-width: 100%; border-radius: 8px; }
.store-form .row3 small { display: none; }
dialog:has(.lightbox) { width: min(1100px, calc(100vw - 32px)); }
.lightbox img { width: 100%; max-height: 75vh; object-fit: contain; border-radius: 10px; }
.lightbox .btns { justify-content: center; }
.place-bar {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 20; display: flex; gap: 12px; align-items: center;
  background: #23262b; color: #fff; padding: 8px 8px 8px 16px; border-radius: 12px; box-shadow: var(--shadow); max-width: calc(100% - 24px);
}
.place-bar[hidden] { display: none; }
body.placing #viewport canvas { cursor: crosshair; }
body.placing .walk-hint { display: none; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: 0.3s;
  background: #23262b; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* wide screens: the inspector has its own column, always shown, so the 3-D view
   never changes size while someone is dragging furniture */
.inspector.empty { display: none; }
@media (min-width: 1100px) {
  body { grid-template-columns: 300px 1fr 320px; grid-template-areas: "top top top" "side view insp"; }
  .inspector {
    position: static; grid-area: insp; width: auto; border-radius: 0; border-width: 0 0 0 1px; box-shadow: none; min-height: 0;
  }
  .inspector.empty { display: flex; }
}
.tips { color: var(--muted); line-height: 1.5; padding-left: 18px; margin: 0; }

/* phones and narrow windows */
@media (max-width: 700px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; grid-template-areas: "top" "view" "side"; }
  .topbar { gap: 6px; padding: 6px 8px; }
  .brand { display: none; }
  .look-box select { flex: 1; width: auto; min-width: 0; }
  .topbar .check, .status, .long { display: none; }
  .look-box { flex: 1 1 auto; min-width: 0; }
  .seg button { padding: 6px 9px; }
  .sidebar { border-right: 0; border-top: 1px solid var(--line); max-height: 50vh; }
  .panel { display: none; }
  body.sheet-open .panel { display: flex; max-height: 42vh; }
  .inspector { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-height: 58vh; }
  body.walking .walk-pad { bottom: 12px; }
  .walk-hint { display: none !important; }
}
@media (max-width: 700px) {
  .room-label { font-size: 10px; padding: 2px 5px; }
  .room-label span { display: none; }
}

.art-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.art-pick { padding: 2px; aspect-ratio: 4/5; overflow: hidden; display: grid; place-items: center; }
.art-pick img { width: 100%; height: 100%; object-fit: cover; border-radius: 5px; }
.art-pick.on { border: 2px solid var(--accent); }
.art-pick .mix { font-size: 11px; white-space: normal; }

/* iPad-size screens: a slimmer sidebar leaves more room for the house */
@media (min-width: 701px) and (max-width: 1099px) {
  body { grid-template-columns: 250px 1fr; }
  .topbar { gap: 8px; }
  .look-box select { width: 170px; }
  .inspector { width: 300px; }
}
.phone-note { display: none; }
@media (max-width: 700px) {
  .phone-note:not([hidden]) {
    display: flex; gap: 8px; align-items: center; position: fixed; left: 8px; right: 8px; top: 96px; z-index: 30;
    background: #23262b; color: #fff; padding: 10px 12px; border-radius: 12px; font-size: 13px; box-shadow: var(--shadow);
  }
  .phone-note button { background: none; border: 0; color: #fff; font-size: 18px; padding: 0 4px; }
}

.room-go { width: 170px; }
@media (min-width: 701px) and (max-width: 1099px) { .room-go { width: 130px; } }
