:root {
  --sand: #e8d2b0;
  --clay: #c47848;
  --ember: #e07038;
  --dusk: #2a1830;
  --night: #120c10;
  --snow: #eef0f6;
  --ink: #1a100c;
  --panel: rgba(18, 10, 8, 0.72);
  --line: rgba(232, 210, 176, 0.22);
  --ok: #7ec87a;
  --mid: #e0b050;
  --hot: #e05040;
  --display: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --ui: Candara, "Trebuchet MS", "Segoe UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(120% 80% at 70% 0%, rgba(224, 112, 56, 0.28), transparent 55%),
    radial-gradient(90% 70% at 10% 100%, rgba(42, 24, 48, 0.55), transparent 50%),
    linear-gradient(165deg, #2a1610 0%, #120c10 48%, #1a1218 100%);
  color: var(--sand);
  font-family: var(--ui);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: #000;
  color: #fff;
  padding: 8px 12px;
  z-index: 100;
}
.skip:focus { left: 8px; }

.stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100dvh;
  background: #1a100c;
  image-rendering: auto;
  box-shadow: 0 0 0 1px rgba(232, 210, 176, 0.08), 0 24px 80px rgba(0, 0, 0, 0.45);
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: linear-gradient(180deg, rgba(12, 8, 10, 0.35), rgba(12, 8, 10, 0.55));
  pointer-events: auto;
}
.overlay[hidden] { display: none !important; }

.panel {
  width: min(520px, 100%);
  padding: 28px 26px 24px;
  border: 1px solid var(--line);
  background:
    linear-gradient(160deg, rgba(255, 180, 100, 0.08), transparent 40%),
    var(--panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  animation: rise 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.kicker {
  margin: 0 0 8px;
  font: 600 11px/1 var(--ui);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ember);
}

h1, h2 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: 0.02em;
  color: var(--snow);
}

h1 {
  font-size: clamp(26px, 5.2vw, 38px);
  text-wrap: balance;
}

h2 { font-size: clamp(24px, 4vw, 32px); }

.lede {
  margin: 0 0 18px;
  color: rgba(232, 210, 176, 0.82);
  font-size: 15px;
  line-height: 1.55;
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  font-size: 13px;
  color: rgba(232, 210, 176, 0.7);
}
.hint-ico {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 18px;
}

.title-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  font-family: var(--ui);
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, border-color 0.2s, color 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  flex: 1;
  padding: 14px 18px;
  background: linear-gradient(180deg, #e88848, #c45828);
  color: #1a0c08;
  border-color: rgba(255, 220, 160, 0.35);
  font-size: 15px;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
  color: var(--sand);
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }
.btn.sm { padding: 8px 10px; font-size: 14px; }
.btn.icon { min-width: 48px; }

.record {
  margin: 0 0 12px;
  font-size: 13px;
  color: rgba(232, 210, 176, 0.65);
}
.record strong { color: var(--snow); font-weight: 700; }

.back {
  color: rgba(232, 210, 176, 0.55);
  text-decoration: none;
  font-size: 13px;
}
.back:hover { color: var(--sand); }

/* HUD */
.hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  padding: calc(10px + var(--safe-t)) 14px calc(12px + var(--safe-b));
}
.hud[hidden] { display: none !important; }

.mission-pill {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: 14px;
  z-index: 2;
  max-width: min(280px, 70vw);
  padding: 8px 12px;
  background: rgba(12, 8, 10, 0.55);
  border: 1px solid rgba(232, 210, 176, 0.14);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
}
.mission-tag {
  display: block;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ember);
  margin-bottom: 2px;
}
.mission-label {
  display: block;
  font-size: 12.5px;
  color: var(--snow);
  line-height: 1.3;
  margin-bottom: 6px;
}
.mission-bar {
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.mission-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7dffc4, #ffe08a);
  transition: width 0.2s linear;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  padding-top: 52px;
}

.stat {
  padding: 8px 12px;
  background: rgba(12, 8, 10, 0.45);
  border: 1px solid rgba(232, 210, 176, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  min-width: 88px;
}
.stat .label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(232, 210, 176, 0.55);
  margin-bottom: 2px;
}
.stat strong {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 400;
  color: var(--snow);
}
#hudCombo[data-hot="1"] {
  color: #ffd24a;
  text-shadow: 0 0 12px rgba(255, 200, 80, 0.45);
}

