:root {
  color-scheme: dark;
  --bg: #101217;
  --panel: rgba(14, 16, 22, 0.82);
  --panel-2: rgba(27, 31, 40, 0.9);
  --line: rgba(245, 241, 232, 0.18);
  --text: #f5f1e8;
  --muted: #bbb3a5;
  --gold: #e7b75f;
  --green: #69c48f;
  --red: #df6d62;
  --blue: #70a9cf;
  --ink: #0c0d10;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(16, 18, 23, 0.92), #101217),
    repeating-linear-gradient(90deg, #151820 0 2px, #111319 2px 4px);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1280px, calc(100vw - 24px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 10px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 0 10px;
}

.top-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 2.2vw, 2.25rem);
  line-height: 1.02;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(1.3rem, 2vw, 2rem);
  line-height: 1.12;
}

h3 {
  margin-bottom: 8px;
  font-size: 1rem;
  line-height: 1.25;
}

.start-panel,
.summary-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
  gap: 24px;
  align-items: stretch;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(36, 42, 51, 0.96), rgba(19, 22, 28, 0.96));
  padding: 26px;
}

.start-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 620px;
}

.start-copy p {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.primary-action,
.secondary-action,
.icon-action {
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms ease, filter 160ms ease;
}

.primary-action {
  width: fit-content;
  min-height: 44px;
  margin-top: 8px;
  padding: 0 18px;
  color: var(--ink);
  background: var(--gold);
}

.secondary-action {
  min-height: 38px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(36, 42, 51, 0.94);
  border: 1px solid var(--line);
}

.icon-action {
  min-height: 34px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(12, 13, 16, 0.7);
  border: 1px solid var(--line);
}

.primary-action:hover,
.secondary-action:hover,
.icon-action:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.start-card {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 34%, rgba(231, 183, 95, 0.2), transparent 34%),
    repeating-linear-gradient(0deg, #20252d 0 16px, #1b2028 16px 32px);
}

.mini-map {
  display: grid;
  gap: 8px;
}

.map-node {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  color: var(--muted);
  font-size: 0.84rem;
}

.map-dot {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: #171a20;
  font-size: 0.72rem;
  font-weight: 800;
}

.game-panel {
  display: block;
}

.encounter-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0b0d11;
}

.scene-frame {
  position: relative;
  height: min(760px, calc(100dvh - 112px));
  min-height: 600px;
  overflow: hidden;
  background: #0b0d11;
}

.scene-background,
.scene-monster {
  position: absolute;
  image-rendering: pixelated;
}

.scene-background {
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scene-monster {
  left: 50%;
  bottom: min(138px, 19%);
  z-index: 1;
  width: min(43%, 440px);
  max-width: 64%;
  height: min(54%, 420px);
  object-fit: contain;
  object-position: center bottom;
  transform: translateX(-50%);
  filter: drop-shadow(0 18px 14px rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

.scene-frame.has-boss .scene-monster {
  width: min(52%, 540px);
  height: min(62%, 500px);
}

.scene-vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  background:
    linear-gradient(180deg, rgba(6, 8, 12, 0.68), rgba(6, 8, 12, 0) 28%, rgba(6, 8, 12, 0.72)),
    radial-gradient(circle at 50% 44%, transparent 0 44%, rgba(0, 0, 0, 0.45) 78%);
  pointer-events: none;
}

.effect-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.scene-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(120px, 0.8fr) minmax(130px, 0.8fr) auto;
  gap: 8px;
  align-items: start;
}

.hud-bar,
.loot-hud,
.room-chip,
.enemy-hud,
.inventory-popover,
.dialogue-panel {
  border: 1px solid rgba(245, 241, 232, 0.12);
  border-radius: var(--radius);
  background: rgba(8, 10, 14, 0.42);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(6px);
}

.hud-bar {
  min-width: 0;
  padding: 8px 10px;
}

.hud-bar span,
.enemy-hud small,
.room-chip span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.hud-bar strong,
.enemy-hud strong,
.room-chip strong {
  display: block;
  margin-top: 3px;
  font-size: 0.9rem;
}

.meter {
  position: relative;
  width: 100%;
  height: 7px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(245, 241, 232, 0.18);
}

.meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--red);
  transition: width 220ms ease;
}

