: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; }

.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); }
.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); }

/* ---------- 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: 236px; --map-h: 330px; }
#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; }
