/* ── Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,400;0,14..32,500;0,14..32,600;0,14..32,700;0,14..32,800;0,14..32,900&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css');

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ── */
:root {
    --bg:           #141428;
    --surface:      #191930;
    --surface-2:    #1f1f38;
    --border:       #1e1e2e;
    --border-2:     #28283c;
    --text:         #ededf5;
    --muted:        #636387;
    --primary:      #6366f1;
    --primary-2:    #8b5cf6;
    --primary-glow: rgba(99,102,241,.18);
    --green:        #22c55e;
    --green-glow:   rgba(34,197,94,.14);
    --red:          #f43f5e;
    --red-glow:     rgba(244,63,94,.14);
    --amber:        #f59e0b;
    --radius:       16px;
    --radius-sm:    10px;
    --shadow:       0 12px 48px rgba(0,0,0,.6);
    --shadow-sm:    0 4px 16px rgba(0,0,0,.4);
}

/* ── Base ── */
html, body {
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.container {
    max-width: 880px;
    margin: 0 auto;
    padding: 48px 24px;
}

/* ── Hero ── */
.hero {
    text-align: center;
    margin-bottom: 56px;
}

.logo {
    font-size: 3.8rem;
    font-weight: 900;
    letter-spacing: -3px;
    line-height: 1;
    background: linear-gradient(135deg, #818cf8 0%, #a78bfa 40%, #6366f1 70%, #818cf8 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 5s linear infinite;
}

@keyframes shimmer {
    0%   { background-position: 0% center; }
    100% { background-position: 200% center; }
}

.tagline {
    margin-top: 12px;
    color: var(--muted);
    font-size: .95rem;
    font-weight: 500;
    letter-spacing: .01em;
}

/* ── Cards ── */
.cards {
    display: flex;
    align-items: flex-start;
    gap: 20px;
}

.card {
    flex: 1;
    background: linear-gradient(160deg, var(--surface) 0%, var(--surface-2) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.04);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(99,102,241,.5), transparent);
    pointer-events: none;
}

.card h2 {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -.01em;
    margin-bottom: 24px;
}

.divider {
    align-self: center;
    color: var(--muted);
    font-size: .8rem;
    font-weight: 500;
    padding: 0 4px;
    white-space: nowrap;
}

/* ── Forms ── */
.field { margin-bottom: 20px; }

.field label {
    display: block;
    font-size: .72rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: 8px;
}

.field input[type="text"] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 11px 16px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

.field input[type="text"]::placeholder { color: var(--muted); }

.field input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── Radio options ── */
.round-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.round-option { flex: 1; min-width: 0; cursor: pointer; }
.round-option input[type="radio"] { display: none; }

.round-option span {
    display: block;
    text-align: center;
    padding: 9px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--bg);
    color: var(--muted);
    font-weight: 600;
    font-size: .88rem;
    transition: all .2s;
    white-space: nowrap;
}

.round-option input[type="radio"]:checked + span {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-glow);
    box-shadow: 0 0 0 1px var(--primary);
}

/* ── Buttons ── */
.btn {
    display: block;
    width: 100%;
    padding: 13px 20px;
    border: none;
    border-radius: 999px;
    font-family: inherit;
    font-size: .95rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 10px;
    transition: all .2s;
    letter-spacing: .01em;
}

.btn:active { transform: scale(.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    box-shadow: 0 4px 24px rgba(99,102,241,.4);
}

.btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 6px 32px rgba(99,102,241,.55);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-2);
}

.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

/* ── Lobby ── */
.lobby {
    text-align: center;
    max-width: 480px;
    margin: 60px auto;
}

.lobby h2 {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -.02em;
    margin-bottom: 10px;
}

.lobby p { color: var(--muted); margin-bottom: 28px; font-weight: 500; }

.game-code {
    display: inline-block;
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: 8px;
    color: var(--primary);
    background: var(--primary-glow);
    border: 1px solid rgba(99,102,241,.3);
    border-radius: var(--radius);
    padding: 18px 36px;
    margin-bottom: 24px;
    box-shadow: 0 0 48px rgba(99,102,241,.12), inset 0 1px 0 rgba(99,102,241,.2);
}

