:root {
  --bg: #121212;
  --panel: #1b1b1d;
  --line: #2c2c30;
  --text: #e8e4dc;
  --muted: #9a958c;
  --accent: #d4a65a;
  --accent-soft: rgba(212, 166, 90, 0.14);
  --say: #9cc3e6;
  --error: #e07a6a;
  --prose: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  display: flex;
  flex-direction: column;
}

.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.title { font-family: var(--prose); font-size: 20px; color: var(--accent); letter-spacing: 0.5px; }
.meta { display: flex; gap: 12px; align-items: center; font-size: 13px; color: var(--muted); }
.conn { padding: 2px 8px; border-radius: 10px; border: 1px solid var(--line); }
.music-btn {
  background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 10px;
  width: 30px; height: 24px; font-size: 14px; cursor: pointer; line-height: 1;
}
.music-btn.playing { color: var(--accent); border-color: var(--accent); }
.music-panel {
  position: absolute; right: 16px; top: 52px; z-index: 5; width: 250px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); font-size: 14px;
}
.music-panel[hidden] { display: none; }
.music-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.music-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.music-row input[type="checkbox"] { accent-color: var(--accent); }
.music-row select {
  flex: 1; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 4px;
}
.music-note { margin: 0; color: var(--muted); font-size: 12px; }
.conn.online { color: #8fc98f; border-color: #3b5a3b; }

.layout { flex: 1; display: flex; min-height: 0; }
.feed { flex: 1; overflow-y: auto; padding: 24px 16px 8px; min-width: 0; }
.feed > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.entry.state {
  font-size: 12.5px; color: var(--muted); font-style: italic; margin-top: -10px;
  padding-left: 12px; border-left: 2px solid var(--line);
}

.panel {
  width: 290px; flex-shrink: 0; overflow-y: auto; border-left: 1px solid var(--line);
  background: var(--panel); padding: 16px 16px 24px; font-size: 14px;
}
.panel-section { margin-bottom: 20px; }
.panel-section h2 {
  font: 600 11px/1 var(--ui); letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin: 0 0 8px;
}
.p-where { font-family: var(--prose); font-size: 17px; color: var(--accent); }
.p-desc { color: var(--muted); font-size: 13px; margin-top: 4px; line-height: 1.4; }
.p-time { color: var(--muted); font-size: 12px; margin-top: 6px; }
.p-empty { color: var(--muted); font-size: 13px; }
.pc { margin-bottom: 14px; }
.pc-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.pc-name .dot { width: 7px; height: 7px; border-radius: 50%; background: #555; }
.pc-name .dot.on { background: #8fc98f; }
.pc-name .you { font-weight: normal; color: var(--muted); font-size: 12px; }
.pc-loc { color: var(--muted); font-size: 12px; margin: 2px 0 0 13px; }
.pc-inv { list-style: none; margin: 4px 0 0 13px; padding: 0; font-size: 13px; color: var(--text); }
.pc-inv li { padding: 1px 0; }
.pc-inv .qty { color: var(--muted); }
.tags { margin: 4px 0 0 13px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 9px; border: 1px solid var(--line); color: var(--muted); }
.tag.cond { color: var(--error); border-color: rgba(224, 122, 106, 0.4); }
.npc { margin-bottom: 10px; }
.npc.down { opacity: 0.55; }
.npc-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.npc-name { font-weight: 600; }
.npc-desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; line-height: 1.35; }
.tag.friendly { color: #8fc98f; border-color: #3b5a3b; }
.tag.wary { color: #d9b36a; border-color: #6a5630; }
.tag.hostile { color: var(--error); border-color: rgba(224, 122, 106, 0.5); }
.flag { font-size: 13px; margin-bottom: 4px; }
.flag .k { color: var(--muted); }
.panel-btn {
  display: none; background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 10px; padding: 2px 10px; font-size: 13px; cursor: pointer;
}
@media (max-width: 900px) {
  .panel {
    position: fixed; top: 49px; right: 0; bottom: 0; z-index: 6; width: min(320px, 88vw);
    transform: translateX(100%); transition: transform 0.2s ease; box-shadow: -8px 0 24px rgba(0, 0, 0, 0.5);
  }
  .panel.open { transform: none; }
  .panel-btn { display: inline-block; }
  .players { display: none; }
}
.entry { margin: 0 auto 18px; line-height: 1.6; }
.entry.gm { font-family: var(--prose); font-size: 18px; }
.entry.gm p { margin: 0 0 12px; }
.entry.do, .entry.say {
  font-size: 15px; padding: 8px 12px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 6px 6px 0;
}
.entry.say { border-left-color: var(--say); background: rgba(156, 195, 230, 0.10); }
.entry .who { font-weight: 600; margin-right: 6px; }
.entry.do .text { font-style: italic; }
.entry.ooc { font-size: 13px; color: var(--muted); }
.entry.system {
  text-align: center; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 2px;
}
.entry.error { color: var(--error); font-size: 14px; }
.entry.streaming::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.reroll {
  background: none; border: none; color: var(--muted); font-size: 12px;
  cursor: pointer; padding: 0; text-decoration: underline;
}
.reroll:hover { color: var(--text); }

.start-wrap { text-align: center; padding: 8px 16px 16px; }
.start {
  font-family: var(--prose); font-size: 18px; padding: 10px 22px; cursor: pointer;
  background: var(--accent); color: #1a1407; border: none; border-radius: 6px;
}

.composer {
  border-top: 1px solid var(--line); background: var(--panel);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.composer > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.status { font-size: 13px; color: var(--accent); margin-bottom: 6px; }
.modes { display: flex; gap: 6px; margin-bottom: 8px; }
.mode {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  border-radius: 14px; padding: 4px 14px; font-size: 13px; cursor: pointer;
}
.mode.active { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.send { display: flex; gap: 8px; }
.send textarea {
  flex: 1; resize: none; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 10px; font: 15px/1.4 var(--ui);
}
.send textarea:focus { outline: none; border-color: var(--accent); }
.send button {
  background: var(--accent); color: #1a1407; border: none; border-radius: 6px;
  padding: 0 18px; font-weight: 600; cursor: pointer;
}
.send button:disabled { opacity: 0.5; cursor: default; }

.join {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.85); z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.join[hidden] { display: none; }
.join-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 28px; width: 100%; max-width: 360px; text-align: center;
}
.join-card h1 { font-family: var(--prose); color: var(--accent); margin: 0 0 8px; font-weight: normal; }
.join-card p { color: var(--muted); margin: 0 0 16px; }
.join-card input {
  width: 100%; padding: 10px; margin-bottom: 12px; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; font-size: 16px;
}
.join-card button {
  width: 100%; padding: 10px; background: var(--accent); color: #1a1407;
  border: none; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 16px;
}

/* ---- device approval ---- */
.gate-card p { line-height: 1.5; }
.gate-code {
  font: 600 28px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 3px; color: var(--accent);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px 10px; margin-bottom: 12px;
}
.host-btn {
  background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 10px;
  padding: 2px 10px; font-size: 13px; cursor: pointer; position: relative;
}
.host-btn .badge {
  display: inline-block; margin-left: 6px; min-width: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--accent); color: #1a1407; font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
}
.host-panel { width: min(360px, calc(100vw - 32px)); max-height: 78vh; overflow-y: auto; }
.host-panel h3 {
  font: 600 11px/1 var(--ui); letter-spacing: 1.5px; text-transform: uppercase; color: var(--accent); margin: 4px 0 10px;
}
.host-panel h3:not(:first-child) { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.host-panel h4 {
  font: 600 11px/1 var(--ui); letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px;
}
.host-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.host-note { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 10px 0 0; }
.door { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.door-state { font-weight: 600; }
.door-state.open { color: #8fc98f; }
.door-note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.door-btn, .dev-actions button, .request button, .host-actions button, .modal-actions button, .ed button {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.dev-actions button.ok, .request button.ok, .modal-actions button.ok { border-color: #3b5a3b; color: #8fc98f; }
.dev-actions button.no, .request button.no, .host-actions button.no, .modal-actions button.no, .ed button.no {
  border-color: rgba(224, 122, 106, 0.5); color: var(--error);
}
button:disabled { opacity: 0.45; cursor: default; }
.dev { padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.dev:first-child { border-top: none; }
.dev-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dev-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--accent); white-space: nowrap; }
.dev-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dev-actions { display: flex; gap: 6px; }
.dev-list .none { color: var(--muted); font-size: 12px; }
.requests { position: fixed; top: 56px; left: 50%; transform: translateX(-50%); z-index: 8; width: min(520px, 92vw); }
.request {
  background: var(--panel); border: 1px solid var(--accent); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 14px;
}
@media (max-width: 420px) {
  .top { padding: 10px 12px; }
  .title { font-size: 17px; }
  .meta { gap: 6px; }
  .music-panel { right: 12px; }
}

/* ---- host tools: rewind, character editor, dialogs ---- */
.entry-tool {
  background: none; border: none; color: var(--muted); font: 12px var(--ui); cursor: pointer; padding: 0;
  text-decoration: underline; margin-left: 14px; opacity: 0; transition: opacity 0.15s;
}
.entry:hover .entry-tool, .entry-tool:focus { opacity: 1; }
.entry-tool:hover { color: var(--text); }
@media (hover: none) { .entry-tool { opacity: 0.7; } }
.pc-edit {
  margin-left: auto; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 8px;
  font-size: 11px; padding: 1px 8px; cursor: pointer;
}
.pc-edit:hover { color: var(--text); border-color: var(--muted); }
.modal-wrap { z-index: 20; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px 22px 18px;
  width: 100%; max-width: 440px; max-height: 88vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.modal-card h2 { font-family: var(--prose); font-weight: normal; color: var(--accent); margin: 0 0 10px; font-size: 22px; }
.modal-body { font-size: 14px; line-height: 1.5; color: var(--text); }
.modal-body p { margin: 0 0 10px; color: var(--muted); }
.modal-body input, .modal-body select, .modal-body textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
  font: 14px var(--ui); min-width: 0;
}
.modal-body textarea { width: 100%; resize: vertical; }
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus { outline: none; border-color: var(--accent); }
.modal-body .wide { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }
.modal-actions button { padding: 6px 14px; font-size: 13px; }
.ed h4 {
  font: 600 11px/1 var(--ui); letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin: 16px 0 8px;
}
.ed-row { display: flex; gap: 6px; align-items: center; }
.ed-row input:not([type="number"]) { flex: 1; }
.ed-row input[type="number"] { width: 64px; }
.ed-row select { flex: 1; }
.ed-hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.ed-items { list-style: none; margin: 0 0 8px; padding: 0; }
.ed-items li { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-top: 1px solid var(--line); }
.ed-items li:first-child { border-top: none; }
.ed-items .nm { flex: 1; }
.ed-items .qty { color: var(--muted); }
.ed-empty { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.ed .tags { margin: 0 0 8px; }
.ed .tag button { background: none; border: none; color: inherit; cursor: pointer; padding: 0 0 0 4px; font-size: 12px; }
.toast {
  position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%); z-index: 30; max-width: min(520px, 92vw);
  background: var(--panel); border: 1px solid #3b5a3b; color: var(--text); border-radius: 8px; padding: 10px 14px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.toast.bad { border-color: rgba(224, 122, 106, 0.6); }
