:root {
  --paper: #f7f0e4;
  --parchment: #fbf6ee;
  --ink: #201810;
  --muted: #6e6255;
  --line: #d3c4b2;
  --accent: #8f3823;
  --accent-strong: #5e1f10;
  --gold: #c49b4a;
  --shadow: rgba(49, 31, 16, 0.12);
  --active: #234d3a;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  background:
    radial-gradient(circle at top, rgba(196, 155, 74, 0.22), transparent 28%),
    radial-gradient(circle at bottom right, rgba(143, 56, 35, 0.12), transparent 24%),
    linear-gradient(180deg, #efe4d2 0%, var(--paper) 34%, #f6f0e7 100%);
}

body.player-screen {
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(212, 180, 109, 0.18), transparent 24%),
    radial-gradient(circle at bottom left, rgba(23, 51, 40, 0.24), transparent 28%),
    linear-gradient(180deg, #140f0c 0%, #211810 34%, #171310 100%);
  color: #f7efe1;
}

body.dm-screen {
  background: #ece8df;
}

a {
  color: var(--accent-strong);
}

.dm-layout,
.player-layout,
.session-shell {
  width: min(1460px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 26px 0 48px;
}

.dm-layout {
  display: block;
}

.dm-screen .dm-layout,
.dm-screen .session-panel {
  width: min(1600px, calc(100vw - 24px));
}

.dm-screen .session-panel {
  border-radius: 12px;
  padding: 18px;
  background: #f7f5ef;
  box-shadow: none;
}

.dm-screen .session-panel::before {
  display: none;
}

.dm-screen .lede,
.dm-screen .lede.compact {
  max-width: none;
  line-height: 1.45;
}

.session-panel,
.player-scene-hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(251, 246, 238, 0.96), rgba(246, 239, 229, 0.94));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 18px 50px var(--shadow);
}

.session-panel::before,
.player-scene-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.5), transparent 35%),
    radial-gradient(circle at 100% 0, rgba(196, 155, 74, 0.18), transparent 30%);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.status-line {
  margin: 14px 0 0;
  color: var(--accent-strong);
  font-size: 0.88rem;
}

.dm-utility-bar {
  display: grid;
  grid-template-columns: 140px minmax(220px, 1fr) minmax(260px, 1.2fr);
  gap: 12px;
  margin-bottom: 16px;
}

.utility-item {
  padding: 10px 12px;
  border: 1px solid #d7ccbb;
  border-radius: 8px;
  background: #fcfaf5;
}

.utility-item strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.utility-item-wide strong {
  color: var(--accent-strong);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: normal;
}

h1 {
  font-size: clamp(2rem, 3vw, 2.7rem);
}

h2 {
  font-size: 1.55rem;
}

h3 {
  font-size: 1.22rem;
}

.lede {
  max-width: 60ch;
  color: var(--muted);
  line-height: 1.65;
}

.lede.compact {
  font-size: 0.98rem;
  margin-top: 10px;
}

.control-stats,
.combat-grid {
  display: grid;
  gap: 12px;
}

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

.control-stats > div,
.mini-stat {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(211, 196, 178, 0.9);
}

.control-stats strong,
.mini-stat strong {
  display: block;
  font-size: 1.2rem;
}

.stack,
.toolbar,
.card-actions,
.legend,
.mode-switch,
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stack {
  margin-top: 16px;
}

.compact-stack {
  margin-top: 0;
  margin-bottom: 14px;
}

button,
.primary-button,
.secondary-button,
.filter-chip,
.condition-chip,
.turn-chip,
.mode-button,
.tab-button {
  appearance: none;
  border: 1px solid rgba(143, 56, 35, 0.28);
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.7);
  color: var(--accent-strong);
  transition: transform 120ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
}

button:hover,
.primary-button:hover,
.secondary-button:hover,
.filter-chip:hover,
.condition-chip:hover,
.turn-chip:hover,
.mode-button:hover,
.tab-button:hover {
  transform: translateY(-1px);
}

.primary-button,
.filter-chip.active,
.condition-chip.active,
.mode-button.active,
.tab-button.active {
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
}

