:root {
  --felt: #0f3d2e;
  --felt-2: #145a41;
  --felt-edge: #0a2a20;
  --cream: #f6efdf;
  --ink: #1d1a16;
  --muted: #6d665b;
  --red: #c4161c;
  --gold: #f0b429;
  --blue: #1f5aa6;
  --panel: rgba(246, 239, 223, .97);
  --radius: 14px;
  --card-w: clamp(62px, 17vw, 92px);
  --card-h: calc(var(--card-w) * 1.6);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --filigrana: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23f6efdf' stroke-width='1.6' stroke-linejoin='round' opacity='.075'%3E%3Ccircle cx='40' cy='40' r='15'/%3E%3Ccircle cx='40' cy='40' r='10'/%3E%3Ccircle cx='40' cy='40' r='3.5'/%3E%3Cpath d='M28 106h24c0 10-5 16-12 17-7-1-12-7-12-17zM37 123h6l1 7h-8zM31 140c0-4 4-6 9-6s9 2 9 6zM28 106c0 2 24 2 24 0'/%3E%3Cpath d='M120 18c6 12 6 28 2 40h-4c-2-12-2-28 2-40zM110 58c6-2 14-2 20 0M118 60v8h4v-8M120 70v0' /%3E%3Ccircle cx='120' cy='71' r='2.5'/%3E%3Cpath d='M114 97c0-5 12-5 12 0l-3 44c0 3-6 3-6 0zM125 110l4-3M115 124l-4-2' transform='rotate(-22 120 120)'/%3E%3Cpath d='M80 86c-3-4-9-3-9 2 0 5 9 10 9 10s9-5 9-10c0-5-6-6-9-2z'/%3E%3C/g%3E%3C/svg%3E");
}
@font-face {
  font-family: "Fraunces"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url("../fonts/fraunces.woff2") format("woff2");
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html { background: var(--felt-edge); }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    var(--filigrana) 0 0 / 160px 160px,
    radial-gradient(ellipse at 50% 30%, var(--felt-2), var(--felt) 55%, var(--felt-edge));
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.view { min-height: 100dvh; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* --- Marchio --- */
.marchio { display: flex; align-items: center; gap: .5rem; color: var(--cream); }
.marchio h1, .marchio span { font-family: var(--serif); font-weight: 700; margin: 0; letter-spacing: -.02em; line-height: 1; }
.marchio h1 { font-size: clamp(3rem, 11vw, 5.4rem); font-variation-settings: "SOFT" 100, "WONK" 1; }
.marchio .cuore { fill: var(--red); width: clamp(2.4rem, 8vw, 3.8rem); height: auto; flex: none; filter: drop-shadow(0 3px 0 rgba(0,0,0,.25)); }
.marchio.piccolo span { font-size: 1.5rem; }
.marchio.piccolo .cuore { width: 1.4rem; filter: none; }

/* --- Elementi base --- */
.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 999px; padding: .7rem 1.3rem;
  background: #e5dcc8; color: var(--ink); cursor: pointer; transition: transform .1s, filter .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--red); color: #fff; }
.btn.big { font-size: 1.4rem; padding: 1rem 3.4rem; box-shadow: 0 6px 0 #8c0b20; }
.btn.small { font-size: .85rem; padding: .45rem .9rem; }
.btn.ok { background: #2f7d4f; color: #fff; }
.btn.oro { background: var(--gold); color: var(--ink); box-shadow: 0 6px 0 #a87612; }
.btn.oro:active { transform: translateY(4px); box-shadow: 0 2px 0 #a87612; }
.btn.grande { width: 100%; font-size: 1.35rem; padding: 1.05rem 1.5rem; font-family: var(--serif); font-weight: 700; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; opacity: .8; }
.err { color: var(--red); min-height: 1.2em; margin: .3rem 0 0; font-size: .9rem; font-weight: 600; }
.hint { color: var(--muted); font-size: .9rem; max-width: 34ch; margin: 1rem auto 0; }
.row { display: flex; align-items: center; gap: .6rem; }
.between { justify-content: space-between; }
.center { text-align: center; }

/* --- Ingresso --- */
#v-auth { padding: 0 16px 48px; }
.ingresso {
  max-width: 1040px; margin: 0 auto; min-height: min(100dvh, 760px);
  display: grid; grid-template-columns: 1.15fr .85fr; gap: 56px; align-items: center; padding: 40px 0 24px;
}
.hero .sottotitolo { color: #d7e8dd; font-size: 1.15rem; line-height: 1.5; max-width: 34ch; margin: 1rem 0 0; }
.ventaglio { position: relative; height: calc(var(--fan-w) * 1.6 + 40px); --fan-w: 132px; margin-top: 28px; }
.ventaglio .card {
  --card-w: var(--fan-w); position: absolute; left: calc(50% - var(--fan-w) / 2); bottom: 0;
  transform-origin: 50% 115%; transition: transform .7s cubic-bezier(.2,.8,.2,1); transform: rotate(0deg);
  box-shadow: 0 12px 24px rgba(0,0,0,.4);
}
.ventaglio.aperto .card:nth-child(1) { transform: rotate(-15deg) translateX(-38px); }
.ventaglio.aperto .card:nth-child(3) { transform: rotate(15deg) translateX(38px); }
.ventaglio .card .badge { font-size: .95rem; }
.hero { display: grid; justify-items: start; }
.hero .ventaglio { width: 100%; max-width: 440px; }

.accesso { background: var(--panel); border-radius: 20px; padding: 28px 26px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.accesso .nota { color: var(--muted); font-size: .92rem; line-height: 1.45; margin: .9rem 0 1.2rem; text-align: center; }
.conto { border-top: 1px solid #e0d4ba; padding-top: 1rem; }
.conto summary { cursor: pointer; font-weight: 600; color: var(--ink); list-style: none; display: flex; justify-content: space-between; align-items: center; }
.conto summary::-webkit-details-marker { display: none; }
.conto summary::after { content: "+"; font-size: 1.4rem; line-height: 1; color: var(--red); transition: transform .2s; }
.conto[open] summary::after { transform: rotate(45deg); }
.tabs { display: flex; background: #e9dfc9; border-radius: 999px; padding: 4px; margin: 1rem 0; }
.tab { flex: 1; border: 0; background: none; color: var(--muted); padding: .55rem; border-radius: 999px; font: inherit; cursor: pointer; }
.tab.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
#f-auth { display: grid; gap: .8rem; }
#f-auth label { display: grid; gap: .3rem; font-size: .85rem; color: var(--muted); }
#f-auth input { font: inherit; padding: .65rem .8rem; border: 1px solid #d6ccb6; border-radius: 10px; background: #fffdf8; color: var(--ink); }
#f-auth input:focus { outline: 2px solid var(--gold); border-color: transparent; }
#f-auth:not(.signup) .only-signup { display: none; }
.vai-regole { display: block; text-align: center; margin-top: .6rem; color: var(--felt); font-weight: 600; }

/* --- Come si gioca --- */
.come { max-width: 1040px; margin: 0 auto; padding-top: 24px; color: var(--cream); }
.come h2 { font-family: var(--serif); font-size: clamp(2rem, 5vw, 2.8rem); margin: 0 0 1.4rem; letter-spacing: -.01em; }
.passi { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 22px; counter-reset: passo; }
.passi li { counter-increment: passo; display: grid; grid-template-rows: 130px auto auto; align-content: start; }
.passi .arte { display: flex; align-items: flex-end; justify-content: center; gap: 0; --card-w: 52px; padding-bottom: 12px; border-bottom: 1px solid rgba(246,239,223,.2); }
.passi .arte > * + * { margin-left: -14px; }
.passi .arte .card { box-shadow: 0 4px 10px rgba(0,0,0,.35); }
.passi .arte .card .badge { font-size: .62rem; padding: 0 .35rem; bottom: -7px; }
.passi .arte .card:nth-child(odd) { transform: rotate(-6deg); }
.passi .arte .card:nth-child(even) { transform: rotate(5deg) translateY(-4px); }
.passi h3 { font-family: var(--serif); font-size: 1.15rem; margin: 14px 0 6px; display: flex; gap: .5rem; align-items: baseline; }
.passi h3::before { content: counter(passo); color: var(--gold); font-size: 1.6rem; font-weight: 700; }
.passi p { margin: 0; line-height: 1.5; font-size: .95rem; color: #d7e8dd; }
.passi .mini-mazzo { width: 46px; height: 74px; border-radius: 6px; border: 2px solid var(--cream); background: repeating-linear-gradient(45deg, #9e0d25 0 5px, #b5112b 5px 10px); box-shadow: 2px 2px 0 #d8ceb6, 4px 4px 0 #bfb39a; }
.passi .moneta { width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe28a, var(--gold) 55%, #a5671b); border: 3px solid #c48a2a; align-self: center; margin: 0 10px !important; font: 700 1rem var(--serif); color: #6b4510; display: grid; place-items: center; }
.passi .freccia { color: var(--gold); font-size: 1.6rem; align-self: center; margin: 0 8px !important; }
.passi.chiaro { grid-template-columns: 1fr; gap: 18px; margin-top: 1rem; }
.passi.chiaro li { grid-template-columns: 150px 1fr; grid-template-rows: auto auto; column-gap: 16px; }
.passi.chiaro .arte { grid-row: span 2; border: 0; padding: 6px 0 10px; }
.passi.chiaro h3 { margin-top: 0; color: var(--ink); }
.passi.chiaro p { color: var(--muted); }

@media (max-width: 860px) {
  .ingresso { grid-template-columns: 1fr; gap: 28px; padding-top: 28px; min-height: 0; }
  .hero { justify-items: center; text-align: center; }
  .marchio { justify-content: center; }
  .hero .sottotitolo { margin-inline: auto; }
  .ventaglio { --fan-w: 100px; margin-top: 18px; }
  .passi { grid-template-columns: 1fr; gap: 26px; }
  .passi li { grid-template-columns: 130px 1fr; grid-template-rows: auto auto; column-gap: 16px; }
  .passi .arte { grid-row: span 2; border: 0; padding: 4px 0 8px; }
  .passi h3 { margin-top: 0; }
}
@media (max-width: 420px) {
  .passi li, .passi.chiaro li { grid-template-columns: 1fr; }
  .passi .arte, .passi.chiaro .arte { grid-row: auto; justify-content: flex-start; }
}

.ospite { background: #fff4d6; border: 1px solid #efd58f; font-size: .93rem; }
#f-salva { display: grid; gap: .6rem; margin-top: .9rem; }
#f-salva label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
#f-salva input { font: inherit; padding: .55rem .7rem; border: 1px solid #d6ccb6; border-radius: 10px; background: #fffdf8; }

/* --- Lobby --- */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; color: var(--cream); max-width: 640px; margin: 0 auto; }
.who { display: flex; gap: .8rem; align-items: center; }
.lobby { max-width: 640px; margin: 0 auto; padding: 0 16px 32px; display: grid; gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats div { background: rgba(0,0,0,.22); color: var(--cream); border-radius: var(--radius); padding: .7rem; text-align: center; }
.stats b { display: block; font-size: 1.6rem; font-family: var(--serif); }
.stats span { font-size: .8rem; opacity: .75; }
.panel { background: var(--panel); border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.panel h2 { font-size: 1.05rem; margin: 0 0 .7rem; }
#p-cerca { padding: 2rem 1rem; }
.invitati, .inviti { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .5rem; }
.invitati li { display: flex; align-items: center; gap: .5rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #b9b09d; flex: none; }
.dot.on { background: #2f9e5b; box-shadow: 0 0 0 3px rgba(47,158,91,.2); }
.inviti li { display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; background: #fff8e8; border-radius: 10px; border: 1px solid #efdfbc; animation: pop .3s; }
.inviti li .chi { flex: 1; }
.inviti li.empty { background: none; border: 0; color: var(--muted); padding: 0; animation: none; }
.countdown { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }
.regole summary { cursor: pointer; font-weight: 600; }
.regole ul { margin: .7rem 0 0; padding-left: 1.2rem; line-height: 1.5; font-size: .93rem; }

/* --- Tavolo --- */
#v-gioco { display: flex; }
.table { flex: 1; display: grid; grid-template-rows: auto 1fr auto auto; max-width: 640px; margin: 0 auto; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); min-height: 100dvh; color: var(--cream); }
.seat { display: flex; align-items: center; gap: 14px; }
.seat.opp { justify-content: flex-start; }
.seat.me { justify-content: flex-end; }
.name { font-weight: 600; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.name.turn::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 10px var(--gold); animation: pulse 1.2s infinite; }

.deck {
  position: relative; width: calc(var(--card-w) * .8); height: calc(var(--card-h) * .8);
  border-radius: 9px; border: 3px solid var(--cream);
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.18) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, #9e0d25 0 6px, #b5112b 6px 12px);
  box-shadow: 2px 2px 0 #d8ceb6, 4px 4px 0 #bfb39a, 0 8px 18px rgba(0,0,0,.35);
  padding: 0; font: inherit; color: #fff;
}
.deck.empty { opacity: .25; }
.deck .count { position: absolute; top: -10px; right: -10px; background: var(--ink); color: var(--cream); border-radius: 999px; padding: .15rem .5rem; font-size: .85rem; font-weight: 700; }
.deck.mine { width: var(--card-w); height: var(--card-h); cursor: pointer; transition: transform .12s; }
.deck.mine .tap { position: absolute; inset: auto 0 10px; text-align: center; font-weight: 700; letter-spacing: .5px; text-shadow: 0 1px 2px #000; opacity: 0; }
.deck.mine.ready { animation: nudge 1.6s infinite; box-shadow: 2px 2px 0 #d8ceb6, 4px 4px 0 #bfb39a, 0 0 0 4px var(--gold), 0 0 24px var(--gold); }
.deck.mine.ready .tap { opacity: 1; }
.deck.mine:disabled { cursor: default; }
.deck.mine:active:not(:disabled) { transform: translateY(-6px) scale(.98); }

.middle { display: grid; place-items: center; align-content: center; gap: 10px; padding: 10px 0; }
.status { min-height: 2.4em; text-align: center; font-weight: 600; font-size: 1.05rem; background: rgba(0,0,0,.25); padding: .5rem 1rem; border-radius: 999px; }
.status.debt { background: var(--red); color: #fff; animation: pop .25s; }
.pile { position: relative; width: calc(var(--card-w) * 2.2); height: calc(var(--card-h) * 1.25); }
.pile .card { position: absolute; left: 50%; top: 50%; }
.pile.sweep-0 .card, .pile.sweep-1 .card { transition: transform .5s ease-in, opacity .5s ease-in; opacity: 0; }
.pile-count { font-size: .85rem; opacity: .8; min-height: 1.2em; }
.msg { min-height: 1.5em; text-align: center; font-size: .95rem; color: #fbe7a6; }
.game-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 10px; }

/* --- Carta (SVG napoletana) --- */
.card {
  width: var(--card-w); height: calc(var(--card-w) * 1.6); border-radius: 7px; position: relative;
  box-shadow: 0 3px 10px rgba(0,0,0,.35); user-select: none;
}
.card svg.napoletana { display: block; width: 100%; height: 100%; }
.card.special { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(232,179,58,.7), 0 3px 10px rgba(0,0,0,.35); }
.card .badge { position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%); background: var(--gold); color: var(--ink); font-weight: 800; font-size: .8rem; padding: .1rem .5rem; border-radius: 999px; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.card.in-0 { animation: fromBottom .28s ease-out; }
.card.in-1 { animation: fromTop .28s ease-out; }

/* --- Overlay --- */
.overlay { position: fixed; inset: 0; background: rgba(5,20,14,.78); display: grid; place-items: center; align-content: center; gap: 1.2rem; z-index: 20; color: var(--cream); text-align: center; padding: 16px; animation: fade .2s; }
.coin { width: 120px; height: 120px; position: relative; transform-style: preserve-3d; }
.coin .f { position: absolute; inset: 0; border-radius: 50%; display: grid; place-items: center; font: 700 3rem var(--serif); color: #6b4510; background: radial-gradient(circle at 35% 30%, #ffe28a, var(--gold) 55%, #a5671b); border: 5px solid #c48a2a; backface-visibility: hidden; }
.coin .croce { transform: rotateY(180deg); }
.coin.spin-testa { animation: spinT 1.6s cubic-bezier(.2,.7,.3,1) forwards; }
.coin.spin-croce { animation: spinC 1.6s cubic-bezier(.2,.7,.3,1) forwards; }
#coin-txt { font-size: 1.2rem; font-weight: 600; min-height: 1.5em; }
.end-card { background: var(--panel); color: var(--ink); border-radius: var(--radius); padding: 2rem 1.5rem; width: min(360px, 100%); }
.end-card h2 { font-family: var(--serif); font-size: 2rem; margin: 0 0 .5rem; }

/* --- Toast --- */
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 30; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--ink); color: var(--cream); padding: .75rem 1rem; border-radius: 12px; box-shadow: 0 8px 20px rgba(0,0,0,.35); animation: pop .25s; font-size: .95rem; }
.toast.err { background: var(--red); color: #fff; }

@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pulse { 50% { opacity: .3; } }
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes fromBottom { from { transform: translate(-50%, 120%) rotate(0deg) scale(.9); opacity: .4; } }
@keyframes fromTop { from { transform: translate(-50%, -170%) rotate(0deg) scale(.9); opacity: .4; } }
@keyframes spinT { from { transform: rotateY(0); } to { transform: rotateY(1800deg); } }
@keyframes spinC { from { transform: rotateY(0); } to { transform: rotateY(1980deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
