:root {
  --bg-1: #4a0f20;
  --bg-2: #1c060c;
  --card-1: #6b1528;
  --card-2: #2a0812;
  --gold: #d9a94e;
  --gold-soft: rgba(217, 169, 78, 0.35);
  --text: #f6e7d0;
  --muted: rgba(246, 231, 208, 0.6);
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Josefin Sans", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, var(--bg-1), var(--bg-2) 70%) fixed;
  background-color: var(--bg-2);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

.screen {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

#screen-setup, #screen-end { justify-content: center; gap: 12px; }

h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.6rem, 11vw, 3.4rem);
  line-height: 1.02;
  margin: 4px 0;
  color: var(--gold);
}

h2 { font-family: var(--serif); font-weight: 600; color: var(--gold); font-size: 1.7rem; margin: 20px 0 8px; }
h3 { font-family: var(--sans); font-weight: 600; font-size: .8rem; letter-spacing: .15em; text-transform: uppercase; margin: 16px 0 4px; color: var(--gold); }

.subtitle { font-family: var(--serif); font-style: italic; font-size: 1.25rem; color: var(--muted); margin: 0 0 16px; }

.eyebrow {
  font-family: var(--sans);
  font-size: .68rem;
  letter-spacing: .35em;
  text-transform: uppercase;
  color: var(--gold);
}

.spark { color: var(--gold); font-size: 1.1rem; }
.spark.small { font-size: .8rem; margin-top: auto; }

/* Giocatori */
.players { display: flex; gap: 12px; width: 100%; margin: 8px 0 12px; }
.player { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.player > label {
  font-size: .65rem; letter-spacing: .25em; text-transform: uppercase; color: var(--muted);
}

.seg {
  display: flex;
  border: 1px solid var(--gold-soft);
  border-radius: 10px;
  overflow: hidden;
}
.seg button {
  flex: 1;
  padding: 10px 4px;
  background: rgba(0,0,0,.2);
  color: var(--muted);
  border: 0;
  font: 600 .66rem var(--sans);
  letter-spacing: .15em;
  text-transform: uppercase;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--gold-soft); }
.seg button.on { background: var(--gold); color: #2a0812; }

.couple { font-family: var(--serif); font-style: italic; font-size: 1.15rem; color: var(--muted); }
.couple.ok { color: var(--gold); }

.check {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--gold-soft); border-radius: 10px;
  text-align: left; cursor: pointer;
  font-size: .9rem;
}
.check input { width: 20px; height: 20px; accent-color: var(--gold); flex: none; }
.check small { display: block; color: var(--muted); font-size: .75rem; margin-top: 2px; }

#btn-start:disabled { opacity: .4; cursor: not-allowed; }
.players input {
  width: 100%;
  background: rgba(0,0,0,.25);
  border: 1px solid var(--gold-soft);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  font: 500 1.1rem var(--serif);
  outline: none;
}
.players input:focus { border-color: var(--gold); }

/* Bottoni */
.btn {
  width: 100%;
  border-radius: 999px;
  padding: 15px 20px;
  font: 600 .78rem var(--sans);
  letter-spacing: .22em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform .1s, opacity .2s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn-gold { background: linear-gradient(180deg, #e8bd64, #c28f34); color: #2a0812; }
.btn-ghost { background: rgba(255,255,255,.06); color: var(--text); border-color: var(--gold-soft); }
.btn-outline { background: transparent; color: var(--gold); border-color: var(--gold); }
.btn-link { background: none; color: var(--muted); padding: 10px; }
.btn-sm { width: auto; padding: 10px 18px; }

.row { display: flex; gap: 10px; width: 100%; }
.row .btn-ghost { flex: 0 0 34%; }

/* Barra in alto */
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.06); border: 1px solid var(--gold-soft);
  color: var(--gold); font-size: 1.1rem; cursor: pointer;
}
.deck-label { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.remaining {
  min-width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--gold-soft); color: var(--muted); font-size: .8rem;
}

.dots { display: flex; gap: 6px; justify-content: center; }
.dots i { width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--gold); display: block; }
.dots i.on { background: var(--gold); }

.turn { margin: 14px 0 10px; font-family: var(--serif); font-size: 1.3rem; color: var(--muted); font-style: italic; }
.turn strong { color: var(--text); font-style: normal; font-weight: 600; }

/* Carta */
.stage { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; perspective: 1400px; min-height: 0; }

.card {
  width: min(78vw, 330px, calc((100dvh - 330px) * 0.563));
  min-width: 220px;
  aspect-ratio: 328 / 584;
  cursor: pointer;
}
.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .7s cubic-bezier(.3,.9,.3,1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card.flipped { cursor: default; }

.card-back, .card-front {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 18px;
  background: radial-gradient(ellipse at 50% 0%, var(--card-1), var(--card-2) 75%);
  box-shadow: 0 20px 50px rgba(0,0,0,.55), inset 0 0 0 1px var(--gold-soft);
  display: flex; flex-direction: column; align-items: center;
  padding: 26px 20px 20px;
}
.card-back::before, .card-front::before {
  content: ""; position: absolute; inset: 10px;
  border: 1px solid var(--gold-soft); border-radius: 12px; pointer-events: none;
}
.card-back { justify-content: center; gap: 16px; }
.back-title { font-family: var(--serif); font-size: 2rem; line-height: 1.05; color: var(--gold); }

.card-front { transform: rotateY(180deg); gap: 10px; }
.card-front .dots { margin-top: 2px; }
.card-text {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.3rem, 5.6vw, 1.65rem);
  line-height: 1.3;
  margin: 10px 0 auto;
  text-wrap: balance;
}
.card-front .foot { font-size: .55rem; color: var(--muted); }

.card.deal { animation: deal .45s ease-out; }
@keyframes deal { from { transform: translateY(30px) scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

.empty { font-family: var(--serif); font-size: 1.35rem; font-style: italic; color: var(--muted); padding: 0 12px; }

/* Timer */
.timer { margin: 12px 0 0; }
#btn-timer.running { background: var(--gold); color: #2a0812; }
#btn-timer.done { animation: pulse 1s ease-in-out 3; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* Azioni */
.actions { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-top: 16px; padding-bottom: 64px; }

/* STOP */
.stop-btn {
  position: fixed;
  right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  width: 64px; height: 64px; border-radius: 50%;
  background: #120307; color: var(--gold);
  border: 1.5px solid var(--gold);
  font: 600 .7rem var(--sans); letter-spacing: .2em; padding-left: .2em;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  cursor: pointer; z-index: 5;
}

/* Overlay */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(10, 2, 5, .88);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade .25s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.overlay-box {
  width: 100%; max-width: 420px; max-height: 100%;
  overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center;
}
.overlay-box p { font-family: var(--serif); font-size: 1.2rem; line-height: 1.4; margin: 4px 0; }
.stop-word { font: 600 4.5rem var(--sans); letter-spacing: .25em; padding-left: .25em; color: var(--gold); }

#ov-stop { background: #000; }

.rules { text-align: left; align-items: stretch; padding: 8px 4px 24px; }
.rules h2:first-child { margin-top: 8px; }
.rules p { font-size: 1.12rem; color: rgba(246,231,208,.85); }
.rules .center { text-align: center; }
.rules .btn { margin-top: 16px; }
