:root {
  color-scheme: dark;
  --ink: #f5ead8;
  --muted: #b9afa0;
  --soft: #897e70;
  --line: rgba(245, 234, 216, 0.14);
  --panel: rgba(33, 30, 27, 0.88);
  --panel-strong: rgba(25, 23, 21, 0.96);
  --accent: #d7a84b;
  --accent-2: #62b1a7;
  --danger: #d45d4c;
  --bg: #151310;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(rgba(21, 19, 16, 0.74), rgba(21, 19, 16, 0.88)),
    url("data:image/svg+xml,%3Csvg width='1400' height='900' viewBox='0 0 1400 900' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='1400' height='900' fill='%23211d18'/%3E%3Cpath d='M73 133C204 44 396 58 537 155c158 110 288 86 443 2 143-78 279-77 372-13v756H73z' fill='%23282018'/%3E%3Cpath d='M0 713c116-47 230-54 344-21 108 31 215 27 322-13 160-61 317-57 471 11 88 39 176 42 263 7v203H0z' fill='%23161513'/%3E%3Cg fill='none' stroke='%236b5635' stroke-opacity='.55' stroke-width='3'%3E%3Cpath d='M157 633c60-134 156-207 288-219 113-11 209-62 287-153 90-105 200-146 331-123'/%3E%3Cpath d='M258 730c79-67 162-93 250-77 82 14 160 1 233-40 104-59 211-68 321-26 77 30 151 28 223-5'/%3E%3Cpath d='M106 281c72 34 139 39 200 15 80-32 154-26 223 19 44 28 91 35 142 20'/%3E%3C/g%3E%3Cg fill='%23d7a84b' fill-opacity='.28'%3E%3Ccircle cx='227' cy='240' r='7'/%3E%3Ccircle cx='1018' cy='282' r='6'/%3E%3Ccircle cx='676' cy='693' r='5'/%3E%3Ccircle cx='1241' cy='640' r='8'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
  letter-spacing: 0;
}

body.is-splashing {
  overflow: hidden;
}

body.is-splashing .app-shell {
  visibility: hidden;
}

.production-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #080706;
  opacity: 1;
  transition: opacity 650ms ease;
}

.production-splash.is-closing {
  opacity: 0;
}

.production-splash__art,
.production-splash__shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.production-splash__art {
  object-fit: cover;
  object-position: center;
  animation: production-camera 5s ease-out both;
}

.production-splash__shade {
  background: rgba(5, 5, 4, 0.36);
}

.production-splash__identity {
  position: relative;
  z-index: 1;
  width: min(680px, calc(100% - 40px));
  padding-top: 25vh;
  color: #fff8e8;
  text-align: center;
  text-shadow: 0 3px 18px rgba(0, 0, 0, 0.92);
  animation: production-title 5s ease both;
}

.production-splash__kicker {
  display: block;
  margin-bottom: 10px;
  color: #cfb476;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.production-splash__title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0;
}

.production-splash__title strong {
  display: block;
  margin-bottom: 7px;
  color: #f2d48e;
  font-size: 4rem;
  font-weight: 700;
}

.production-splash__rule {
  display: block;
  width: 110px;
  height: 2px;
  margin: 20px auto 0;
  background: #cfb476;
  box-shadow: 0 0 18px rgba(207, 180, 118, 0.8);
}

.production-splash__progress {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
}

.production-splash__progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: #d7a84b;
  transform: scaleX(0);
  transform-origin: left;
  animation: production-progress 5s linear both;
}

@keyframes production-camera {
  0% { opacity: 0.25; transform: scale(1.08); }
  18% { opacity: 1; }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes production-title {
  0%, 18% { opacity: 0; transform: translateY(18px); }
  34%, 82% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0.8; transform: translateY(-3px); }
}

@keyframes production-progress {
  to { transform: scaleX(1); }
}

