:root {
  --card-w: clamp(72px, 7.2vw, 98px);
  --card-h: calc(var(--card-w) * 1.42);
  --dungeon-gold: #f0c95d;
  --dungeon-cream: #fff7e4;
  --dungeon-muted: rgba(248, 239, 216, 0.68);
  --dungeon-panel: color-mix(in srgb, var(--table-rail) 82%, transparent);
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -10%, rgba(239, 197, 94, 0.16), transparent 30%),
    linear-gradient(180deg, rgba(4, 10, 7, 0.1), rgba(4, 10, 7, 0.54)),
    var(--table-background-image),
    var(--table-felt);
  background-attachment: fixed;
}

.dungeon-app {
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px clamp(14px, 2.3vw, 34px) 28px;
  display: grid;
  gap: 14px;
}

.dungeon-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 6px 4px 2px 132px;
}

.dungeon-title h1,
.rules-header h2 {
  margin: 0;
  color: var(--dungeon-cream);
  font-family: Georgia, Charter, serif;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
}

.dungeon-title > p:last-child {
  margin: 8px 0 0;
  color: var(--dungeon-muted);
  font-size: 0.92rem;
}

.dungeon-kicker,
.eyebrow {
  margin: 0 0 5px;
  color: var(--dungeon-gold);
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.dungeon-controls,
.action-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.dungeon-meters {
  display: grid;
  grid-template-columns: minmax(190px, 1.4fr) minmax(190px, 1.4fr) repeat(3, minmax(92px, 0.7fr));
  gap: 8px;
}

.adventure-meter,
.dungeon-stat {
  position: relative;
  min-height: 66px;
  border: 1px solid rgba(248, 239, 216, 0.18);
  border-radius: 10px;
  background: rgba(7, 18, 12, 0.55);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.05);
}

.adventure-meter {
  padding: 10px 34px 10px 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 5px;
  align-items: center;
  column-gap: 10px;
}

.meter-icon {
  grid-row: 1 / 3;
  color: #d65b52;
  font-family: Georgia, serif;
  font-size: 1.7rem;
}

.adventure-meter.torch .meter-icon { color: var(--dungeon-gold); }

