:root {
  color-scheme: dark;
  --bg: #120d18;
  --panel: rgba(35, 24, 48, 0.94);
  --panel-light: #30203e;
  --ink: #fff8e8;
  --muted: #c7b8cf;
  --gold: #ffc857;
  --hot: #ef476f;
  --green: #5bd49c;
  --line: rgba(255, 255, 255, 0.13);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 5%, #4b1d61 0, transparent 32rem),
    radial-gradient(circle at 90% 15%, #5c1f32 0, transparent 28rem),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 46px;
  padding: 0.75rem 1.15rem;
  border: 0;
  border-radius: 0.8rem;
  color: #211326;
  font-weight: 800;
  background: var(--gold);
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

button.secondary {
  color: var(--ink);
  background: var(--panel-light);
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  color: var(--ink);
  background: #17101f;
}

label {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

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

h1,
h2 {
  line-height: 1.05;
}

.hero {
  display: grid;
  grid-template-columns: minmax(120px, 210px) 1fr;
  align-items: center;
  gap: 1.4rem;
  width: min(1100px, calc(100% - 2rem));
  margin: 1rem auto 0;
}

.hero img {
  width: 100%;
  border-radius: 1.2rem;
  transform: rotate(-2deg);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.hero h1 {
  margin-bottom: 0.6rem;
  font-size: clamp(2rem, 6vw, 4.7rem);
  text-transform: uppercase;
}

.hero p:last-child {
  max-width: 58ch;
  color: var(--muted);
}

.hero.is-compact {
  grid-template-columns: 58px 1fr;
  gap: 0.8rem;
  margin-top: 0.7rem;
}

.hero.is-compact img {
  width: 58px;
  height: 58px;
  border-radius: 0.8rem;
  object-fit: cover;
  transform: none;
}

.hero.is-compact .eyebrow,
.hero.is-compact p:last-child {
  display: none;
}

.hero.is-compact h1 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 3vw, 2rem);
}

main {
  width: min(1100px, calc(100% - 2rem));
  margin: 2rem auto 5rem;
}

.hero.is-compact + main {
  margin-top: 1rem;
}

.panel {
  padding: clamp(1rem, 3vw, 1.7rem);
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: var(--panel);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
}

.welcome-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  padding: 0;
  overflow: hidden;
}

.welcome-grid form {
  display: grid;
  align-content: start;
  gap: 1rem;
  padding: clamp(1.2rem, 4vw, 2rem);
}

.welcome-grid form + form {
  border-left: 1px solid var(--line);
}

.eyebrow {
  margin-bottom: 0.4rem;
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.room-code-input,
#room-code {
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.room-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.room-heading h2 {
  margin-bottom: 0.4rem;
  font-size: clamp(2rem, 8vw, 4rem);
}

.room-heading p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

#room.is-playing .room-heading {
  align-items: center;
  padding: 0.75rem 1rem;
}

#room.is-playing .room-heading .eyebrow,
#room.is-playing #room-hint {
  display: none;
}

#room.is-playing .room-heading h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

#room.is-playing + #game {
  margin-top: 0.75rem;
}

.room-controls {
  display: flex;
  align-items: end;
  gap: 0.8rem;
}

.dev-switch {
  min-width: 170px;
}

.players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.8rem;
  margin: 1rem 0;
}

.player {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(0, 0, 0, 0.18);
}

.player.is-me {
  border-color: var(--gold);
}

.player h3 {
  margin-bottom: 0.35rem;
}

.player p {
  margin-bottom: 0;
  color: var(--muted);
}

.start-button {
  width: 100%;
}

#game {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.65rem;
}

.score {
  padding: 0.85rem;
  border-radius: 0.85rem;
  background: rgba(0, 0, 0, 0.2);
}

.score strong,
.score span {
  display: block;
}

.score span {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.action-panel h2 {
  margin-bottom: 0.5rem;
}

.status-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 0.55fr);
  gap: 1rem;
  align-items: start;
}

.status-heading h2 {
  margin-bottom: 0.5rem;
}

.status-heading > div > p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

.turn-status {
  border-color: rgba(255, 200, 87, 0.42);
  background:
    linear-gradient(120deg, rgba(255, 200, 87, 0.08), transparent 45%),
    var(--panel);
}

.now-label::before {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.45rem;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 0.3rem rgba(255, 200, 87, 0.12);
  content: "";
}

