:root {
  --bg-0: #0c0a09;
  --bg-1: #161211;
  --bg-2: #221c18;
  --ink: #e8ddd0;
  --ink-dim: #a89888;
  --accent: #b33a2b;
  --accent-2: #c47a3a;
  --line: rgba(232, 221, 208, 0.12);
  --ok: #6f9e6a;
  --warn: #c9a227;
  --danger: #c44536;
  --font-display: "Cormorant Garamond", "Times New Roman", serif;
  --font-body: "IBM Plex Sans", "Segoe UI", sans-serif;
  --radius: 10px;
  --touch: 48px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(179, 58, 43, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(196, 122, 58, 0.12), transparent 50%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  color: var(--ink);
  font-family: var(--font-body);
}

body {
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0 0 0.4rem;
}

.muted {
  color: var(--ink-dim);
}

.shell {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0 2.5rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.brand {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  line-height: 1;
}

.brand span {
  display: block;
  font-family: var(--font-body);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-top: 0.35rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.badge.online::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(111, 158, 106, 0.2);
}

.badge.offline::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--danger);
}

.panel {
  background: linear-gradient(180deg, rgba(34, 28, 24, 0.92), rgba(12, 10, 9, 0.88));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--ink);
  min-height: var(--touch);
  padding: 0.7rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.btn:hover {
  border-color: rgba(232, 221, 208, 0.28);
  background: #2b241f;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(180deg, #8f2f24, #6d221a);
  border-color: rgba(196, 122, 58, 0.35);
}

.btn-ghost {
  background: transparent;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
}

.card-char {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: left;
  min-height: 210px;
}

.card-char img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #000;
  filter: contrast(1.05) saturate(0.85);
}

.card-char.taken {
  opacity: 0.45;
  cursor: not-allowed;
}

.card-char.mine {
  border-color: rgba(196, 122, 58, 0.7);
  box-shadow: 0 0 0 1px rgba(196, 122, 58, 0.25);
}

.stat-row {
  display: grid;
  gap: 0.55rem;
}

.bar {
  display: grid;
  gap: 0.25rem;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--ink-dim);
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  border: 1px solid var(--line);
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  transition: width 0.25s ease;
}

.bar-fill.hp {
  background: linear-gradient(90deg, #7a2b24, #c44536);
}

.bar-fill.xp {
  background: linear-gradient(90deg, #8a5a24, #c47a3a);
}

.bar-fill.stress {
  background: linear-gradient(90deg, #3a4a6a, #7a8cb0);
}

.bar-fill.stress.panic {
  background: linear-gradient(90deg, #6a2040, #c2275a);
  animation: pulse 1.1s ease infinite;
}

@keyframes pulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.35);
  }
}

.log {
  display: grid;
  gap: 0.45rem;
  max-height: 240px;
  overflow: auto;
  font-size: 0.85rem;
}

.log-item {
  padding: 0.45rem 0.55rem;
  border-left: 2px solid var(--line);
  color: var(--ink-dim);
}

.log-item.player {
  border-color: var(--accent-2);
}

.log-item.dm {
  border-color: var(--accent);
}

.log-item.system {
  border-color: #555;
}

.toast-host {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: grid;
  gap: 0.5rem;
  z-index: 50;
  width: min(340px, calc(100% - 2rem));
}

.toast {
  background: rgba(20, 14, 12, 0.94);
  border: 1px solid rgba(196, 122, 58, 0.45);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.layout-dm {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  gap: 0.85rem;
}

.layout-player {
  display: grid;
  gap: 0.85rem;
}

.map-stage,
.map-board-host {
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink-dim);
  position: relative;
  overflow: hidden;
}

.map-board-host.live {
  min-height: 60vh;
}

.map-board-host.otherworld {
  filter: sepia(0.35) saturate(1.2) hue-rotate(-15deg) contrast(1.1);
}

.map-board-host .fog-layer,
.map-stage .fog-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
  background:
    radial-gradient(circle at 30% 40%, rgba(180, 180, 190, 0.18), transparent 40%),
    radial-gradient(circle at 70% 60%, rgba(140, 150, 160, 0.16), transparent 45%),
    linear-gradient(180deg, rgba(40, 45, 50, 0.15), rgba(10, 10, 12, 0.35));
  transition: opacity 0.4s ease;
}

.map-board-host .fog-layer.on,
.map-stage .fog-layer.on {
  opacity: var(--fog-intensity, 0.45);
}

.map-board-host .fog-layer.otherworld-fog {
  background:
    radial-gradient(circle at 25% 35%, rgba(160, 40, 30, 0.22), transparent 42%),
    radial-gradient(circle at 75% 65%, rgba(90, 20, 20, 0.2), transparent 48%),
    linear-gradient(180deg, rgba(60, 10, 10, 0.2), rgba(10, 4, 4, 0.4));
}

