/* Layout: a working studio. Library rail left, room stage center, room + item controls right.
   The 3D stage is the one bold element; everything around it stays quiet. */
:root {
  --bg: #FAFBFC;
  --surface: #FFFFFF;
  --ink: #0F1419;
  --muted: #5B6672;
  --line: #E2E7EC;
  --navy: #0A192F;
  --on-navy: #F3F6F9;
  --accent: #0F766E;
  --accent-ink: #FFFFFF;
  --accent-soft: #E2F2EF;
  --bright: #00D1C1;
  --stage: #E7ECF0;
  --thumb: #F1F4F6;
  --warn: #B4531A;
  --shadow: 0 1px 2px rgba(10, 25, 47, .06), 0 8px 24px rgba(10, 25, 47, .06);
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A1320; --surface: #111C2D; --ink: #E9EEF4; --muted: #93A1B2; --line: #22314A;
    --navy: #070F1C; --on-navy: #F3F6F9; --accent: #2CC5B4; --accent-ink: #06201D; --accent-soft: #11343A;
    --bright: #00D1C1; --stage: #0D1828; --thumb: #18263B; --warn: #F0A56A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0A1320; --surface: #111C2D; --ink: #E9EEF4; --muted: #93A1B2; --line: #22314A;
  --navy: #070F1C; --on-navy: #F3F6F9; --accent: #2CC5B4; --accent-ink: #06201D; --accent-soft: #11343A;
  --bright: #00D1C1; --stage: #0D1828; --thumb: #18263B; --warn: #F0A56A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 14px; line-height: 1.5; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--bright); outline-offset: 2px; }

.wrap { max-width: 1440px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

.site { background: var(--navy); color: var(--on-navy); }
.site-in { display: flex; align-items: center; gap: 14px; padding-block: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .08em; font-size: 15px; color: var(--on-navy); text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 50%; background: conic-gradient(from 20deg, #00D1C1, #2F80ED, #F2994A, #00D1C1); }
.brand-sub { font-family: var(--display); font-style: italic; font-size: 17px; color: var(--bright); padding-left: 14px; border-left: 1px solid rgba(255, 255, 255, .2); }

.intro { display: flex; align-items: baseline; gap: 8px 28px; flex-wrap: wrap; padding-block: 22px 16px; }
.intro h1 { font-family: var(--display); font-weight: 600; font-size: clamp(24px, 3vw, 34px); line-height: 1.12; margin: 0; text-wrap: balance; letter-spacing: -.01em; }
.intro h1 em { color: var(--accent); font-weight: 500; }
.intro p { margin: 0; color: var(--muted); max-width: 58ch; flex: 1 1 320px; }

.work { display: grid; grid-template-columns: 300px minmax(0, 1fr) 290px; gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.panel h2 { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* Library */
.lib { display: flex; flex-direction: column; gap: 10px; min-width: 0; max-height: 760px; }
.field-label { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.search { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-width: 0; }
.search::placeholder { color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 500; cursor: pointer; color: var(--muted); }
.chip[aria-selected="true"] { background: var(--navy); border-color: var(--navy); color: var(--on-navy); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; overflow-y: auto; padding-right: 2px; min-height: 120px; }
.card { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 6px 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; transition: border-color .12s, transform .12s; min-width: 0; }
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card .thumb { aspect-ratio: 4 / 3; width: 100%; border-radius: 5px; background: var(--thumb); display: block; object-fit: contain; }
.card b { font-size: 12.5px; font-weight: 600; line-height: 1.25; padding-top: 4px; overflow-wrap: anywhere; }
.card i { font-style: normal; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { grid-column: 1 / -1; color: var(--muted); font-size: 13px; padding: 8px 2px; }
.custom { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.custom b { font-size: 13px; overflow-wrap: anywhere; }
.custom span { font-size: 12px; color: var(--muted); }

/* Stage */
.stage { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.stagebar { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 18px; border-radius: 6px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button[aria-selected="true"], .seg button.on { background: var(--navy); color: var(--on-navy); }
.seg.small button { padding: 5px 11px; font-size: 12px; }
.btn { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: 8px; padding: 8px 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--warn); border-color: var(--line); }
.btn.tog[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.sel { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; min-width: 0; max-width: 100%; }

.viewport { position: relative; height: clamp(380px, 68vh, 680px); border-radius: 12px; overflow: hidden; background: var(--stage); border: 1px solid var(--line); box-shadow: var(--shadow); }
.viewport canvas#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.viewport.dragging canvas#view { cursor: grabbing; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.labels span { position: absolute; transform: translate(-50%, -50%); font-size: 11px; font-weight: 600; color: #0A192F; background: rgba(255, 255, 255, .86); padding: 1px 6px; border-radius: 4px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.labels span.dim { background: #0A192F; color: #F3F6F9; font-weight: 500; }
.labels span.tick { background: transparent; color: #0A192F; font-weight: 500; font-size: 10.5px; padding: 0; }
.labels span.sel { background: #0F766E; color: #FFFFFF; }
.hint { position: absolute; left: 12px; top: 12px; max-width: calc(100% - 24px); background: rgba(10, 25, 47, .82); color: #F3F6F9; font-size: 12px; padding: 6px 10px; border-radius: 7px; pointer-events: none; }
.hint.low { top: auto; bottom: 12px; }
.eye { position: absolute; right: 12px; top: 12px; }
.minimap { position: absolute; left: 12px; bottom: 12px; width: 132px; height: 132px; border-radius: 9px; background: rgba(255, 255, 255, .93); border: 1px solid rgba(10, 25, 47, .25); cursor: crosshair; }
.walkpad { position: absolute; right: 12px; bottom: 12px; display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(2, 46px); gap: 5px; }
.walkpad button { border: 0; border-radius: 10px; background: rgba(10, 25, 47, .78); color: #F3F6F9; font-size: 18px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.walkpad button:active { background: #0F766E; }
#padBack { grid-column: 2; }
.nogl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--ink); background: var(--stage); }
.statline { display: flex; gap: 6px 18px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.statline b { color: var(--ink); font-weight: 600; }
.statline .warn { color: var(--warn); font-weight: 600; }

/* Side controls */
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.num, .pick { display: flex; flex-direction: column; gap: 3px; position: relative; min-width: 0; }
.num span, .pick span { font-size: 11.5px; color: var(--muted); }
.num input { width: 100%; padding: 8px 24px 8px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-variant-numeric: tabular-nums; min-width: 0; }
.num i { position: absolute; right: 8px; bottom: 9px; font-style: normal; font-size: 11px; color: var(--muted); pointer-events: none; }
.sel.full { width: 100%; margin-bottom: 8px; }
.buy img.photo { object-fit: cover; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.sw { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); cursor: pointer; padding: 0; }
.sw[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }
.stylepick { margin-top: 12px; }
.stylestrip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.stylestrip img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; display: block; background: var(--thumb); }
.item-name { width: 100%; margin-bottom: 8px; font-weight: 600; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.item-actions .btn { padding: 6px 10px; font-size: 12.5px; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.sub { font-size: 11.5px; color: var(--muted); margin: 8px 0 0; }
.saverow { display: flex; gap: 6px; }
.layouts { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.layouts li { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.layouts li span { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.layouts li small { color: var(--muted); display: block; font-weight: 400; font-size: 11.5px; }
.layouts button { border: 0; background: transparent; color: var(--accent); font-weight: 600; cursor: pointer; padding: 4px 6px; }
.layouts button.del { color: var(--muted); }

.shop { margin-top: 16px; }
.shop-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px 20px; flex-wrap: wrap; margin-bottom: 12px; }
.shop-head h2 { font-family: var(--display); font-size: 22px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--ink); margin: 0 0 2px; }
.shop-acts { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; justify-content: flex-end; }
.seg button.on { background: var(--navy); color: var(--on-navy); }
.rule { font-size: 11.5px; line-height: 1.35; border-left: 3px solid var(--line); padding-left: 7px; color: var(--muted); margin: 2px 0; overflow-wrap: anywhere; }
.rule.warn, .rule.stop { border-left-color: var(--warn); color: var(--ink); }
.rule.ok { border-left-color: var(--accent); }
.sharebox { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.sharedbar { display: flex; align-items: center; justify-content: space-between; gap: 10px 18px; flex-wrap: wrap; background: var(--navy); color: var(--on-navy); border-radius: 10px; padding: 12px 16px; margin-bottom: 14px; }
.sharedbar p { margin: 0; flex: 1 1 320px; min-width: 0; }
.sharedacts { display: flex; gap: 8px; flex-wrap: wrap; }
.sharedbar .btn.ghost { background: transparent; color: var(--on-navy); border-color: rgba(255, 255, 255, .35); text-decoration: none; }
.join { margin-top: 12px; display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.join .hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.shop-total { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.shop-total b { color: var(--ink); font-size: 16px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.buy { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; align-items: start; }
.buy img { width: 76px; aspect-ratio: 4 / 3; object-fit: contain; background: var(--thumb); border-radius: 5px; display: block; }
.buy-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.buy-body b { font-size: 13px; }
.buy-body b small { font-weight: 500; color: var(--muted); }
.buy-body span { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.buy-body .price { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.buy-link { align-self: flex-start; margin-top: 4px; font-size: 12.5px; font-weight: 600; color: var(--accent-ink); background: var(--accent); border-radius: 6px; padding: 5px 10px; text-decoration: none; }
.buy-link:hover { filter: brightness(1.08); }
.shop-link { display: inline-block; margin-top: 10px; font-size: 12.5px; font-weight: 600; color: var(--accent); }
.foot { color: var(--muted); font-size: 12px; padding-block: 14px 28px; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: #0A192F; color: #F3F6F9; padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 40; max-width: calc(100% - 32px); box-shadow: var(--shadow); }

@media (max-width: 1180px) {
  .work { grid-template-columns: 270px minmax(0, 1fr); }
  .side { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  .side .panel { flex: 1 1 260px; }
}
@media (max-width: 760px) {
  .work { grid-template-columns: minmax(0, 1fr); }
  .stage { order: 1; }
  .side { order: 2; }
  .lib { order: 3; max-height: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); overflow: visible; }
  .viewport { height: clamp(340px, 62vh, 520px); }
  .seg button { padding: 7px 14px; }
  .minimap { width: 104px; height: 104px; }
}
@media (prefers-reduced-motion: reduce) { .card { transition: none; } }

.shop-total small { display: block; font-size: 11px; line-height: 1.35; max-width: 46ch; margin-top: 2px; }
.regbox { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 8px; padding: 12px; margin: 0 0 14px; font-size: 13px; display: flex; flex-direction: column; gap: 8px; }
.regbox form, .regbox #regDone { display: flex; flex-direction: column; gap: 8px; }
.regbox .sub { margin: 0; }
.regrow { display: flex; gap: 10px; flex-wrap: wrap; }
.regrow label { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--muted); }
.regacts { display: flex; gap: 8px; flex-wrap: wrap; }
.regbox .saverow { flex-wrap: wrap; }
.regbox .saverow input { flex: 1 1 220px; min-width: 0; }
.join .chk { display: flex; align-items: center; gap: 6px; font-size: 11.5px; }
.join .chk input { margin: 0; }

/* shop rows: the Amazon button sits in its own cell */
.buy > .buy-link { grid-column: 2; margin-top: -4px; justify-self: start; }
.shopmore, .tiersel { display: none; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.foldbtn { all: unset; box-sizing: border-box; display: block; width: 100%; cursor: default; }
.foldbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

@media (max-width: 760px) {
  /* library: search, one row of chips, two swipeable rows of pieces, right under the room */
  .stage { order: 1; } .lib { order: 2; gap: 8px; } .side { order: 3; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .chips::-webkit-scrollbar, .grid::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; }
  .grid { grid-template-columns: none; grid-auto-flow: column; grid-template-rows: repeat(2, auto); grid-auto-columns: 104px; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity; scrollbar-width: none; min-height: 0; padding: 0 0 2px; }
  .card { scroll-snap-align: start; padding: 5px 5px 6px; }
  .card b { font-size: 12px; }

  /* side panels fold to a heading row */
  .side { gap: 8px; }
  .side .panel.fold { padding: 0; }
  .side .panel.fold > h2 { margin: 0; }
  .side .panel.fold .foldbtn { padding: 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
  .side .panel.fold .foldbtn::after { content: ""; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin: -4px 4px 0 0; transition: transform .15s; }
  .side .panel.fold.closed .foldbtn::after { transform: rotate(-45deg); margin-top: 0; }
  .side .panel.fold > :not(h2) { margin-left: 14px; margin-right: 14px; }
  .side .panel.fold > :last-child { margin-bottom: 14px; }
  .side .panel.fold.closed > :not(h2) { display: none !important; }

  /* shop: dropdown for price level, full-width actions, one-line rows, first six shown */
  .shop-head { align-items: stretch; margin-bottom: 10px; }
  .shop-acts { justify-content: stretch; width: 100%; gap: 8px; }
  .shop-acts #tierSeg { display: none; }
  .tiersel { display: block; flex: 1 1 140px; }
  .tiersel .sel { width: 100%; }
  .shop-acts .btn { flex: 1 1 150px; text-align: center; justify-content: center; }
  .shop-total { order: -1; width: 100%; }
  .shop-grid { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .buy { grid-template-columns: 48px minmax(0, 1fr) auto; gap: 10px; padding: 6px 8px; align-items: center; }
  .buy img { width: 48px; }
  .buy > .buy-link { grid-column: 3; margin: 0; padding: 7px 10px; white-space: nowrap; }
  .buy-body { gap: 1px; }
  .buy-body > span:not(.rule) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .buy-body .rule { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
  .buy-body .rule.open { -webkit-line-clamp: unset; display: block; }
  .shop-grid:not(.all) .buy.more { display: none; }
  .shopmore { display: block; width: 100%; margin-top: 8px; }
  .shopmore[hidden] { display: none; }
}

.toast-act { margin-left: 10px; background: transparent; color: #7FD6CD; border: 1px solid #7FD6CD; border-radius: 999px; padding: 3px 10px; font: inherit; font-weight: 600; cursor: pointer; }
.toast-act:hover { background: #7FD6CD; color: #0A192F; }