.meter.xp i {
  background: var(--blue);
}

.meter.mastery i {
  background: var(--green);
}

.meter.monster i {
  background: var(--red);
}

.loot-hud {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  min-height: 52px;
  padding: 8px;
}

.loot-strip {
  display: flex;
  gap: 6px;
}

.loot-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(231, 183, 95, 0.55);
  border-radius: 6px;
  color: var(--gold);
  background: rgba(12, 13, 16, 0.74);
  font-size: 0.72rem;
  font-weight: 900;
}

.room-chip {
  position: absolute;
  top: 76px;
  left: 12px;
  z-index: 4;
  min-width: 134px;
  padding: 8px 10px;
}

.enemy-hud {
  position: absolute;
  top: 76px;
  right: 12px;
  z-index: 4;
  width: 230px;
  padding: 9px 10px;
}

.enemy-hud span {
  display: block;
  font-weight: 900;
}

.dice-tray {
  position: absolute;
  right: 18px;
  bottom: 232px;
  z-index: 5;
  display: grid;
  gap: 6px;
  min-height: 44px;
}

.roll-card {
  display: grid;
  grid-template-columns: 44px minmax(104px, auto);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(8, 10, 14, 0.78);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
  padding: 7px;
}

.die {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid #f8e4b3;
  border-radius: 8px;
  color: var(--ink);
  background: #f7d886;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32);
  font-weight: 900;
}

.roll-formula {
  min-width: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.1;
  white-space: nowrap;
}

.roll-formula strong {
  display: block;
  color: var(--text);
  font-size: 1.05rem;
}

.roll-formula b {
  color: var(--gold);
}

.roll-card.is-success .roll-formula strong {
  color: var(--green);
}

.roll-card.is-fail .roll-formula strong {
  color: var(--red);
}

.die.is-rolling {
  animation: roll 520ms ease-in-out;
}

.dialogue-panel {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(190px, 0.58fr) minmax(0, 1.42fr);
  gap: 8px;
  padding: 8px 10px;
  border-color: rgba(245, 241, 232, 0.08);
  background: linear-gradient(180deg, rgba(7, 9, 13, 0.42), rgba(7, 9, 13, 0.2));
  box-shadow: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.82);
}

.dm-box {
  min-width: 0;
  padding: 3px 2px;
}

.dm-box p:last-child {
  margin-bottom: 0;
  color: rgba(245, 241, 232, 0.82);
  font-size: 0.94rem;
  line-height: 1.34;
}

.question-card,
.result-panel {
  min-width: 0;
  border: 0;
  border-radius: 6px;
  background: rgba(6, 8, 12, 0.22);
  padding: 7px 8px;
}

.question-label {
  margin-bottom: 5px;
  color: var(--blue);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.question-card h3 {
  margin-bottom: 7px;
  font-size: 1.08rem;
  line-height: 1.2;
}

.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.answer-button {
  min-height: 38px;
  border: 1px solid rgba(245, 241, 232, 0.14);
  border-radius: 6px;
  color: var(--text);
  background: rgba(11, 14, 19, 0.5);
  cursor: pointer;
  text-align: left;
  padding: 7px 9px;
  font-size: 0.94rem;
  line-height: 1.16;
  backdrop-filter: blur(2px);
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.answer-button:hover {
  border-color: var(--gold);
  background: rgba(16, 19, 26, 0.68);
  transform: translateY(-1px);
}

.answer-button.is-correct {
  border-color: var(--green);
  background: rgba(105, 196, 143, 0.24);
}

.answer-button.is-wrong {
  border-color: var(--red);
  background: rgba(223, 109, 98, 0.24);
}

.answer-button:disabled {
  cursor: default;
  transform: none;
}

.question-card.is-resolved {
  padding: 6px 8px;
}

.question-card.is-resolved .question-label,
.question-card.is-resolved .answers {
  display: none;
}

.question-card.is-resolved h3 {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.result-panel {
  display: grid;
  grid-column: 2;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.9fr) auto;
  align-items: start;
  gap: 8px;
  margin-top: 6px;
}

.result-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.38;
}

.explanation {
  border-left: 1px solid var(--line);
  padding-left: 10px;
}

.explanation strong {
  color: var(--gold);
}

.inventory-popover {
  position: absolute;
  top: 76px;
  right: 12px;
  z-index: 6;
  width: 250px;
  padding: 12px;
}

.inventory-popover ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.5;
}

