:root {
  --ink: #251914;
  --paper: #fff7df;
  --paper-deep: #ead6a1;
  --ember: #d66a32;
  --ember-dark: #a23d24;
  --moss: #446b4d;
  --moss-light: #7fa76e;
  --teal: #2f6f73;
  --night: #17232b;
  --shadow: rgba(27, 18, 12, 0.28);
  --line: rgba(37, 25, 20, 0.18);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  background:
    radial-gradient(circle at 10% 10%, rgba(214, 106, 50, 0.22), transparent 28rem),
    radial-gradient(circle at 90% 15%, rgba(47, 111, 115, 0.20), transparent 24rem),
    linear-gradient(135deg, #2c201a 0%, #15252b 55%, #1c3026 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.start-screen {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 2rem;
  min-height: 100vh;
  padding: clamp(1rem, 3vw, 3rem);
  overflow: hidden;
}

.start-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.moon {
  position: absolute;
  top: 9%;
  right: 18%;
  width: 120px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #fff1b8;
  box-shadow: 0 0 60px rgba(255, 241, 184, 0.45);
}

.table-glow {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: -12%;
  height: 42%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 197, 101, 0.5), rgba(118, 70, 35, 0.2) 45%, transparent 70%);
}

.floating-card,
.floating-die {
  position: absolute;
  display: grid;
  place-items: center;
  box-shadow: 0 20px 40px var(--shadow);
  animation: floaty 5s ease-in-out infinite;
}

.floating-card {
  width: 96px;
  height: 136px;
  border: 3px solid rgba(37, 25, 20, 0.5);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ember-dark);
  font-size: 3rem;
  font-weight: 900;
}

.floating-die {
  width: 86px;
  height: 86px;
  border-radius: 18px;
  transform: rotate(12deg);
  background: #f2c66d;
  color: var(--night);
  font-size: 2rem;
  font-weight: 900;
}

.card-a {
  left: 12%;
  top: 18%;
  transform: rotate(-14deg);
}

.card-k {
  left: 32%;
  bottom: 15%;
  transform: rotate(10deg);
  animation-delay: -1.8s;
}

.die-a {
  right: 30%;
  bottom: 23%;
  animation-delay: -0.8s;
}

.die-b {
  right: 12%;
  top: 38%;
  animation-delay: -2.4s;
}

@keyframes floaty {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -14px; }
}

.start-copy,
.rules-card,
.end-card,
.panel,
dialog {
  border: 1px solid rgba(255, 247, 223, 0.32);
  border-radius: var(--radius);
  background: rgba(255, 247, 223, 0.92);
  box-shadow: 0 24px 70px var(--shadow);
  backdrop-filter: blur(10px);
}

.start-copy {
  position: relative;
  align-self: end;
  max-width: 760px;
  padding: clamp(1.25rem, 4vw, 3rem);
}

.eyebrow {
  margin: 0 0 0.4rem;
  color: var(--teal);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.start-copy h1,
.end-card h1 {
  margin-bottom: 0.8rem;
  font-size: clamp(3rem, 8vw, 6rem);
  line-height: 0.9;
}

.subtitle {
  max-width: 56ch;
  font-size: 1.18rem;
  line-height: 1.55;
}

.name-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

label {
  display: grid;
  gap: 0.35rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 46px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 0 0.8rem;
  color: var(--ink);
  background: #fffdf3;
}

.rules-card {
  position: relative;
  align-self: center;
  padding: 1.4rem;
  font-size: 1.02rem;
  line-height: 1.45;
}

.rules-card ul {
  padding-left: 1.2rem;
}

.primary-btn,
.ghost-btn,
.danger-btn {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  padding: 0.65rem 1rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 900;
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
}

.primary-btn {
  color: #fffaf0;
  background: linear-gradient(180deg, var(--ember), var(--ember-dark));
  box-shadow: 0 8px 0 #6f271a, 0 14px 30px rgba(162, 61, 36, 0.3);
}

.ghost-btn {
  color: var(--ink);
  background: #fff7df;
  border: 2px solid var(--line);
}

.danger-btn {
  color: #fffaf0;
  background: linear-gradient(180deg, #8c385f, #57233c);
  box-shadow: 0 8px 0 #351629, 0 14px 30px rgba(87, 35, 60, 0.25);
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.04);
}

button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.game-screen {
  padding: 1rem;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 auto 1rem;
  max-width: 1480px;
  color: #fff7df;
}

.top-bar h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
}