.meter-copy {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.meter-copy small,
.dungeon-stat small {
  color: var(--dungeon-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.meter-copy strong,
.dungeon-stat strong { color: var(--dungeon-cream); }

.meter-track {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.1);
}

.meter-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #d65b52;
  transition: width 220ms ease;
}

.torch .meter-track i { background: var(--dungeon-gold); }

.dungeon-stat {
  padding: 11px 32px 9px 13px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.dungeon-stat strong { font-size: 1.35rem; }

.info-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(248, 239, 216, 0.3);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: rgba(248, 239, 216, 0.72);
  font-family: Georgia, serif;
  font-size: 0.7rem;
  font-style: italic;
}

[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 80;
  left: 50%;
  bottom: calc(100% + 9px);
  width: min(280px, 82vw);
  padding: 9px 11px;
  border: 1px solid rgba(240, 201, 93, 0.52);
  border-radius: 7px;
  background: #101b15;
  color: #fff7e4;
  box-shadow: 0 12px 28px rgba(0,0,0,.38);
  font-size: 0.78rem;
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

[data-tip]:hover::after,
[data-tip]:focus::after,
[data-tip]:focus-within::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.dungeon-board {
  min-width: 0;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  grid-template-areas:
    "torches route"
    "stage stage"
    "supplies supplies";
  gap: 10px;
}

.info-zone,
.encounter-stage {
  position: relative;
  border: 1px solid rgba(248, 239, 216, 0.17);
  border-radius: 12px;
  background:
    linear-gradient(145deg, rgba(255,255,255,.035), transparent 45%),
    rgba(8, 21, 14, 0.51);
  box-shadow: inset 0 1px rgba(255,255,255,.035), 0 12px 24px rgba(3, 8, 5, 0.1);
}

.zone-heading {
  position: relative;
  min-height: 29px;
  padding: 8px 31px 4px 11px;
  color: var(--dungeon-muted);
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.zone-heading .info-dot { top: 6px; }

.torch-rack { grid-area: torches; padding: 0 8px 8px; }
.torch-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.torch-slot {
  position: relative;
  height: 66px;
  overflow: hidden;
  border: 1px dashed rgba(248, 239, 216, 0.2);
  border-radius: 6px;
  display: grid;
  place-content: center;
  text-align: center;
  color: rgba(248,239,216,.32);
  background: rgba(0,0,0,.08);
}
.torch-slot > span { font-family: Georgia, serif; font-size: 1.25rem; }
.torch-slot > small { font-size: 0.54rem; text-transform: uppercase; }
.torch-slot:last-child { border-color: rgba(214,91,82,.35); color: rgba(214,91,82,.52); }
.torch-slot .playing-card { position: absolute; top: 0; left: 0; width: 100%; height: calc(100% * 1.42); border-radius: 5px; }

.route-section { grid-area: route; min-width: 0; }
.route-heading { display: flex; align-items: center; gap: 14px; }
.route-legend { margin-left: auto; color: rgba(248,239,216,.5); font-size: .58rem; letter-spacing: .02em; }
.route-legend i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--dungeon-gold); }
.route-legend .legend-retreat { background: #76b8ae; }
.route-scroll { overflow-x: auto; padding: 0 8px 8px; scrollbar-width: thin; }
.route-map {
  min-width: calc(var(--route-columns) * 67px);
  display: grid;
  grid-template-columns: repeat(var(--route-columns), minmax(59px, 1fr));
  grid-template-rows: 38px 38px;
  gap: 4px;
}
.route-slot {
  position: relative;
  overflow: hidden;
  border: 1px dashed rgba(248,239,216,.14);
  border-radius: 5px;
  display: grid;
  place-items: center;
  color: rgba(248,239,216,.24);
  background: rgba(0,0,0,.09);
}
.route-slot.retreat { border-color: rgba(118,184,174,.18); }
.route-depth { font-family: Georgia, serif; }
.route-slot .route-card { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 4px; background-size: cover; opacity: .75; }
.route-card.turn-won { outline: 2px solid rgba(240,201,93,.45); outline-offset: -3px; }
.route-card.turn-failed { filter: saturate(.45) brightness(.7); }
.turn-tag { z-index: 2; padding: 2px 5px; border-radius: 999px; color: #fff7e4; background: rgba(7,16,11,.82); font-size: .52rem; font-weight: 800; text-transform: uppercase; }
.route-slot.is-active { border: 1px solid var(--dungeon-gold); color: var(--dungeon-cream); }
.active-pulse { position: absolute; width: 30px; height: 30px; border-radius: 50%; background: rgba(240,201,93,.2); animation: chamber-pulse 1.8s ease-in-out infinite; }
.route-slot.is-active strong { z-index: 2; font-size: .65rem; text-transform: uppercase; }
.turning-point { color: var(--dungeon-gold); border-style: solid; }
.turning-point span { font-size: 1.2rem; line-height: 1; }
.turning-point small { position: absolute; bottom: 2px; font-size: .48rem; text-transform: uppercase; }

.encounter-stage {
  grid-area: stage;
  min-height: 240px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 0%, rgba(240,201,93,.12), transparent 39%),
    linear-gradient(145deg, rgba(0,0,0,.05), rgba(0,0,0,.2)),
    rgba(7,18,12,.5);
}
.encounter-stage.phase-lost { border-color: rgba(214,91,82,.5); }
.encounter-stage.phase-escaped { border-color: rgba(240,201,93,.58); }
.encounter-heading { padding: 12px 14px 4px; display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.encounter-heading h2 { margin: 1px 0 0; color: var(--dungeon-cream); font-family: Georgia, serif; font-size: 1.2rem; }
.phase-pill { padding: 5px 9px; border: 1px solid rgba(240,201,93,.35); border-radius: 999px; color: var(--dungeon-gold); background: rgba(0,0,0,.13); font-size: .64rem; font-weight: 800; text-transform: uppercase; }
.encounter-cards { min-height: 188px; padding: 2px 18px 16px; display: flex; align-items: center; justify-content: center; overflow-x: auto; }
.encounter-card-wrap { position: relative; flex: 0 0 var(--card-w); margin-left: calc(var(--card-w) * -.2); padding-bottom: 24px; transition: transform 160ms ease; }
.encounter-card-wrap:first-child { margin-left: 0; }
.encounter-card-wrap:hover { z-index: 10; transform: translateY(-5px); }
.encounter-card-wrap .playing-card:hover { transform: none; }
.card-role { position: absolute; z-index: 4; left: 50%; bottom: 2px; width: max-content; max-width: calc(var(--card-w) + 18px); padding: 3px 6px; border-radius: 999px; transform: translateX(-50%); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff7e4; background: rgba(8,18,13,.9); box-shadow: 0 3px 8px rgba(0,0,0,.24); font-size: .58rem; font-weight: 700; }
.empty-chamber { display: grid; place-items: center; color: rgba(248,239,216,.4); text-align: center; }
.empty-chamber > span { font-family: Georgia, serif; font-size: 3rem; color: rgba(240,201,93,.28); }
.empty-chamber p { margin: -7px 0 0; font-size: .78rem; }

.supply-row { grid-area: supplies; display: grid; grid-template-columns: repeat(3, 150px) minmax(0, 1fr); gap: 10px; }
.supply-zone { min-height: 145px; padding: 0 9px 9px; }
.mini-pile { position: relative; height: 103px; display: grid; place-items: center; }
.mini-pile .playing-card { width: 64px; height: 91px; }
.pile-badge { position: absolute; right: calc(50% - 42px); bottom: 1px; min-width: 23px; height: 23px; padding: 0 5px; border: 2px solid #fff7e4; border-radius: 999px; display: grid; place-items: center; color: #17231c; background: var(--dungeon-gold); font-size: .66rem; font-weight: 900; }
.empty-mark { width: 64px; height: 91px; border: 1px dashed rgba(248,239,216,.2); border-radius: 7px; display: grid; place-items: center; color: rgba(248,239,216,.28); font-family: Georgia,serif; font-size: 1.4rem; }

.hand-zone { min-width: 0; min-height: 145px; padding: 0 9px 9px; }
.hand-zone .zone-heading { display: flex; gap: 12px; }
.hand-key { margin-left: auto; color: rgba(248,239,216,.42); font-size: .57rem; letter-spacing: 0; text-transform: none; }
.hand-cards { min-height: 103px; display: flex; align-items: center; gap: 7px; overflow-x: auto; padding: 2px 3px 7px; }
.hand-card-wrap { position: relative; flex: 0 0 64px; padding-bottom: 16px; }
.hand-card-wrap .playing-card { width: 64px; height: 91px; border-radius: 6px; }
.hand-card-wrap.can-drop .playing-card { cursor: pointer; outline: 3px solid var(--dungeon-gold); outline-offset: 1px; animation: drop-glow 1.4s ease-in-out infinite; }
.hand-card-wrap.can-drop .playing-card:disabled { pointer-events: none; }
.hand-label { position: absolute; z-index: 5; left: 50%; bottom: 0; max-width: 82px; padding: 2px 5px; border-radius: 999px; transform: translateX(-50%); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff7e4; background: rgba(8,18,13,.92); font-size: .51rem; }
.empty-hand { margin: auto; color: rgba(248,239,216,.4); font-size: .76rem; }

.playing-card:disabled { opacity: 1; color: var(--suit-ink); }
.card-back { background: var(--card-back-image), linear-gradient(135deg,#243b2d,#13241a); background-size: cover; }
.joker-card { display: grid; place-items: center; align-content: center; gap: 2px; color: #8f4c37 !important; background: radial-gradient(circle at center, rgba(240,201,93,.42), transparent 36%), var(--card-face); }
.joker-corner { position: absolute; left: 8px; top: 7px; font-size: 1rem; }
.joker-art { font-size: calc(var(--card-w) * .4); line-height: 1; }
.joker-card strong { font-family: Georgia,serif; font-size: calc(var(--card-w) * .12); letter-spacing: .12em; }
.joker-card small { font-size: calc(var(--card-w) * .07); }
.hand-card-wrap .joker-card .joker-art, .mini-pile .joker-card .joker-art { font-size: 1.7rem; }
.hand-card-wrap .joker-card strong, .mini-pile .joker-card strong { font-size: .48rem; }
.hand-card-wrap .joker-card small, .mini-pile .joker-card small { font-size: .36rem; }

.action-panel {
  min-height: 82px;
  padding: 13px 15px;
  border: 1px solid rgba(240,201,93,.34);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: linear-gradient(100deg, rgba(240,201,93,.09), rgba(7,18,12,.65) 48%);
  box-shadow: 0 16px 28px rgba(2,8,4,.16);
}
.action-copy p { margin: 2px 0 0; max-width: 76ch; color: #fff7e4; font-size: .88rem; line-height: 1.35; }
.primary-action,
.secondary-action,
.retreat-action,
.skill-action,
.danger-action {
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  color: #172119;
  background: var(--dungeon-gold);
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(0,0,0,.18);
}
.secondary-action { color: var(--dungeon-cream); border-color: rgba(248,239,216,.28); background: rgba(255,255,255,.08); }
.retreat-action { color: #10211e; background: #76b8ae; }
.skill-action { color: #1b1730; background: #b6a3e4; }
.danger-action { color: #fff7e4; background: #a8433f; }
.drop-hint { align-self: center; max-width: 130px; color: var(--dungeon-muted); font-size: .66rem; line-height: 1.2; }

.dungeon-footer { position: relative; min-height: 28px; padding: 2px 5px; display: flex; align-items: center; gap: 18px; color: var(--dungeon-muted); font-size: .7rem; }
.log-toggle { margin-left: auto; border: 0; color: var(--dungeon-gold); background: transparent; cursor: pointer; font: inherit; }
.adventure-log { display: none; position: absolute; z-index: 40; right: 0; bottom: 30px; width: min(430px, 92vw); margin: 0; padding: 13px 13px 13px 30px; border: 1px solid rgba(240,201,93,.4); border-radius: 8px; color: #fff7e4; background: #101b15; box-shadow: 0 18px 36px rgba(0,0,0,.4); line-height: 1.45; }
.adventure-log.is-open { display: block; }

.rules-dialog {
  width: min(920px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 0;
  border: 1px solid rgba(240,201,93,.48);
  border-radius: 16px;
  color: #fff7e4;
  background: #14231b;
  box-shadow: 0 30px 90px rgba(0,0,0,.72);
}
.rules-dialog::backdrop { background: rgba(2,7,4,.76); backdrop-filter: blur(5px); }
.rules-header { position: sticky; z-index: 5; top: 0; padding: 22px 24px 17px; display: flex; justify-content: space-between; align-items: start; background: linear-gradient(180deg,#14231b 78%,transparent); }
.rules-header h2 { font-size: clamp(1.7rem,4vw,2.4rem); }
.dialog-close { width: 36px; height: 36px; border: 1px solid rgba(248,239,216,.24); border-radius: 50%; color: #fff7e4; background: rgba(255,255,255,.06); cursor: pointer; font-size: 1.4rem; }
.rules-objective { margin: 0 24px 15px; padding: 13px 15px; border-left: 3px solid var(--dungeon-gold); background: rgba(240,201,93,.07); }
.rules-objective span { color: var(--dungeon-gold); font-size: .65rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.rules-objective p { margin: 4px 0 0; line-height: 1.45; }
.rules-grid { padding: 0 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.rules-grid article { position: relative; min-height: 150px; padding: 14px 14px 14px 56px; border: 1px solid rgba(248,239,216,.12); border-radius: 9px; background: rgba(255,255,255,.035); }
.rules-grid h3, .rules-tips h3 { margin: 0 0 6px; font-family: Georgia,serif; font-size: 1rem; }
.rules-grid p { margin: 0; color: rgba(248,239,216,.7); font-size: .78rem; line-height: 1.45; }
.rule-suit { position: absolute; left: 15px; top: 13px; font-family: Georgia,serif; font-size: 1.8rem; }
.rule-suit.red { color: #d65b52; }
.rule-suit.black { color: #d7ddd7; }
.card-key { margin: 10px 24px; padding: 10px; display: flex; flex-wrap: wrap; gap: 6px; border: 1px solid rgba(248,239,216,.12); border-radius: 9px; }
.card-key span { padding: 4px 7px; border-radius: 5px; color: rgba(248,239,216,.74); background: rgba(0,0,0,.12); font-size: .68rem; }
.card-key b { color: var(--dungeon-gold); }
.rules-tips { margin: 0 24px; }
.rules-tips ol { margin: 0; padding-left: 20px; color: rgba(248,239,216,.72); font-size: .76rem; line-height: 1.6; }
.rules-actions { padding: 16px 24px 22px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.rules-actions a { color: #9bd4ca; font-size: .76rem; }

@keyframes chamber-pulse { 50% { transform: scale(1.35); opacity: .4; } }
@keyframes drop-glow { 50% { box-shadow: 0 0 20px rgba(240,201,93,.62); } }

@media (max-width: 900px) {
  .dungeon-header { padding-left: 0; }
  .dungeon-meters { grid-template-columns: 1fr 1fr repeat(3, minmax(74px,.55fr)); }
  .dungeon-board { grid-template-columns: 200px minmax(0,1fr); }
  .supply-row { grid-template-columns: repeat(3, 118px) minmax(260px,1fr); overflow-x: auto; }
}

@media (max-width: 680px) {
  :root { --card-w: 78px; }
  .dungeon-app { padding: 12px 10px 20px; gap: 10px; }
  .dungeon-header { align-items: start; flex-direction: column; gap: 12px; }
  .dungeon-title h1 { font-size: 2.25rem; }
  .dungeon-controls { justify-content: start; }
  .dungeon-meters { grid-template-columns: 1fr 1fr 1fr; }
  .adventure-meter { grid-column: span 3; }
  .dungeon-stat { min-height: 54px; }
  .dungeon-board { grid-template-columns: 1fr; grid-template-areas: "torches" "route" "stage" "supplies"; }
  .torch-rack { max-width: 330px; }
  .encounter-stage { min-height: 220px; }
  .encounter-cards { justify-content: flex-start; min-height: 166px; }
  .supply-row { grid-template-columns: repeat(3, 110px) minmax(260px, 1fr); }
  .action-panel { align-items: stretch; flex-direction: column; gap: 10px; }
  .action-buttons { justify-content: start; }
  .rules-grid { grid-template-columns: 1fr; }
  .rules-grid article { min-height: auto; }
}

@media (max-width: 420px) {
  .dungeon-controls .theme-select { max-width: 130px; }
  .encounter-heading { align-items: start; flex-direction: column; gap: 6px; }
  .rules-header, .rules-actions { padding-left: 16px; padding-right: 16px; }
  .rules-objective, .rules-tips { margin-left: 16px; margin-right: 16px; }
  .rules-grid { padding: 0 16px; }
  .card-key { margin-left: 16px; margin-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .active-pulse, .hand-card-wrap.can-drop .playing-card { animation: none; }
}
