/* ===== Tokens ===== */
:root {
  --bg: #050505;
  --bg-2: #0b0b0b;
  --panel: #111111;
  --panel-2: #161616;

  --yellow: #f7c325;
  --yellow-bright: #ffd94d;
  --yellow-deep: #b8901a;

  --brick: #1c1c1c;
  --brick-edge: #333333;
  --brick-shadow: #050505;

  --text: #f5f3ec;
  --text-muted: #8a8a86;
  --border: #232323;

  --radius: 6px;

  /* Tamaños del bastión, escalados por altura de viewport para que TODO
     quepa siempre en una sola pantalla, sin scroll. */
  --block-h: clamp(4px, 1.05vh, 8px);
  --block-w: clamp(7px, 1.85vh, 14px);
  --row-gap: clamp(1px, 0.28vh, 3px);
  --block-gap: clamp(1px, 0.32vh, 3px);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(ellipse at 50% 0%, #121212 0%, var(--bg) 60%, #000000 100%);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ===== Layout: todo cabe en una sola vista ===== */
.app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: 2.2vh 20px 2.4vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  overflow: hidden;
}

.app-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.eyebrow {
  font-size: clamp(10px, 1.4vh, 12px);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--yellow);
  margin: 0 0 0.6vh;
  font-weight: 600;
}

h1 {
  font-family: 'Bebas Neue', 'Inter', sans-serif;
  font-size: clamp(30px, 7vh, 52px);
  font-weight: 400;
  letter-spacing: 0.08em;
  line-height: 1;
  margin: 0 0 0.9vh;
  color: var(--yellow);
  text-shadow: 0 0 26px rgba(247, 195, 37, 0.22);
}

.subtitle {
  font-size: clamp(11px, 1.5vh, 13px);
  line-height: 1.4;
  color: var(--text-muted);
  margin: 0;
  letter-spacing: 0.01em;
}

/* ===== Divisor de "cinta de precaución" ===== */
.hazard-divider {
  width: 100%;
  max-width: 340px;
  height: 6px;
  flex-shrink: 0;
  margin: 1.6vh 0;
  border-radius: 2px;
  background: repeating-linear-gradient(
    -45deg,
    var(--yellow) 0px,
    var(--yellow) 10px,
    #0a0a0a 10px,
    #0a0a0a 20px
  );
  opacity: 0.85;
}

/* ===== Zona del bastión ===== */
.castle-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: visible;
}

.castle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--row-gap);
  padding: 1.4vh 16px;
  background: linear-gradient(180deg, var(--panel), #0a0a0a);
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 1px var(--border),
    inset 0 20px 32px -28px rgba(247, 195, 37, 0.1);
  position: relative;
}

.row {
  display: flex;
  gap: var(--block-gap);
  justify-content: center;
  transform: translateY(0);
}

.row.impact {
  animation: rowImpact 0.18s ease;
}

@keyframes rowImpact {
  0% { transform: translateY(0); }
  40% { transform: translateY(1.5px) scaleY(0.9); }
  100% { transform: translateY(0); }
}

.block {
  width: var(--block-w);
  height: var(--block-h);
  border-radius: 2px;
}

.block.empty {
  border: 1.3px dashed #2a2a2a;
  opacity: 0.4;
}

.block.filled {
  background: linear-gradient(160deg, var(--brick-edge), var(--brick) 55%, var(--brick-shadow));
  box-shadow:
    inset 0 -1.5px 0 rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 0 0 1px rgba(247, 195, 37, 0.08);
}

