:root {
  --bg: #0c0a10;
  --bg-2: #14111c;
  --panel: #1a1626;
  --panel-2: #221c33;
  --edge: #352b4d;
  --ink: #e9e3f5;
  --ink-dim: #a99fc2;
  --ink-faint: #6e6488;
  --gold: #c9a14a;
  --gold-soft: #e6c878;
  --violet: #7c5cff;
  --violet-soft: #a48bff;
  --danger: #c2536b;
  --ok: #5fbf8f;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --serif: "EB Garamond", Georgia, serif;
  --display: "Cinzel", "EB Garamond", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--serif);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 50% -10%, #1d1730 0%, transparent 60%),
    radial-gradient(900px 600px at 90% 110%, #1a1426 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 18px;
  line-height: 1.5;
}

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px 56px;
}

.screen {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  animation: rise 0.4s ease both;
}
.screen.wide { max-width: 980px; }

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

/* --- Branding --- */
.brand { text-align: center; }
.brand .sigil {
  font-size: 54px;
  line-height: 1;
  color: var(--gold-soft);
  text-shadow: 0 0 26px rgba(201, 161, 74, 0.45);
}
.brand.small .sigil { font-size: 38px; }
.brand h1 {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.06em;
  margin: 14px 0 4px;
  font-size: 30px;
}
.brand.small h1 { font-size: 23px; margin-top: 10px; }
.subtitle {
  margin: 0;
  color: var(--ink-dim);
  font-style: italic;
  letter-spacing: 0.03em;
}

/* --- Cards / choice --- */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--edge);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 30px 18px;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.choice:hover {
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.6);
}
.choice-glyph { font-size: 40px; }
.choice-title { font-family: var(--display); font-size: 19px; letter-spacing: 0.04em; }
.choice-sub { color: var(--ink-dim); font-size: 15px; text-align: center; }

/* --- Panels & forms --- */
.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--edge);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.panel h2 {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.05em;
  margin: 0 0 16px;
  color: var(--gold-soft);
}

.form { display: flex; flex-direction: column; gap: 18px; }
label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 15px;
  color: var(--ink-dim);
  letter-spacing: 0.03em;
}
input {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--ink);
  background: #0f0c17;
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.2);
}
.code-input {
  text-transform: uppercase;
  letter-spacing: 0.35em;
  text-align: center;
  font-family: var(--display);
  font-size: 24px;
}

.row { display: flex; gap: 12px; justify-content: flex-end; }

/* --- Buttons --- */
.btn {
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.05em;
  padding: 12px 22px;
  border-radius: 10px;
  border: 1px solid var(--edge);
  cursor: pointer;
  background: transparent;
  color: var(--ink);
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: linear-gradient(180deg, var(--violet-soft), var(--violet));
  border-color: var(--violet);
  color: #120e1f;
  font-weight: 700;
}
.btn.primary:hover { box-shadow: 0 10px 30px rgba(124, 92, 255, 0.4); }
.btn.ghost { color: var(--ink-dim); }
.btn.ghost:hover { border-color: var(--gold); color: var(--ink); }
.btn.small { padding: 8px 14px; font-size: 13px; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* --- GM lobby --- */
.gm-lobby-stack { display: flex; flex-direction: column; gap: 20px; }

.world-symbol {
  font-size: 30px;
  width: 46px;
  text-align: center;
  color: var(--gold-soft);
  flex: none;
}
.world-meta { color: var(--ink-faint); font-size: 13px; margin-top: 2px; }

/* World selection tiles — game-portal style */
.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px;
}
.world-tile {
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.world-tile:hover {
  transform: translateY(-4px);
  border-color: var(--gold);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.62);
}
.world-cover {
  position: relative;
  height: 128px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--edge);
  background: #14101e; /* fallback if color-mix unsupported */
  background:
    radial-gradient(130px 96px at 50% 40%,
      color-mix(in srgb, var(--accent, var(--violet)) 60%, transparent), transparent 72%),
    linear-gradient(158deg,
      color-mix(in srgb, var(--accent, var(--violet)) 26%, #15111f), #110d1a);
}
.world-cover .glyph { font-size: 58px; filter: drop-shadow(0 6px 20px rgba(0, 0, 0, 0.55)); }
.world-cover .play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 10, 16, 0.58);
  opacity: 0;
  transition: opacity 0.16s ease;
  font-family: var(--display);
  letter-spacing: 0.08em;
  font-size: 15px;
  color: var(--gold-soft);
}
.world-tile:hover .play { opacity: 1; }
.world-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
}
.world-body .name { font-family: var(--display); font-size: 17px; letter-spacing: 0.03em; }
.world-body .tag { color: var(--ink-dim); font-size: 14px; line-height: 1.34; flex: 1; }
.world-body .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-faint);
  font-size: 13px;
  margin-top: 6px;
}
.world-body .badge { border: 1px solid var(--edge); border-radius: 999px; padding: 2px 10px; }

