:root {
  --ink: #e9dfc7;
  --ink-dim: rgba(233, 223, 199, 0.62);
  --ink-faint: rgba(233, 223, 199, 0.32);
  --brass: #f0c27a;
  --brass-deep: #c99a52;
  --sage: #7b8167;
  --sage-deep: #4d5341;
  --night: #121210;
  --panel: rgba(20, 20, 18, 0.82);
  --panel-solid: #171715;
  --line: rgba(233, 223, 199, 0.12);
  --danger: #e05a47;
  --ok: #8fc98a;
  --display: "Big Shoulders Display", "Arial Narrow", sans-serif;
  --body: "Karla", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --r: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--ink); font-family: var(--body); font-size: 14px; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; cursor: default; touch-action: none; }
#view.looking { cursor: grabbing; }
body.placing #view { cursor: crosshair; }

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: 0.06; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap; font-weight: 600; letter-spacing: 0.01em;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--ink-faint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--brass); color: #1b160d; border-color: var(--brass); }
.btn.primary:hover { background: #f6d197; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.wide { width: 100%; justify-content: center; }
.btn.danger:hover { border-color: var(--danger); color: #ffb3a8; }
.btn kbd { font-size: 10px; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; width: 28px; height: 28px; border-radius: 50%;
  font-size: 18px; line-height: 1; color: var(--ink-dim);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--ink); }
kbd {
  font-family: var(--mono); font-size: 11px; border: 1px solid var(--ink-faint); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 4px; margin: 0 1px; color: var(--ink); background: rgba(255,255,255,0.04);
}

.panel {
  background: var(--panel); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel h2, #lobby h2 {
  font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; font-size: 22px; margin: 0;
}
.panel-note { color: var(--ink-dim); margin: 4px 0 14px; font-size: 13px; line-height: 1.4; }

/* ---------- Lobby ---------- */
#lobby {
  position: fixed; inset: 0; z-index: 10; display: none;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.9fr); gap: 6vw; padding: 7vh 6vw;
  background:
    radial-gradient(120% 90% at 0% 0%, rgba(18, 18, 16, 0.94) 30%, rgba(18, 18, 16, 0.55) 70%, rgba(18,18,16,0.25)),
    linear-gradient(to top, rgba(10,10,9,0.85), transparent 40%);
  overflow-y: auto;
}
body.in-lobby #lobby { display: grid; }
body.in-lobby #mapwrap, body.in-lobby #help, body.in-lobby #picker, body.in-lobby #plans { display: none; }