.scene-frame.hit .scene-monster {
  animation: monsterHitShake 520ms cubic-bezier(0.2, 0.8, 0.24, 1);
}

.scene-frame.hit .effect-layer::before {
  content: "";
  position: absolute;
  inset: 16% 22% 30%;
  background:
    linear-gradient(135deg, transparent 42%, rgba(245, 241, 232, 0.92) 47%, transparent 52%),
    radial-gradient(circle at 52% 52%, rgba(231, 183, 95, 0.36), transparent 36%);
  animation: slash 460ms ease;
}

.scene-frame.miss .effect-layer::before,
.scene-frame.damage .effect-layer::before {
  content: "";
  position: absolute;
  inset: 10% 5% 20%;
  background:
    linear-gradient(112deg, transparent 0 39%, rgba(255, 235, 222, 0.82) 40% 41.5%, rgba(118, 11, 13, 0.58) 42.5% 44%, transparent 45%),
    linear-gradient(72deg, transparent 0 52%, rgba(255, 235, 222, 0.64) 53% 54%, rgba(118, 11, 13, 0.5) 55% 56%, transparent 57%);
  mix-blend-mode: screen;
  animation: scratchFlash 560ms ease forwards;
}

.scene-frame.miss .effect-layer::after,
.scene-frame.damage .effect-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 48%, transparent 0 42%, rgba(223, 109, 98, 0.24) 72%),
    rgba(223, 109, 98, 0.2);
  animation: fadeOut 520ms ease forwards;
}

.scene-frame.reward .effect-layer::before {
  content: "";
  position: absolute;
  inset: 18% 22%;
  border: 2px solid rgba(231, 183, 95, 0.8);
  box-shadow: 0 0 44px rgba(231, 183, 95, 0.34);
  animation: pulse 760ms ease;
}

.summary-panel {
  display: block;
  min-height: 0;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.summary-grid div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 14px;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.summary-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 1.35rem;
}

.is-hidden {
  display: none !important;
}

@keyframes roll {
  0% { transform: rotate(0deg) scale(1); }
  35% { transform: rotate(18deg) scale(1.12); }
  70% { transform: rotate(-14deg) scale(0.96); }
  100% { transform: rotate(0deg) scale(1); }
}

@keyframes slash {
  from { opacity: 0; transform: translateX(-18%) scaleX(0.2); }
  30% { opacity: 1; }
  to { opacity: 0; transform: translateX(18%) scaleX(1); }
}

@keyframes monsterHitShake {
  0%, 100% { transform: translateX(-50%) translateY(0) rotate(0deg); }
  16% { transform: translateX(calc(-50% - 10px)) translateY(2px) rotate(-2deg); }
  32% { transform: translateX(calc(-50% + 9px)) translateY(-1px) rotate(2deg); }
  48% { transform: translateX(calc(-50% - 7px)) translateY(1px) rotate(-1deg); }
  64% { transform: translateX(calc(-50% + 5px)) translateY(0) rotate(1deg); }
  82% { transform: translateX(calc(-50% - 2px)) translateY(0) rotate(0deg); }
}