.block.tower.filled {
  background: linear-gradient(160deg, var(--yellow-bright), var(--yellow) 55%, var(--yellow-deep));
  box-shadow:
    inset 0 -1.5px 0 rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.block.capstone.filled {
  box-shadow:
    0 0 16px 3px rgba(247, 195, 37, 0.55),
    inset 0 -1.5px 0 rgba(0, 0, 0, 0.3);
}

/* Ladrillo "cayendo" — clon animado vía JS (Web Animations API) */
.falling-brick {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  border-radius: 2px;
  background: linear-gradient(160deg, var(--brick-edge), var(--brick) 55%, var(--brick-shadow));
  box-shadow:
    inset 0 -1.5px 0 rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 6px 10px rgba(0, 0, 0, 0.5);
}

.falling-brick.tower {
  background: linear-gradient(160deg, var(--yellow-bright), var(--yellow) 55%, var(--yellow-deep));
  box-shadow:
    inset 0 -1.5px 0 rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 6px 10px rgba(0, 0, 0, 0.5);
}

/* Polvo al impactar */
.dust-puff {
  position: absolute;
  pointer-events: none;
  z-index: 4;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(247, 195, 37, 0.5), rgba(247, 195, 37, 0) 70%);
  animation: dustPuff 0.42s ease-out forwards;
}

@keyframes dustPuff {
  0% { transform: scale(0.3) translateY(0); opacity: 0.9; }
  100% { transform: scale(1.8) translateY(-8px); opacity: 0; }
}

/* ===== Estado / temporizador ===== */
.status {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.timer {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(28px, 6.4vh, 48px);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 1.2vh 0 0;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.timer-label {
  font-size: clamp(10px, 1.3vh, 12px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0.2vh 0 1.4vh;
}

.progress-track {
  width: min(280px, 70vw);
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: repeating-linear-gradient(
    -45deg,
    #1a1a1a 0px,
    #1a1a1a 6px,
    #0a0a0a 6px,
    #0a0a0a 12px
  );
  box-shadow: inset 0 0 0 1px var(--border);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--yellow-deep), var(--yellow-bright));
  transition: width 0.3s ease;
}

.progress-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(11px, 1.4vh, 13px);
  color: var(--text-muted);
  margin: 0.9vh 0 0;
}

/* ===== Controles ===== */
.controls {
  display: flex;
  gap: 12px;
  margin-top: 1.6vh;
  flex-shrink: 0;
}

button {
  font-family: 'Inter', system-ui, sans-serif;
  cursor: pointer;
  border: none;
}

button.primary {
  background: var(--yellow);
  color: #0a0800;
  padding: 1.3vh 26px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: clamp(13px, 1.7vh, 15px);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

button.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(247, 195, 37, 0.25);
  background: var(--yellow-bright);
}

button.primary:active {
  transform: translateY(0);
}

button.primary:disabled {
  background: var(--panel-2);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  padding: 1.3vh 22px;
  border-radius: var(--radius);
  font-size: clamp(13px, 1.7vh, 15px);
  transition: border-color 0.15s ease, color 0.15s ease;
}

button.ghost:hover {
  border-color: var(--yellow-deep);
  color: var(--yellow);
}

button.ghost.small {
  padding: 9px 18px;
  font-size: 13px;
}

button:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

/* ===== Botón de sonido ===== */
.sound-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--border);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.sound-toggle:hover {
  box-shadow: inset 0 0 0 1px var(--yellow-deep);
}

/* ===== Aviso de finalización ===== */
.completion-banner {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-140%);
  background: linear-gradient(180deg, #191400, var(--panel));
  box-shadow: inset 0 0 0 1px var(--yellow-deep), 0 20px 40px rgba(0, 0, 0, 0.5);
  border-radius: var(--radius);
  padding: 16px 24px;
  text-align: center;
  max-width: 300px;
  transition: transform 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  z-index: 30;
}

.completion-banner.show {
  transform: translateX(-50%) translateY(0);
}

.completion-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 20px;
  letter-spacing: 0.04em;
  color: var(--yellow);
  margin: 0 0 4px;
}

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

/* ===== Movimiento y accesibilidad ===== */
@media (prefers-reduced-motion: reduce) {
  .row.impact,
  .dust-puff,
  .completion-banner {
    animation: none !important;
    transition: none !important;
  }
}

/* ===== Pantallas muy bajas / móvil horizontal ===== */
@media (max-height: 620px) {
  .subtitle {
    display: none;
  }
  .hazard-divider {
    margin: 1vh 0;
    height: 4px;
  }
}