.waiting {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
    font-size: .9rem;
    font-weight: 500;
}

.dot-pulse { display: flex; gap: 5px; }

.dot-pulse span {
    width: 5px; height: 5px;
    background: var(--primary);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite;
}

.dot-pulse span:nth-child(2) { animation-delay: .2s; }
.dot-pulse span:nth-child(3) { animation-delay: .4s; }

@keyframes dotPulse {
    0%, 80%, 100% { opacity: .2; transform: scale(.8); }
    40%           { opacity: 1;  transform: scale(1.2); }
}

/* ── Scoreboard ── */
.scoreboard {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(16,16,26,.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,.06);
    border-radius: var(--radius);
    padding: 18px 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,.04);
    position: relative;
    overflow: hidden;
}

.scoreboard::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(99,102,241,.25), transparent);
}

.player-score { text-align: center; min-width: 84px; }

.player-score .name {
    font-size: .72rem;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 90px;
}

.player-score .pts {
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: -2px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.round-info { text-align: center; color: var(--muted); font-size: .78rem; font-weight: 500; }
.round-info strong { display: block; font-size: .95rem; color: var(--text); font-weight: 700; margin-bottom: 3px; }

/* ── Phase boxes ── */
.phase-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
    transition: border-color .35s;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.phase-box[data-phase="message"] { border-color: rgba(245,158,11,.45); }
.phase-box[data-phase="choice"]  { border-color: rgba(99,102,241,.45); }

.phase-box h3 {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    margin-bottom: 14px;
    transition: color .35s;
}

.phase-box[data-phase="message"] h3 { color: var(--amber); }
.phase-box[data-phase="choice"]  h3 { color: var(--primary); }

/* ── Messages ── */
.message-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.msg-btn {
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 11px 14px;
    font-family: inherit;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    line-height: 1.4;
    transition: all .2s;
}

.msg-btn:hover    { border-color: var(--amber); color: var(--amber); background: rgba(245,158,11,.06); }
.msg-btn.selected { border-color: var(--amber); background: rgba(245,158,11,.1); color: var(--amber); }

/* ── Choice buttons ── */
.choice-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.choice-btn {
    padding: 32px 16px;
    border-radius: var(--radius);
    border: 2px solid transparent;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    text-align: center;
    transition: all .22s;
    position: relative;
    overflow: hidden;
    letter-spacing: -.01em;
}

.choice-btn .icon { font-size: 2.4rem; display: block; margin-bottom: 10px; }

.choice-btn.cooperate {
    background: var(--green-glow);
    border-color: rgba(34,197,94,.3);
    color: var(--green);
}

.choice-btn.betray {
    background: var(--red-glow);
    border-color: rgba(244,63,94,.3);
    color: var(--red);
}

.choice-btn.cooperate:hover {
    background: rgba(34,197,94,.2);
    border-color: var(--green);
    box-shadow: 0 0 32px rgba(34,197,94,.22);
    transform: translateY(-2px);
}

.choice-btn.betray:hover {
    background: rgba(244,63,94,.2);
    border-color: var(--red);
    box-shadow: 0 0 32px rgba(244,63,94,.22);
    transform: translateY(-2px);
}

.choice-btn.selected { transform: scale(1.04) translateY(-2px); }
.choice-btn.cooperate.selected { border-color: var(--green); background: rgba(34,197,94,.22); box-shadow: 0 0 40px rgba(34,197,94,.28); }
.choice-btn.betray.selected    { border-color: var(--red);   background: rgba(244,63,94,.22);  box-shadow: 0 0 40px rgba(244,63,94,.28); }

/* ── Timer ring ── */
.timer-ring-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    position: relative;
    width: 72px;
    height: 72px;
    margin-left: auto;
    margin-right: auto;
}

.timer-ring-wrap svg {
    transform: rotate(-90deg);
    width: 72px;
    height: 72px;
}

.timer-ring-bg   { fill: none; stroke: var(--border-2); stroke-width: 5; }
.timer-ring-fill {
    fill: none;
    stroke: var(--primary);
    stroke-width: 5;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s linear, stroke .4s;
}