.campaign-list { display: flex; flex-direction: column; gap: 12px; }
.campaign {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: #15111f;
}
.campaign .world-symbol { font-size: 24px; width: 36px; }
.campaign-main { flex: 1; min-width: 0; }
.campaign-name { font-family: var(--display); font-size: 16px; letter-spacing: 0.02em; }
.campaign-sub { color: var(--ink-dim); font-size: 13px; }
.campaign-actions { display: flex; gap: 8px; flex: none; }

.empty { color: var(--ink-faint); font-style: italic; font-size: 15px; margin: 6px 2px 0; }

/* --- Session --- */
.session-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 4px;
}
.session-world { display: flex; align-items: center; gap: 16px; }
.session-symbol {
  font-size: 44px;
  color: var(--gold-soft);
  text-shadow: 0 0 22px rgba(201, 161, 74, 0.4);
}
.session-head h1 { font-family: var(--display); font-size: 24px; margin: 0; letter-spacing: 0.04em; }
.session-worldname { margin: 2px 0 0; color: var(--ink-dim); font-style: italic; }
.status-pill {
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  color: var(--ink-dim);
}
.status-pill[data-status="active"] {
  color: var(--ok);
  border-color: rgba(95, 191, 143, 0.5);
  background: rgba(95, 191, 143, 0.08);
}

.session-body {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 20px;
  align-items: start;
}

.invite { text-align: center; }
.invite-hint { color: var(--ink-dim); font-size: 15px; margin: 0 0 14px; }
.code-display {
  font-family: var(--display);
  font-weight: 700;
  font-size: 46px;
  letter-spacing: 0.2em;
  color: var(--gold-soft);
  background: #0f0c17;
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 16px 10px;
  margin-bottom: 14px;
  text-shadow: 0 0 24px rgba(201, 161, 74, 0.3);
}

.waiting { text-align: center; }
.gm-indicator { margin-top: 16px; color: var(--ink-dim); font-size: 15px; }
.dot-label { color: var(--danger); }
.dot-label[data-online="1"] { color: var(--ok); }

.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: #15111f;
}
.player .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex: none;
  box-shadow: 0 0 0 3px rgba(110, 100, 136, 0.15);
}
.player .dot[data-online="1"] { background: var(--ok); box-shadow: 0 0 0 3px rgba(95, 191, 143, 0.18); }
.player-name { flex: 1; }
.count { color: var(--ink-faint); font-weight: 400; }

.session-actions { display: flex; justify-content: flex-end; gap: 12px; }

/* Per-world full-bleed backdrop behind the session screen */
.world-backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-position: center 28%;
  background-size: cover;
  background-repeat: no-repeat;
  opacity: 0.20;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.3) 55%, transparent);
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.3) 55%, transparent);
}

/* --- Connection status + toast --- */
.conn-status {
  position: fixed;
  top: 12px;
  right: 14px;
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(20, 17, 28, 0.85);
  color: var(--ink-dim);
  z-index: 50;
}
.conn-status[data-state="open"] { color: var(--ok); }
.conn-status[data-state="closed"] { color: var(--danger); }

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--gold);
  color: var(--ink);
  padding: 12px 22px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 60;
  animation: rise 0.25s ease both;
}

[hidden] { display: none !important; }

/* --- Responsive --- */
@media (max-width: 760px) {
  body { font-size: 17px; }
  .session-body { grid-template-columns: 1fr; }
  .choice-grid { grid-template-columns: 1fr; }
  .session-head { flex-direction: column; align-items: flex-start; }
}