.top-actions {
  display: flex;
  gap: 0.6rem;
}

.scoreboard,
.table-grid {
  max-width: 1480px;
  margin: 0 auto;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.player-strip {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) repeat(4, auto);
  gap: 0.75rem;
  align-items: center;
  min-height: 70px;
  padding: 0.8rem;
  border-radius: var(--radius);
  background: rgba(255, 247, 223, 0.9);
  border: 2px solid transparent;
}

.player-strip.active {
  border-color: #f1c06d;
  box-shadow: 0 0 0 4px rgba(241, 192, 109, 0.24);
}

.stat-pill {
  min-width: 70px;
  border-left: 1px solid var(--line);
  padding-left: 0.7rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 800;
}

.stat-pill strong {
  display: block;
  font-size: 1.15rem;
}

.table-grid {
  display: grid;
  grid-template-columns: 1.05fr 0.8fr 1fr;
  gap: 1rem;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 1rem;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 900;
}

.panel-title span {
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
}

.dungeon-panel,
.hand-panel,
.log-panel {
  grid-row: span 2;
}

.enemy-card {
  position: relative;
  min-height: 270px;
  display: grid;
  align-content: end;
  gap: 0.5rem;
  padding: 1rem;
  border-radius: var(--radius);
  color: #fff7df;
  background:
    linear-gradient(180deg, rgba(23, 35, 43, 0.15), rgba(23, 35, 43, 0.9)),
    linear-gradient(135deg, #425c4b, #3b2430 60%, #1c2529);
  overflow: hidden;
}

.enemy-card::before {
  content: "";
  position: absolute;
  inset: 15% 14% 28%;
  background:
    radial-gradient(circle at 50% 22%, #f3c96f 0 12%, transparent 13%),
    radial-gradient(circle at 38% 50%, #f3c96f 0 5%, transparent 6%),
    radial-gradient(circle at 62% 50%, #f3c96f 0 5%, transparent 6%),
    linear-gradient(135deg, transparent 42%, rgba(255,255,255,0.25) 43% 45%, transparent 46%);
  opacity: 0.55;
  filter: drop-shadow(0 10px 24px rgba(0,0,0,0.4));
}

.enemy-card > * {
  position: relative;
}

.enemy-card h2 {
  margin: 0;
  font-size: 2rem;
}

.enemy-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.enemy-meta span {
  border: 1px solid rgba(255, 247, 223, 0.28);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  background: rgba(0, 0, 0, 0.16);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 800;
}

.progress-wrap {
  margin-top: 1rem;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.86rem;
  font-weight: 900;
}

.progress-track {
  height: 12px;
  margin-top: 0.4rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(37, 25, 20, 0.14);
}

#progressFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--moss-light), var(--ember));
  transition: width 280ms ease;
}

.dungeon-actions,
.dice-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 1rem;
}

.piles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.deck-stack,
.discard-pile {
  position: relative;
  min-height: 170px;
  border: 0;
  border-radius: var(--radius);
  color: var(--paper);
  background: #334d46;
  box-shadow: 0 14px 30px var(--shadow);
  overflow: hidden;
}

.deck-stack span {
  position: absolute;
  inset: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: var(--radius);
}

.deck-stack span:nth-child(1) { transform: rotate(-5deg); background: #4f755e; }
.deck-stack span:nth-child(2) { transform: rotate(2deg); background: #bf6a3f; }
.deck-stack span:nth-child(3) { transform: rotate(7deg); background: #2f6f73; }

.deck-stack strong,
.discard-pile strong {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.7rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 1rem;
}

.discard-pile {
  display: grid;
  place-items: center;
  background: #f8edd1;
  color: var(--ink);
  border: 2px dashed rgba(37, 25, 20, 0.25);
}

#discardTop {
  display: grid;
  place-items: center;
  width: 74px;
  height: 104px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf3;
  font-size: 1.3rem;
  font-weight: 900;
}

.hint,
.roll-summary {
  min-height: 42px;
  margin-top: 0.8rem;
  color: rgba(37, 25, 20, 0.78);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.35;
}

.dice-tray {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  gap: 0.7rem;
  min-height: 112px;
}

.die {
  display: grid;
  gap: 0.25rem;
  place-items: center;
  min-height: 86px;
  border: 2px solid rgba(37, 25, 20, 0.2);
  border-radius: var(--radius);
  background: #fffdf3;
  box-shadow: inset 0 -8px 0 rgba(37, 25, 20, 0.08);
  user-select: none;
}

.die.locked {
  background: #dcebc8;
  border-color: var(--moss);
}

.die.rolling {
  animation: tumble 420ms ease;
}

.die strong {
  font-size: 2rem;
  line-height: 1;
}

.die span {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.72rem;
  font-weight: 900;
}

@keyframes tumble {
  0% { transform: rotate(0deg) scale(1); }
  35% { transform: rotate(-8deg) scale(1.06); }
  70% { transform: rotate(8deg) scale(0.96); }
  100% { transform: rotate(0deg) scale(1); }
}

.combo-buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.8rem;
}

.combo-buttons button {
  min-height: 40px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf3;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 900;
}

.hand-area {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.55rem;
  align-items: start;
}

.card {
  position: relative;
  min-height: 104px;
  border: 2px solid rgba(37, 25, 20, 0.18);
  border-radius: var(--radius);
  padding: 0.45rem;
  background: #fffdf3;
  box-shadow: 0 8px 18px rgba(27, 18, 12, 0.16);
  text-align: left;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.card.red {
  color: #a23d24;
}

.card.selected {
  transform: translateY(-8px);
  border-color: var(--ember);
  box-shadow: 0 14px 24px rgba(162, 61, 36, 0.22);
}

.card-rank {
  display: block;
  font-size: 1.35rem;
  font-weight: 900;
}

.card-suit {
  position: absolute;
  right: 0.45rem;
  bottom: 0.35rem;
  font-size: 1.45rem;
}

.log-panel {
  max-height: 430px;
}

.combat-log {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 350px;
  overflow: auto;
  padding-right: 0.2rem;
}

.log-entry {
  border-left: 4px solid var(--teal);
  padding: 0.5rem 0.65rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: rgba(255,255,255,0.42);
  line-height: 1.35;
}

.log-entry.hit { border-color: var(--ember); }
.log-entry.good { border-color: var(--moss-light); }
.log-entry.bad { border-color: #8c385f; }

.end-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.end-card {
  width: min(720px, 100%);
  padding: clamp(1.4rem, 5vw, 3rem);
  text-align: center;
}

dialog {
  width: min(680px, calc(100% - 2rem));
  border: 0;
  padding: 1.4rem;
  line-height: 1.55;
}

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

.close-btn {
  float: right;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--night);
  color: #fff7df;
  font-size: 1.5rem;
}

.pulse {
  animation: pulse 500ms ease;
}

@keyframes pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}

@media (max-width: 1050px) {
  .start-screen,
  .table-grid {
    grid-template-columns: 1fr;
  }

  .rules-card {
    align-self: end;
  }

  .dungeon-panel,
  .hand-panel,
  .log-panel {
    grid-row: auto;
  }
}

@media (max-width: 720px) {
  .game-screen {
    padding: 0.6rem;
  }

  .top-bar,
  .scoreboard,
  .player-strip,
  .name-grid,
  .combo-buttons {
    grid-template-columns: 1fr;
  }

  .top-bar {
    display: grid;
  }

  .scoreboard {
    gap: 0.6rem;
  }

  .player-strip {
    align-items: start;
  }

  .stat-pill {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 0.45rem 0 0;
  }

  .piles,
  .dungeon-actions,
  .dice-actions {
    grid-template-columns: 1fr;
  }

  .hand-area {
    grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  }
}