.rules-tip {
  display: grid;
  gap: 0.35rem;
  padding: 0.9rem;
  border-left: 3px solid var(--gold);
  border-radius: 0.65rem;
  color: var(--muted);
  background: rgba(255, 200, 87, 0.08);
}

.rules-tip strong {
  color: var(--gold);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.phase-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 1.2rem 0 0;
  padding: 0;
  list-style: none;
}

.phase-steps li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.16);
}

.phase-steps li > span {
  display: grid;
  flex: 0 0 1.65rem;
  width: 1.65rem;
  height: 1.65rem;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  font-size: 0.78rem;
  background: var(--panel-light);
}

.phase-steps li > strong {
  overflow: hidden;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phase-steps .is-done {
  color: var(--green);
}

.phase-steps .is-current {
  border-color: var(--gold);
  color: var(--ink);
  background: rgba(255, 200, 87, 0.1);
}

.phase-steps .is-current > span {
  color: #211326;
  background: var(--gold);
}

.summary-note {
  margin-bottom: 0;
  color: var(--muted);
}

.game-table {
  padding: clamp(1rem, 2.5vw, 1.5rem);
  background:
    radial-gradient(circle at 50% 45%, rgba(91, 212, 156, 0.08), transparent 45%),
    rgba(25, 18, 33, 0.96);
}

.table-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.table-heading h2 {
  margin-bottom: 0.4rem;
}

.table-heading p:last-child {
  max-width: 62ch;
  margin-bottom: 0;
  color: var(--muted);
}

.turn-order {
  display: grid;
  gap: 0.25rem;
  max-width: 45%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: rgba(0, 0, 0, 0.2);
}

.turn-order strong {
  color: var(--gold);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.turn-order span {
  color: var(--muted);
  font-size: 0.78rem;
}

.table-players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.8rem;
}

.table-player {
  min-width: 0;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(49, 33, 62, 0.72);
}

.table-player.is-me {
  border-color: rgba(255, 200, 87, 0.6);
}

.table-player.is-current {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 200, 87, 0.13);
}

.table-player.is-dead {
  opacity: 0.62;
}

.table-player-heading {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.65rem;
}

.table-player-heading > img,
.wizard-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 0.8rem;
  object-fit: cover;
  background: var(--panel-light);
}

.wizard-placeholder {
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 1.5rem;
  font-weight: 900;
}

.table-player-heading p,
.table-player-heading h3,
.table-player-heading span {
  margin-bottom: 0;
}

.table-player-heading p {
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 800;
}

.table-player-heading h3 {
  margin: 0.12rem 0;
  font-size: 1rem;
}

.table-player-heading span {
  color: var(--muted);
  font-size: 0.75rem;
}

.player-state {
  padding: 0.35rem 0.5rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.66rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.25);
}

.table-player.is-current .player-state {
  color: #211326;
  background: var(--gold);
}

.table-spell {
  margin-top: 0.75rem;
  padding: 0.7rem;
  border-radius: 0.8rem;
  background: rgba(0, 0, 0, 0.2);
}

.table-spell > p:first-child {
  margin-bottom: 0.55rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.table-spell-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.table-spell-card,
.spell-card-back {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: #21172c;
}

.table-spell-card img {
  display: block;
  width: 100%;
  aspect-ratio: 0.72;
  object-fit: cover;
}

.table-spell-card > div {
  padding: 0.45rem;
}

.table-spell-card span,
.table-spell-card strong {
  display: block;
}

.table-spell-card span {
  margin-bottom: 0.15rem;
  color: var(--gold);
  font-size: 0.56rem;
  font-weight: 900;
  text-transform: uppercase;
}

.table-spell-card strong {
  font-size: 0.68rem;
  line-height: 1.15;
}

.table-spell-card.is-resolved {
  opacity: 0.48;
}

.table-spell-card.is-current {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 200, 87, 0.16);
}

.spell-card-back {
  display: grid;
  min-height: 145px;
  place-items: center;
  align-content: center;
  gap: 0.3rem;
  color: var(--muted);
  text-align: center;
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(255, 200, 87, 0.08) 0 8px,
      transparent 8px 16px
    ),
    #21172c;
}

.spell-card-back span {
  color: var(--gold);
  font-size: 1.7rem;
  font-weight: 900;
}

.spell-card-back strong {
  padding: 0 0.3rem;
  font-size: 0.62rem;
}

