:root {
  color-scheme: dark;
  --bg: #0b0f12;
  --bg-2: #10171b;
  --panel: #141c21;
  --panel-2: #1a242b;
  --panel-3: #202c34;
  --text: #e9e2d5;
  --muted: #94a0a7;
  --border: #2a363e;
  --accent: #c9a85c;
  --accent-2: #8fb3c7;
  --danger: #d07b63;
  --success: #7fbf8f;
  --shadow: 0 18px 60px rgba(0, 0, 0, .35);
  --radius: 14px;
  --font-ui: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-prose: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body, #main { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(1100px 600px at 80% -10%, rgba(201, 168, 92, .08), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(111, 143, 168, .08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
::selection { background: rgba(201, 168, 92, .3); }

.app-shell { min-height: 100vh; }
.center-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.sigil {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid rgba(201, 168, 92, .45);
  border-radius: 50%;
  color: var(--accent);
  background: rgba(201, 168, 92, .08);
  box-shadow: 0 0 24px rgba(201, 168, 92, .12) inset;
}
.muted { color: var(--muted); }
.small { font-size: .78rem; }
.hint { color: var(--muted); font-size: .82rem; line-height: 1.5; }
.center { text-align: center; }

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(440px, 100%);
  background: linear-gradient(180deg, rgba(26, 36, 43, .96), rgba(16, 23, 27, .96));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 22px; }
.brand h1 {
  margin: 10px 0 6px;
  font-family: var(--font-prose);
  font-size: 2rem;
  letter-spacing: .06em;
  font-weight: 500;
}
.brand p { margin: 0; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 18px;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 10px;
  border-radius: 8px;
}
.tab.active { background: var(--panel-3); color: var(--text); }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: .8rem; color: var(--muted); letter-spacing: .03em; }
input, textarea, select {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: rgba(201, 168, 92, .6);
  box-shadow: 0 0 0 3px rgba(201, 168, 92, .1);
}
textarea { resize: vertical; min-height: 54px; }
select { appearance: none; }

.primary, .ghost {
  border-radius: 10px;
  padding: 11px 16px;
  border: 1px solid transparent;
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.primary {
  background: linear-gradient(180deg, #d4b56a, #b99446);
  color: #171208;
  font-weight: 650;
  box-shadow: 0 8px 22px rgba(201, 168, 92, .18);
}
.primary:hover { transform: translateY(-1px); }
.primary:active { transform: translateY(0); }
.primary.wide { width: 100%; }
.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.ghost:hover { color: var(--text); border-color: rgba(201, 168, 92, .4); }
.alert {
  border: 1px solid rgba(208, 123, 99, .4);
  background: rgba(208, 123, 99, .1);
  color: #f0b3a3;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: .86rem;
}
.wide-alert { width: min(720px, 100%); margin: 0 auto 14px; }

.lobby-screen { min-height: 100vh; padding: 26px; max-width: 1080px; margin: 0 auto; }
.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}
.lobby-header > div:first-child { display: flex; align-items: center; gap: 12px; }
.lobby-header h1 {
  margin: 0;
  font-family: var(--font-prose);
  font-weight: 500;
  letter-spacing: .05em;
  font-size: 1.7rem;
}
.lobby-user { display: flex; align-items: center; gap: 12px; }

.world-card {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
  background: linear-gradient(135deg, rgba(26, 36, 43, .96), rgba(13, 19, 23, .96));
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.world-art {
  display: grid;
  place-items: center;
  min-height: 280px;
  font-size: 5rem;
  color: rgba(201, 168, 92, .8);
  background:
    radial-gradient(300px 200px at 50% 40%, rgba(201, 168, 92, .18), transparent 70%),
    linear-gradient(180deg, #162026, #0e1519);
  border-right: 1px solid var(--border);
}
.world-body { padding: 28px; }
.world-body h2 {
  margin: 0 0 8px;
  font-family: var(--font-prose);
  font-weight: 500;
  letter-spacing: .04em;
  font-size: 1.8rem;
}
.world-meta {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin: 16px 0 20px;
  color: var(--muted);
  font-size: .86rem;
}
.world-meta strong { color: var(--text); }
.join-form { max-width: 520px; }
.world-select {
  max-width: 420px;
  margin: 0 auto 16px;
}
.world-select select { padding: 10px 12px; }
.create-world {
  max-width: 1080px;
  margin: 16px auto 0;
}
.create-card { margin-top: 0; }
.create-card .world-art { min-height: 200px; font-size: 3rem; }
.create-card h3 {
  margin: 0 0 12px;
  font-family: var(--font-prose);
  font-weight: 500;
  font-size: 1.3rem;
}
.wide-ghost {
  width: 100%;
  padding: 14px 16px;
}
.npc-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px dashed rgba(255, 255, 255, .06);
}
.npc-row:first-of-type { border-top: 0; }
.npc-name { font-size: .86rem; color: var(--accent-2); }
.npc-desc {
  font-size: .74rem;
  color: var(--muted);
  text-align: right;
  max-width: 60%;
}
.editor-section .mini { margin-top: 6px; }

.game-shell { min-height: 100vh; display: flex; flex-direction: column; }
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 18, 22, .9);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.game-title { display: flex; align-items: center; gap: 12px; }
.game-title h1 {
  margin: 0;
  font-family: var(--font-prose);
  font-weight: 500;
  letter-spacing: .05em;
  font-size: 1.2rem;
}
.game-title p { margin: 2px 0 0; font-size: .78rem; }
.game-status { display: flex; align-items: center; gap: 10px; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: var(--muted);
}
.dot.online { background: var(--success); box-shadow: 0 0 10px rgba(127, 191, 143, .6); }
.dot.offline { background: #5c666c; }

.game-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
}
.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(16, 23, 27, .55);
  padding: 14px;
  overflow-y: auto;
  max-height: calc(100vh - 65px);
}
.panel {
  background: rgba(20, 28, 33, .8);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}
