/*
 * Stile di Burranando.
 *  - Le misure di progetto dell'interfaccia di gioco sono in px (variabili in :root): lo script
 *    burraco.js scala l'intera interfaccia con `zoom`, quindi qui non servono media query.
 *  - Sezioni: layout del tavolo, combinazioni calate, carte, mano, finestre, lobby.
 */
:root {
	--felt: #1d6b3f; --felt-d: #14522f;
	/* Misure di progetto in px: tutta l'interfaccia viene scalata in proporzione (zoom) dallo script */
	--bw: 58px;                                   /* carta di mano, tallone, pozzo */
	--card-w: var(--bw);
	--mh: 68px;                                   /* altezza carta calata */
	--mw: calc(var(--mh) * .742);
	--melds-h: calc(var(--mh) * 5.42 + 66px);      /* contiene la scala più lunga (14 carte) */
}
* { box-sizing: border-box; }
html { overflow-x: hidden; }
body { margin: 0; font: 15px/1.35 system-ui, sans-serif; background: var(--felt-d); color: #fff; }
#app { box-sizing: border-box; width: 100%; margin: 0; padding: 8px 16px 12px; display: flex; flex-direction: column; gap: 8px; }
header { display: flex; align-items: center; gap: 16px; }
h1 { margin: 0; font-size: 22px; }
#scores { flex: 1; display: flex; gap: 16px; font-weight: 600; }
button { font: inherit; padding: 6px 14px; border: 0; border-radius: 6px; background: #f3c744; color: #222; cursor: pointer; font-weight: 600; }
button:disabled { opacity: .35; cursor: default; }

main { display: grid; grid-template-columns: 110px 1fr 110px; grid-template-rows: auto 1fr; grid-template-areas: "north north north" "west table east"; gap: 8px; flex: 1; position: relative; }
#north { grid-area: north; justify-self: center; }
#west { grid-area: west; align-self: center; }
#east { grid-area: east; align-self: center; }
#table { grid-area: table; background: var(--felt); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 10px; min-width: 0; box-shadow: inset 0 0 40px rgba(0,0,0,.3); }
.seat { text-align: center; font-size: 13px; }
.seat.turn .seat-name { background: #f3c744; color: #222; }
.seat-name { display: inline-block; padding: 2px 10px; border-radius: 10px; background: rgba(0,0,0,.3); margin-bottom: 4px; }

#melds-1 { order: 0; }
#center { order: 1; }
#melds-0 { order: 2; background: rgba(243,199,68,.12); }
.melds { display: flex; flex-direction: column; gap: 4px; height: var(--melds-h); padding: 8px; border-radius: 8px; background: rgba(0,0,0,.12); } /* altezza fissa: contiene la scala più lunga (14 carte) */
.melds .label { font-size: 12px; opacity: .8; }
.meldlist { display: flex; align-items: flex-start; gap: 12px; flex: 1; min-height: 0; overflow: auto; }
.meld { flex: none; display: flex; flex-direction: column; align-items: center; padding: 4px; border-radius: 6px; cursor: default; }
.meld.mine.droppable { cursor: pointer; outline: 2px dashed rgba(243,199,68,.8); }
.meld.burraco { background: rgba(243,199,68,.25); }
.meld .card { --card-w: var(--mw); height: var(--mh); flex-direction: row; justify-content: flex-start; align-items: flex-start; gap: 2px; margin-top: calc(var(--mh) * -.66); font-size: 17px; padding: 2px 4px; }
.meld .card:first-child { margin-top: 0; }
.meld .card .as { position: static; font-size: 12px; margin-left: 2px; }
.tag { font-size: 10px; margin-top: 4px; text-align: center; color: #f3c744; font-weight: 700; }

#center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; flex: 1; }
#piles { display: flex; align-items: flex-start; justify-content: center; gap: 24px; }
.pile { position: relative; text-align: center; }
.pile .count { margin-top: 4px; font-size: 12px; }
#stock.active .card, #discard.active .fan .card:last-child { outline: 3px solid #f3c744; cursor: pointer; }
#info { margin-top: 8px; max-width: min(560px, 100%); text-align: center; font-size: 12px; line-height: 1.3; opacity: .85; pointer-events: none; }

.card { display: inline-flex; flex-direction: column; justify-content: space-between; width: var(--card-w); height: calc(var(--card-w) * 1.45); background: #fff; color: #111; border-radius: 6px; padding: 3px 5px; font-weight: 700; font-size: calc(var(--card-w) * .26); line-height: 1; box-shadow: 0 1px 3px rgba(0,0,0,.5); user-select: none; position: relative; flex: none; }
.card.red { color: #c9202b; }
.card .s { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 2.2em; }
.card .sc { display: none; }
.meld .card .sc, .fan .card .sc { display: inline; }
.card .as { position: absolute; right: 2px; bottom: 1px; font-size: 9px; color: #555; }
.card.wild { background: #fff8d6; }
.card.back { background: repeating-linear-gradient(45deg, #2a4fa3, #2a4fa3 4px, #1f3d82 4px, #1f3d82 8px); border: 2px solid #fff; }
.seat .card { --card-w: calc(var(--bw) * .52); margin: calc(var(--bw) * -.5) 0 0; font-size: 8px; }
.seat .card:first-child { margin-top: 0; }
#north .card { margin: 0 0 0 calc(var(--bw) * -.34); }
#north .card:first-child { margin-left: 0; }

footer { display: flex; flex-direction: column; gap: 8px; }
#hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 14px 6px 6px; min-height: calc(var(--bw) * 1.45 + 24px); }
#hand .card { cursor: pointer; transition: transform .1s; }
#hand .card.sel { transform: translateY(-14px); box-shadow: 0 0 0 3px #f3c744; }
#actions { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; max-width: min(90vw, 480px); padding: 10px 18px; border-radius: 8px; font-weight: 600; text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,.4); animation: toast-in .2s ease-out; pointer-events: none; }
#toast.err { background: #b3261e; color: #fff; }
#toast.ok { background: #222; color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }

#log { position: absolute; left: 100px; top: 0; max-width: 300px; font-size: 12px; background: rgba(0,0,0,.35); border-radius: 8px; padding: 6px 10px; pointer-events: none; opacity: .9; }
#log div:last-child { font-weight: 700; }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 10; }
#modal[hidden] { display: none; }
#modal .box { background: #fff; color: #222; border-radius: 12px; padding: 20px 26px; max-width: 520px; }
#modal table { width: 100%; border-collapse: collapse; margin: 10px 0; }
#modal td, #modal th { padding: 3px 8px; text-align: right; }
#modal td:first-child, #modal th:first-child { text-align: left; }
#modal tr.total { font-weight: 700; border-top: 2px solid #222; }

.fan { display: flex; flex-wrap: wrap; row-gap: 6px; max-width: 520px; justify-content: center; padding-left: calc(var(--bw) * .45); }
.fan .card { flex-direction: row; justify-content: flex-start; align-items: flex-start; gap: 2px; margin-left: calc(var(--bw) * -.45); }
.fan.compact .card { --card-w: calc(var(--bw) * .86); margin-left: calc(var(--bw) * -.4); } /* ridotte solo se il pozzo è molto grande */
.fan .card:last-child { box-shadow: 0 0 0 2px #f3c744, 0 1px 3px rgba(0,0,0,.5); }

.badge { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: 10px; background: #f3c744; color: #222; font-size: 11px; font-weight: 700; }
.badge.off { visibility: hidden; }
.seat.me { display: flex; gap: 8px; justify-content: center; align-items: center; }
.seat.me .badge { margin-top: 0; }
.seat.me .badge.off { display: none; }

/* L'attributo hidden deve vincere anche sugli elementi con display esplicito (es. #app è flex). */
[hidden] { display: none !important; }

/* ---- Lobby e sala d'attesa ---- */
.screen { max-width: 520px; margin: 0 auto; padding: 40px 20px; }
.screen h1 { font-size: 34px; }
.screen .sub { opacity: .85; margin: 4px 0 24px; }
.screen label { display: block; font-weight: 600; margin-bottom: 4px; }
.screen input { width: 100%; padding: 10px 12px; border: 0; border-radius: 6px; font: inherit; color: #222; }
.screen .row { display: flex; gap: 10px; margin-top: 14px; }
.screen .row input { flex: 1; width: auto; text-transform: uppercase; }
.screen #w-link { text-transform: none; }
.screen button { padding: 10px 16px; }
.screen button.secondary { background: rgba(255,255,255,.2); color: #fff; }
.screen .msg { min-height: 22px; margin-top: 14px; color: #ffd0d0; font-weight: 600; }
#w-code { letter-spacing: 4px; color: #f3c744; }
#w-seats { margin: 18px 0; display: grid; gap: 8px; }
.wseat { display: flex; justify-content: space-between; padding: 10px 14px; border-radius: 8px; background: rgba(0,0,0,.25); }
.wseat.me { outline: 2px solid #f3c744; }
.wseat .team { opacity: .75; }
#room-code { font-weight: 700; color: #f3c744; letter-spacing: 1px; }

/* ---- Finestra di conferma (<dialog>) ---- */
#confirm { border: 0; border-radius: 12px; padding: 20px 26px; max-width: min(90vw, 380px); background: #fff; color: #222; box-shadow: 0 8px 32px rgba(0,0,0,.5); }
#confirm::backdrop { background: rgba(0,0,0,.65); }
#confirm h3 { margin: 0 0 6px; font-size: 18px; }
#confirm p { margin: 0 0 18px; color: #555; }
#confirm .buttons { display: flex; gap: 10px; justify-content: flex-end; }
#confirm button.cancel { background: #e4e4e4; }
#confirm button.danger { background: #b3261e; color: #fff; }