.active-card-effect {
  display: grid;
  gap: 0.25rem;
  margin: 0.65rem 0 0;
  padding: 0.65rem;
  border-left: 3px solid var(--gold);
  border-radius: 0.55rem;
  color: var(--muted);
  font-size: 0.72rem;
  background: rgba(255, 200, 87, 0.07);
}

.active-card-effect strong {
  color: var(--ink);
}

.table-assets {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.65rem;
}

.table-card-group {
  min-width: 0;
}

.table-card-group > p {
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.empty-assets {
  color: var(--muted);
  font-size: 0.72rem;
}

.table-asset-cards {
  display: grid;
  gap: 0.4rem;
}

.table-asset-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: #21172c;
}

.table-asset-card img {
  width: 46px;
  height: 64px;
  object-fit: cover;
}

.table-asset-card > div {
  align-self: center;
  min-width: 0;
  padding: 0.4rem 0.5rem;
}

.table-asset-card strong,
.table-asset-card span {
  display: block;
}

.table-asset-card strong {
  margin-bottom: 0.15rem;
  color: var(--gold);
  font-size: 0.72rem;
}

.table-asset-card span {
  color: var(--muted);
  font-size: 0.64rem;
  line-height: 1.25;
}

.table-asset-card.is-hidden {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.65rem;
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(255, 200, 87, 0.08) 0 8px,
      transparent 8px 16px
    ),
    #21172c;
}

.table-asset-card.is-hidden strong {
  margin: 0;
  font-size: 1.1rem;
}

.scheduled-bonus {
  padding: 0.55rem 0.65rem;
  border-left: 3px solid var(--gold);
  border-radius: 0.55rem;
  color: var(--ink);
  font-size: 0.7rem;
  background: rgba(255, 200, 87, 0.08);
}

.empty-spell {
  display: grid;
  min-height: 72px;
  place-items: center;
  padding: 0.7rem;
  border: 1px dashed var(--line);
  border-radius: 0.65rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.battle-log h2 {
  margin-bottom: 0.7rem;
}

.battle-log ol {
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding-left: 1.3rem;
  color: var(--muted);
}

.battle-log li::marker {
  color: var(--gold);
  font-weight: 900;
}

.wizard-grid,
.hand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}

.card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: #21172c;
}

.card.selected {
  border: 2px solid var(--gold);
  transform: translateY(-3px);
}

.card img {
  display: block;
  width: 100%;
  aspect-ratio: 0.72;
  object-fit: cover;
  background: #0d0911;
}

.card-copy {
  padding: 0.9rem;
}

.card h3 {
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.card-text {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: pre-line;
}

.card-slot {
  margin-bottom: 0.25rem;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

.card button {
  width: 100%;
  margin-top: 0.8rem;
}

.card-select {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.choice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 1rem;
}

.hand-section h2 {
  margin-bottom: 0.3rem;
}

.hand-section > p {
  color: var(--muted);
}

.commit-bar {
  position: sticky;
  z-index: 4;
  bottom: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(23, 16, 31, 0.96);
  backdrop-filter: blur(12px);
}

.message {
  position: sticky;
  z-index: 10;
  top: 0.7rem;
  margin-bottom: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 0.8rem;
  color: #25121a;
  font-weight: 800;
  background: var(--hot);
}

.message.success {
  color: #082219;
  background: var(--green);
}

.hidden {
  display: none !important;
}

@media (max-width: 680px) {
  .hero {
    grid-template-columns: 95px 1fr;
    gap: 0.9rem;
  }

  .hero h1 {
    font-size: clamp(1.7rem, 8vw, 2.7rem);
  }

  .hero p:last-child {
    display: none;
  }

  .welcome-grid {
    grid-template-columns: 1fr;
  }

  .welcome-grid form + form {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .room-heading,
  .room-controls,
  .commit-bar,
  .status-heading,
  .table-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .status-heading,
  .table-heading {
    display: flex;
  }

  .room-controls {
    display: grid;
    grid-template-columns: 1fr auto;
  }

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

  .phase-steps,
  .table-players {
    grid-template-columns: 1fr;
  }

  .turn-order {
    max-width: none;
  }

  .phase-steps li > strong {
    white-space: normal;
  }

  .card-copy {
    padding: 0.7rem;
  }

  .card-text {
    max-height: 7rem;
    overflow: auto;
  }
}