.panel h3 {
  margin: 0 0 10px;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 600;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.panel-head h3 { margin-bottom: 10px; }
button.mini {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: .72rem;
  line-height: 1.2;
}
button.mini:hover {
  color: var(--text);
  border-color: rgba(201, 168, 92, .45);
}
.scene-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px;
  border-top: 1px dashed rgba(255, 255, 255, .06);
  border-radius: 8px;
}
.scene-row:first-of-type { border-top: 0; }
.scene-row.active { background: rgba(201, 168, 92, .07); }
.scene-info { min-width: 0; flex: 1; }
.scene-name {
  font-size: .86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scene-meta { font-size: .7rem; color: var(--muted); margin-top: 2px; }
.scene-here {
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  white-space: nowrap;
}
.scene-form { display: grid; gap: 8px; margin-top: 10px; }
.scene-form input, .scene-form select { padding: 8px 10px; font-size: .82rem; }
.scene-form-actions { display: flex; gap: 8px; }
.scene-form-actions .primary, .scene-form-actions .ghost {
  flex: 1;
  padding: 8px 10px;
  font-size: .8rem;
}
.person {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-radius: 10px;
}
.person:hover { background: rgba(255, 255, 255, .025); }
.person-body { min-width: 0; flex: 1; }
.person-name { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-meta { font-size: .72rem; color: var(--muted); }
.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #12100b;
  font-weight: 750;
  background: var(--char-color, #9aa4aa);
  border: 1px solid rgba(255, 255, 255, .16);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
.avatar.small { width: 28px; height: 28px; flex-basis: 28px; font-size: .78rem; }
.vitals {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: .78rem;
  margin-bottom: 8px;
}
.item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px dashed rgba(255, 255, 255, .06);
  font-size: .84rem;
}
.item:first-of-type { border-top: 0; }

.chat-pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 65px);
}
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 26px clamp(16px, 4vw, 56px) 18px;
  scroll-behavior: smooth;
}
.chat-scroll::-webkit-scrollbar { width: 10px; }
.chat-scroll::-webkit-scrollbar-thumb {
  background: #26323a;
  border-radius: 999px;
  border: 3px solid var(--bg);
}

