/* --- Escribí ------------------------------------------------------- */
/* A wax catacomb rendered on a tired CRT. Colours here mirror PAL in   */
/* palette.js; keep the two in step.                                    */

:root {
  --void0: #0b0a10;
  --void1: #17141f;
  --void2: #241d2b;
  --shadow: #3a2b33;
  --wax0: #4d3a2a;
  --wax2: #8c6a34;
  --wax3: #b08c3f;
  --honey0: #d8a441;
  --honey1: #f0c85a;
  --ink: #fff0b8;
  --blood1: #c4453c;
  --arcane: #9a86c4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--void0);
  color: var(--ink);
  font-family: "VT323", "Courier New", monospace;
  font-size: 20px;
  -webkit-tap-highlight-color: transparent;
}

/* --- Cambio de pantalla -------------------------------------------- */

.screen { display: none; }
body.screen-start #screen-start,
body.screen-game #screen-game,
body.screen-end #screen-end { display: flex; }

#screen-start, #screen-end {
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 16px;
}

#screen-game {
  position: fixed;
  inset: 0;
  flex-direction: column;
}

/* --- Paneles -------------------------------------------------------- */

.panel {
  width: min(640px, 100%);
  background: var(--void1);
  border: 1px solid var(--wax0);
  box-shadow: inset 1px 1px 0 var(--wax2), 0 0 0 4px var(--void0);
  padding: 24px 28px 20px;
  margin: auto;
}

h1 {
  margin: 0 0 4px;
  font-size: 64px;
  line-height: 1;
  letter-spacing: 6px;
  color: var(--honey1);
  text-shadow: 3px 3px 0 var(--void0), 0 0 18px rgba(216, 164, 65, 0.35);
}

h2 {
  margin: 0 0 8px;
  font-size: 40px;
  color: var(--honey1);
  letter-spacing: 2px;
}

.tagline { margin: 0 0 18px; color: var(--wax3); font-size: 22px; }

.rules { margin: 0 0 22px; padding-left: 22px; line-height: 1.35; color: var(--ink); }
.rules li { margin-bottom: 6px; }
.rules em { color: var(--arcane); font-style: normal; }
.rules strong { color: var(--honey1); font-weight: normal; }

.durations-label { margin: 0 0 10px; color: var(--wax3); letter-spacing: 2px; }

.durations { display: flex; flex-wrap: wrap; gap: 10px; }

.duration {
  flex: 1 1 110px;
  min-height: 76px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  color: var(--ink);
  background: var(--wax0);
  border: 0;
  border-radius: 0;
  box-shadow: inset 1px 1px 0 var(--wax2), inset -1px -1px 0 var(--void0);
  font-family: inherit;
  font-size: 20px;
  transition: background 90ms steps(2);
}
.duration:hover:not(:disabled) { background: var(--wax2); }
.duration:active:not(:disabled) { box-shadow: inset -1px -1px 0 var(--wax2), inset 1px 1px 0 var(--void0); }
.duration:disabled { opacity: 0.45; cursor: progress; }
.duration .mins { font-size: 38px; line-height: 1; color: var(--honey1); }
.duration .unit { font-size: 16px; color: var(--wax3); letter-spacing: 2px; }
.duration .best { font-size: 15px; color: var(--wax3); }

.status { min-height: 24px; margin: 14px 0 4px; color: var(--honey0); }
.hint { margin: 0 0 16px; font-size: 17px; color: var(--shadow); filter: brightness(2.2); }
.hint kbd {
  background: var(--void2);
  border: 1px solid var(--wax0);
  padding: 0 5px;
  font-family: inherit;
}

.back-link {
  display: inline-block;
  color: var(--wax3);
  text-decoration: none;
  border-bottom: 1px dotted var(--wax0);
}
.back-link:hover { color: var(--honey1); }

/* --- Escenario ------------------------------------------------------ */

#stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--void0);
}

#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--void0);
  touch-action: none;
}

#stage.shake { animation: shake 240ms steps(3); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  33% { transform: translateX(-4px); }
  66% { transform: translateX(4px); }
}

/* --- Teclado en pantalla -------------------------------------------- */

.keyboard {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--void1);
  border-top: 1px solid var(--wax0);
  transform: translateY(110%);
  transition: transform 140ms steps(3);
  z-index: 4;
}
.keyboard.is-open { transform: translateY(0); }

.key-row { display: flex; justify-content: center; gap: 4px; margin-bottom: 4px; }
.key-row:last-child { margin-bottom: 0; }

