/* Press Start 2P has no uppercase accented glyphs, so it is only used for the
   English title and digits; Portuguese text uses Jersey 20, whose C and G stay
   distinct at small sizes. It is drawn narrow, hence size-adjust, and has a single
   weight, hence the weight range, which stops browsers faking a bold. */
@font-face {
  font-family: 'Arcade';
  src: url('fonts/press-start-2p.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: 'Pixel';
  src: url('fonts/jersey-20.woff2') format('woff2');
  font-weight: 100 900;
  size-adjust: 120%;
  font-display: swap;
}

:root {
  --bg: #150b26;
  --bg-2: #24123d;
  --panel: rgba(21, 11, 38, 0.86);
  --line: rgba(255, 244, 230, 0.16);
  --cream: #fff4e6;
  --muted: #cbb9dd;
  --gold: #f7c948;
  --blush: #ff5c8a;
  --mint: #5ef2c2;
  --danger: #ff8a7a;
  --pixel: 'Pixel', ui-monospace, 'Courier New', monospace;
  --arcade: 'Arcade', ui-monospace, 'Courier New', monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(ellipse at top, #2c1650 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--cream);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }

#app {
  position: relative;
  width: min(100vw, 520px, calc(100dvh * 0.68));
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none;
  -webkit-user-select: none;
}
@media (min-width: 700px) {
  #app { box-shadow: 0 0 0 1px var(--line), 0 30px 80px rgba(0, 0, 0, 0.6); }
}

/* ---------- HUD ---------- */
#hud {
  padding: 6px 8px 4px;
  background: linear-gradient(var(--bg-2), var(--bg));
  border-bottom: 2px solid var(--line);
  font-family: var(--pixel);
}
.hud-row { display: flex; gap: 6px; align-items: flex-end; }
.hud-row + .hud-row { margin-top: 6px; }
.stat { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.label { font-size: 11px; letter-spacing: 0.5px; color: var(--muted); white-space: nowrap; }
.value { font-family: var(--arcade); font-size: 13px; color: var(--cream); white-space: nowrap; }
#hud-score { color: var(--gold); }
.hearts { color: var(--blush); letter-spacing: 2px; }
.meter-wrap { flex: 3; display: flex; flex-direction: column; gap: 3px; }
.meter { height: 10px; background: #0c0616; border: 2px solid var(--line); }
.meter-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, var(--blush) 0 6px, #ff85a7 6px 8px);
  transition: width 0.15s linear;
}
.meter.full .meter-fill { background: repeating-linear-gradient(90deg, var(--gold) 0 6px, #ffe28a 6px 8px); }
.mult .value { color: var(--mint); }
#hud-time.low { color: var(--blush); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; min-height: 0; }
.chips:not(:empty) { margin-top: 5px; }
.chip {
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--gold);
  color: var(--gold);
  background: rgba(247, 201, 72, 0.1);
}
.chip.perfect { border-color: var(--blush); color: var(--blush); background: rgba(255, 92, 138, 0.12); }
@media (min-width: 400px) {
  .label { font-size: 12px; }
  .value { font-size: 15px; }
  .chip { font-size: 12px; }
}

/* ---------- Stage / canvas ---------- */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#game { display: block; touch-action: none; image-rendering: pixelated; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 18px;
  text-align: center;
  background: var(--panel);
  overflow-y: auto;
  animation: screen-in 0.25s ease-out;
}
.screen[hidden] { display: none; }
#screen-menu { background: linear-gradient(rgba(21, 11, 38, 0.55), rgba(21, 11, 38, 0.8)); }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }

h1, h2, h3 { font-family: var(--pixel); font-weight: 700; margin: 0; }
h2 { font-size: clamp(22px, 7vw, 30px); line-height: 1.2; color: var(--gold); text-shadow: 3px 3px 0 #6b2340; }
h3 { font-size: 14px; color: var(--muted); margin-bottom: 6px; }

.couple { font-family: var(--pixel); font-size: clamp(18px, 5.4vw, 24px); color: var(--cream); margin: 0; letter-spacing: 1px; }
.date { font-family: var(--arcade); font-size: 10px; color: var(--muted); margin: 0; letter-spacing: 2px; }
.title {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: var(--arcade);
  font-size: clamp(34px, 12vw, 54px);
  line-height: 1;
  margin: 14px 0 10px;
  color: var(--cream);
  text-shadow: 4px 4px 0 var(--blush), 8px 8px 0 #6b2340;
}
.title .love { color: var(--gold); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.best-line { font-family: var(--pixel); font-size: 15px; color: var(--mint); margin: 0; }

.lead { font-size: 17px; line-height: 1.45; margin: 0; max-width: 34ch; }
.sub { font-size: 14px; line-height: 1.45; color: var(--muted); margin: 0; max-width: 36ch; }
.sub strong { color: var(--cream); }
.keys { font-size: 12px; }

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 380px; }
.legend > div { border: 2px solid var(--line); padding: 8px; }
.legend > div:last-child { grid-column: 1 / -1; }
.icons { font-size: 24px; margin: 0; letter-spacing: 2px; line-height: 1.3; }
.legend ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; text-align: left; font-size: 12px; }
.legend li b { font-family: var(--pixel); font-size: 13px; color: var(--gold); display: block; }

.stack { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; margin-top: 6px; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.btn {
  font-family: var(--pixel);
  font-size: 19px;
  font-weight: 700;
  min-height: 52px;
  padding: 12px 14px;
  border: 3px solid var(--cream);
  background: transparent;
  color: var(--cream);
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5);
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
  touch-action: manipulation;
}
a.btn { display: block; box-sizing: border-box; text-align: center; text-decoration: none; }
.btn.primary { background: var(--blush); border-color: var(--blush); color: #fff; }
.btn.small { font-size: 16px; min-height: 48px; padding: 10px 8px; }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5); }
.btn:disabled { opacity: 0.5; cursor: default; }
@media (hover: hover) {
  .btn:hover { background: rgba(255, 244, 230, 0.12); }
  .btn.primary:hover { background: #ff7aa0; }
}
:focus-visible { outline: 3px solid var(--mint); outline-offset: 3px; }

.chars { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.char {
  width: 132px;
  padding: 16px 8px 14px;
  border: 3px solid var(--line);
  background: rgba(255, 244, 230, 0.04);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  touch-action: manipulation;
}
.char .emoji { font-size: 64px; line-height: 1; }
.char .name { font-family: var(--pixel); font-size: 20px; }
.char:active, .char:focus-visible { border-color: var(--gold); }
@media (hover: hover) { .char:hover { border-color: var(--gold); background: rgba(247, 201, 72, 0.08); } }

.countdown { background: rgba(21, 11, 38, 0.45); }
#countdown-text {
  font-family: var(--arcade);
  font-size: clamp(64px, 24vw, 120px);
  color: var(--gold);
  text-shadow: 6px 6px 0 var(--blush);
  margin: 0;
}
#countdown-text.pop { animation: pop 0.9s ease-out; }
#countdown-text.ido { font-size: clamp(44px, 16vw, 84px); color: var(--cream); }
@keyframes pop { from { transform: scale(2.2); opacity: 0; } 30% { transform: scale(1); opacity: 1; } }

.happy { font-size: clamp(22px, 7vw, 30px); }
.reason { font-family: var(--pixel); font-size: 15px; color: var(--muted); margin: 0; }
.results { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; max-width: 340px; margin: 0; }
.results > div { border: 2px solid var(--line); padding: 8px 6px; }
.results .wide { grid-column: 1 / -1; }
.results dt { font-family: var(--pixel); font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.results dd { margin: 0; font-family: var(--arcade); font-size: 18px; color: var(--gold); }
.results .title-award { font-family: var(--pixel); font-size: 20px; line-height: 1.2; color: var(--mint); }

.score-form { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 320px; text-align: left; }
.score-form label { font-family: var(--pixel); font-size: 15px; color: var(--muted); }
.score-form input {
  font-size: 16px; /* >=16px stops iOS zoom */
  padding: 12px;
  min-height: 48px;
  border: 3px solid var(--cream);
  background: #0c0616;
  color: var(--cream);
  border-radius: 0;
  user-select: text;
  -webkit-user-select: text;
}
.status { font-size: 14px; min-height: 1.2em; margin: 0; color: var(--muted); text-align: center; }
.status.error { color: var(--danger); }
.status.ok { color: var(--mint); }

.board { width: 100%; max-width: 380px; border-collapse: collapse; font-size: 15px; }
.board th { font-family: var(--pixel); font-size: 13px; color: var(--muted); font-weight: normal; padding: 6px 4px; border-bottom: 2px solid var(--line); }
.board td { padding: 9px 4px; border-bottom: 1px solid var(--line); }
.board td:first-child { font-family: var(--arcade); font-size: 11px; width: 3.5em; }
.board td:nth-child(2) { text-align: left; overflow-wrap: anywhere; }
.board td:last-child { font-family: var(--arcade); font-size: 12px; color: var(--gold); text-align: right; }
.board th:nth-child(2) { text-align: left; }
.board th:last-child { text-align: right; }
.board tr.top1 td:first-child { color: var(--gold); }
.board tr.me td { background: rgba(94, 242, 194, 0.14); color: var(--mint); }
.board tr.gap td { text-align: center; color: var(--muted); border: 0; padding: 2px; }

/* ---------- Touch controls ---------- */
#controls {
  display: flex;
  gap: 10px;
  padding: 8px 10px 10px;
  background: var(--bg);
  border-top: 2px solid var(--line);
}
#controls[hidden] { display: none; }
.ctrl {
  flex: 1;
  height: 72px;
  font-size: 34px;
  border: 3px solid var(--cream);
  background: rgba(255, 244, 230, 0.06);
  touch-action: none;
  cursor: pointer;
}
.ctrl.down { background: var(--blush); border-color: var(--blush); }
@media (pointer: fine) and (hover: hover) { .ctrl { height: 52px; font-size: 24px; } }

.icon-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  font-family: var(--pixel);
  font-size: 14px;
  min-height: 36px;
  padding: 6px 9px;
  border: 2px solid var(--line);
  background: var(--panel);
  cursor: pointer;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { padding: 24px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