.timer-ring-fill.urgent { stroke: var(--red); }

.timer-ring-num {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

/* Compatibility: keep old bar for replay progress */
.timer-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 20px;
    overflow: hidden;
}

.timer-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
    border-radius: 2px;
    transition: width 1s linear;
}

.timer-fill.urgent { background: var(--red); }

/* ── Reveal cards ── */
.reveal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.flip-card { perspective: 900px; height: 150px; }

.flip-card-inner {
    position: relative;
    width: 100%; height: 100%;
    transition: transform .75s cubic-bezier(.4,0,.2,1);
    transform-style: preserve-3d;
}

.flip-card.flipped .flip-card-inner { transform: rotateY(180deg); }

.flip-front, .flip-back {
    position: absolute;
    width: 100%; height: 100%;
    border-radius: var(--radius);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.flip-front {
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    color: var(--muted);
    font-size: 2.2rem;
}

.flip-back {
    transform: rotateY(180deg);
    font-size: .95rem;
}

.flip-back .icon { font-size: 2.2rem; margin-bottom: 8px; }
.flip-back.cooperate { background: rgba(34,197,94,.1);  border: 1px solid var(--green); color: var(--green); box-shadow: inset 0 0 40px rgba(34,197,94,.08); }
.flip-back.betray    { background: rgba(244,63,94,.1);   border: 1px solid var(--red);   color: var(--red);   box-shadow: inset 0 0 40px rgba(244,63,94,.08); }

/* ── Event banner ── */
.event-banner {
    background: linear-gradient(135deg, rgba(99,102,241,.14), rgba(139,92,246,.1));
    border: 1px solid rgba(99,102,241,.4);
    border-radius: var(--radius);
    padding: 14px 20px;
    margin-bottom: 16px;
    text-align: center;
    font-size: .95rem;
    font-weight: 700;
    color: #a5b4fc;
    box-shadow: 0 0 28px rgba(99,102,241,.12);
}

/* ── History ── */
.history { margin-top: 24px; }

.history h3 {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin-bottom: 10px;
}

.history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 5px;
    font-size: .875rem;
    transition: border-color .2s, transform .15s;
}

.history-row:hover { border-color: var(--border-2); transform: translateX(2px); }

.history-row .round-num { color: var(--muted); font-size: .72rem; font-weight: 600; width: 58px; }
.history-row .choices   { display: flex; gap: 12px; flex-wrap: wrap; font-weight: 500; flex: 1; }
.history-row .pts-delta { font-weight: 800; width: 68px; text-align: right; font-variant-numeric: tabular-nums; }
.history-row .pts-delta.positive { color: var(--green); }
.history-row .pts-delta.negative { color: var(--red); }
.history-row .pts-delta.neutral  { color: var(--muted); }

/* ── Results ── */
.results {
    text-align: center;
    max-width: 520px;
    margin: 48px auto;
}

.results .winner-label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 8px;
}