@keyframes scratchFlash {
  0% { opacity: 0; transform: translateX(-8%) scaleX(0.82); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translateX(5%) scaleX(1.02); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(7px); }
  75% { transform: translateX(-4px); }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes pulse {
  from { opacity: 0; transform: scale(0.82); }
  35% { opacity: 1; }
  to { opacity: 0; transform: scale(1.08); }
}

@media (max-width: 980px) {
  .start-panel {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
  }

  .scene-frame {
    height: calc(100dvh - 84px);
    min-height: 0;
  }

  .scene-hud {
    grid-template-columns: minmax(82px, 1fr) minmax(82px, 1fr) minmax(88px, 1fr) auto;
  }

  .loot-hud {
    grid-column: auto;
    justify-content: flex-end;
  }

  .room-chip,
  .enemy-hud {
    top: 72px;
  }

  .dialogue-panel {
    grid-template-columns: 1fr;
    max-height: min(330px, 43dvh);
    overflow: auto;
  }

  .scene-monster {
    bottom: min(280px, 34%);
    width: min(58%, 420px);
    height: min(46%, 380px);
  }

  .result-panel {
    grid-column: 1;
    grid-template-columns: 1fr;
  }

  .explanation {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 10px 0 0;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 10px, 1280px);
    padding: 4px 0 6px;
  }

  .topbar {
    min-height: 38px;
    padding: 2px 0 5px;
  }

  .topbar .eyebrow,
  .top-note {
    display: none;
  }

  h1 {
    font-size: 1.05rem;
  }

  .start-panel,
  .summary-panel {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .scene-frame {
    height: calc(100dvh - 50px);
    min-height: 0;
  }

  .scene-hud {
    top: 7px;
    left: 7px;
    right: 7px;
    grid-template-columns: minmax(72px, 1fr) minmax(72px, 1fr) minmax(78px, 1fr) auto;
    gap: 4px;
  }

  .hud-bar {
    padding: 5px 6px;
  }

  .hud-bar span,
  .enemy-hud small,
  .room-chip span {
    font-size: 0.6rem;
  }

  .hud-bar strong,
  .enemy-hud strong,
  .room-chip strong {
    font-size: 0.72rem;
  }

  .meter {
    height: 5px;
    margin-top: 4px;
  }

  .loot-hud {
    grid-column: auto;
    min-height: 37px;
    padding: 4px;
  }

  .icon-action {
    min-height: 28px;
    padding: 0 8px;
    font-size: 0.72rem;
  }

  .loot-icon {
    width: 26px;
    height: 26px;
    font-size: 0.64rem;
  }

  .room-chip {
    top: 55px;
    left: 7px;
    min-width: 105px;
    padding: 5px 7px;
  }

  .enemy-hud,
  .inventory-popover {
    top: 55px;
    right: 7px;
    width: min(178px, calc(100% - 126px));
    padding: 6px 7px;
  }

  .inventory-popover {
    left: auto;
    width: 210px;
  }

  .dialogue-panel {
    left: 6px;
    right: 6px;
    bottom: 6px;
    max-height: 43dvh;
    padding: 6px;
    gap: 6px;
  }

  .scene-monster {
    bottom: calc(43dvh + 12px);
    width: min(76%, 300px);
    height: 32dvh;
  }

  .scene-frame.has-boss .scene-monster {
    width: min(86%, 340px);
    height: 36dvh;
  }

  .dm-box p:last-child {
    display: -webkit-box;
    overflow: hidden;
    font-size: 0.86rem;
    line-height: 1.26;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .question-card,
  .result-panel {
    padding: 6px;
  }

  .question-label {
    margin-bottom: 3px;
    font-size: 0.63rem;
  }

  h3 {
    margin-bottom: 6px;
    font-size: 0.82rem;
  }

  .question-card h3 {
    margin-bottom: 6px;
    font-size: 1.02rem;
    line-height: 1.16;
  }

  .answers {
    gap: 5px;
  }

  .answer-button {
    min-height: 38px;
    padding: 6px 7px;
    font-size: 0.94rem;
    line-height: 1.12;
  }

  .result-panel {
    gap: 7px;
    margin-top: 6px;
  }

  .result-panel p {
    font-size: 0.84rem;
    line-height: 1.28;
  }

  .secondary-action {
    min-height: 34px;
    font-size: 0.84rem;
  }

  .dice-tray {
    right: 10px;
    bottom: calc(43dvh + 18px);
  }

  .roll-card {
    grid-template-columns: 34px minmax(82px, auto);
    gap: 6px;
    padding: 5px;
  }

  .die {
    width: 34px;
    height: 34px;
    font-size: 0.82rem;
  }

  .roll-formula {
    font-size: 0.62rem;
  }

  .roll-formula strong {
    font-size: 0.9rem;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }
}
