:root {
  --bg: #090912;
  --ink: #f7efe0;
  --muted: #bdb4a5;
  --panel: rgba(17, 18, 30, 0.88);
  --panel-strong: rgba(27, 27, 42, 0.96);
  --gold: #f5bd42;
  --teal: #35d5ca;
  --red: #e75b4f;
  --violet: #9b6cff;
  --green: #a9df6b;
  --line: rgba(255, 255, 255, 0.15);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 10%, rgba(53, 213, 202, 0.16), transparent 34%),
    radial-gradient(circle at 86% 2%, rgba(245, 189, 66, 0.12), transparent 32%),
    linear-gradient(135deg, #090912 0%, #171121 45%, #071b24 100%);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app {
  min-height: 100vh;
  padding: 22px;
}

.hidden {
  display: none !important;
}

.setup {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 22px;
  max-width: 1240px;
  margin: 0 auto;
  min-height: calc(100vh - 44px);
  align-items: stretch;
}

.setup-copy,
.player-builder,
.panel,
.event-card,
.turn-card,
.player-mini,
dialog {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(18px);
}

.setup-copy {
  display: flex;
  flex-direction: column;
  justify-content: end;
  padding: 34px;
  border-radius: 8px;
  background:
    linear-gradient(rgba(8, 8, 18, 0.2), rgba(8, 8, 18, 0.78)),
    url("assets/mystic-board.png") center / cover;
  min-height: 520px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.2rem, 5vw, 5.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  letter-spacing: 0;
}

.setup-copy p:not(.eyebrow) {
  max-width: 54ch;
  color: #efe4cd;
  font-size: 1.04rem;
  line-height: 1.6;
}

.setup-actions,
.topbar-actions,
.event-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary,
.secondary,
.icon-button,
.roll-button,
.choice-button {
  min-height: 44px;
  border-radius: 8px;
  color: var(--ink);
  transition: transform 0.18s ease, filter 0.18s ease, border-color 0.18s ease;
}

.primary {
  padding: 0 18px;
  background: linear-gradient(135deg, #f6c85f, #cc7c24);
  color: #1e1309;
  font-weight: 900;
}

.secondary,
.choice-button,
.icon-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  padding: 0 16px;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.15rem;
  font-weight: 900;
}

button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
  transform: none;
}

.player-builder {
  border-radius: 8px;
  padding: 22px;
  overflow: auto;
}

.builder-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.builder-head span {
  color: var(--muted);
  font-weight: 800;
}

.player-form {
  display: grid;
  gap: 16px;
}

label,
.field-label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  padding: 12px 14px;
  resize: vertical;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: rgba(245, 189, 66, 0.75);
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(78px, 1fr));
  gap: 10px;
}

.avatar-option {
  min-height: 118px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  padding: 8px;
}

.avatar-option[aria-pressed="true"] {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(245, 189, 66, 0.2), inset 0 0 24px rgba(245, 189, 66, 0.12);
}

.avatar-option img {
  width: 100%;
  height: 72px;
  object-fit: contain;
  image-rendering: auto;
}

.avatar-option span {
  display: block;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
}

.roster,
.players-panel {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.roster-card,
.player-mini {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  padding: 12px;
}

.roster-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
}

.roster-card img,
.turn-player img,
.player-mini img {
  object-fit: contain;
  image-rendering: auto;
}

.roster-card img {
  width: 58px;
  height: 58px;
}

.stats-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.stats-list ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  max-width: 1540px;
  margin: 0 auto 16px;
}

.topbar h1 {
  font-size: clamp(1.65rem, 3vw, 3rem);
  margin: 0;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 360px;
  gap: 16px;
  max-width: 1540px;
  margin: 0 auto;
  align-items: start;
}

.board-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #050712;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.board {
  display: block;
  width: 100%;
  aspect-ratio: 1536 / 1024;
  object-fit: cover;
}

.tokens,
.spaces,
.effects {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.space-marker {
  position: absolute;
  width: 3.2%;
  aspect-ratio: 1;
  translate: -50% -50%;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.1);
  opacity: 0;
}

