:root {
  --navy: #0b1220;
  --panel: rgba(8, 14, 24, 0.88);
  --line: rgba(125, 211, 252, 0.28);
  --orange: #f97316;
  --amber: #fdba74;
  --cyan: #7dd3fc;
  --text: #e8eef7;
  --muted: #94a3b8;
  --danger: #fb7185;
  --ok: #34d399;
  --hud: rgba(6, 12, 22, 0.72);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Ubuntu, Cantarell,
    "Noto Sans", sans-serif;
}

#app,
.screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.screen {
  display: none;
  opacity: 0;
}

.screen.active {
  display: block;
  opacity: 1;
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ========== TITLE ========== */
#screen-title .title-bg {
  position: absolute;
  inset: 0;
  background-image: var(--title-bg);
  background-size: cover;
  background-position: center;
  transform: scale(1.04);
  filter: saturate(1.05) contrast(1.05);
}

#screen-title .title-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(
      180deg,
      rgba(3, 8, 16, 0.35) 0%,
      rgba(3, 8, 16, 0.55) 40%,
      rgba(3, 8, 16, 0.92) 100%
    ),
    radial-gradient(ellipse at 50% 20%, rgba(249, 115, 22, 0.18), transparent 55%);
}

.title-content {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: calc(24px + var(--safe-bottom)) 24px 28px;
  max-width: 760px;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--cyan);
  font-weight: 600;
}

.title-content h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1.05;
  font-weight: 800;
  text-shadow: 0 8px 30px rgba(0, 0, 0, 0.55);
}

.tagline {
  margin: 0 0 22px;
  color: #dbe7f5;
  font-size: clamp(1rem, 2.6vw, 1.2rem);
  max-width: 36rem;
  line-height: 1.45;
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn.primary {
  background: linear-gradient(180deg, #fb923c, #ea580c);
  color: #1a0b00;
  box-shadow: 0 10px 30px rgba(249, 115, 22, 0.35);
}

.btn.primary:hover {
  background: linear-gradient(180deg, #fdba74, #f97316);
}

.btn.ghost {
  background: rgba(8, 15, 28, 0.55);
  color: var(--text);
  border-color: rgba(125, 211, 252, 0.35);
}

.btn.ghost:hover {
  border-color: var(--cyan);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

/* ========== GAME ========== */
.bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: background-image 0.35s ease, filter 0.35s ease;
  filter: saturate(1.05);
}

.bg-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.45) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.25) 0%, transparent 22%, transparent 48%, rgba(0, 0, 0, 0.72) 100%);
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
}

.meter-block {
  min-width: 0;
  background: var(--hud);
  border: 1px solid rgba(148, 163, 184, 0.18);
  padding: 8px 9px 9px;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.meter-label b {
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.meter-track {
  height: 5px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.meter-track i {
  display: block;
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, #0ea5e9, #7dd3fc);
  transition: width 0.35s ease;
}

.meter-block:nth-child(1) .meter-track i {
  background: linear-gradient(90deg, #f59e0b, #fde68a);
}
.meter-block:nth-child(2) .meter-track i {
  background: linear-gradient(90deg, #10b981, #6ee7b7);
}
.meter-block:nth-child(3) .meter-track i {
  background: linear-gradient(90deg, #f97316, #fdba74);
}
.meter-block:nth-child(4) .meter-track i {
  background: linear-gradient(90deg, #8b5cf6, #c4b5fd);
}

.meter-block[data-warn="1"] {
  border-color: rgba(251, 113, 133, 0.55);
}
.meter-block[data-warn="1"] .meter-label b {
  color: var(--danger);
}

.sprite-layer {
  position: absolute;
  bottom: clamp(168px, 28vh, 250px);
  height: min(68vh, 720px);
  width: min(42vw, 420px);
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.35s ease;
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.55));
}

.sprite-layer.visible {
  opacity: 1;
}

.sprite-layer[data-pos="right"] {
  right: 2vw;
  transform: translateX(8px);
}

.sprite-layer[data-pos="left"] {
  left: 2vw;
  transform: translateX(-8px);
}

.sprite-layer.visible[data-pos="right"],
.sprite-layer.visible[data-pos="left"] {
  transform: translateX(0);
}

.sprite-layer img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  /* Soften white sprite backdrop into scene */
  mix-blend-mode: normal;
  background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.05) 100%);
}

.stage-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  padding: 0 12px calc(12px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

.choice-btn {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(125, 211, 252, 0.3);
  background: rgba(7, 14, 26, 0.86);
  color: var(--text);
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.35;
  cursor: pointer;
  border-left: 3px solid var(--orange);
  animation: choiceIn 0.28s ease both;
  animation-delay: calc(var(--i, 0) * 0.05s);
}

.choice-btn:hover,
.choice-btn:focus-visible {
  outline: none;
  border-color: rgba(253, 186, 116, 0.75);
  background: rgba(20, 30, 48, 0.95);
}

@keyframes choiceIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dialogue-panel {
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid rgba(249, 115, 22, 0.75);
  padding: 14px 16px 16px;
  min-height: 132px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.35);
}

.dialogue-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.speaker-name {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-height: 1.2em;
}

.type-hint {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dialogue-text {
  margin: 0;
  font-size: clamp(15px, 2.5vw, 18px);
  line-height: 1.55;
  min-height: 4.6em;
  white-space: pre-wrap;
}

/* ========== ENDING ========== */
#screen-ending {
  background: #050a12;
}

#screen-ending .ending-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(249, 115, 22, 0.18), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(14, 165, 233, 0.12), transparent 45%),
    #050a12;
}

.ending-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 28px));
  background: rgba(8, 14, 24, 0.92);
  border: 1px solid rgba(125, 211, 252, 0.25);
  padding: 28px 24px 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.ending-rank {
  display: inline-block;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  margin-bottom: 12px;
  border: 1px solid currentColor;
}

.ending-rank[data-rank="GOLD"] {
  color: #fbbf24;
}
.ending-rank[data-rank="SILVER"] {
  color: #cbd5e1;
}
.ending-rank[data-rank="IRON"] {
  color: #fdba74;
}
.ending-rank[data-rank="BLACK"] {
  color: #fb7185;
}

.ending-card h2 {
  margin: 0 0 10px;
  font-size: 1.55rem;
  line-height: 1.2;
}

.ending-summary {
  margin: 0 0 18px;
  color: #c7d2e0;
  line-height: 1.5;
}

.ending-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.ending-stats div {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.15);
  padding: 10px 12px;
}

.ending-stats span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.ending-stats b {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 720px) {
  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .sprite-layer {
    width: min(70vw, 320px);
    height: min(52vh, 480px);
    bottom: clamp(200px, 34vh, 280px);
  }

  .dialogue-panel {
    min-height: 148px;
  }

  .title-content {
    padding-left: 18px;
    padding-right: 18px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding-top: 6px;
  }

  .sprite-layer {
    height: 70vh;
    bottom: 120px;
    width: min(34vw, 280px);
  }

  .dialogue-panel {
    min-height: 96px;
    padding: 10px 12px;
  }

  .dialogue-text {
    min-height: 2.8em;
    font-size: 14px;
  }
}