/* === Session: GM management + player sheet ============================== */

/* generic online dot (used by participant + roster rows) */
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ink-faint); flex: none;
  box-shadow: 0 0 0 3px rgba(110, 100, 136, 0.15);
}
.dot[data-online="1"] { background: var(--ok); box-shadow: 0 0 0 3px rgba(95, 191, 143, 0.18); }

.session-gm {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
}
.session-gm > .invite { grid-row: span 2; }
.session-player {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  align-items: start;
}
.panel h2 .btn { float: right; margin-top: -4px; }

/* Participants */
.participant-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.participant {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--edge); border-radius: 10px; background: #15111f;
}
.participant .p-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assign-select, .char-status {
  font-family: var(--serif); font-size: 14px; color: var(--ink);
  background: #0f0c17; border: 1px solid var(--edge); border-radius: 8px; padding: 6px 8px; outline: none;
}
.assign-select:focus, .char-status:focus { border-color: var(--violet); }

/* Characters (GM) */
.character-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.character {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--edge); border-radius: 10px; background: #15111f;
  border-left: 3px solid var(--ok);
}
.character[data-status="dead"] { border-left-color: var(--danger); opacity: 0.85; }
.character[data-status="retired"] { border-left-color: var(--ink-faint); }
.character .char-name { flex: 1; font-family: var(--display); font-size: 15px; letter-spacing: 0.02em; }
.char-actions { display: flex; gap: 6px; flex: none; }

/* Player sheet */
.sheet-panel { min-height: 120px; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; }
.char-status-badge {
  font-family: var(--display); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--edge); color: var(--ok);
}
.char-status-badge[data-status="dead"] { color: var(--danger); border-color: rgba(194, 83, 107, 0.5); background: rgba(194, 83, 107, 0.08); }
.char-status-badge[data-status="retired"] { color: var(--ink-faint); }
.sheet { display: flex; flex-direction: column; gap: 16px; }
.sheet-concept { margin: 0; color: var(--ink-dim); font-style: italic; }
.attr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.attr {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 12px; border: 1px solid var(--edge); border-radius: 8px; background: #15111f;
}
.attr-k { color: var(--ink-dim); font-size: 14px; }
.attr-v { font-family: var(--display); font-size: 20px; color: var(--gold-soft); }
.res-box { display: flex; flex-direction: column; gap: 10px; }
.res-label { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-dim); margin-bottom: 4px; }
.res-num { font-family: var(--display); color: var(--ink); }
.res-bar { height: 9px; border-radius: 999px; background: #0f0c17; border: 1px solid var(--edge); overflow: hidden; }
.res-fill { height: 100%; background: linear-gradient(90deg, var(--violet), var(--violet-soft)); }
.sheet-block h3 { font-family: var(--display); font-size: 14px; font-weight: 500; letter-spacing: 0.05em; color: var(--gold-soft); margin: 0 0 8px; }
.inv-list { margin: 0; padding-left: 20px; color: var(--ink); }
.inv-list li { margin: 2px 0; }
.sheet-notes { margin: 0; color: var(--ink-dim); white-space: pre-wrap; }

/* Roster (player) */
.roster-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.roster-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--edge); border-radius: 10px; background: #15111f; }
.roster-name { flex: none; }
.roster-char { color: var(--ink-faint); font-size: 13px; font-style: italic; margin-left: auto; }

/* GM online indicator (player) */
.gm-indicator { margin: 14px 0 0; color: var(--ink-dim); font-size: 14px; }
.dot-label { color: var(--danger); }
.dot-label[data-online="1"] { color: var(--ok); }