.instinct-stat { min-width: 110px; }
.instinct-meter {
  display: flex;
  gap: 3px;
  margin: 4px 0 3px;
}
.instinct-meter i {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(232, 210, 176, 0.15);
}
.instinct-meter i.on {
  background: linear-gradient(180deg, #ffd24a, #e07038);
  box-shadow: 0 0 8px rgba(255, 180, 60, 0.45);
}
.instinct-meter i.fever {
  animation: feverPulse 0.35s ease-in-out infinite alternate;
}
@keyframes feverPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.35); }
}
.instinct-bar {
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.instinct-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #e07038, #ffd24a);
  transition: width 0.15s linear;
}
.instinct-fill[data-active="1"] {
  background: linear-gradient(90deg, #ffe08a, #fff6d0);
  box-shadow: 0 0 10px rgba(255, 220, 120, 0.6);
}

.hud-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

.threat {
  position: absolute;
  left: 14px;
  bottom: calc(14px + var(--safe-b));
  width: min(220px, 46vw);
  padding: 8px 10px;
  background: rgba(12, 8, 10, 0.45);
  border: 1px solid rgba(232, 210, 176, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.threat-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(232, 210, 176, 0.55);
  margin-bottom: 6px;
}
.threat-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.threat-fill {
  height: 100%;
  width: 18%;
  background: var(--ok);
  transition: width 0.2s linear, background 0.25s;
}
.threat-fill[data-level="mid"] { background: var(--mid); }
.threat-fill[data-level="hot"] { background: var(--hot); }

/* Game over */
.go-panel { width: min(560px, 100%); }
.go-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0 0 16px;
}
.go-stats div {
  padding: 10px 12px;
  border: 1px solid rgba(232, 210, 176, 0.12);
  background: rgba(255, 255, 255, 0.03);
}
.go-stats span {
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(232, 210, 176, 0.55);
  margin-bottom: 4px;
}
.go-stats strong {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 400;
  color: var(--snow);
}

.fact-card {
  margin: 0 0 18px;
  padding: 14px 14px 12px;
  border-left: 3px solid var(--ember);
  background: linear-gradient(90deg, rgba(224, 112, 56, 0.12), transparent 70%);
}
.fact-label {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ember);
}
.fact-label em { font-style: italic; letter-spacing: 0; text-transform: none; }
.fact-body {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: rgba(238, 240, 246, 0.9);
}

.retry-hint {
  margin: 8px 0 12px;
  font-size: 12px;
  color: rgba(232, 210, 176, 0.45);
  text-align: center;
}

.ranking-btn {
  width: 100%;
  margin: 0 0 12px;
  font-size: 13px;
}

.go-panel-wide { width: min(640px, 100%); max-height: min(92dvh, 900px); overflow-y: auto; }
.go-panel-wide .go-stats { grid-template-columns: repeat(3, 1fr); }

.bitacora-card {
  margin: 0 0 14px;
  padding: 14px;
  border: 1px solid rgba(255, 210, 120, 0.22);
  background:
    linear-gradient(135deg, rgba(224, 112, 56, 0.12), transparent 55%),
    rgba(0, 0, 0, 0.25);
}
.bitacora-status {
  margin: 8px 0 0;
  font-size: 13px;
  color: rgba(232, 210, 176, 0.65);
  animation: pulseSoft 1.1s ease-in-out infinite;
}
@keyframes pulseSoft {
  50% { opacity: 0.55; }
}
.rank-title {
  margin: 6px 0 8px;
  font-family: var(--display);
  font-size: clamp(20px, 3.5vw, 26px);
  font-weight: 400;
  color: #ffd24a;
}
.field-note {
  margin: 0 0 10px;
  font-style: italic;
  font-size: 14px;
  line-height: 1.45;
  color: rgba(255, 240, 220, 0.92);
}

.rank-form {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr auto;
  gap: 8px;
  margin: 0 0 12px;
}
.rank-form input {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--snow);
  padding: 11px 12px;
  font: 500 13px/1.2 var(--ui);
  min-width: 0;
}
.rank-form input:focus {
  outline: 1px solid rgba(255, 210, 120, 0.55);
}
.go-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
.go-actions .btn.primary { flex: 1; }

.ranking-modal { z-index: 40; }
.ranking-panel { width: min(480px, 100%); }
.ranking-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: min(55dvh, 420px);
  overflow-y: auto;
}
.ranking-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(232, 210, 176, 0.1);
}
.ranking-list .pos {
  font-family: var(--display);
  color: var(--ember);
}
.ranking-list .who strong { display: block; color: var(--snow); }
.ranking-list .who em {
  display: block;
  font-style: normal;
  font-size: 12px;
  color: rgba(255, 210, 120, 0.75);
  margin-top: 2px;
}
.ranking-list .pts {
  font-family: var(--display);
  font-size: 18px;
  color: var(--snow);
}
.ranking-list .muted {
  display: block;
  padding: 16px 4px;
  color: rgba(232, 210, 176, 0.55);
  grid-column: 1 / -1;
}

@media (max-width: 640px) {
  .rank-form { grid-template-columns: 1fr; }
  .go-panel-wide .go-stats { grid-template-columns: repeat(2, 1fr); }
  .go-actions { flex-direction: column; }
}

.pause-panel { text-align: center; }
.pause-panel p { margin: 0 0 16px; color: rgba(232, 210, 176, 0.7); }

.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  gap: 12px;
  background: rgba(10, 6, 8, 0.92);
  text-align: center;
  padding: 24px;
}
.rotate-hint[hidden] { display: none !important; }
.rotate-hint span {
  font-size: 48px;
  animation: spin 2.4s linear infinite;
}
@keyframes spin {
  to { transform: rotate(90deg); }
}

@media (max-width: 520px) {
  .panel { padding: 22px 18px 18px; }
  .stat strong { font-size: 18px; }
  .go-stats { grid-template-columns: 1fr 1fr; }
}