.turn-chip.active {
  color: #fff;
  border-color: var(--active);
  background: linear-gradient(180deg, var(--active), #19392c);
}

.mode-switch {
  margin-top: 18px;
}

.tab-bar {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.tab-panel[hidden] {
  display: none;
}

.mini-field {
  display: block;
}

.mini-field span,
.stat-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mini-field input,
.search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  background: rgba(255, 255, 255, 0.85);
}

.callout {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}

.compact-grid {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.encounter-grid {
  display: grid;
  gap: 16px;
}

.catalog-card,
.combatant-card,
.player-card,
.scene-card {
  background: var(--parchment);
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(61, 41, 22, 0.06);
}

.catalog-card.is-muted {
  opacity: 0.55;
}

.combatant-card.is-active,
.player-card.is-active {
  border-color: rgba(35, 77, 58, 0.45);
  box-shadow: 0 18px 36px rgba(35, 77, 58, 0.16);
}

.catalog-card img,
.combatant-card img,
.player-card img,
.scene-card img,
.scene-hero-media img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #d8cab7;
}

.catalog-body,
.combatant-body,
.player-body {
  padding: 16px;
}

.catalog-row,
.combatant-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.card-copy {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.combatant-head,
.player-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.combat-grid {
  grid-template-columns: minmax(0, 160px) minmax(0, 1fr);
  margin-top: 14px;
}

.type-pill,
.hit-pill,
.initiative-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 11px;
  background: #efe2d2;
  color: var(--accent-strong);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.initiative-pill {
  background: rgba(196, 155, 74, 0.22);
  color: #6e4c11;
}

.hit-controls {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.hit-controls button {
  font-size: 1.1rem;
  padding: 12px 0;
}

.hit-count {
  text-align: center;
  padding: 12px 10px;
  border-radius: 16px;
  background: #f0e6dc;
  color: var(--accent-strong);
}

.condition-row,
.player-conditions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.condition-chip {
  padding: 7px 11px;
  font-size: 0.78rem;
}

.image-flag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.image-flag input {
  margin: 0;
  accent-color: var(--accent);
}

.legend {
  margin-bottom: 14px;
}

.card-fallback {
  display: grid;
  place-items: center;
  min-height: 160px;
  background:
    linear-gradient(135deg, rgba(143, 56, 35, 0.24), rgba(196, 155, 74, 0.24)),
    #e4d5c1;
  color: var(--accent-strong);
  font-size: 0.92rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.card-fallback.large {
  min-height: 100%;
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.44);
}

.utilitarian-empty {
  padding: 16px;
  border-radius: 8px;
  background: #faf8f2;
}

.control-stack {
  display: grid;
  gap: 18px;
}

.control-section {
  display: grid;
  gap: 10px;
}

.control-table-shell {
  border: 1px solid #cfc4b2;
  border-radius: 8px;
  overflow: hidden;
  background: #fffdf9;
}

.control-table {
  display: grid;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 110px 90px 90px 150px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid #e2d8c8;
  font-size: 0.92rem;
}

.control-row:first-child {
  border-top: 0;
}

.control-row-head {
  background: #f1ece2;
  color: #51463a;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.control-name-cell strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-start;
}

.control-actions button,
.hit-inline button {
  padding: 6px 10px;
  border-radius: 6px;
  background: #f7f2e8;
}

.row-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: #dfeee7;
  color: #21523c;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.table-number {
  width: 72px;
  border: 1px solid #cfc4b2;
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
  background: #fff;
}

.hit-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.control-condition-row {
  margin-top: 0;
}

.control-condition-row .condition-chip {
  padding: 5px 8px;
}

.control-row.is-active {
  background: #eef6f1;
}

.control-table-shell #encounter-list,
.control-table-shell #scene-featured,
.control-table-shell #scene-location,
.control-table-shell #compendium-list {
  border: 0;
}

.dm-screen #compendium-list .control-row {
  grid-template-columns: minmax(220px, 1.6fr) 120px 90px 90px 150px;
}

.dm-screen #scene-location .control-row,
.dm-screen #scene-featured .control-row {
  grid-template-columns: minmax(220px, 1.6fr) 140px 90px 180px;
}

.dm-screen #encounter-list .control-row {
  grid-template-columns: minmax(180px, 1.4fr) 110px 80px 90px 120px 220px minmax(220px, 1.4fr);
}

.dm-screen .image-flag {
  gap: 5px;
  font-size: 0.82rem;
}

.empty-state.wide {
  grid-column: 1 / -1;
}

.exploration-shell {
  display: grid;
  gap: 18px;
}

.scene-slot {
  display: grid;
  gap: 12px;
}

.primary-scene {
  max-width: 680px;
}

.player-layout {
  width: 100vw;
  max-width: none;
  height: 100vh;
  padding: 0;
}

.player-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
  padding: 8px;
}

.player-scene {
  display: grid;
  gap: 0;
  min-height: 0;
  padding: 0;
}

.player-idle-stage,
.player-scene-stage {
  position: relative;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: #090807;
}