.results .winner-name {
    font-size: 2.8rem;
    font-weight: 900;
    letter-spacing: -1px;
    background: linear-gradient(135deg, #818cf8, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.results .final-scores {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 40px;
    margin: 32px 0;
}

.results .final-scores .player-score .pts { font-size: 2.8rem; }

/* ── Touch & iOS ── */
* { -webkit-tap-highlight-color: transparent; }
input, button, select { font-size: 16px; font-family: inherit; }

/* ── Responsive ── */
@media (max-width: 600px) {
    .container { padding: 20px 16px; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
    .hero { margin-bottom: 28px; }
    .logo { font-size: 2.8rem; letter-spacing: -2px; }
    .cards { flex-direction: column; }
    .divider { padding: 4px 0; }
    .card { padding: 20px; }
    .round-options { flex-wrap: wrap; }
    .round-option { flex: 1 1 calc(50% - 4px); }
    .lobby { margin: 24px auto; }
    .game-code { font-size: 1.7rem; letter-spacing: 4px; padding: 14px 20px; }
    .scoreboard { padding: 14px 12px; }
    .player-score .pts  { font-size: 1.9rem; }
    .player-score .name { font-size: .68rem; max-width: 72px; }
    .phase-box { padding: 16px; }
    .message-grid { grid-template-columns: 1fr; }
    .msg-btn { padding: 12px 14px; min-height: 44px; }
    .choice-grid { gap: 10px; }
    .choice-btn { padding: 24px 10px; min-height: 100px; }
    .choice-btn .icon { font-size: 2rem; }
    .reveal-grid { gap: 10px; }
    .flip-card { height: 118px; }
    .history-row { flex-wrap: wrap; gap: 4px; font-size: .8rem; }
    .history-row .round-num { width: auto; }
    .history-row .choices { flex: 1 1 100%; }
    .history-row .pts-delta { width: auto; flex: 1 1 100%; text-align: left; }
    .results { margin: 20px auto; }
    .results .winner-name { font-size: 2rem; }
    .results .final-scores { gap: 20px; }
    .results .final-scores .player-score .pts { font-size: 2.2rem; }
    .btn { min-height: 44px; }
    .timer-ring-wrap, .timer-ring-wrap svg { width: 60px; height: 60px; }
    .timer-ring-num { font-size: .9rem; }
}

/* ── Index: two-column layout ── */
.page-wrap {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    column-gap: 36px;
    max-width: 1120px;
    margin: 0 auto;
    padding: 28px 24px;
    height: 100vh;
    box-sizing: border-box;
    align-items: start;
}

.page-sep {
    width: 1px;
    align-self: stretch;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        var(--border-2) 12%,
        var(--border-2) 88%,
        transparent 100%
    );
}

.col-right {
    width: 100%;
    height: calc(100vh - 56px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
#dashboard-list > div { width: 100%; }
.col-right::-webkit-scrollbar       { width: 4px; }
.col-right::-webkit-scrollbar-track { background: transparent; }
.col-right::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Left column: hero aligned left, compact spacing */
.col-left .hero    { text-align: left; margin-bottom: 20px; }
.col-left .logo    { font-size: 2.8rem; letter-spacing: -2px; }
.col-left .tagline { font-size: 1rem; }

/* Cards stack vertically, full width */
.col-left .cards { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
.col-left .card  { padding: 14px 20px; width: 100%; }
.col-left .card h2 { font-size: .95rem; margin-bottom: 12px; }

/* "Unisciti" card — secondary treatment */
.col-left .cards > .card:last-child {
    background: rgba(16,16,26,.5);
    border-color: var(--border);
    box-shadow: none;
}
.col-left .cards > .card:last-child::before { opacity: .25; }

/* Compact form spacing */
.col-left .field                    { margin-bottom: 10px; }
.col-left .field label              { margin-bottom: 6px; }
.col-left .field input[type="text"] { padding: 8px 14px; font-size: 15px; }
.col-left .round-option span        { padding: 6px 5px; font-size: .82rem; }
.col-left .btn                      { padding: 10px 20px; margin-top: 4px; font-size: .9rem; }

/* "Oppure" divider with flanking lines */
.col-left .divider {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 0;
    color: var(--muted);
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
}
.col-left .divider::before,
.col-left .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-2);
}

/* Index responsive */
@media (max-width: 860px) {
    .page-wrap {
        grid-template-columns: 1fr;
        height: auto;
        padding: 20px 16px;
        column-gap: 0;
        row-gap: 28px;
    }
    .page-sep { display: none; }
    .col-right { height: auto; overflow-y: visible; }
    .col-left .hero    { margin-bottom: 28px; }
    .col-left .logo    { font-size: 2.6rem; letter-spacing: -2px; }
    .col-left .tagline { font-size: .95rem; }
    .col-left .card    { padding: 20px; }
    .col-left .cards > .card:last-child { padding: 20px; }
    .col-left .field   { margin-bottom: 16px; }
    .col-left .field label { margin-bottom: 8px; }
    .col-left .field input[type="text"] { padding: 10px 14px; font-size: 16px; }
    .col-left .round-option span { padding: 8px 6px; font-size: .88rem; }
    .col-left .btn     { padding: 12px 20px; font-size: .95rem; }
    .col-left .divider { padding: 14px 0; }
}