.lobby-left { max-width: 640px; align-self: center; }
.brand { display: flex; align-items: center; gap: 16px; margin-bottom: 6vh; animation: rise 0.7s both; }
.brand-mark { font-family: var(--display); font-weight: 800; font-size: 46px; letter-spacing: 0.06em; line-height: 0.8; }
.brand-sub { font-size: 12px; text-transform: uppercase; letter-spacing: 0.22em; color: var(--ink-dim); border-left: 1px solid var(--ink-faint); padding-left: 16px; line-height: 1.6; }
#lobby h1 {
  font-family: var(--display); font-weight: 800; text-transform: uppercase; font-size: clamp(48px, 7.4vw, 108px);
  line-height: 0.88; letter-spacing: 0.005em; margin: 0 0 24px; animation: rise 0.7s 0.08s both;
}
#lobby h1 em { font-style: normal; color: var(--brass); }
.lede { font-size: 17px; line-height: 1.55; color: var(--ink-dim); max-width: 34em; margin: 0 0 22px; animation: rise 0.7s 0.16s both; }
.room-facts { display: flex; gap: 28px; margin: 0 0 34px; animation: rise 0.7s 0.22s both; }
.room-facts div { border-top: 1px solid var(--ink-faint); padding-top: 8px; }
.room-facts dt { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-faint); }
.room-facts dd { margin: 2px 0 0; font-family: var(--mono); font-size: 14px; }
#lobby-form { animation: rise 0.7s 0.3s both; }
#lobby-form label { display: block; font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-dim); margin-bottom: 8px; }
.name-row { display: flex; gap: 10px; flex-wrap: wrap; }
.name-row input, #name-dialog input {
  flex: 1 1 220px; min-width: 0; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--ink-faint); border-radius: 999px;
  padding: 12px 18px; font-size: 16px; outline: none;
}
.name-row input:focus, #name-dialog input:focus { border-color: var(--brass); background: rgba(255, 255, 255, 0.09); }
.name-row .btn { padding: 12px 22px; font-size: 15px; }
.fine { font-size: 12.5px; color: var(--ink-faint); margin-top: 10px; }
.copyright { font-size: 12px; color: var(--ink-faint); margin: 5vh 0 0; animation: rise 0.7s 0.4s both; }
.copyright a { color: var(--ink-dim); }
.copyright a:hover { color: var(--brass); }
.lang-switch { font: inherit; font-size: 12px; color: var(--ink-dim); background: transparent; border: 0; padding: 0; cursor: pointer; }
.lang-switch:hover { color: var(--brass); }
.lang-switch option { color: #111; }

.lobby-right { align-self: center; animation: rise 0.7s 0.36s both; }
.lobby-right h2 { margin-bottom: 14px; color: var(--ink-dim); font-size: 18px; }
#lobby-list { max-height: 62vh; overflow-y: auto; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- Plan list ---------- */
.plan-list { display: flex; flex-direction: column; gap: 6px; }
.plan-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px;
  animation: rise 0.45s both; animation-delay: calc(var(--i) * 40ms + 0.4s);
  transition: background 0.15s, border-color 0.15s;
}
#plans .plan-row { animation-delay: calc(var(--i) * 25ms); }
.plan-row:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--ink-faint); }
.plan-row.current { border-color: var(--brass); }
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--display); font-weight: 700; font-size: 15px; letter-spacing: 0.04em; color: #f4ecda;
}
.plan-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.plan-author { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.plan-meta { font-size: 12.5px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-go { color: var(--ink-faint); font-size: 13px; font-weight: 600; }
.plan-row:hover .plan-go { color: var(--brass); }
.badge { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; background: var(--sage-deep); color: var(--ink); border-radius: 4px; padding: 1px 5px; }
.empty { color: var(--ink-faint); font-style: italic; }

/* ---------- Top bar ---------- */
#planbar {
  position: fixed; top: 14px; left: 14px; right: 14px; z-index: 5; display: flex; align-items: center; gap: 14px;
  padding: 8px 10px 8px 8px; background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.logo {
  font-family: var(--display); font-weight: 800; font-size: 20px; letter-spacing: 0.08em; background: var(--ink); color: var(--night);
  border: 0; border-radius: 999px; padding: 6px 14px; cursor: pointer;
}
.logo:hover { background: var(--brass); }
/* The preview's way back to the editor: the brightest thing on the bar. */
.preview .logo {
  background: var(--brass); font-family: var(--body); font-weight: 700; font-size: 15px; letter-spacing: 0;
  text-transform: none; padding: 9px 18px; white-space: nowrap;
}
.preview .logo:hover { background: var(--ink); }
.preview .pb-who, .preview #pb-count { display: none; }
.preview .pb-actions { margin-left: auto; }
.pb-who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.pb-who .avatar { width: 30px; height: 30px; font-size: 13px; }
.pb-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
#pb-author { font-size: 11px; text-transform: uppercase; letter-spacing: 0.16em; color: var(--ink-dim); }
#pb-title { background: transparent; border: 0; outline: none; font-weight: 700; font-size: 15px; padding: 0; min-width: 0; width: 100%; text-overflow: ellipsis; }
#pb-title:not([readonly]):hover, #pb-title:not([readonly]):focus { box-shadow: 0 1px 0 var(--ink-faint); }
#pb-title::placeholder { color: var(--ink-faint); }
.pill { font-family: var(--mono); font-size: 12px; color: var(--ink-dim); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; white-space: nowrap; }
.status { font-size: 12px; white-space: nowrap; color: var(--ink-faint); min-width: 64px; }
.status[data-kind="ok"]::before { content: "● "; color: var(--ok); }
.status[data-kind="pending"]::before { content: "● "; color: var(--brass); }
.status[data-kind="err"] { color: #ffb3a8; }
.status:empty::before { content: none; }
.pb-actions { display: flex; gap: 4px; }
.count { font-family: var(--mono); font-size: 11px; background: rgba(255,255,255,0.1); border-radius: 999px; padding: 0 6px; }
body.readonly .edit-only { display: none; }

#readonly-banner {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 4; padding: 7px 8px 7px 16px; border-radius: 999px;
  background: rgba(77, 83, 65, 0.88); backdrop-filter: blur(10px); border: 1px solid rgba(233,223,199,0.18);
  display: flex; align-items: center; gap: 12px; font-size: 13.5px; white-space: nowrap;
}

/* ---------- Picker ---------- */
#picker {
  position: fixed; z-index: 4; top: 76px; left: 14px; bottom: 14px; width: 340px; padding: 16px 16px 0;
  display: flex; flex-direction: column; transform: translateX(calc(-100% - 20px)); transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
}
#picker.open { transform: none; }
body.readonly #picker { display: none; }
#picker-list { overflow-y: auto; margin: 0 -16px; padding: 0 16px 16px; }
.cat h3 {
  font-family: var(--display); font-size: 14px; letter-spacing: 0.16em; text-transform: uppercase; margin: 16px 0 8px;
  display: flex; align-items: center; gap: 8px; color: var(--ink-dim); font-weight: 700;
}
.cat h3::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--c); }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card {
  display: flex; flex-direction: column; align-items: stretch; text-align: left; gap: 2px; padding: 6px 6px 8px; cursor: pointer;
  background: rgba(255, 255, 255, 0.035); border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--ink-faint); background: rgba(255, 255, 255, 0.07); transform: translateY(-1px); }
