/* ============================================================
   Matrimillas — retro cabinet styling
   ============================================================ */

:root {
  --primary: #ff4d7d;
  --accent: #ffd166;
  --bg: #140a1f;
  --panel: #1e1030;
  --panel-2: #281540;
  --text: #fdf3f7;
  --dim: #b79cc8;
  --font-pixel: "Press Start 2P", "Courier New", monospace;
}

/* Press Start 2P joins "fi"/"fl" into one glyph ("Sofi" reads "Soñ").
   Ligatures stay off everywhere, form fields included (AV-039). */
*, *::before, *::after {
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "clig" 0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-pixel);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(120% 90% at 50% 0%, #2a1145 0%, var(--bg) 55%, #0b0513 100%);
}

#app {
  position: relative;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* CRT scanlines over everything */
#app::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.04) 0px,
    rgba(255, 255, 255, 0.04) 1px,
    transparent 1px,
    transparent 4px
  );
  z-index: 50;
}

/* ---------------- marquee ---------------- */

#marquee {
  padding: 14px 12px 10px;
  text-align: center;
  border-bottom: 3px solid var(--primary);
  background: linear-gradient(180deg, #33124d, #1d0c30);
  box-shadow: 0 4px 24px rgba(255, 77, 125, 0.25);
  flex: none;
}

#marquee-names {
  font-size: clamp(15px, 4.5vw, 22px);
  color: var(--primary);
  text-shadow: 0 0 8px var(--primary), 0 0 24px rgba(255, 77, 125, 0.6);
  animation: neon-flicker 3.2s infinite;
  letter-spacing: 1px;
}

#marquee-sub {
  margin-top: 8px;
  font-size: 9px;
  color: var(--accent);
  letter-spacing: 4px;
}

@keyframes neon-flicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.55; }
  94% { opacity: 1; }
  96% { opacity: 0.75; }
  97% { opacity: 1; }
}

/* ---------------- menu ---------------- */

#menu {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#welcome {
  font-size: 10px;
  line-height: 1.8;
  text-align: center;
  color: var(--dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#welcome img {
  width: 52px;
  height: 52px;
  image-rendering: pixelated;
  flex: none;
}

#couple-score {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--panel);
  font-size: 10px;
  color: var(--accent);
}

#couple-score b { font-size: 16px; }

#grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* An odd card count (e.g. the 3-game Spark gift) centers the last card. */
#grid > .card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  justify-self: center;
  width: calc(50% - 6px);
}

.card {
  position: relative;
  border: 2px solid #4b2a6e;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  padding: 14px 10px 12px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: transform 0.08s, border-color 0.15s, box-shadow 0.15s;
}

.card:hover, .card:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 16px rgba(255, 77, 125, 0.35);
  outline: none;
}

.card:active { transform: scale(0.96); }

.card .icon { font-size: 30px; line-height: 1; }

.card h3 {
  margin-top: 10px;
  font-size: 10px;
  color: var(--text);
  letter-spacing: 0.5px;
}

.card p {
  margin-top: 7px;
  font-size: 7px;
  line-height: 1.7;
  color: var(--dim);
}

.card .best {
  margin-top: 9px;
  font-size: 8px;
  color: var(--accent);
}

.card .tier-tag {
  position: absolute;
  top: -8px;
  right: -6px;
  font-size: 7px;
  background: var(--primary);
  color: #fff;
  padding: 4px 6px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.card.locked {
  filter: grayscale(0.9) brightness(0.6);
  cursor: not-allowed;
}

.card.locked .lock {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 20px;
  background: rgba(10, 4, 18, 0.55);
  border-radius: 8px;
}

.card.locked .lock small {
  font-size: 7px;
  color: var(--accent);
  line-height: 1.6;
  padding: 0 8px;
}

#menu-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
}

#btn-mute {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--dim);
  background: var(--panel);
  border: 2px solid #4b2a6e;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

#demo-mark {
  font-size: 7px;
  color: var(--dim);
  text-align: right;
  line-height: 1.6;
}

/* ---------------- stage ---------------- */

#stage {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#stage[hidden] { display: none; }

#stage-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 2px solid #3a1e59;
}

#btn-back {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--primary);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

#stage-title {
  flex: 1;
  font-size: 10px;
  color: var(--primary);
  text-align: center;
  text-shadow: 0 0 8px rgba(255, 77, 125, 0.7);
}

#stage-best { font-size: 8px; color: var(--accent); }

#canvas-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 6px;
}

canvas#game {
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 360 / 640;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 3px solid #3a1e59;
  border-radius: 10px;
  background: #000;
  touch-action: none;
  box-shadow: 0 0 40px rgba(255, 77, 125, 0.18), inset 0 0 60px rgba(0, 0, 0, 0.4);
}

