:root {
  --bg: #f7efe6;
  --bg-2: #efe3d3;
  --ink: #3d3226;
  --ink-soft: #7a6a56;
  --gold: #c9a24b;
  --rose: #d98a8a;
  --card: #fffdf9;
  --shadow: 0 18px 40px rgba(80, 60, 30, 0.18);
  --radius: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(120% 80% at 50% 0%, var(--bg) 0%, var(--bg-2) 100%);
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- Schermate --- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
}
.screen.active { display: grid; }

.card {
  width: min(440px, 92vw);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 26px 26px;
  text-align: center;
  border: 1px solid rgba(201, 162, 75, 0.25);
}

.couple-art {
  display: block;
  width: min(220px, 60%);
  margin: 0 auto 6px;
  height: auto;
}

.eyebrow {
  margin: 0 0 6px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 500;
}

.couple {
  font-family: "Playfair Display", serif;
  font-size: clamp(38px, 12vw, 56px);
  margin: 0 0 8px;
  line-height: 1;
}
.couple span { color: var(--gold); font-style: italic; }

.subtitle { margin: 0 0 22px; color: var(--ink-soft); font-size: 16px; }

.field { display: block; text-align: left; margin: 0 0 18px; }
.field span {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 6px 4px;
  font-weight: 500;
}
.field input {
  width: 100%;
  font-family: inherit;
  font-size: 18px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 2px solid rgba(201, 162, 75, 0.4);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--gold); }

.btn {
  width: 100%;
  font-family: inherit;
  font-weight: 600;
  font-size: 18px;
  padding: 15px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  margin-top: 10px;
  transition: transform 0.08s ease, box-shadow 0.15s;
}
.btn:active { transform: translateY(2px) scale(0.99); }
.btn-primary {
  background: linear-gradient(180deg, var(--gold), #b3892f);
  color: #fff;
  box-shadow: 0 10px 20px rgba(179, 137, 47, 0.35);
}
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 2px solid rgba(122, 106, 86, 0.25);
}

.name-error {
  margin: -8px 0 4px;
  font-size: 14px;
  font-weight: 600;
  color: #c0392b;
}

.hint { margin: 18px 0 0; font-size: 13px; color: var(--ink-soft); }

/* --- HUD di gioco --- */
#screen-game { padding: 0; align-content: start; }
.hud {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 14px);
  left: 0; right: 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0 18px;
  pointer-events: none;
}
.hud-score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 30px;
  color: var(--ink);
  line-height: 1;
}
.hud-score small {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-top: 4px;
}
.hud-quit {
  pointer-events: auto;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink-soft);
  font-size: 18px;
  cursor: pointer;
}

#game-canvas { display: block; width: 100vw; height: 100vh; touch-action: none; }

.tap-hint {
  position: absolute;
  bottom: 22%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(61, 50, 38, 0.85);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 15px;
  z-index: 3;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 0.6; } 50% { opacity: 1; } }
.tap-hint.hidden { display: none; }

/* --- Game over --- */
.result { margin: 10px 0 6px; }
.result-score { line-height: 1; }
.result-score span {
  font-family: "Playfair Display", serif;
  font-size: 64px;
  color: var(--gold);
}
.result-score small { display: block; color: var(--ink-soft); letter-spacing: 0.1em; text-transform: uppercase; font-size: 12px; }
.result-msg { margin: 12px 0 0; color: var(--ink-soft); min-height: 20px; }

.rank-pill {
  display: inline-block;
  margin: 16px auto 4px;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(201, 162, 75, 0.15);
  color: #8a6a1f;
  font-weight: 600;
  font-size: 15px;
}

/* --- Classifica --- */
.board-card { padding-top: 26px; }
.board-title { font-family: "Playfair Display", serif; font-size: 34px; margin: 0; }
.board-sub { margin: 4px 0 18px; color: var(--ink-soft); font-size: 14px; }
.board-list {
  list-style: none;
  margin: 0 0 4px;
  padding: 0;
  max-height: 46vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.board-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  font-size: 16px;
}
.board-list li:nth-child(odd) { background: rgba(201, 162, 75, 0.06); }
.board-list li.me { background: rgba(217, 138, 138, 0.16); font-weight: 600; }
.board-rank {
  width: 30px;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: center;
  flex: none;
}
.board-list li:nth-child(1) .board-rank { color: var(--gold); }
.board-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-best { font-variant-numeric: tabular-nums; font-weight: 700; }
.board-empty { color: var(--ink-soft); padding: 20px; }

.board-mine {
  margin: 8px 0 4px;
  padding: 12px;
  border-radius: 12px;
  border: 2px dashed rgba(201, 162, 75, 0.4);
  font-size: 15px;
  color: var(--ink);
}

@media (max-height: 620px) {
  .card { padding: 22px 22px 20px; }
  .couple { font-size: clamp(32px, 10vw, 44px); }
  .subtitle { margin-bottom: 16px; }
}
