:root {
  color-scheme: dark;
  --ink: #f5f0ed;
  --muted: #a69ca3;
  --dim: #6b6269;
  --bg: #0d0910;
  --panel: #171019;
  --panel-2: #1c141e;
  --line: rgba(255, 255, 255, .1);
  --red: #d72b4b;
  --red-soft: #ff6680;
  --gold: #e9b949;
  --blue: #5cc8ff;
  --green: #73dfb2;
  --shadow: 0 24px 80px rgba(0, 0, 0, .32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at 76% 18%, rgba(117, 24, 54, .22), transparent 34rem), var(--bg); letter-spacing: .01em; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.is-hidden { display: none !important; }
.noise { position: fixed; inset: 0; pointer-events: none; opacity: .025; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E"); z-index: 10; }

.auth-layout { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr); gap: 8vw; align-items: center; max-width: 1320px; padding: 8vw; margin: auto; }
.brand-panel { max-width: 680px; }
.brand-mark, .mini-mark { color: var(--red-soft); text-shadow: 0 0 28px rgba(255, 70, 104, .45); }
.brand-mark { font-family: serif; font-size: clamp(9rem, 18vw, 16rem); line-height: .7; margin-bottom: 4rem; transform: rotate(-8deg); }
.mini-mark { font-family: serif; font-size: 1.7rem; line-height: 1; }
.eyebrow, .section-label { margin: 0; color: var(--red-soft); font-size: .7rem; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
.brand-panel h1 { max-width: 620px; margin-bottom: 1.2rem; font-size: clamp(3.5rem, 7vw, 7.5rem); line-height: .88; letter-spacing: -.08em; }
.lede { max-width: 480px; margin-bottom: 3rem; color: var(--muted); font-size: 1.08rem; line-height: 1.7; }
.seal-row { display: flex; flex-wrap: wrap; gap: 1rem 1.6rem; color: var(--dim); font-size: .65rem; font-weight: 700; letter-spacing: .13em; }
.panel { border: 1px solid var(--line); background: linear-gradient(145deg, rgba(33, 22, 36, .92), rgba(18, 12, 21, .96)); box-shadow: var(--shadow); }
.auth-card { padding: 1.3rem; border-radius: 1.5rem; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: .25rem; gap: .3rem; margin-bottom: 2rem; border-radius: .85rem; background: rgba(0,0,0,.28); }
.tab { border: 0; border-radius: .65rem; padding: .75rem; color: var(--muted); background: transparent; }
.tab.is-active { color: var(--ink); background: var(--red); }
label { display: block; margin: 1rem 0; color: var(--muted); font-size: .8rem; }
input, textarea { width: 100%; margin-top: .45rem; border: 1px solid var(--line); border-radius: .65rem; padding: .8rem .85rem; outline: 0; color: var(--ink); background: rgba(0,0,0,.23); transition: border .2s, box-shadow .2s; }
input:focus, textarea:focus { border-color: var(--red-soft); box-shadow: 0 0 0 3px rgba(255, 102, 128, .1); }
textarea { resize: vertical; }
.field-help { color: var(--dim); font-size: .72rem; line-height: 1.55; }
.primary-button, .ghost-button, .icon-button, .send-button { border: 1px solid transparent; border-radius: .65rem; color: var(--ink); transition: transform .2s, background .2s, border .2s; }
.primary-button { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-top: 1.4rem; padding: .86rem 1rem; background: var(--red); font-weight: 800; }
.primary-button:hover, .ghost-button:hover, .icon-button:hover, .send-button:hover { transform: translateY(-1px); }
.primary-button:hover { background: var(--red-soft); }
.primary-button.compact { width: auto; margin-top: 0; gap: 1rem; padding: .72rem 1rem; }
.ghost-button { padding: .58rem .75rem; color: var(--muted); border-color: var(--line); background: rgba(255,255,255,.04); font-size: .75rem; }
.ghost-button:hover { color: var(--ink); border-color: rgba(255,255,255,.22); background: rgba(255,255,255,.08); }
.icon-button { width: 32px; height: 32px; padding: 0; color: var(--muted); border-color: var(--line); background: transparent; font-size: 1.25rem; }
.file-button { position: relative; overflow: hidden; cursor: pointer; }
.file-button input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; opacity: 0; cursor: pointer; }
.form-error { min-height: 1.2rem; margin: .9rem 0 .1rem; color: var(--red-soft); font-size: .78rem; }

.app-shell { min-height: 100vh; padding: 1rem; }
.topbar { display: flex; align-items: center; gap: 1.2rem; min-height: 3.5rem; max-width: 1600px; margin: 0 auto 1rem; padding: 0 .8rem; border-bottom: 1px solid var(--line); }
.top-brand { display: flex; align-items: center; gap: .6rem; min-width: 190px; font-weight: 800; }
.top-brand b { color: var(--red-soft); }
.room-status { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .72rem; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 12px currentColor; }
.status-dot.online { color: var(--green); background: var(--green); }
.status-dot.offline { color: var(--red-soft); background: var(--red-soft); }
.room-code { padding: .25rem .45rem; border: 1px solid var(--line); border-radius: .35rem; color: var(--ink); font-family: monospace; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; margin-left: auto; }
.identity-chip { padding: .42rem .65rem; border-radius: 99px; color: var(--ink); background: rgba(255,255,255,.06); font-size: .72rem; }
.app-grid { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1rem; max-width: 1600px; min-height: calc(100vh - 5.5rem); margin: auto; }
.sidebar { display: flex; flex-direction: column; min-height: 680px; padding: 1rem; border-radius: 1rem; }
.sidebar-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 2rem; }
.sidebar-heading h2 { margin: .3rem 0 0; font-size: 1.05rem; letter-spacing: -.03em; }
.live-count { color: var(--green); font-family: monospace; }
.main-nav { display: grid; gap: .3rem; }
.nav-button { display: flex; align-items: center; gap: .75rem; padding: .72rem .7rem; border: 1px solid transparent; border-radius: .65rem; color: var(--muted); background: transparent; text-align: left; }
.nav-button:hover { color: var(--ink); background: rgba(255,255,255,.04); }
.nav-button.is-active { color: var(--ink); border-color: rgba(255, 102, 128, .2); background: rgba(215, 43, 75, .16); }
.nav-icon { width: 1.2rem; color: var(--red-soft); text-align: center; }
.nav-badge { margin-left: auto; color: var(--dim); font-size: .7rem; }
.presence-block { margin-top: 3rem; }
.section-label { display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: .65rem; }
.section-label span:last-child { color: var(--dim); font-weight: 500; letter-spacing: .05em; text-transform: none; }
.presence-list { display: grid; gap: .55rem; margin-top: .9rem; }
.presence-item { display: flex; align-items: center; gap: .55rem; color: var(--muted); font-size: .78rem; }
.presence-avatar { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; color: var(--bg); background: var(--blue); font-weight: 800; font-size: .65rem; }
.presence-avatar.gm { background: var(--gold); }
.presence-item small { display: block; color: var(--dim); font-size: .6rem; }
.sidebar-footer { display: flex; justify-content: space-between; gap: .5rem; margin-top: auto; padding-top: 1rem; color: var(--dim); border-top: 1px solid var(--line); font-size: .58rem; letter-spacing: .08em; }
.version-tag { color: var(--red-soft); }
.workspace { min-width: 0; }
.module-pane { display: none; height: 100%; }
.module-pane.is-active { display: block; }
.module-head { display: flex; align-items: flex-start; justify-content: space-between; min-height: 130px; padding: 2rem .8rem 1rem; }
.module-head h1 { margin: .35rem 0 .7rem; font-size: clamp(2.1rem, 4vw, 4.5rem); letter-spacing: -.07em; line-height: .9; }
.module-subtitle { max-width: 580px; margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.5; }
.module-glyph { color: rgba(255, 102, 128, .55); font-family: serif; font-size: 4rem; line-height: 1; }
.panel-inner { min-height: 575px; border-radius: 1rem; }
.chat-layout { display: grid; grid-template-rows: 1fr auto; overflow: hidden; }
.chat-list { min-height: 0; padding: 1rem; overflow: auto; }
.chat-empty { display: grid; place-items: center; height: 100%; min-height: 300px; color: var(--dim); font-size: .85rem; }
.chat-message { display: grid; grid-template-columns: 34px 1fr; gap: .7rem; max-width: 760px; margin-bottom: 1rem; }
.message-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--bg); background: var(--blue); font-size: .65rem; font-weight: 900; }
.message-avatar.gm { background: var(--gold); }
.message-meta { display: flex; align-items: baseline; gap: .55rem; margin-bottom: .23rem; }
.message-meta strong { font-size: .8rem; }
.message-meta time { color: var(--dim); font-size: .6rem; }
.message-content { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-composer { display: flex; gap: .6rem; padding: .8rem; border-top: 1px solid var(--line); }
.chat-composer input { margin: 0; }
.send-button { min-width: 44px; color: var(--ink); background: var(--red); }

.dice-layout, .npc-layout, .map-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, .6fr); gap: 1rem; }
.dice-console, .roll-history, .npc-list-panel, .npc-editor, .map-panel, .map-controls { min-height: 575px; padding: 1rem; border-radius: 1rem; }
.dice-input-row { display: flex; gap: .6rem; margin-top: 1.5rem; }
.dice-input-row input { margin: 0; font-family: monospace; font-size: 1.3rem; }
.quick-dice { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1.4rem 0; }
.quick-dice button { min-width: 50px; padding: .65rem; border: 1px solid var(--line); border-radius: .5rem; color: var(--muted); background: rgba(255,255,255,.04); }
.quick-dice button:hover { color: var(--ink); border-color: var(--red-soft); }
code { color: var(--red-soft); }
.roll-history { overflow: hidden; }
.roll-list { display: grid; gap: .6rem; max-height: 500px; margin-top: 1rem; overflow: auto; }
.roll-card { padding: .7rem; border: 1px solid var(--line); border-left: 2px solid var(--red); border-radius: .55rem; background: rgba(255,255,255,.025); }
.roll-card strong { display: block; margin-bottom: .25rem; font-size: .75rem; }
.roll-card p { margin: 0; color: var(--muted); font-family: monospace; font-size: .78rem; }
.roll-card b { color: var(--gold); }
.roll-card time { display: block; margin-top: .35rem; color: var(--dim); font-size: .58rem; }
.npc-list { display: grid; gap: .7rem; max-height: 510px; margin-top: 1rem; overflow: auto; }
.npc-card { padding: .85rem; border: 1px solid var(--line); border-left: 3px solid var(--red); border-radius: .6rem; background: rgba(255,255,255,.025); cursor: pointer; }
.npc-card:hover, .npc-card.is-selected { background: rgba(215, 43, 75, .1); }
.npc-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .6rem; }
.npc-card h3 { margin: 0; font-size: .9rem; }
.npc-card .npc-grade { color: var(--gold); font-size: .62rem; }
.npc-card p { margin: .45rem 0 0; color: var(--muted); font-size: .72rem; line-height: 1.4; }
.npc-delete { border: 0; color: var(--dim); background: transparent; }
.npc-editor label { margin-top: 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .55rem; margin-top: 1rem; }
.npc-readonly { margin-top: 1.5rem; }
.map-layout { grid-template-columns: minmax(0, 1fr) 245px; }
.map-panel { min-width: 0; }
.map-toolbar { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; color: var(--dim); font-size: .65rem; }
.map-toolbar .section-label { color: var(--red-soft); }
.map-stage { width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: .7rem; background: #0c1117; }
#mapCanvas { display: block; width: 100%; min-width: 500px; aspect-ratio: 12 / 7; cursor: crosshair; background-color: #0c1117; background-size: cover; background-position: center; }
.map-controls { min-height: 0; }
.marker-legend { display: grid; gap: .55rem; margin-top: 1.5rem; }
.legend-line { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .7rem; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.gm-map-tools { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.toast-stack { position: fixed; right: 1rem; bottom: 1rem; z-index: 20; display: grid; gap: .5rem; }
.toast { max-width: 330px; padding: .7rem .85rem; border: 1px solid var(--line); border-left: 3px solid var(--red-soft); border-radius: .6rem; color: var(--ink); background: #1d1420; box-shadow: var(--shadow); font-size: .75rem; animation: toast-in .25s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 980px) {
  .auth-layout { grid-template-columns: 1fr; gap: 2rem; max-width: 620px; padding: 2rem 1rem; }
  .brand-mark { margin-bottom: 2.5rem; font-size: 8rem; }
  .brand-panel h1 { font-size: 4rem; }
  .app-grid { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
  .main-nav { grid-template-columns: repeat(4, 1fr); }
  .nav-button { justify-content: center; flex-direction: column; gap: .3rem; padding: .55rem; text-align: center; }
  .nav-badge { display: none; }
  .presence-block { margin-top: 1.2rem; }
  .presence-list { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .sidebar-footer { margin-top: 1.2rem; }
}
@media (max-width: 720px) {
  .app-shell { padding: .5rem; }
  .topbar { flex-wrap: wrap; gap: .7rem; padding-bottom: .7rem; }
  .top-brand { min-width: auto; }
  .room-status { order: 3; width: 100%; }
  .top-actions { margin-left: auto; }
  .top-actions .ghost-button { display: none; }
  .module-head { min-height: auto; padding: 1.4rem .3rem 1rem; }
  .module-head h1 { font-size: 2.6rem; }
  .module-glyph { font-size: 2.5rem; }
  .dice-layout, .npc-layout, .map-layout { grid-template-columns: 1fr; }
  .dice-console, .roll-history, .npc-list-panel, .npc-editor, .map-panel, .map-controls { min-height: auto; }
  .roll-history { min-height: 350px; }
  .map-controls { order: -1; }
}