/* ---------------- overlay (ready / game over) ---------------- */

#overlay {
  position: absolute;
  inset: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 4, 18, 0.82);
  border-radius: 10px;
  z-index: 5;
}

#overlay[hidden] { display: none; }

.ov-panel {
  width: min(86%, 330px);
  text-align: center;
  padding: 22px 16px;
  border: 3px solid var(--primary);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 0 0 30px rgba(255, 77, 125, 0.35);
}

.ov-panel .ov-icon { font-size: 40px; }

/* The couple's mood portraits in overlays. */
.ov-face {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
}

.ov-faces {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.ov-faces img {
  width: 72px;
  height: 72px;
  image-rendering: pixelated;
}

.ov-faces .ov-icon { font-size: 26px; }

.ov-panel h2 {
  margin-top: 12px;
  font-size: 14px;
  color: var(--primary);
  text-shadow: 0 0 10px rgba(255, 77, 125, 0.8);
  line-height: 1.5;
}

.ov-panel .ov-howto {
  margin-top: 14px;
  font-size: 8px;
  line-height: 1.9;
  color: var(--dim);
}

.ov-panel .ov-start {
  margin-top: 18px;
  font-size: 11px;
  color: var(--accent);
  animation: pulse 0.9s infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.45; transform: scale(0.98); }
  to   { opacity: 1;    transform: scale(1.02); }
}

.ov-score {
  margin-top: 14px;
  font-size: 30px;
  color: var(--text);
  text-shadow: 0 0 12px var(--primary);
}

.ov-best { margin-top: 10px; font-size: 9px; color: var(--accent); }

.ov-newbest {
  display: inline-block;
  margin-top: 10px;
  font-size: 9px;
  color: #140a1f;
  background: var(--accent);
  padding: 6px 10px;
  border-radius: 6px;
  animation: pulse 0.5s infinite alternate;
}

.ov-quote {
  margin-top: 14px;
  font-size: 8px;
  line-height: 1.9;
  color: var(--dim);
  font-style: italic;
}

.ov-btns {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ov-btn {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: #fff;
  background: var(--primary);
  border: 0;
  border-radius: 8px;
  padding: 13px 10px;
  cursor: pointer;
  box-shadow: 0 4px 0 #b02c52;
}

.ov-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b02c52; }

.ov-btn.ghost {
  background: transparent;
  border: 2px solid #4b2a6e;
  color: var(--dim);
  box-shadow: none;
}

/* ---------------- turn matches (two players, one device) ---------------- */

.ov-panel .ov-duel { margin-top: 8px; font-size: 8px; line-height: 1.7; color: var(--accent); }

.ov-panel .ov-turn,
.ov-panel .ov-turnscore {
  margin-top: 14px;
  font-size: 10px;
  line-height: 1.6;
  color: var(--text);
}

.ov-panel .ov-turnscore { margin: 0 0 12px; color: var(--accent); }

