:root {
  --night: #070d1c;
  --ink: #e9eef8;
  --muted: #93a3bd;
  --line: rgba(190, 212, 255, 0.16);
  --gold: #e8c27a;
  --gold-soft: #f6dfae;
  --glass: rgba(9, 15, 30, 0.8);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 50% 0%, #12203d 0%, #070d1c 55%, #04060d 100%);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 85% at 50% 35%, transparent 42%, rgba(2, 5, 12, 0.55) 100%);
}

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(14px, 2.4vw, 28px) clamp(16px, 3vw, 36px);
  pointer-events: none;
}

.brand {
  padding-top: 4px;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold-soft);
  text-shadow: 0 0 26px rgba(232, 194, 122, 0.35);
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.progress {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.bar {
  display: block;
  width: clamp(90px, 14vw, 160px);
  height: 2px;
  overflow: hidden;
  background: rgba(190, 212, 255, 0.18);
}

.bar i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #87b7ff, var(--gold));
  transition: width 0.5s ease;
}

.element-badge {
  padding: 6px 10px;
  border: 1px solid rgba(232, 194, 122, 0.4);
  border-radius: 999px;
  background: rgba(232, 194, 122, 0.08);
  color: var(--gold-soft);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---------- panel ---------- */

.content {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.panel {
  position: absolute;
  left: 50%;
  bottom: clamp(16px, 3vh, 32px);
  display: flex;
  flex-direction: column;
  width: min(780px, calc(100% - 32px));
  max-height: min(62vh, 560px);
  padding: 22px clamp(18px, 3vw, 30px) 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(13, 21, 40, 0.9), rgba(7, 12, 24, 0.94));
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
  pointer-events: auto;
}

.speaker {
  margin-bottom: 10px;
  color: var(--gold);
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.text {
  overflow: auto;
  padding-right: 8px;
  color: #e8eef8;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.62;
  scrollbar-width: thin;
}

.text p {
  margin: 0 0 12px;
}

.text p:last-child {
  margin-bottom: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  transition: opacity 0.2s ease;
}

.actions.busy {
  opacity: 0.55;
}

.btn {
  appearance: none;
  padding: 10px 16px;
  border: 1px solid rgba(190, 212, 255, 0.22);
  border-radius: 12px;
  background: rgba(190, 212, 255, 0.06);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: rgba(232, 194, 122, 0.55);
  background: rgba(232, 194, 122, 0.1);
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-primary {
  border-color: rgba(232, 194, 122, 0.6);
  background: linear-gradient(180deg, rgba(232, 194, 122, 0.2), rgba(232, 194, 122, 0.08));
  color: #fbeed2;
}

.stop-note {
  flex-basis: 100%;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.dice-hud {
  align-self: flex-start;
  margin-top: 12px;
  padding: 7px 12px;
  border: 1px solid rgba(190, 212, 255, 0.18);
  border-radius: 999px;
  background: rgba(190, 212, 255, 0.05);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.dice-hud.win {
  border-color: rgba(232, 194, 122, 0.5);
  color: var(--gold-soft);
}

.dice-hud.lose {
  border-color: rgba(255, 140, 120, 0.35);
  color: #e6a396;
}

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(190, 212, 255, 0.08);
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tag {
  color: rgba(147, 163, 189, 0.7);
}

/* ---------- overlays ---------- */

.loading,
.error {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  color: var(--muted);
  font-size: 13px;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

.error {
  border-color: rgba(255, 140, 120, 0.4);
  color: #f0b4a8;
  max-width: min(640px, calc(100% - 32px));
}

.fallback {
  position: absolute;
  top: clamp(64px, 10vh, 96px);
  left: 50%;
  max-width: min(640px, calc(100% - 32px));
  padding: 10px 14px;
  border: 1px solid rgba(232, 194, 122, 0.3);
  border-radius: 12px;
  background: rgba(20, 16, 10, 0.75);
  color: var(--gold-soft);
  font-size: 12px;
  line-height: 1.5;
  transform: translateX(-50%);
  pointer-events: auto;
}

.levelup {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.levelup-text {
  padding: 0 24px;
  color: #f8e9c8;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(22px, 4vw, 40px);
  letter-spacing: 0.04em;
  text-align: center;
  text-shadow: 0 0 60px rgba(232, 194, 122, 0.5);
  opacity: 0;
}

.levelup.visible .levelup-text {
  animation: levelup 3.2s ease forwards;
}

@keyframes levelup {
  0% {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  12% {
    opacity: 1;
    transform: none;
  }
  82% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.no-3d #scene {
  display: none;
}

.no-3d body,
body.no-3d {
  background:
    radial-gradient(90% 70% at 50% 0%, #182848 0%, #070d1c 60%, #04060d 100%);
}

/* ---------- mobile ---------- */

@media (max-width: 640px) {
  .hud {
    padding: 14px 16px;
  }

  .brand {
    max-width: 41vw;
    font-size: 9px;
    line-height: 1.5;
  }

  .hud-right {
    gap: 10px;
  }

  .progress {
    font-size: 8.5px;
    letter-spacing: 0.08em;
    white-space: nowrap;
  }

  .bar {
    width: 64px;
  }

  .panel {
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 58vh;
    padding: 16px 16px 12px;
    border-radius: 18px 18px 0 0;
    transform: none;
  }

  .text {
    font-size: 15.5px;
    line-height: 1.55;
  }

  .btn {
    padding: 9px 13px;
    font-size: 13px;
  }

  .tag {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bar i,
  .btn,
  .actions {
    transition: none;
  }

  .levelup.visible .levelup-text {
    animation: none;
    opacity: 1;
  }
}

.nopanel .panel,
.nopanel .hud {
  display: none;
}