.map-fow {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.fow-cell {
  position: absolute;
  box-sizing: border-box;
}

.fow-cell.fow-hidden {
  background: rgba(4, 3, 3, 0.92);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.fow-cell.fow-explored {
  background: rgba(10, 8, 8, 0.55);
  backdrop-filter: blur(1px);
}

.fow-cell.fow-dm.fow-hidden {
  background: rgba(4, 3, 3, 0.62);
  background-image: repeating-linear-gradient(
    45deg,
    rgba(180, 60, 40, 0.12) 0 4px,
    transparent 4px 8px
  );
}

.fow-cell.fow-dm.fow-explored {
  background: rgba(20, 16, 12, 0.35);
  box-shadow: inset 0 0 0 1px rgba(196, 122, 58, 0.2);
}

.atmosphere-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.atmosphere-controls input[type='range'] {
  width: min(180px, 100%);
  accent-color: var(--accent-2);
}

.tool-mode-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}

.tool-mode-bar .btn.active,
.fog-brush .btn.active {
  border-color: rgba(196, 122, 58, 0.7);
  background: #3a2a20;
}

.map-tokens {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.map-token {
  position: absolute;
  width: calc(var(--cell, 48px) - 8px);
  height: calc(var(--cell, 48px) - 8px);
  border-radius: 50%;
  border: 2px solid rgba(232, 221, 208, 0.55);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  pointer-events: auto;
  background: #1a1410;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

.map-token img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.map-token.pc {
  border-color: rgba(196, 122, 58, 0.85);
}

.map-token.enemy {
  border-color: rgba(196, 70, 55, 0.9);
  border-radius: 8px;
}

.map-token.selected {
  outline: 2px solid #e8c27a;
  outline-offset: 2px;
  z-index: 7;
}

.map-token .token-hp {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: 0.55rem;
  line-height: 1.1;
  text-align: center;
  background: rgba(0, 0, 0, 0.7);
  color: #e8ddd0;
}

.enemy-list {
  display: grid;
  gap: 0.45rem;
  max-height: 220px;
  overflow: auto;
}

.enemy-item {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 0.45rem;
  align-items: center;
  padding: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.enemy-item.selected {
  border-color: rgba(196, 70, 55, 0.7);
}

.enemy-item img {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.map-board-scroll {
  width: 100%;
  height: 100%;
  min-height: inherit;
  overflow: auto;
}

.map-board {
  position: relative;
  margin: 0.5rem;
  background:
    linear-gradient(rgba(232, 221, 208, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 221, 208, 0.045) 1px, transparent 1px),
    #120e0c;
  background-size: var(--cell, 48px) var(--cell, 48px), var(--cell, 48px) var(--cell, 48px), auto;
  box-shadow: inset 0 0 0 1px rgba(232, 221, 208, 0.08);
}

.map-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  text-align: center;
  pointer-events: none;
  z-index: 1;
}

.map-tiles {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.map-tile {
  position: absolute;
  padding: 0;
  border: 1px solid rgba(232, 221, 208, 0.22);
  background: #1a1410;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  appearance: none;
  color: inherit;
}

.map-tile img {
  position: absolute;
  left: 50%;
  top: 50%;
  max-width: none;
  pointer-events: none;
  display: block;
}

.map-tile.hidden-tile {
  opacity: 0.42;
  filter: grayscale(0.35);
  border-style: dashed;
}

.map-tile.selected {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
  z-index: 3;
}

.map-tile-label {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  font-size: 0.65rem;
  line-height: 1.2;
  padding: 0.15rem 0.3rem;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--ink);
  text-align: left;
  z-index: 2;
}

.map-tile.tile-appear {
  animation: tile-appear 0.7s ease;
}

@keyframes tile-appear {
  0% {
    opacity: 0;
    transform: scale(0.92);
    filter: brightness(2.2);
  }
  55% {
    filter: brightness(1.25);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    filter: none;
  }
}

.tile-library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.45rem;
}

.tile-card {
  display: grid;
  gap: 0.3rem;
  padding: 0.4rem;
  min-height: auto;
  text-align: left;
}

.tile-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #000;
}

.tile-card.active {
  border-color: rgba(196, 122, 58, 0.7);
  box-shadow: 0 0 0 1px rgba(196, 122, 58, 0.25);
}

.tile-card small {
  color: var(--ink-dim);
  font-size: 0.7rem;
}

.party-list,
.tool-stack {
  display: grid;
  gap: 0.65rem;
}

.party-item {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 0.6rem;
  align-items: start;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.party-item.selected {
  border-color: rgba(196, 122, 58, 0.65);
  box-shadow: 0 0 0 1px rgba(196, 122, 58, 0.2);
}

.party-item.panic {
  border-color: rgba(194, 39, 90, 0.55);
}

.ctrl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-top: 0.35rem;
}

.ctrl-row .tag {
  font-size: 0.72rem;
  color: var(--ink-dim);
  min-width: 3.2rem;
}

.btn-mini {
  min-height: 34px;
  min-width: 34px;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.btn-mini.wide {
  min-width: 52px;
}

.num-input {
  width: 4.5rem;
  min-height: 34px;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
}

.panic-banner {
  display: none;
  margin-top: 0.5rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid rgba(194, 39, 90, 0.55);
  background: rgba(80, 16, 36, 0.55);
  color: #f0c4d0;
  font-size: 0.88rem;
  animation: pulse 1.1s ease infinite;
}

.panic-banner.on {
  display: block;
}

.actions-pips {
  display: flex;
  gap: 0.35rem;
  margin: 0.35rem 0 0.55rem;
}

.actions-pips span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
}

.actions-pips span.on {
  background: var(--accent-2);
  border-color: rgba(196, 122, 58, 0.7);
  box-shadow: 0 0 0 2px rgba(196, 122, 58, 0.15);
}

.party-item img {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.live-shell {
  width: min(1400px, calc(100% - 1.5rem));
}

.live-title {
  font-size: clamp(2rem, 5vw, 3rem);
}

@media (max-width: 960px) {
  .layout-dm {
    grid-template-columns: 1fr;
  }
}