.ov-match {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ov-side {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  border: 2px solid #4b2a6e;
  border-radius: 10px;
}

.ov-side.win { border-color: var(--accent); box-shadow: 0 0 14px rgba(255, 209, 102, 0.45); }

.ov-side img { width: 72px; height: 72px; image-rendering: pixelated; }
.ov-side b { font-size: 8px; color: var(--text); overflow-wrap: anywhere; }
.ov-side .ov-pts { font-size: 18px; color: var(--text); text-shadow: 0 0 10px var(--primary); }
.ov-side .ov-pb { font-size: 7px; font-style: normal; color: var(--dim); }
.ov-side .ov-pb.new { color: #140a1f; background: var(--accent); padding: 3px 5px; border-radius: 4px; }
.ov-vs { font-size: 9px; color: var(--primary); }

/* ---------------- love letter: menu card + unlock moment ---------------- */

.card.letter-card {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  padding: 14px;
  border-color: var(--primary);
}

.card.letter-card .icon { flex: none; font-size: 34px; }
.card.letter-card .lc-text { flex: 1; min-width: 0; }
.card.letter-card h3 { margin-top: 0; font-size: 11px; color: var(--primary); }
.card.letter-card .lc-sub { margin-top: 8px; font-size: 7px; line-height: 1.7; color: var(--dim); }
.card.letter-card .best { margin-top: 6px; }

.card.letter-card.locked { filter: none; border-color: #4b2a6e; cursor: default; }
.card.letter-card.locked h3 { color: var(--text); }

.lc-bar {
  margin-top: 8px;
  height: 6px;
  border-radius: 3px;
  background: #3a1e59;
  overflow: hidden;
}

.lc-bar i { display: block; height: 100%; background: var(--primary); }

.card.letter-card.is-new { animation: lc-glow 0.9s infinite alternate; }

@keyframes lc-glow {
  from { box-shadow: 0 0 6px rgba(255, 77, 125, 0.3); }
  to   { box-shadow: 0 0 22px rgba(255, 77, 125, 0.75); }
}

.lc-new {
  position: absolute;
  top: -8px;
  right: -6px;
  font-size: 7px;
  color: #140a1f;
  background: var(--accent);
  padding: 4px 6px;
  border-radius: 6px;
}

.ov-unlock {
  margin-top: 14px;
  padding: 12px 10px;
  border: 2px dashed var(--accent);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ov-unlock b {
  font-size: 9px;
  line-height: 1.7;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(255, 209, 102, 0.6);
}

/* ---------------- love letter: full-screen reveal ---------------- */

body.letter-open #app { visibility: hidden; }

#letter {
  position: fixed;
  inset: 0;
  z-index: 40;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(90% 60% at 50% 30%, rgba(255, 77, 125, 0.28), transparent 70%),
    rgba(8, 3, 14, 0.96);
}

#letter[hidden] { display: none; }

.lt-fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.lt-card {
  position: relative;
  width: min(100%, 420px);
  margin: auto;
  padding: 26px 20px 22px;
  text-align: center;
  color: #2a1145;
  background:
    repeating-linear-gradient(180deg, transparent 0 27px, rgba(42, 17, 69, 0.08) 27px 28px),
    #fff6ea;
  border: 4px solid var(--primary);
  border-radius: 14px;
  box-shadow: 0 0 0 4px #fff6ea, 0 0 0 8px var(--accent), 0 0 60px rgba(255, 77, 125, 0.55);
  outline: none;
  animation: lt-in 0.6s cubic-bezier(.2, 1.4, .4, 1) both;
}

@keyframes lt-in {
  from { opacity: 0; transform: translateY(30px) scale(0.92); }
  to   { opacity: 1; transform: none; }
}

.lt-faces {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: -6px;
}

.lt-face {
  width: clamp(92px, 30vw, 128px);
  height: clamp(92px, 30vw, 128px);
  image-rendering: pixelated;
  border-radius: 12px;
  background: var(--bg);
  border: 3px solid var(--primary);
}

.lt-heart {
  font-size: 26px;
  color: var(--primary);
  animation: pulse 0.6s infinite alternate;
}

.lt-kicker { margin-top: 16px; font-size: 8px; letter-spacing: 2px; color: #8a6aa0; }

.lt-to {
  margin-top: 10px;
  font-size: clamp(14px, 4.6vw, 18px);
  line-height: 1.5;
  color: var(--primary);
  overflow-wrap: anywhere;
}

.lt-since {
  margin-top: 8px;
  font-size: 8px;
  line-height: 1.8;
  color: #8a6aa0;
}

.lt-since[hidden] { display: none; }

/* Long letters (up to 1200 chars) scroll inside the card so the
   faces, signature and buttons stay on screen. */
.lt-body {
  position: relative;
  margin-top: 16px;
  min-height: 5.6em;
  max-height: min(38vh, 22em);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  font-size: 11px;
  line-height: 2.1;
  text-align: left;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  scrollbar-width: thin;
  scrollbar-color: #c9b2dc transparent;
}

.lt-caret {
  display: inline-block;
  width: 0.6em;
  height: 1em;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--primary);
  animation: lt-blink 0.8s steps(1) infinite;
}

@keyframes lt-blink { 50% { opacity: 0; } }

.lt-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.lt-sign {
  margin-top: 14px;
  font-size: 12px;
  text-align: right;
  color: var(--primary);
  overflow-wrap: anywhere;
  opacity: 0;
  transition: opacity 0.6s;
}

.lt-skip { margin-top: 14px; font-size: 7px; color: #8a6aa0; }

.lt-btns {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.5s;
}

.lt-btns .ov-btn.ghost { color: #5b3a7a; border-color: #c9b2dc; }

#letter.done .lt-sign { opacity: 1; }
#letter.done .lt-btns { visibility: visible; opacity: 1; }
#letter.done .lt-skip, #letter.done .lt-caret { display: none; }

@media (prefers-reduced-motion: reduce) {
  .lt-card, .lt-heart, .card.letter-card.is-new { animation: none; }
  .lt-sign, .lt-btns { transition: none; }
}

/* Scrollbar cosmetics */
#menu::-webkit-scrollbar { width: 6px; }
#menu::-webkit-scrollbar-thumb { background: #4b2a6e; border-radius: 3px; }