@media (max-width: 640px) {
  .production-splash__art {
    object-position: center;
  }

  .production-splash__identity {
    padding-top: 34vh;
  }

  .production-splash__title {
    font-size: 1.35rem;
  }

  .production-splash__title strong {
    font-size: 2.8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .production-splash,
  .production-splash__art,
  .production-splash__identity,
  .production-splash__progress span {
    animation: none;
    transition: none;
  }

  .production-splash__progress span {
    transform: scaleX(1);
  }
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

button:hover {
  border-color: rgba(215, 168, 75, 0.68);
  background: rgba(215, 168, 75, 0.12);
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: saturate(0.45);
}

button:disabled:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.06);
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(8, 7, 6, 0.45);
  outline: none;
}

input[readonly] {
  color: var(--accent);
  font-weight: 900;
  background: rgba(215, 168, 75, 0.1);
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  padding: 12px;
  resize: vertical;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(16, 14, 12, 0.92);
  backdrop-filter: blur(18px);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.map-dimension-switch { margin: 0 0 14px; display: flex; gap: 6px; }
.map-3d-panel { min-width:0; margin-bottom: 24px; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.map-3d-toolbar,.map-3d-footer { display:flex; flex-wrap:wrap; align-items:center; gap:12px; padding:12px 0; }
.map-3d-toolbar label,.map-3d-footer label { display:grid; gap:5px; font-size:12px; min-width:150px; }
.map-3d-toolbar > button { width:40px; height:40px; padding:0; font-size:21px; }
.map-3d-toolbar .tool-segment { display:flex; gap:4px; }
.map-3d-footer > span { flex:1 1 180px; font-size:13px; color:var(--muted); }
.map-3d-stage { min-width:0; width:100%; height:min(65vh,640px); min-height:340px; position:relative; overflow:hidden; background:#151d1c; }
.map-3d-stage canvas { display:block; width:100%; height:100%; touch-action:none; }
.map-3d-stage.concealed canvas { visibility:hidden; }
body.map-dimension-3d #mapBoard,body.map-dimension-3d .scene-board,body.map-dimension-3d .map-toolbox { display:none; }
@media(max-width:720px) { .map-3d-stage { height:420px; min-height:320px; } .map-3d-footer label { flex:1 1 140px; min-width:0; } .map-3d-toolbar select,.map-3d-footer select { width:100%; max-width:100%; } }

.brand-mark {
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  aspect-ratio: 1;
  display: block;
  object-fit: contain;
}

.brand span,
.account-panel p,
.invite-card span,
.room-chip small,
.muted {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.account-panel .status {
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.account-panel .status.online {
  color: #9fe0d8;
  border-color: rgba(98, 177, 167, 0.42);
  background: rgba(98, 177, 167, 0.1);
}

.account-panel .status.offline {
  color: #f1bf73;
  border-color: rgba(215, 168, 75, 0.42);
  background: rgba(215, 168, 75, 0.1);
}

.share-link {
  line-height: 1.35;
}

.share-link button {
  display: block;
  width: 100%;
  height: auto;
  min-height: 38px;
  margin-top: 7px;
  padding: 8px;
  color: var(--accent);
  overflow-wrap: anywhere;
  text-align: left;
}

.account-panel,
.room-panel {
  display: grid;
  gap: 10px;
}

.account-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.account-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.icon-button {
  padding: 0;
}

.nav-stack {
  display: grid;
  gap: 8px;
}

.nav-item {
  text-align: left;
  padding: 0 14px;
}

.nav-item.active,
.primary-button {
  color: #151310;
  background: var(--accent);
  border-color: transparent;
  font-weight: 800;
}

.room-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.room-list {
  display: grid;
  gap: 8px;
  max-height: 35vh;
  overflow: auto;
}

.room-chip {
  text-align: left;
  height: auto;
  padding: 11px 12px;
}

.room-chip.active {
  border-color: var(--accent);
  background: rgba(215, 168, 75, 0.15);
}

.room-group-title {
  margin: 8px 0 0;
  color: var(--accent-2);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.main-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  gap: 18px;
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar h1 {
  margin: 4px 0 0;
  font-size: clamp(1.35rem, 2.8vw, 2.4rem);
  line-height: 1.08;
}

.topbar-heading {
  flex: 1 1 360px;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 12px;
}

.interface-mode-control {
  display: grid;
  align-content: center;
  gap: 6px;
  min-width: 280px;
}

.interface-mode-control > span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.interface-mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 11, 9, 0.72);
}

.interface-mode-switch button {
  min-height: 40px;
  padding: 8px 12px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.interface-mode-switch button.active {
  border-color: rgba(215, 168, 75, 0.58);
  color: #fff4dc;
  background: rgba(215, 168, 75, 0.18);
}

body[data-interface-mode="summary"] [data-professional-only] {
  display: none !important;
}

.eyebrow {
  margin: 0;
  color: var(--accent-2);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.invite-card {
  min-width: 180px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 19, 16, 0.82);
}

.invite-card button {
  width: 100%;
  margin-top: 7px;
  font-weight: 900;
  color: var(--accent);
}

.view-grid {
  display: grid;
  grid-template-columns: minmax(330px, 0.84fr) minmax(420px, 1.25fr);
  grid-auto-rows: min-content;
  gap: 18px;
  align-content: start;
  align-items: start;
}

.control-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 4px 0 0;
  font-size: 1.08rem;
}

#saveCampaign {
  min-width: 104px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.form-grid.three {
  grid-template-columns: 1.2fr 1fr 0.55fr;
}

.campaign-identity {
  grid-template-columns: minmax(72px, 0.4fr) minmax(0, 1.4fr);
}

.campaign-identity > :last-child {
  grid-column: 1 / -1;
}

.campaign-status-fields {
  margin-top: 14px;
}

.campaign-section {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.hook-editor {
  padding: 16px;
  border: 1px solid rgba(215, 168, 75, 0.42);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: rgba(215, 168, 75, 0.06);
}

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h3 {
  margin: 4px 0 0;
  font-size: 1rem;
}

.master-badge {
  padding: 5px 8px;
  border: 1px solid rgba(215, 168, 75, 0.42);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.sheet-import {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.import-status {
  min-height: 18px;
  margin: 0;
  color: var(--accent-2);
  font-size: 0.78rem;
}

.attachment-list,
.sheet-attachments {
  display: grid;
  gap: 8px;
}

.attachment-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.attachment-preview {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.72rem;
  font-weight: 900;
}

.attachment-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-copy {
  min-width: 0;
}

.attachment-copy strong,
.attachment-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-copy small {
  margin-top: 3px;
  color: var(--muted);
}

.attachment-link {
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 800;
}

.remove-attachment {
  width: 36px;
  min-height: 36px;
  padding: 0;
  font-size: 1.2rem;
}

.map-board {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(215, 168, 75, 0.22);
  border-radius: 8px;
  aspect-ratio: 16 / 10;
  background: #1a1815;
}

.world-map-display {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 260px;
  border: 1px solid rgba(98, 177, 167, 0.34);
  border-radius: 8px;
  aspect-ratio: 3 / 2;
  background: #131817;
}

.world-map-display img,
.player-world-map img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.world-map-empty {
  max-width: 320px;
  padding: 24px;
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
}

.world-map-library {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.world-map-library .eyebrow {
  margin: 0;
}

.world-map-option img {
  aspect-ratio: 3 / 2;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.token-layer {
  position: absolute;
  inset: 0;
}

.token {
  position: absolute;
  width: 34px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 900;
  user-select: none;
  touch-action: none;
  box-shadow: 0 7px 20px rgba(0, 0, 0, 0.4);
}

.token:not(:disabled) {
  cursor: grab;
}

.token.dragging {
  cursor: grabbing;
  z-index: 20;
}

.token.hero {
  background: #2f8f83;
}

.token.monster {
  background: #a33b32;
}

.token.has-image {
  width: var(--token-size, 48px);
  padding: 0;
  overflow: visible;
  background: rgba(34, 25, 18, 0.78);
  border-color: rgba(244, 210, 142, 0.95);
}

.token.has-image img {
  width: 145%;
  height: 145%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.5));
}

.map-tools,
.chat-row,
.event-composer {
  display: grid;
  gap: 10px;
}

.global-chat {
  margin-top: 18px;
}

.global-chat .chat-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.chat-log {
  display: grid;
  gap: 9px;
  min-height: 130px;
  max-height: 320px;
  margin-bottom: 12px;
  overflow: auto;
  align-content: start;
}

.chat-message {
  border-left: 3px solid var(--accent-2);
  background: rgba(255, 255, 255, 0.045);
  padding: 9px 11px;
}

.chat-message strong {
  color: var(--accent);
  font-size: 0.82rem;
}

.chat-message p {
  margin: 3px 0 0;
  color: var(--ink);
  line-height: 1.4;
  white-space: pre-wrap;
}

.map-tools {
  grid-template-columns: repeat(3, 1fr);
  margin-top: 12px;
}

.asset-library {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.asset-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.asset-tab.active {
  border-color: rgba(215, 168, 75, 0.9);
  background: rgba(215, 168, 75, 0.18);
}

.library-panel {
  display: grid;
  gap: 10px;
}

.creature-token-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.creature-token {
  height: auto;
  min-height: 0;
  padding: 8px;
  overflow: hidden;
  text-align: left;
}

.creature-token.active {
  border-color: rgba(215, 168, 75, 0.9);
  background: rgba(215, 168, 75, 0.18);
}

.creature-token img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.creature-token span {
  display: block;
  padding-top: 6px;
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.2;
}

.preset-map-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.preset-map {
  height: auto;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  text-align: left;
}

.preset-map img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.preset-map span {
  display: block;
  padding: 8px;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.2;
}

.file-button {
  display: inline-grid;
  place-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.file-button input {
  position: fixed;
  transform: scale(0);
}

.file-button:has(input:disabled) {
  opacity: 0.42;
  cursor: not-allowed;
  filter: saturate(0.45);
}

.event-list,
.dice-log,
.archive-list,
.player-scene,
.character-list {
  display: grid;
  gap: 10px;
}

.event-list {
  margin-top: 12px;
  max-height: 320px;
  overflow: auto;
}

.event-card,
.log-line,
.archive-card,
.character-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  padding: 12px;
}

.character-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px 82px;
  align-items: end;
  gap: 10px;
}

.character-card p,
.character-card small {
  display: block;
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.character-card strong {
  display: block;
  margin-bottom: 4px;
}

.sheet-details {
  grid-column: 1 / -1;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.sheet-details summary {
  color: var(--accent-2);
  cursor: pointer;
  font-weight: 900;
}

.sheet-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin-top: 12px;
}

.sheet-detail-grid p {
  white-space: pre-wrap;
}

.sheet-detail-grid span {
  display: block;
  margin-bottom: 3px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

.sheet-source-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--accent-2);
  font-weight: 800;
}

.event-card strong,
.archive-card strong {
  display: block;
  margin-bottom: 5px;
}

.event-card p,
.archive-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.event-card.public {
  border-color: rgba(98, 177, 167, 0.5);
}

.dice-log {
  min-height: 330px;
  max-height: 530px;
  overflow: auto;
  align-content: start;
}

.dice-log.compact {
  min-height: 0;
  max-height: 220px;
  margin-top: 12px;
}

.dice-controls {
  display: grid;
  grid-template-columns: repeat(7, minmax(46px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.dice-controls button {
  min-width: 0;
  padding-inline: 8px;
  font-weight: 900;
  color: var(--accent);
}

.dice-animation[hidden] { display: none; }
.dice-animation {
  position: fixed;
  z-index: 1500;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  width: min(360px, calc(100% - 32px));
  min-height: 140px;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid #548c83;
  border-radius: 8px;
  background: #142b2a;
  color: #f4f7f5;
  box-shadow: 0 12px 40px #0008;
  pointer-events: none;
}
.dice-visual { width: 112px; height: 108px; display: grid; place-items: center; }
.dice-body {
  width: 90px; height: 96px;
  display: grid; place-items: center;
  background: #7fe2ca; color: #102c29;
  clip-path: polygon(50% 0, 96% 25%, 96% 75%, 50% 100%, 4% 75%, 4% 25%);
  position: relative;
}
.dice-body::before {
  content: ''; position: absolute; inset: 10px;
  border: 1px solid #205c53;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  background: #b2f4e033;
}
.dice-body span { font-size: 32px; font-weight: 900; font-variant-numeric: tabular-nums; z-index: 1; }
.dice-animation[data-dice="d6"] .dice-body { clip-path: inset(8% round 8px); }
.dice-animation[data-dice="d4"] .dice-body { clip-path: polygon(50% 0, 100% 94%, 0 94%); padding-top: 24px; }
.dice-animation[data-dice="d8"] .dice-body { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.dice-animation[data-phase="rolling"] .dice-body { animation: dice-tumble 1.15s ease-out both; }
.dice-animation[data-phase="result"] .dice-body { animation: dice-land 280ms ease-out both; }
.dice-animation[data-critical="20"] { border-color: #efd06c; }
.dice-animation[data-critical="20"] .dice-body { background: #efd06c; color: #332710; }
.dice-animation[data-critical="1"] .dice-body { background: #f1a5ac; color: #441e25; }
.dice-announcement { min-width: 0; display: grid; gap: 5px; overflow-wrap: anywhere; }
.dice-announcement [data-dice-actor] { font-size: 13px; color: #b9d2cb; max-height: 40px; overflow: hidden; }
.dice-announcement strong { font-size: 24px; }
.dice-announcement [data-dice-status] { font-size: 14px; }
.dice-dismiss { pointer-events: auto; align-self: start; padding: 0; width: 24px; height: 24px; color: #dce9e4; font-size: 22px; border: 0; background: transparent; }
@keyframes dice-tumble {
  0% { transform: translate(-22px, -22px) rotate(-160deg) scale(.65); }
  30% { transform: translate(8px, 5px) rotate(30deg) scale(1); }
  60% { transform: translate(-5px, -15px) rotate(190deg) scale(.9); }
  82% { transform: translate(3px, 3px) rotate(325deg); }
  100% { transform: translate(0, 0) rotate(360deg); }
}
@keyframes dice-land { 0% { transform: scale(.9); } 55% { transform: scale(1.08); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .dice-animation .dice-body { animation: none !important; } }
@media (max-width: 380px) {
  .dice-animation { grid-template-columns: 88px minmax(0, 1fr) 24px; gap: 8px; padding: 12px; }
  .dice-visual { width: 88px; }
}

.log-line {
  color: var(--muted);
}

.log-line b {
  color: var(--ink);
}

.player-view,
.archive-view,
.account-view {
  display: grid;
  grid-template-columns: minmax(320px, 0.85fr) minmax(420px, 1.15fr);
  gap: 18px;
  align-content: start;
  align-items: start;
}

.account-view {
  grid-template-columns: minmax(320px, 560px);
}

.signup-panel {
  max-width: 560px;
}

.signup-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.signup-actions button {
  min-width: 190px;
}

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: min(100%, 560px);
}

.auth-card h1 {
  margin: 4px 0 0;
  font-size: 1.8rem;
}

.signup-form {
  display: grid;
  gap: 14px;
}

.text-link {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

.sheet-panel,
.player-map {
  grid-column: span 1;
}

.player-map {
  grid-row: span 2;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.stat-grid input {
  text-align: center;
  font-weight: 900;
}

.player-scene {
  min-height: 430px;
}

.player-world-map {
  display: grid;
  gap: 8px;
}

.player-world-map .eyebrow {
  margin: 0;
}

.player-world-map img {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  aspect-ratio: 3 / 2;
  background: #131817;
}

.scene-board {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  aspect-ratio: 16 / 10;
  background: #1a1815;
}

.player-scene .scene-board .token:disabled {
  opacity: 1;
  cursor: default;
  filter: none;
  pointer-events: none;
}

.scene-board > img,
.scene-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-board > img {
  object-fit: fill;
}

.scene-fallback {
  background-color: #29342b;
  background-image:
    linear-gradient(rgba(245, 234, 216, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(245, 234, 216, 0.18) 1px, transparent 1px);
  background-size: 5% 7.7%;
}

.player-dice-tools {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.scene-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.scene-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  padding: 11px 12px;
}

.scene-status span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.scene-status strong {
  display: block;
  line-height: 1.35;
  white-space: pre-wrap;
}

.scene-token-roster {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.scene-token-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.scene-token-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 7px 8px;
  border-left: 3px solid var(--accent-2);
  background: rgba(255, 255, 255, 0.045);
}

.scene-token-item.monster {
  border-left-color: var(--danger);
}

.scene-token-item img,
.scene-token-fallback {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.scene-token-fallback {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 900;
}

.scene-token-item strong,
.scene-token-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scene-token-item small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.7rem;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell,
  .view-grid,
  .player-view,
  .archive-view,
  .account-view {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-heading {
    flex-basis: auto;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 180px;
  }

  .map-panel,
  .live-panel {
    grid-row: auto;
  }

  .stat-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .scene-status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .dice-controls {
    grid-template-columns: repeat(4, minmax(46px, 1fr));
  }
}

@media (max-width: 620px) {
  .main-stage,
  .sidebar {
    padding: 16px;
  }

  .form-grid,
  .form-grid.three,
  .campaign-identity,
  .map-tools,
  .creature-token-list,
  .preset-map-list,
  .character-card {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    grid-template-columns: 1fr;
  }

  .interface-mode-control {
    min-width: 0;
  }

  .world-map-display {
    min-height: 0;
  }

  .scene-status-grid,
  .global-chat .chat-row,
  .sheet-detail-grid,
  .scene-token-grid {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .attachment-row {
    grid-template-columns: 48px minmax(0, 1fr) auto;
  }

  .attachment-preview {
    width: 48px;
    height: 48px;
  }

  .attachment-link {
    display: none;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Tactical map tools */
.map-board > canvas,
.map-board > div {
  position: absolute;
  inset: 0;
}

#mapCanvas {
  position: absolute;
  inset: 0;
}

.token-layer {
  z-index: 3;
  pointer-events: none;
}

.token-layer .token {
  pointer-events: auto;
}

.map-mark-layer {
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
}

.map-mark-layer.editing {
  pointer-events: none;
}

.fog-canvas {
  z-index: 5;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.fog-canvas.editing {
  cursor: crosshair;
  pointer-events: auto;
  touch-action: none;
}

.map-toolbox,
.encounter-builder,
.token-manager-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.tool-segment,
.mode-switch,
.combat-actions,
.sound-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-segment button,
.mode-switch button {
  min-height: 38px;
}

.map-tool.active,
.scene-mode.active,
#previewAsPlayer.active {
  border-color: rgba(215, 168, 75, 0.9);
  color: #fff4dc;
  background: rgba(215, 168, 75, 0.2);
}

.map-config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  gap: 10px;
  margin-top: 12px;
}

.toggle-label {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
}

.toggle-label input {
  width: 18px;
  min-height: 18px;
  flex: 0 0 18px;
}

.tool-status,
.source-note {
  display: block;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.map-mark {
  position: absolute;
  height: 4px;
  transform-origin: left center;
  border-radius: 3px;
  background: #f5ca63;
  box-shadow: 0 0 0 1px rgba(20, 14, 8, 0.5), 0 0 10px rgba(245, 202, 99, 0.45);
}

.map-mark.ruler,
.map-mark.line,
.map-mark.cone {
  margin-top: -2px;
}

.map-mark.ruler span {
  position: absolute;
  left: 50%;
  bottom: 8px;
  min-width: max-content;
  padding: 3px 6px;
  border-radius: 4px;
  color: #17130e;
  background: #f5ca63;
  font-size: 0.7rem;
  font-weight: 900;
  transform: translateX(-50%);
}

.map-mark.line {
  height: 16px;
  margin-top: -8px;
  background: rgba(212, 93, 76, 0.58);
}

.map-mark.cone {
  width: 100%;
  height: 72px;
  margin-top: -36px;
  clip-path: polygon(0 46%, 100% 0, 100% 100%, 0 54%);
  background: rgba(215, 168, 75, 0.46);
}

.map-mark.circle {
  height: auto;
  border: 3px solid rgba(98, 177, 167, 0.9);
  border-radius: 50%;
  background: rgba(98, 177, 167, 0.22);
}

.map-mark.ping {
  width: 18px;
  height: 18px;
  border: 3px solid #f5ca63;
  border-radius: 50%;
  background: rgba(245, 202, 99, 0.18);
  transform: translate(-50%, -50%);
  animation: map-ping 1.3s ease-out infinite;
}

.map-mark-editor {
  position: absolute;
  z-index: 3;
  display: flex;
  gap: 3px;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

.map-mark-editor button {
  min-width: 30px;
  min-height: 30px;
  padding: 5px 7px;
  border-color: rgba(245, 202, 99, 0.82);
  border-radius: 4px;
  color: #fff8e8;
  background: rgba(19, 22, 26, 0.94);
  font-size: 0.68rem;
  font-weight: 900;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.45);
}

.map-mark-editor .map-mark-move {
  cursor: grab;
  touch-action: none;
}

.map-mark-editor.dragging .map-mark-move {
  cursor: grabbing;
  border-color: #fff1bf;
  background: #6f5420;
}

.map-mark-editor .map-mark-remove {
  width: 30px;
  color: #ffe4df;
  border-color: rgba(212, 93, 76, 0.78);
}

@keyframes map-ping {
  0% { box-shadow: 0 0 0 0 rgba(245, 202, 99, 0.72); }
  100% { box-shadow: 0 0 0 24px rgba(245, 202, 99, 0); }
}

.compact-list,
.token-manager,
.combat-tracker,
.lore-list,
.session-timeline,
.history-list,
.player-combat,
.player-lore,
.player-timeline {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.compact-row,
.token-manager-row,
.combat-row,
.player-combat-row {
  display: grid;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.compact-row {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.compact-row strong,
.compact-row small,
.token-manager-row strong,
.token-manager-row small {
  display: block;
}

.compact-row small {
  margin-top: 3px;
  color: var(--muted);
}

.token-manager-row {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
}

.token-size-control {
  display: grid;
  gap: 5px;
  min-width: 138px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.token-size-control span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.token-size-control output {
  color: #fff4dc;
}

.token-size-control input[type="range"] {
  width: 100%;
  min-height: 22px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.token-kind-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

/* Scenes, initiative and campaign records */
.scene-image-button {
  align-self: end;
}

.narrative-panel > .primary-button,
.session-panel > .primary-button {
  margin-top: 12px;
}

.combat-toolbar {
  display: grid;
  grid-template-columns: auto minmax(100px, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  text-align: center;
}

.combat-row {
  grid-template-columns: auto minmax(90px, 1fr) repeat(3, minmax(58px, 76px));
}

.combat-row .condition-field {
  grid-column: 2 / 5;
}

.combat-row > button {
  grid-column: 5;
}

.combat-row.current,
.player-combat-row.current {
  border-color: rgba(215, 168, 75, 0.9);
  background: rgba(215, 168, 75, 0.14);
}

.turn-marker {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.combat-row label {
  min-width: 0;
  font-size: 0.68rem;
}

.combat-row input {
  min-width: 0;
}

.library-search { display: grid; gap: 6px; margin: 12px 0; }
.combat-vitals, .hp-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.combat-vitals progress { width: 100px; height: 10px; accent-color: #67bc94; }
.combat-vitals span { font-size: 14px; }
.zero-hp { color: #ff9a9a; font-size: 14px; }
.hp-actions label { display: grid; gap: 4px; width: 90px; font-size: 14px; }
.hp-actions button { align-self: flex-end; }
.hp-actions input { width: 100%; }
.combat-row > strong { overflow-wrap: anywhere; }

.compendium-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.compendium-card,
.lore-card,
.timeline-card,
.sound-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.compendium-card,
.lore-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

.compendium-card[draggable="true"] {
  cursor: grab;
}

.compendium-card small,
.lore-card small,
.sound-card small,
.timeline-card span {
  display: block;
  color: var(--accent-2);
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

.compendium-card strong,
.lore-card strong,
.sound-card strong,
.timeline-card strong {
  display: block;
  margin: 4px 0;
}

.compendium-card p,
.lore-card p,
.timeline-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  white-space: pre-wrap;
}

.lore-card.secret {
  border-color: rgba(212, 93, 76, 0.5);
}

.timeline-card {
  border-left: 3px solid var(--accent-2);
}

.timeline-card small {
  display: block;
  margin-top: 8px;
  color: var(--accent);
}

.player-info-section {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.player-combat-row {
  grid-template-columns: minmax(100px, 1fr) auto auto minmax(100px, 1fr);
}

.player-combat-row span,
.player-combat-row small {
  color: var(--muted);
}

.narrative-stage {
  position: relative;
  display: flex;
  min-height: 420px;
  align-items: end;
  overflow: hidden;
  padding: clamp(20px, 5vw, 54px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: #18201d;
  background-position: center;
  background-size: cover;
}

.narrative-stage > div {
  max-width: 720px;
}

.narrative-stage span {
  color: #f2c96f;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.narrative-stage h3 {
  margin: 7px 0;
  font-size: clamp(1.5rem, 4vw, 2.7rem);
}

.narrative-stage p {
  margin: 0;
  color: #f5ead8;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* Shared soundboard */
.soundboard-panel {
  margin-top: 18px;
}

.sound-volume-row {
  display: grid;
  grid-template-columns: auto minmax(160px, 420px) 48px;
  align-items: center;
  gap: 12px;
}

.sound-volume-row label,
.sound-volume-row span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.sound-volume-row input {
  min-height: 24px;
  padding: 0;
}

.soundboard-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.sound-card {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto auto;
  align-items: center;
  gap: 8px;
}

.sound-card a {
  display: grid;
  min-height: 40px;
  place-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

@media (max-width: 1120px) {
  .combat-row {
    grid-template-columns: auto minmax(90px, 1fr) repeat(3, minmax(58px, 76px));
  }

  .combat-row .condition-field {
    grid-column: 2 / 5;
  }

  .soundboard-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .map-config-grid,
  .compendium-list {
    grid-template-columns: 1fr;
  }

  .token-manager-row,
  .combat-row,
  .player-combat-row,
  .sound-card {
    grid-template-columns: 1fr;
  }

  .compact-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .compact-row > div {
    grid-column: 1 / -1;
  }

  .combat-row .condition-field {
    grid-column: auto;
  }

  .combat-row > button {
    grid-column: auto;
  }

  .sound-volume-row {
    grid-template-columns: auto minmax(100px, 1fr) 42px;
  }

  .narrative-stage {
    min-height: 340px;
  }
}