.narration {
  font-family: var(--font-prose);
  font-size: 1.04rem;
  line-height: 1.75;
  color: #ddd5c6;
  margin: 0 0 18px;
  max-width: 78ch;
}
.line {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  margin: 0 0 16px;
  max-width: 82ch;
}
.line-body { min-width: 0; }
.line-name {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--char-color, var(--accent-2));
  margin-bottom: 3px;
}
.line p { margin: 0; line-height: 1.6; font-size: .96rem; }
.speech p {
  background: linear-gradient(180deg, rgba(255, 255, 255, .025), rgba(255, 255, 255, .008));
  border: 1px solid rgba(255, 255, 255, .06);
  border-left: 3px solid var(--char-color, var(--accent-2));
  border-radius: 0 12px 12px 0;
  padding: 10px 14px;
}
.action-text { color: #b7b0a4; font-style: italic; }
.action { margin-bottom: 14px; }
.thought {
  border: 1px dashed rgba(255, 255, 255, .13);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 0 0 18px;
  max-width: 78ch;
  color: #9fa8ae;
  font-style: italic;
  font-size: .9rem;
  background: rgba(255, 255, 255, .015);
}
.thought p { margin: 4px 0 0; line-height: 1.55; }
.thought-name { color: var(--char-color, var(--accent-2)); font-weight: 650; font-style: normal; }
.whisper {
  border: 1px solid rgba(155, 123, 184, .35);
  border-left: 3px solid var(--char-color, #9b7bb8);
  background: rgba(155, 123, 184, .08);
  border-radius: 0 12px 12px 0;
  padding: 10px 14px;
  margin: 0 0 18px;
  max-width: 78ch;
}
.whisper p { margin: 4px 0 0; line-height: 1.55; }
.whisper-head {
  font-size: .72rem;
  color: #b9a3cf;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.typing {
  color: var(--accent);
  font-size: .84rem;
  letter-spacing: .04em;
  padding: 8px 0 18px;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }

.composer {
  border-top: 1px solid var(--border);
  background: rgba(13, 18, 22, .92);
  padding: 12px clamp(16px, 4vw, 56px) 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}
.composer-tools {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.composer-tools select { width: auto; min-width: 170px; padding: 7px 10px; font-size: .8rem; }
.composer-input { min-height: 54px; max-height: 180px; }
.composer .send { height: 54px; min-width: 128px; }
.chat-pane > .alert { margin: 0 clamp(16px, 4vw, 56px) 10px; }

/* Character sheet, world canon, scene editor */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 8, 10, .72);
  backdrop-filter: blur(4px);
}
.modal {
  width: min(760px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(26, 36, 43, .98), rgba(13, 19, 23, .98));
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  margin: 0;
  font-family: var(--font-prose);
  font-weight: 500;
  letter-spacing: .04em;
  font-size: 1.15rem;
}
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: grid;
  gap: 14px;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: rgba(9, 13, 16, .6);
}
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 12px;
}
.editor-section h4 {
  margin: 4px 0 8px;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
}
.editor-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.editor-row input, .editor-row select {
  padding: 8px 10px;
  font-size: .84rem;
}
.editor-row .qty { width: 82px; flex: 0 0 82px; }
.editor-row .rel-target {
  min-width: 116px;
  max-width: 150px;
  font-size: .8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.editor-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, .015);
  display: grid;
  gap: 6px;
}
.editor-card textarea { min-height: 44px; font-size: .84rem; }
.editor-add {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
}
.editor-add input, .editor-add select {
  flex: 1 1 140px;
  min-width: 0;
  padding: 8px 10px;
  font-size: .84rem;
}
.editor-add .qty { flex: 0 0 78px; }
.canon-input {
  min-height: 260px;
  font-family: var(--font-prose);
  font-size: .95rem;
  line-height: 1.6;
}
button.mini.danger { color: #e0a396; border-color: rgba(208, 123, 99, .4); }
button.mini.danger:hover { background: rgba(208, 123, 99, .12); }
button.primary:disabled { opacity: .55; cursor: default; transform: none; }
.quest-row { padding: 7px 0; border-top: 1px dashed rgba(255, 255, 255, .06); }
.quest-row:first-of-type { border-top: 0; }
.quest-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: .84rem;
}
.quest-status {
  font-size: .62rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
  color: var(--muted);
}
.quest-status.active { color: var(--accent); }
.quest-status.done { color: var(--success); }
.quest-status.failed { color: var(--danger); }
.quest-desc {
  margin: 3px 0 0;
  font-size: .74rem;
  color: var(--muted);
  line-height: 1.45;
}
.rel-row { padding: 7px 0; border-top: 1px dashed rgba(255, 255, 255, .06); }
.rel-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: .84rem;
}
.rel-affinity { color: var(--muted); font-size: .76rem; }
.rel-label { font-size: .74rem; color: var(--muted); }
.rel-bar {
  height: 4px;
  margin-top: 5px;
  border-radius: 999px;
  background: #1c262d;
  overflow: hidden;
}
.rel-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--danger), var(--accent), var(--success));
}

@media (max-width: 860px) {
  .world-card { grid-template-columns: 1fr; }
  .world-art { min-height: 140px; border-right: 0; border-bottom: 1px solid var(--border); font-size: 3.4rem; }
  .world-body { padding: 20px; }
  .game-main { grid-template-columns: 1fr; }
  .sidebar {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: none;
    padding: 10px;
  }
  .sidebar .panel { min-width: 200px; flex: 1 0 200px; margin-bottom: 0; }
  .chat-pane { height: calc(100vh - 65px - 152px); }
  .chat-scroll { padding: 18px 14px 12px; }
  .composer { padding: 10px 14px 14px; }
  .composer .send { min-width: 96px; }
  .editor-grid { grid-template-columns: 1fr; }
  .modal { max-height: 94vh; }
}
@media (max-width: 560px) {
  .game-header { padding: 10px 12px; }
  .game-title h1 { font-size: 1rem; }
  .game-status { gap: 6px; }
  .game-status .muted { display: none; }
  .game-status .ghost { padding: 8px 10px; }
  .chat-pane { height: calc(100vh - 61px - 152px); }
  .line, .narration, .thought, .whisper { max-width: 100%; }
}