.card.active { border-color: var(--brass); background: rgba(240, 194, 122, 0.1); }
.card img {
  width: 100%; aspect-ratio: 11 / 8; object-fit: contain; border-radius: 6px;
  background: radial-gradient(circle at 50% 40%, #5c6150, #2e312a 75%);
}
.card-name { font-weight: 700; font-size: 13px; margin-top: 4px; line-height: 1.2; }
.card-dims { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); }

/* ---------- Room look ---------- */
#look {
  position: fixed; z-index: 5; top: 76px; left: 14px; bottom: 14px; width: 320px; padding: 16px 16px 12px;
  display: flex; flex-direction: column; transform: translateX(calc(-100% - 20px)); transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
}
#look.open { transform: none; }
.look-body { overflow-y: auto; margin: 0 -16px; padding: 0 16px 8px; display: flex; flex-direction: column; gap: 14px; }
.look-room { width: 100%; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,0.05); color: var(--ink); }
.look-room option { background: var(--panel-solid); }
.look-sec h3 { font-family: var(--display); font-size: 14px; letter-spacing: 0.16em; text-transform: uppercase; margin: 0 0 8px; color: var(--ink-dim); font-weight: 700; }
.look-swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.look-swatch {
  aspect-ratio: 1; border-radius: 10px; border: 2px solid var(--line); cursor: pointer; padding: 0; position: relative;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}