.player-backdrop {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.backdrop-scrim {
  position: relative;
  z-index: 1;
  height: 100%;
  width: 100%;
  background:
    linear-gradient(180deg, rgba(8, 7, 6, 0.18) 0%, rgba(8, 7, 6, 0.42) 55%, rgba(8, 7, 6, 0.88) 100%),
    linear-gradient(90deg, rgba(8, 7, 6, 0.2) 0%, rgba(8, 7, 6, 0) 26%, rgba(8, 7, 6, 0) 74%, rgba(8, 7, 6, 0.28) 100%);
}

.player-title-lockup {
  position: absolute;
  left: 44px;
  right: 44px;
  bottom: 186px;
  z-index: 2;
}

.player-title-lockup-large {
  bottom: 76px;
}

.player-title-lockup h2 {
  margin: 0;
  max-width: 16ch;
  color: #f7efe1;
  font-size: clamp(2.8rem, 5.3vw, 6rem);
  line-height: 0.92;
  letter-spacing: -0.04em;
  text-shadow: 0 10px 32px rgba(0, 0, 0, 0.42);
}

.portrait-frame {
  aspect-ratio: 3 / 4;
}

.landscape-frame {
  aspect-ratio: auto;
}

.media-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.player-screen .media-image {
  aspect-ratio: auto;
  object-fit: contain;
}

.media-image-portrait {
  padding: 0;
}

.media-image-landscape {
  padding: 0;
}

.scene-feature-strip {
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 20px;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.scene-feature-strip.is-dense {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.feature-tile,
.encounter-tile {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #0e0b09;
}

.feature-media,
.encounter-media {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  background: #0e0b09;
}

.feature-tile {
  aspect-ratio: 3 / 4;
}

.tile-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(6, 5, 4, 0.04) 0%, rgba(6, 5, 4, 0.12) 46%, rgba(6, 5, 4, 0.88) 100%);
  pointer-events: none;
}

.tile-nameplate {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 2;
}

.tile-nameplate h3 {
  margin: 0;
  color: #f7efe1;
  font-size: clamp(1.1rem, 1.55vw, 1.9rem);
  line-height: 0.98;
  letter-spacing: -0.03em;
  text-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
}

.encounter-hud {
  position: absolute;
  inset: 12px 12px auto 12px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: start;
}

.encounter-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 0 14px 14px;
}

.encounter-tile {
  display: block;
  border: 0;
  box-shadow: none;
}

.encounter-tile.is-active {
  box-shadow: inset 0 0 0 3px rgba(112, 184, 145, 0.9), 0 0 0 1px rgba(112, 184, 145, 0.3);
}

.encounter-tile .player-conditions {
  margin-top: 10px;
}

.hit-pill,
.initiative-pill {
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(10, 9, 8, 0.72);
  color: #f7efe1;
  border: 1px solid rgba(247, 239, 225, 0.18);
  backdrop-filter: blur(6px);
}

.player-screen .player-grid,
.player-screen .player-scene {
  height: 100vh;
}

.player-screen .player-grid {
  align-content: stretch;
  grid-auto-rows: 1fr;
}

.player-screen .condition-chip {
  padding: 5px 8px;
  font-size: 0.66rem;
  border-radius: 999px;
  background: rgba(10, 9, 8, 0.72);
  color: #f7efe1;
  border: 1px solid rgba(247, 239, 225, 0.18);
}

.player-screen .type-pill,
.player-screen .initiative-pill {
  font-size: 0.68rem;
}

.player-screen .player-grid[data-density="compact"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.player-screen .player-grid[data-density="dense"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.player-screen .player-grid[data-density="ultra"] {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.player-screen .player-grid[data-density="compact"] .tile-nameplate h3,
.player-screen .player-grid[data-density="dense"] .tile-nameplate h3 {
  font-size: clamp(1rem, 1.15vw, 1.3rem);
}

.player-screen .player-grid[data-density="dense"] .portrait-frame {
  aspect-ratio: 5 / 6;
}

.player-screen .player-grid[data-density="ultra"] .portrait-frame {
  aspect-ratio: 9 / 10;
}

.player-screen .player-grid[data-density="dense"] .condition-chip {
  padding: 4px 7px;
  font-size: 0.62rem;
}

.player-screen .player-grid[data-density="ultra"] .condition-chip {
  padding: 3px 6px;
  font-size: 0.58rem;
}

.player-screen .player-grid[data-density="ultra"] .type-pill,
.player-screen .player-grid[data-density="ultra"] .initiative-pill {
  font-size: 0.6rem;
}

.player-screen .player-grid[data-density="ultra"] .tile-nameplate h3 {
  font-size: clamp(0.88rem, 0.9vw, 1rem);
}

.idle-scene-rail {
  position: absolute;
  left: 44px;
  bottom: 32px;
  z-index: 3;
  display: flex;
  gap: 10px;
}

.idle-dot {
  width: 12px;
  height: 12px;
  min-width: 12px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(247, 239, 225, 0.4);
  background: rgba(247, 239, 225, 0.18);
}

.idle-dot.active {
  background: #f7efe1;
  border-color: #f7efe1;
}

.ken-burns {
  animation: ken-burns-pan 12s ease-in-out forwards;
  transform-origin: center center;
}

@keyframes ken-burns-pan {
  0% {
    transform: scale(1) translate3d(0, 0, 0);
  }
  100% {
    transform: scale(1.03) translate3d(0.6%, -0.6%, 0);
  }
}

@media (max-width: 980px) {
  .dm-layout {
    grid-template-columns: 1fr;
  }

  .sticky-panel {
    position: static;
  }

  .section-head,
  .player-scene-hero {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .control-stats,
  .combat-grid {
    grid-template-columns: 1fr;
  }
}