.key {
  flex: 0 1 44px;
  min-width: 30px;
  height: 40px;
  color: var(--ink);
  background: var(--wax0);
  border: 0;
  border-radius: 0;
  box-shadow: inset 1px 1px 0 var(--wax2), inset -1px -1px 0 var(--void0);
  font-family: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.key:hover { background: var(--wax2); }
.key.is-down { background: var(--wax3); box-shadow: inset -1px -1px 0 var(--wax2), inset 1px 1px 0 var(--void0); }

.key-row--tilde .key { background: var(--void2); color: var(--arcane); flex-basis: 52px; }
.key-row--tilde .key:hover { background: var(--shadow); }

.keyboard.hint-tilde .key-row--tilde .key { animation: tildePulse 300ms steps(2) 4; }
@keyframes tildePulse {
  0%, 100% { background: var(--void2); color: var(--arcane); }
  50% { background: var(--arcane); color: var(--void0); }
}

/* --- Mandos --------------------------------------------------------- */

.dpad {
  position: fixed;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: 156px;
  height: 156px;
  display: grid;
  grid-template-areas: ". up ." "left . right" ". down .";
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
  opacity: 0.75;
  z-index: 3;
}
.dpad-btn {
  color: var(--honey1);
  background: var(--void2);
  border: 1px solid var(--wax0);
  border-radius: 0;
  font-family: inherit;
  font-size: 22px;
  cursor: pointer;
  touch-action: manipulation;
}
.dpad-btn:active { background: var(--wax0); }
.dpad-btn.up { grid-area: up; }
.dpad-btn.down { grid-area: down; }
.dpad-btn.left { grid-area: left; }
.dpad-btn.right { grid-area: right; }

.action-btn, .quit-btn {
  position: fixed;
  z-index: 3;
  color: var(--ink);
  background: var(--void2);
  border: 1px solid var(--wax0);
  border-radius: 0;
  font-family: inherit;
  font-size: 20px;
  padding: 8px 12px;
  cursor: pointer;
}
.action-btn {
  left: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  color: var(--blood1);
}
.action-btn small { display: block; font-size: 14px; color: var(--wax3); }
.action-btn.is-active { background: var(--blood1); color: var(--void0); }
.quit-btn { right: 10px; top: 10px; padding: 4px 10px; color: var(--wax3); }

.hidden-input {
  position: fixed;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
  left: -100px;
  top: 0;
}

/* --- Resumen -------------------------------------------------------- */

.record {
  margin: 0 0 6px;
  color: var(--honey1);
  font-size: 30px;
  letter-spacing: 4px;
  animation: recordBlink 600ms steps(2) infinite;
}
@keyframes recordBlink { 50% { opacity: 0.35; } }

.final-score { margin: 6px 0 10px; font-size: 72px; line-height: 1; color: var(--honey1); }
.final-score small { font-size: 20px; color: var(--wax3); margin-left: 10px; letter-spacing: 3px; }

.detail { color: var(--wax3); margin-bottom: 12px; }
.detail p { margin: 2px 0; }
.detail strong { color: var(--honey1); font-weight: normal; }

.words {
  list-style: none;
  margin: 0 0 18px;
  padding: 8px;
  max-height: 34vh;
  overflow-y: auto;
  background: var(--void0);
  border: 1px solid var(--wax0);
}
.words li { display: flex; justify-content: space-between; padding: 1px 4px; }
.words li:nth-child(odd) { background: rgba(255, 240, 184, 0.04); }
.words em { font-style: normal; color: var(--honey0); }
.words .empty { color: var(--shadow); filter: brightness(2.2); justify-content: center; }

.end-actions { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.end-actions .duration { flex: 0 0 auto; min-height: 48px; padding: 10px 20px; }

/* --- CRT ------------------------------------------------------------ */

.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  background:
    repeating-linear-gradient(rgba(0, 0, 0, 0.28) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.55) 100%);
  animation: crtFlicker 5s steps(12) infinite;
}
@keyframes crtFlicker {
  0%, 100% { opacity: 1; }
  47% { opacity: 0.94; }
  52% { opacity: 1; }
}

/* Las rayas del CRT dan dolor de cabeza a algunas personas. */
@media (prefers-reduced-motion: reduce) {
  .crt-overlay { animation: none; background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.5) 100%); }
  .record { animation: none; }
}

/* --- Pantallas pequeñas --------------------------------------------- */

@media (max-width: 560px) {
  h1 { font-size: 44px; }
  .panel { padding: 16px; }
  .dpad { width: 120px; height: 120px; opacity: 0.6; }
  .key { flex-basis: 34px; height: 36px; font-size: 20px; }
  .action-btn { font-size: 17px; padding: 6px 9px; }
}

@media (max-height: 520px) {
  .rules { display: none; }
  h1 { font-size: 36px; }
}