/* === Character editor modal ============================================ */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 6, 12, 0.7); padding: 20px;
}
.modal-card {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--edge); border-radius: 16px; box-shadow: var(--shadow);
  padding: 24px;
}
.modal-title { font-family: var(--display); color: var(--gold-soft); margin: 0 0 16px; letter-spacing: 0.05em; }
.modal-body { display: flex; flex-direction: column; gap: 14px; }
.modal-body textarea {
  font-family: var(--serif); font-size: 16px; color: var(--ink);
  background: #0f0c17; border: 1px solid var(--edge); border-radius: 10px; padding: 10px 12px; outline: none; resize: vertical;
}
.modal-body textarea:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.2); }
.modal-body select {
  font-family: var(--serif); font-size: 16px; color: var(--ink);
  background: #0f0c17; border: 1px solid var(--edge); border-radius: 10px; padding: 10px 12px; outline: none;
}
.editor-section { border-top: 1px solid var(--edge); padding-top: 12px; }
.editor-section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; color: var(--ink-dim); font-size: 14px; letter-spacing: 0.03em; }
.kv-rows { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: flex; gap: 8px; align-items: center; }
.kv-row .kv-key { flex: 1; }
.kv-row .kv-val, .kv-row .kv-cur, .kv-row .kv-max { width: 80px; }
.kv-row input { font-size: 15px; padding: 8px 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 20px; }

@media (max-width: 760px) {
  .session-gm, .session-player { grid-template-columns: 1fr; }
  .session-gm > .invite { grid-row: auto; }
  .participant, .character { flex-wrap: wrap; }
}

/* === LOTM sheet: identity, roles, grant/pending, fixed editor grids ===== */
.p-name.link { background: none; border: none; color: var(--ink); font: inherit; cursor: pointer; text-align: left; padding: 0; text-decoration: underline dotted var(--ink-faint); }
.p-name.link:hover { color: var(--gold-soft); }

.char-name-wrap { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.char-role { font-size: 12px; color: var(--ink-faint); font-style: italic; }
.tag-chip { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--edge); color: var(--ink-dim); flex: none; }
.tag-chip.granted { color: var(--ok); border-color: rgba(95, 191, 143, 0.5); background: rgba(95, 191, 143, 0.08); }
.pending-btn { color: var(--gold-soft); border-color: var(--gold); background: rgba(201, 161, 74, 0.08); flex: none; }
.pending-btn:hover { background: rgba(201, 161, 74, 0.16); }
.pending-note { color: var(--gold-soft); font-size: 14px; margin: 10px 0 0; }

/* identity strip on the sheet */
.sheet-identity { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sheet-path, .sheet-seq, .sheet-role { font-family: var(--display); font-size: 13px; letter-spacing: 0.04em; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--edge); }
.sheet-path { color: var(--gold-soft); }
.sheet-seq { color: var(--ink-dim); }
.sheet-role { color: var(--violet-soft); border-color: rgba(124, 92, 255, 0.4); background: rgba(124, 92, 255, 0.08); }

/* editor: pathway/sequence + role preview */
.path-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.role-line { display: flex; align-items: center; gap: 8px; color: var(--ink-dim); font-size: 14px; }
.role-line-label { color: var(--ink-faint); }
.role-preview { font-family: var(--display); color: var(--violet-soft); }
.editor-section-head { color: var(--ink-dim); font-size: 14px; }

/* fixed attribute grid + resource rows in the editor */
.fixed-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fixed-grid label { font-size: 14px; }
.fixed-grid input { font-size: 16px; padding: 8px 10px; }
.res-edit-row { display: grid; grid-template-columns: 1fr 70px auto 70px; gap: 8px; align-items: center; margin-bottom: 8px; }
.res-edit-label { color: var(--ink-dim); font-size: 14px; }
.res-edit-row input { font-size: 15px; padding: 7px 8px; }
.res-edit-row .slash { color: var(--ink-faint); text-align: center; }

.checkbox-label { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); font-size: 15px; }
.checkbox-label input { width: auto; }
.review-hint { color: var(--ink-dim); margin: 0 0 10px; font-style: italic; }

.invite-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.resume-bar { align-self: center; margin-top: 4px; }

/* test-mode role switcher */
.test-bar { position: fixed; top: 10px; left: 14px; z-index: 60; display: flex; align-items: center; gap: 6px; background: rgba(20, 17, 28, 0.92); border: 1px solid var(--gold); border-radius: 999px; padding: 4px 6px 4px 12px; box-shadow: var(--shadow); }
.test-tag { font-size: 12px; letter-spacing: 0.04em; color: var(--gold-soft); margin-right: 2px; }
.test-bar .btn.active { background: linear-gradient(180deg, var(--violet-soft), var(--violet)); color: #120e1f; border-color: var(--violet); font-weight: 700; }