.token {
  position: absolute;
  width: clamp(34px, 5.2vw, 72px);
  aspect-ratio: 1;
  translate: -50% -88%;
  transition: left 0.46s ease, top 0.46s ease, filter 0.22s ease;
  filter: drop-shadow(0 10px 8px rgba(0, 0, 0, 0.7));
  z-index: 5;
}

.token.active {
  filter: drop-shadow(0 0 14px rgba(245, 189, 66, 0.9)) drop-shadow(0 10px 8px rgba(0, 0, 0, 0.7));
}

.token img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.panel {
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 118px);
  overflow: auto;
}

.turn-card,
.event-card,
.player-mini {
  border-radius: 8px;
  padding: 14px;
}

.turn-player {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.turn-player img {
  width: 62px;
  height: 62px;
}

.roll-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: linear-gradient(135deg, #2bd3ca, #2452bd);
  font-weight: 900;
}

.roll-button strong {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  font-size: 1.25rem;
}

.event-card h2 {
  font-size: 1.2rem;
}

.event-card p:not(.eyebrow) {
  color: #ddd1bc;
  line-height: 1.48;
}

.player-mini {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 10px;
}

.player-mini img {
  width: 46px;
  height: 46px;
}

.player-mini strong,
.roster-card strong {
  display: block;
}

.player-mini small,
.roster-card small {
  color: var(--muted);
}

.badge {
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(245, 189, 66, 0.14);
  color: var(--gold);
  font-weight: 900;
  white-space: nowrap;
}

.fx {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 18%;
  aspect-ratio: 1;
  translate: -50% -50%;
  border-radius: 50%;
  z-index: 4;
  animation: fx-pop 1.25s ease forwards;
}

.fx.blessing {
  background: radial-gradient(circle, rgba(255, 231, 132, 0.95), rgba(245, 189, 66, 0.22) 38%, transparent 68%);
}

.fx.curse,
.fx.shadow {
  background: radial-gradient(circle, rgba(120, 75, 255, 0.75), rgba(62, 25, 87, 0.32) 42%, transparent 72%);
  filter: blur(1px);
}

.fx.combat,
.fx.storm {
  background: radial-gradient(circle, rgba(255, 99, 71, 0.9), rgba(229, 67, 49, 0.22) 35%, transparent 70%);
}

.fx.oracle,
.fx.sea {
  background: radial-gradient(circle, rgba(73, 218, 244, 0.9), rgba(53, 213, 202, 0.24) 42%, transparent 72%);
}

.fx.forge {
  background: radial-gradient(circle, rgba(255, 146, 57, 0.92), rgba(190, 67, 27, 0.26) 40%, transparent 72%);
}

.smoke {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 14px;
  height: 14px;
  translate: -50% -50%;
  border-radius: 999px;
  background: rgba(218, 206, 196, 0.65);
  filter: blur(3px);
  animation: smoke-rise 1.6s ease-out forwards;
  z-index: 6;
}

.shake {
  animation: board-shake 0.44s linear;
}

dialog {
  max-width: 480px;
  border-radius: 8px;
  color: var(--ink);
  padding: 0;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.winner {
  padding: 24px;
}

@keyframes fx-pop {
  0% {
    opacity: 0;
    scale: 0.3;
  }
  35% {
    opacity: 1;
    scale: 1;
  }
  100% {
    opacity: 0;
    scale: 1.35;
  }
}

@keyframes smoke-rise {
  0% {
    opacity: 0;
    transform: translate(0, 20px) scale(0.45);
  }
  30% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), -82px) scale(3.1);
  }
}

@keyframes board-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

@media (max-width: 1050px) {
  .setup,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .game-layout {
    max-width: 900px;
  }

  .panel {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app {
    padding: 12px;
  }

  .setup-copy,
  .player-builder {
    padding: 18px;
  }

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

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

  .game-layout {
    gap: 12px;
  }

  .board-wrap {
    overflow-x: auto;
  }

  .board,
  .tokens,
  .spaces,
  .effects {
    min-width: 720px;
  }
}