.look-swatch.on { border-color: var(--brass); box-shadow: 0 0 0 2px rgba(240,194,122,0.35); }
.look-swatch.custom { display: grid; place-items: center; background: conic-gradient(#e05a47, #f0c27a, #8fc98a, #6fa8dc, #9a7fd1, #e05a47); }
.look-swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.look-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.look-opt {
  display: flex; flex-direction: column; gap: 5px; align-items: stretch; padding: 5px 5px 7px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: rgba(255,255,255,0.035); color: var(--ink); font-size: 12px; line-height: 1.2; text-align: center;
}
.look-opt:hover { border-color: var(--ink-faint); }
.look-opt.on { border-color: var(--brass); background: rgba(240,194,122,0.1); }
.look-tile { display: block; height: 38px; border-radius: 6px; background: #efeee9; position: relative; overflow: hidden; }
.ceil-plain { background: #efeee9; }
.ceil-tiles-white { background: #ebeae5; background-image: linear-gradient(#c9c7c0 2px, transparent 2px), linear-gradient(90deg, #c9c7c0 2px, transparent 2px); background-size: 13px 13px; }
.ceil-tiles-dark { background: #1d1b1b; background-image: linear-gradient(#050505 2px, transparent 2px), linear-gradient(90deg, #050505 2px, transparent 2px); background-size: 13px 13px; }
.ceil-concrete { background: radial-gradient(circle at 30% 40%, #a8a6a1, #8e8c87 60%), #9a9893; }
.ceil-black { background: #191919; }
.ceil-slats { background: repeating-linear-gradient(90deg, #b8865a 0 5px, #141210 5px 7px); }
/* Light previews: a grey ceiling seen from below, with the fittings glowing. */
.look-tile[class*="light-"] { background-color: #8d8c87; background-repeat: no-repeat; }
.look-tile.light-downlights { background-image: radial-gradient(circle, #fffaf0 3px, #111 4px, transparent 5px); background-size: 18px 18px; background-repeat: repeat; background-position: 0 1px; }
.light-panels { background-image: linear-gradient(#fffaf0, #fffaf0), linear-gradient(#fffaf0, #fffaf0); background-size: 16px 16px, 16px 16px; background-position: 22% 50%, 78% 50%; }
.light-strips { background-image: linear-gradient(#fffaf0, #fffaf0), linear-gradient(#fffaf0, #fffaf0); background-size: 84% 3px, 84% 3px; background-position: 50% 11px, 50% 24px; }
.light-pendants { background-image: radial-gradient(ellipse 9px 6px at 30% 24px, #f4f2ec 98%, transparent), radial-gradient(ellipse 9px 6px at 70% 24px, #f4f2ec 98%, transparent); }
.light-pendants::before, .light-pendants::after { content: ""; position: absolute; top: 0; width: 1px; height: 19px; background: #222; left: 30%; }
.light-pendants::after { left: 70%; }
.tone-warm { background: linear-gradient(#ffd5a6, #e9b880); }
.tone-neutral { background: linear-gradient(#fff4e6, #e8ddcf); }
.tone-cool { background: linear-gradient(#eef4ff, #c9d6ee); }
.look-status { font-size: 12px; color: var(--ink-faint); padding-top: 8px; min-height: 1.4em; }
@media (max-width: 600px) { #look { top: auto; left: 8px; right: 8px; width: auto; max-height: 60vh; } }

/* ---------- Fix with Claude ---------- */
#fixchat {
  position: fixed; z-index: 6; top: 76px; right: 14px; bottom: 14px; width: 360px; padding: 16px 16px 12px;
  display: flex; flex-direction: column; transform: translateX(calc(100% + 20px)); transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
}
#fixchat.open { transform: none; }
.fix-log { flex: 1; overflow-y: auto; margin: 0 -16px; padding: 4px 16px 12px; display: flex; flex-direction: column; gap: 8px; }
.fix-empty, .fix-wait { color: var(--ink-faint); font-size: 13px; line-height: 1.45; margin: 0; }
.fix-msg { padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 88%; }
.fix-msg.owner { align-self: flex-end; background: rgba(240, 194, 122, 0.16); border: 1px solid rgba(240, 194, 122, 0.35); border-bottom-right-radius: 4px; }
.fix-msg.claude { align-self: flex-start; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.fix-msg.claude.busy { display: flex; padding: 9px 12px; font-weight: 500; }
.fix-msg.claude.err { color: #ffc2b8; border-color: rgba(224, 90, 71, 0.5); }
.fix-msg ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-dim); font-size: 13px; white-space: normal; }
.fix-changed { display: block; margin-top: 6px; font-size: 12px; color: #a6dba0; font-weight: 600; }
.fix-changed::before { content: "✓ "; }
.fix-form { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.fix-form textarea {
  width: 100%; resize: vertical; min-height: 64px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(255,255,255,0.05); color: var(--ink); font: inherit; font-size: 14px; line-height: 1.4;
}
.fix-form textarea:focus { outline: none; border-color: var(--brass); }
.fix-form .btn { align-self: flex-end; }
.fix-why { margin: 0; font-size: 12.5px; color: var(--ink-dim); line-height: 1.4; }
.fix-why[hidden] { display: none; }
@media (max-width: 600px) { #fixchat { top: auto; left: 8px; right: 8px; width: auto; max-height: 70vh; } }

/* ---------- Suggestions drawer ---------- */
#plans {
  position: fixed; z-index: 6; top: 76px; right: 14px; width: 360px; max-height: calc(100vh - 92px); padding: 16px;
  display: flex; flex-direction: column; gap: 12px; transform: translateX(calc(100% + 20px)); transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
}
#plans.open { transform: none; }
#plan-list { overflow-y: auto; }

/* ---------- Inspector ---------- */
#inspector {
  position: fixed; z-index: 4; right: 14px; bottom: calc(var(--map-h) + 60px); width: 300px; padding: 14px;
  animation: rise 0.2s both;
}
.insp-head { display: flex; align-items: center; gap: 8px; }
.insp-head strong { font-family: var(--display); font-size: 21px; text-transform: uppercase; letter-spacing: 0.04em; flex: 1; }
.swatch { width: 10px; height: 10px; border-radius: 2px; }
.insp-spec { color: var(--ink-dim); font-size: 12.5px; line-height: 1.45; margin: 4px 0 10px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0 0 10px; font-size: 12.5px; }
.facts dt { color: var(--ink-faint); }
.facts dd { margin: 0; font-family: var(--mono); font-size: 12px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--ink-dim); }
.field input, .field select {
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px;
  font-family: var(--mono); font-size: 13px; outline: none;
}
.field select option { background: var(--panel-solid); }
.field input:focus, .field select:focus { border-color: var(--brass); }
.insp-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Minimap ---------- */
:root { --map-w: 248px; --map-h: 340px; }
#mapwrap {
  position: fixed; z-index: 3; right: 14px; bottom: 14px; width: var(--map-w); padding: 8px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 50px rgba(0,0,0,0.45); transition: width 0.25s, height 0.25s;
}
.map-head { display: flex; align-items: center; gap: 8px; padding: 0 2px 6px; font-size: 11px; color: var(--ink-dim); }
.map-head > span { font-family: var(--display); font-weight: 800; font-size: 14px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink); margin-right: auto; }
.tog { display: flex; align-items: center; gap: 3px; cursor: pointer; }
.tog input { accent-color: var(--brass); margin: 0; }
#minimap { display: block; width: 100%; height: var(--map-h); border-radius: 8px; cursor: crosshair; background: #232421; touch-action: none; }
body.bigmap #mapwrap { width: min(560px, calc(100vw - 28px)); }
body.bigmap { --map-h: min(780px, calc(100vh - 140px)); }
body.bigmap #inspector { right: calc(min(560px, calc(100vw - 28px)) + 28px); bottom: 14px; }

/* ---------- Help, hints, toast ---------- */
#help {
  position: fixed; z-index: 3; left: 14px; bottom: 14px; font-size: 12.5px; color: var(--ink-dim);
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px 10px; max-width: 300px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: left 0.28s cubic-bezier(.2,.8,.2,1);
}
#picker.open ~ #help { left: 368px; }
#help ul { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
#help.collapsed ul { display: none; }
#help.collapsed { padding-bottom: 6px; }
.help-toggle { border: 0; background: transparent; cursor: pointer; padding: 2px 0; font-family: var(--display); font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink); }
.help-toggle::after { content: " ▴"; color: var(--ink-faint); }
#help.collapsed .help-toggle::after { content: " ▾"; }

#hint {
  position: fixed; z-index: 4; left: 50%; bottom: 22px; transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
  background: rgba(20, 20, 18, 0.9); border: 1px solid rgba(240, 194, 122, 0.45); color: var(--ink); border-radius: 999px;
  padding: 9px 18px; font-size: 13.5px; transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 600px); text-align: center;
}
#hint.show { opacity: 1; transform: translate(-50%, 0); }
#toast {
  position: fixed; z-index: 20; left: 50%; top: 84px; transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--night); font-weight: 600; border-radius: 999px; padding: 9px 18px; transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4); max-width: calc(100vw - 32px); text-align: center;
  user-select: text; overflow-wrap: anywhere;
}
#toast.show { pointer-events: auto; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Dialog ---------- */
#name-dialog {
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel-solid); color: var(--ink); padding: 24px; width: min(420px, calc(100vw - 32px));
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
#name-dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px); }
#name-dialog h2 { font-family: var(--display); font-weight: 800; text-transform: uppercase; font-size: 30px; margin: 0 0 6px; }
#name-dialog p { color: var(--ink-dim); margin: 0 0 16px; line-height: 1.45; }
#name-dialog input { width: 100%; }
#name-dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 18px 0 0; }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  #lobby { grid-template-columns: 1fr; padding: 6vh 16px; gap: 28px; }
  .brand { margin-bottom: 24px; }
  .pb-actions .btn { padding: 6px 9px; font-size: 12.5px; }
  #pb-count, #pb-status { display: none; }
  #picker { width: calc(100vw - 28px); }
  #picker.open ~ #help { display: none; }
  :root { --map-w: 170px; --map-h: 230px; }
  #hint { max-width: calc(100vw - 32px); bottom: auto; top: 120px; }
  #inspector { width: calc(100vw - 28px - var(--map-w) - 12px); right: calc(var(--map-w) + 26px); bottom: 14px; max-height: 50vh; overflow-y: auto; }
  #plans { width: calc(100vw - 28px); }
  #readonly-banner { top: 70px; font-size: 12px; }
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(233,223,199,0.25) transparent; }

/* ---------- Phones ---------- */
@media (max-width: 600px) {
  #planbar { gap: 6px; padding: 6px; }
  .pb-who { flex: 0 0 auto; }
  .pb-who .avatar { display: none; }
  .pb-text { display: none; }
  .pb-actions { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  /* Right-aligned while it fits; when it overflows the auto margin collapses and it scrolls from the start. */
  .pb-actions > :first-child { margin-left: auto; }
  .pb-actions::-webkit-scrollbar { display: none; }
  .pb-actions .btn { padding: 6px 10px; }
  #btn-copy-plan { display: none; }
  .map-head .tog { display: none; }
  #readonly-banner { white-space: normal; width: calc(100vw - 28px); justify-content: space-between; top: 64px; }
}

/* ---------- Collapsible map and touch joystick ---------- */
.dock-btn {
  position: fixed; z-index: 3; bottom: 14px; display: none; align-items: center; gap: 7px;
  padding: 10px 14px; border-radius: 999px; border: 1px solid var(--line); cursor: pointer;
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-family: var(--display); font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.dock-btn:hover { border-color: var(--ink-faint); }
.dock-right { right: 14px; }
.dock-left { left: 14px; }
body.map-collapsed #mapwrap { display: none; }
body.map-collapsed:not(.in-lobby) #map-show { display: inline-flex; }

#stick { display: none; position: fixed; z-index: 3; left: 18px; bottom: 18px; touch-action: none; user-select: none; -webkit-user-select: none; }
body.touch-ui:not(.stick-collapsed):not(.in-lobby) #stick { display: block; }
body.touch-ui.stick-collapsed:not(.in-lobby) #stick-show { display: inline-flex; }
.stick-base {
  width: 132px; height: 132px; border-radius: 50%; position: relative; touch-action: none;
  background: radial-gradient(circle, rgba(20,20,18,0.35) 0 55%, rgba(20,20,18,0.6) 56%);
  border: 1px solid rgba(233,223,199,0.22); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35), inset 0 0 0 10px rgba(233,223,199,0.04);
}
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #f6d197, var(--brass) 55%, var(--brass-deep));
  box-shadow: 0 6px 16px rgba(0,0,0,0.45); transition: transform 0.15s ease-out; pointer-events: none;
}
.stick-base.active .stick-knob { transition: none; }
.stick-hide {
  position: absolute; right: -10px; top: -10px; width: 30px; height: 30px; background: var(--panel-solid);
  border: 1px solid var(--line); color: var(--ink);
}

/* On touch screens the keyboard help is no use and the joystick needs its corner. */
body.touch-ui #help { display: none; }
body.touch-ui #picker.open ~ #help { display: none; }
@media (max-width: 900px) {
  /* With the map hidden or small, the inspector sits under the top bar instead. */
  body.touch-ui #inspector { top: 70px; bottom: auto; right: 14px; width: calc(100vw - 28px); max-height: 42vh; }
  body.touch-ui.readonly #inspector { top: 124px; }
}
.map-head { gap: 6px; }
.map-head .icon-btn { width: 24px; height: 24px; font-size: 16px; flex: none; }
.map-head .tog { white-space: nowrap; }
@media (max-width: 900px) {
  .map-head .tog { display: none; }
}

/* ---------- New version banner ---------- */
#update-banner {
  position: fixed; z-index: 30; top: 0; left: 0; right: 0; height: 44px;
  display: flex; align-items: center; justify-content: center; gap: 14px; padding: 0 16px;
  background: var(--brass); color: #1b160d; font-weight: 600; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35); animation: slide-down 0.3s both;
}
#update-banner .btn { background: #1b160d; color: var(--ink); border-color: #1b160d; }
#update-banner .btn:hover { background: #2b241a; }
@keyframes slide-down { from { transform: translateY(-100%); } to { transform: none; } }
/* Everything pinned to the top moves down while the banner shows. */
body.has-update #planbar { top: 58px; }
body.has-update #readonly-banner { top: 118px; }
body.has-update #picker, body.has-update #plans { top: 120px; }
body.has-update #toast { top: 128px; }
body.has-update #lobby { padding-top: calc(7vh + 44px); }
@media (max-width: 900px) {
  body.has-update.touch-ui #inspector { top: 114px; }
}
@media (max-width: 600px) {
  #update-banner { font-size: 12.5px; gap: 10px; justify-content: space-between; }
  body.has-update #readonly-banner { top: 108px; }
}

/* ---------- Deleting suggestions ---------- */
.plan-del {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 1px solid transparent; background: transparent;
  color: var(--ink-faint); cursor: pointer; display: grid; place-items: center;
}
.plan-del:hover { color: #ffb3a8; border-color: rgba(224,90,71,0.5); background: rgba(224,90,71,0.12); }
.plan-row:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-solid:hover { background: #ec6b58; }
#confirm-dialog, #pdf-dialog {
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel-solid); color: var(--ink); padding: 24px;
  width: min(420px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
#confirm-dialog::backdrop, #pdf-dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px); }
#confirm-dialog h2, #pdf-dialog h2 { font-family: var(--display); font-weight: 800; text-transform: uppercase; font-size: 28px; margin: 0 0 8px; }
#confirm-dialog p, #pdf-dialog p { color: var(--ink-dim); margin: 0; line-height: 1.5; }
#confirm-dialog menu, #pdf-dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 20px 0 0; }
#pdf-dialog { width: min(480px, calc(100vw - 32px)); }
.pdf-quick { display: flex; gap: 6px; margin: 14px 0 8px; }
.pdf-types { max-height: min(46vh, 360px); overflow-y: auto; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 6px 0; }
.pdf-types h3 { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faint); font-weight: 600; margin: 10px 0 4px; }
.pdf-types .tog { padding: 3px 0; gap: 8px; }
.pdf-types .tog .count { color: var(--ink-faint); font-family: var(--mono); font-size: 12px; margin-left: auto; }
.pdf-opt { margin-top: 12px; gap: 8px; }

/* ---------- Owner lobby, list sections, blocker ---------- */
.lobby-left h1.plain { font-size: clamp(36px, 4.6vw, 64px); overflow-wrap: break-word; hyphens: auto; }
.name-row.no-name { justify-content: flex-start; }
.lobby-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; animation: rise 0.7s 0.35s both; }
.lobby-actions .btn { text-decoration: none; color: var(--ink); }
.list-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); margin: 16px 0 6px; font-weight: 600; }
.list-head:first-child { margin-top: 0; }
.plan-pub {
  border: 1px solid var(--line); background: transparent; color: var(--ink-dim); border-radius: 999px;
  font-size: 11px; padding: 3px 8px; cursor: pointer; white-space: nowrap;
}
.plan-pub:hover { border-color: var(--ink-faint); color: var(--ink); }
.plan-pub.on { border-color: rgba(240, 194, 122, 0.5); color: var(--brass); }
.blocker { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--night); padding: 16px; }
.blocker-card { max-width: 440px; text-align: center; display: flex; flex-direction: column; gap: 18px; align-items: center; }
.blocker-card p { color: var(--ink-dim); line-height: 1.5; margin: 0; font-size: 15px; }
.blocker-card .wordmark { font-family: var(--display); font-weight: 800; font-size: 28px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink); text-decoration: none; }
.blocker-card .wordmark span { color: var(--brass); }
.blocker-card .btn { text-decoration: none; }
.insp-bad { color: #ffb3a8; font-size: 12.5px; margin: 0 0 10px; line-height: 1.4; }

/* ---------- Share dialog ---------- */
.share-dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel-solid); color: var(--ink); padding: 24px; width: min(520px, calc(100vw - 32px)); }
.share-dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px); }
.share-body { display: flex; flex-direction: column; gap: 12px; }
.share-body h2 { font-family: var(--display); font-weight: 800; text-transform: uppercase; font-size: 28px; margin: 0; }
.share-body h3 { margin: 6px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); }
.share-body p { margin: 0; color: var(--ink-dim); line-height: 1.45; }
.share-opts { display: flex; flex-direction: column; gap: 6px; }
.share-opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.share-opt.on { border-color: var(--brass); background: rgba(240, 194, 122, 0.06); }
.share-opt input { margin-top: 3px; accent-color: var(--brass); }
.share-opt span { display: flex; flex-direction: column; gap: 2px; }
.share-opt span span { color: var(--ink-dim); font-size: 13px; line-height: 1.4; }
.share-link { display: flex; gap: 8px; }
.share-link input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12.5px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,0.05); color: var(--ink); }
.share-qr-row { display: grid; grid-template-columns: 112px 1fr; gap: 6px 14px; align-items: center; }
.share-qr-row .btn { grid-column: 2; justify-self: start; text-decoration: none; color: var(--ink); }
.share-qr { width: 112px; height: 112px; border-radius: 8px; background: #fff; grid-row: span 2; image-rendering: pixelated; }
.share-err { color: #ffb3a8 !important; }
.share-body menu { display: flex; justify-content: flex-end; padding: 0; margin: 4px 0 0; }

/* ---------- Guide tips and spinners (planner, editor, dashboard) ---------- */
dialog.guide {
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel-solid); color: var(--ink); padding: 0;
  width: min(480px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
dialog.guide::backdrop { background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px); }
.guide-body { display: flex; flex-direction: column; gap: 10px; padding: 24px 24px 18px; }
.guide-kicker { margin: 0; font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brass); }
.guide-body h2 { font-family: var(--display); font-weight: 800; text-transform: uppercase; font-size: 28px; line-height: 1; margin: 0 0 2px; }
.guide-body p { margin: 0; color: var(--ink-dim); line-height: 1.5; }
.guide-list { margin: 0; padding-left: 20px; color: var(--ink-dim); line-height: 1.5; display: flex; flex-direction: column; gap: 4px; }
.guide-list li::marker { color: var(--brass); font-weight: 700; }
.guide-form { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.guide-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-dim); }
.guide-form input { padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255,255,255,0.05); color: var(--ink); font-size: 16px; width: 140px; }
.guide-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.guide-actions .spacer { flex: 1; }
.guide-stop { border: 0; background: none; color: var(--ink-faint); font-size: 12.5px; cursor: pointer; padding: 4px 0; text-decoration: underline; text-underline-offset: 3px; }
.guide-stop:hover { color: var(--ink-dim); }

.spinner {
  display: inline-block; width: 18px; height: 18px; flex: none; border-radius: 50%;
  border: 2px solid rgba(240, 194, 122, 0.25); border-top-color: var(--brass); animation: spin 0.8s linear infinite;
}
.spinner.small { width: 11px; height: 11px; border-width: 1.5px; margin-right: 6px; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.busy { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: rgba(240, 194, 122, 0.06); font-weight: 600; }
.btn.primary .spinner { border-color: rgba(0, 0, 0, 0.2); border-top-color: #1b1a17; }
