:root {
  --bg: #0f172a; --surface: #1e293b; --line: #334155;
  --text: #f1f5f9; --muted: #94a3b8; --accent: #695af1; --error: #fca5a5;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, sans-serif; }
.a-canvas { cursor: grab; }
.a-canvas.dragging { cursor: grabbing; }

button, input, select { font: inherit; color: inherit; }
button { border: 0; border-radius: 8px; padding: 10px 16px; background: var(--accent); color: #fff; cursor: pointer; }
button:hover:not(:disabled) { filter: brightness(1.12); }
button:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }

#lobby {
  position: fixed; inset: 0; z-index: 20; display: grid; overflow: auto; padding: 16px;
  background: rgba(15, 23, 42, 0.72); backdrop-filter: blur(6px);
}
#lobby-form {
  margin: auto; width: min(500px, 100%); padding: 24px;
  display: grid; gap: 18px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
h1 { margin: 0; font-size: 22px; }
.field { display: grid; gap: 6px; }
.field span, legend { color: var(--muted); font-size: 13px; padding: 0; }
input[type="text"], select {
  width: 100%; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.chip, .swatch { position: relative; cursor: pointer; }
.chip input, .swatch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.chip span { display: block; padding: 7px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.chip input:checked + span { border-color: var(--accent); background: #2e2a5f; }
.swatch span { display: block; width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--bg); }
.swatch input:checked + span { box-shadow: 0 0 0 2px #fff; }
.chip input:focus-visible + span, .swatch input:focus-visible + span { outline: 2px solid #a5b4fc; outline-offset: 3px; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
#mic-device { margin-top: 8px; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
#lobby-message { margin: 0; font-size: 14px; white-space: pre-line; color: var(--muted); }
#lobby-message:empty { display: none; }
#lobby-message.error { color: var(--error); }

#hud {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 10;
  display: flex; align-items: center; gap: 14px; padding: 8px 8px 8px 16px; white-space: nowrap;
  background: rgba(15, 23, 42, 0.9); border: 1px solid var(--line); border-radius: 12px;
}
#occupants { color: var(--muted); font-size: 14px; }
#hud button { padding: 8px 14px; background: var(--surface); }
#notice {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 30; max-width: calc(100% - 32px);
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--error); border-radius: 8px;
}
#stage-note { padding: 4px 10px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 13px; }
#hud button.live { background: #166534; }
#hud button.active { background: var(--accent); }
#tooltip {
  position: fixed; z-index: 10; pointer-events: none; transform: translate(14px, 14px); max-width: 260px;
  padding: 6px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}
#edit-bar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 100000; display: flex; gap: 8px; }
#share-menu {
  position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%);
  display: grid; gap: 6px; padding: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
@media (max-width: 520px) {
  #hud {
    gap: 8px; padding: 6px; width: max-content; max-width: calc(100% - 16px); flex-wrap: wrap; justify-content: center;
    bottom: calc(8px + env(safe-area-inset-bottom));
  }
  #hud button { padding: 10px 12px; }
  #occupants { display: none; }
  #lobby-form { padding: 18px; gap: 14px; }
  input[type="text"], select { font-size: 16px; } /* stops iPhones zooming in */
}
.test-label { margin-left: 6px; padding: 2px 8px; border-radius: 6px; background: #78350f; color: #fde68a; }

#tools { position: fixed; right: 16px; top: 16px; z-index: 11; display: flex; gap: 8px; }
#tools button { background: rgba(15, 23, 42, 0.9); border: 1px solid var(--line); }
#tools button[aria-expanded="true"] { background: var(--accent); }
#chat-unread { margin-left: 4px; padding: 1px 7px; border-radius: 10px; background: #dc2626; font-size: 12px; }
#panel {
  position: fixed; right: 16px; top: 72px; z-index: 11; width: 320px; max-height: calc(100% - 160px);
  display: flex; flex-direction: column; overflow: hidden;
  background: rgba(15, 23, 42, 0.95); border: 1px solid var(--line); border-radius: 12px;
}
#panel header, #info-dialog header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--line);
}
#panel h2, #info-dialog h2 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.close { padding: 6px 12px; background: var(--surface); }
#panel section { padding: 12px; overflow: auto; min-height: 0; }
#map canvas { display: block; width: auto; max-width: 100%; max-height: 300px; margin: 0 auto 12px; background: var(--bg); border-radius: 8px; cursor: pointer; }
.places { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.areas-title { margin: 12px 0 6px; font-size: 13px; font-weight: 600; opacity: 0.8; }
.places button, #people button { padding: 8px 10px; background: var(--surface); font-size: 13px; text-align: left; }
#people { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
#people li { display: flex; align-items: center; gap: 8px; min-height: 36px; }
#people .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.role { padding: 1px 7px; border-radius: 6px; background: #2e2a5f; color: #c7d2fe; font-size: 12px; }
.dim { color: var(--muted); font-size: 12px; }
#panel .chat { display: flex; flex-direction: column; overflow: hidden; }
#chat-log { height: 300px; min-height: 60px; flex-shrink: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; overflow-wrap: anywhere; }
.line { padding: 6px 10px; border-radius: 8px; background: var(--surface); }
.line.mine { background: #2e2a5f; }
#chat-error { margin: 6px 0; color: var(--error); font-size: 13px; }
#chat-error:empty { margin: 4px 0; }
#chat-form { display: flex; gap: 6px; }
#chat-form input { min-width: 0; }
#info-dialog {
  width: min(820px, calc(100% - 24px)); max-height: calc(100% - 24px); padding: 0; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
#info-dialog::backdrop { background: rgba(15, 23, 42, 0.7); }
#info-dialog .body { display: grid; gap: 14px; padding: 16px; }
#info-dialog p { margin: 0; white-space: pre-line; }
#info-dialog img, #info-dialog video { display: block; max-width: 100%; max-height: 60vh; margin: 0 auto; border-radius: 8px; }
#info-dialog iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 8px; background: #000; }
#info-dialog iframe.tall { aspect-ratio: auto; height: 60vh; background: #fff; }
a.button { justify-self: start; padding: 10px 16px; border-radius: 8px; background: var(--accent); color: #fff; text-decoration: none; }
@media (max-width: 520px) {
  #tools { right: 8px; top: calc(8px + env(safe-area-inset-top)); }
  #panel { right: 8px; left: 8px; width: auto; top: calc(60px + env(safe-area-inset-top)); max-height: 60%; }
  #map canvas { max-height: 200px; }
  #chat-log { height: 200px; }
}
#people li { flex-wrap: wrap; }
#people .name { flex-basis: 100px; }
#host-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
#host-bar button { padding: 8px 10px; background: var(--surface); font-size: 13px; }
#host-bar button.active { background: #78350f; }
#host-bar .gather { grid-column: 1 / -1; display: flex; gap: 6px; }
#host-bar .gather button { flex-shrink: 0; background: var(--accent); }

/* Avatar choice in the lobby */
#avatar-pick { display: flex; gap: 14px; margin-top: 10px; }
#avatar-pick > div { flex: 1; min-width: 0; }
#avatar-pick .row { margin-top: 0; gap: 6px; }
#avatar-preview { width: 130px; height: 300px; flex: none; border-radius: 12px; background: linear-gradient(#e2e8f0, #94a3b8); }
.person { position: relative; cursor: pointer; }
.person input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.person span { display: block; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: #cbd5e1; }
.person img { display: block; width: 42px; height: 56px; object-fit: cover; }
.person input:checked + span { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.person input:focus-visible + span { outline: 2px solid #a5b4fc; outline-offset: 2px; }
.look { margin-top: 10px; font-size: 13px; }
.look > span { display: block; margin-bottom: 5px; color: var(--muted); }
.look .swatch span { width: 26px; height: 26px; border: 2px solid #64748b; }
@media (max-width: 480px) { #avatar-preview { width: 96px; height: 250px; } }

/* Poster reader */
#poster-reader { width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #10141c; color: var(--text); }
#poster-reader[open] { display: flex; flex-direction: column; }
#poster-reader header { display: flex; align-items: center; gap: 6px; padding: 8px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid var(--line); }
#poster-reader header button { min-width: 42px; min-height: 42px; padding: 6px 10px; background: var(--surface); font-size: 16px; }
#poster-reader header strong { min-width: 40px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#poster-reader .gap { flex: 1; }
#poster-reader .view { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; cursor: grab; }
#poster-reader .view:active { cursor: grabbing; }
#poster-reader img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; user-select: none; }
#poster-reader [hidden] { display: none; }
#poster-reader .view p { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 20px; text-align: center; }
@media (max-width: 520px) {
  #poster-reader header [aria-label^="Zoom"] { display: none; }
  #poster-reader header a.button { padding: 8px 12px; }
}
