* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0c0c14;
    --surface: #161622;
    --surface2: #1e1e2e;
    --surface3: #2a2a3c;
    --border: rgba(255,255,255,0.06);
    --text: #e8e8ef;
    --text2: #7a7a8e;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --red: #ff6b6b;
    --green: #51cf66;
    --gold: #fcc419;
    --card-white: #f8f9fa;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

#app, .app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Header ── */
.header {
    padding: 0 1.25rem;
    height: 48px;
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
    letter-spacing: -0.01em;
}

.header h1 span { color: var(--accent-light); }

.error-banner {
    background: var(--red);
    color: #fff;
    padding: 0.3rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem 1.25rem;
}

/* ── Buttons ── */
button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.12s ease;
    font-family: inherit;
}

button:hover:not(:disabled) { filter: brightness(1.15); }
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-play {
    background: var(--green);
    color: #111;
    padding: 0.6rem 1.75rem;
    font-size: 0.9rem;
}

.btn-pass {
    background: var(--surface3);
    color: var(--text2);
    padding: 0.6rem 1.75rem;
    font-size: 0.9rem;
}

.btn-fill {
    background: var(--gold);
    color: #111;
    padding: 0.6rem 1.75rem;
    font-size: 0.9rem;
    font-weight: 700;
}

.btn-bomb {
    background: var(--red);
    color: #fff;
    padding: 0.6rem 1.75rem;
    font-size: 0.9rem;
    font-weight: 700;
}

.btn-clear {
    background: var(--accent);
    color: #fff;
    padding: 0.6rem 1.75rem;
    font-size: 0.9rem;
}

.btn-ready {
    background: var(--surface3);
    color: var(--text);
    padding: 0.6rem 2rem;
}

.btn-ready.active {
    background: var(--green);
    color: #111;
}

.btn-secondary {
    background: var(--surface3);
    color: var(--text2);
}

.btn-ghost {
    background: transparent;
    color: var(--text2);
    font-size: 0.8rem;
    padding: 0.35rem 0.6rem;
}

.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface3); }

/* ── Inputs ── */
input[type="text"] {
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text2); }

/* ── Lobby ── */
.lobby { max-width: 420px; width: 100%; }

.name-entry {
    text-align: center;
    margin-top: 4rem;
}

.name-entry h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text2);
}

.name-entry form { display: flex; gap: 0.5rem; }

.name-entry input { flex: 1; }

.name-entry button {
    background: var(--accent);
    color: #fff;
}

.welcome {
    text-align: center;
    margin-bottom: 1.75rem;
    font-size: 0.9rem;
    color: var(--text2);
}

.welcome strong { color: var(--text); }

.lobby-actions { display: flex; flex-direction: column; gap: 1rem; }

.create-room, .join-room {
    background: var(--surface);
    padding: 1rem 1.15rem;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.section-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text2);
    margin-bottom: 0.65rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
    font-size: 0.82rem;
    color: var(--text2);
    cursor: pointer;
}

.checkbox-label input { accent-color: var(--accent); }

.create-buttons { display: flex; gap: 0.5rem; }
.create-buttons button { flex: 1; }
.create-room button { background: var(--accent); color: #fff; }

.join-room form { display: flex; gap: 0.5rem; }

.join-room input {
    flex: 1;
    text-align: center;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    font-weight: 600;
}

.join-room button { background: var(--accent); color: #fff; }

.room-list { margin-top: 1.5rem; }

.rooms { display: flex; flex-direction: column; gap: 0.35rem; }

.room-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface);
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.room-code {
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.12em;
    color: var(--accent-light);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.room-players { flex: 1; color: var(--text2); font-size: 0.8rem; }

.room-item button {
    background: var(--accent);
    color: #fff;
    padding: 0.3rem 0.75rem;
    font-size: 0.78rem;
}

/* ── Room ── */
.room { max-width: 400px; width: 100%; }

.room-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.room-header h2 { font-size: 1.05rem; font-weight: 600; }

.room-header .code {
    color: var(--accent-light);
    letter-spacing: 0.12em;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.room-tag {
    background: var(--surface3);
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.72rem;
    color: var(--text2);
    margin-bottom: 1rem;
    font-weight: 500;
}

.player-list {
    background: var(--surface);
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 0.85rem;
    margin-bottom: 1.25rem;
}

.player-list h3 {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text2);
    margin-bottom: 0.6rem;
}

.player-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0;
}

.player-row + .player-row { border-top: 1px solid var(--border); }

.player-row.me .player-name { color: var(--accent-light); }

.player-name { font-size: 0.88rem; font-weight: 500; }

.player-ready { font-size: 0.78rem; color: var(--text2); }
.player-ready.is-ready { color: var(--green); font-weight: 600; }

.room-actions { text-align: center; }

.hint { margin-top: 0.5rem; font-size: 0.78rem; color: var(--text2); }
.hint.starting { color: var(--green); font-weight: 500; }

/* ── Game ── */
.game-container {
    width: 100%;
    max-width: 860px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.game-top-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.turn-banner {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.3rem 0.85rem;
    border-radius: 6px;
    background: var(--green);
    color: #111;
}

.turn-banner.waiting {
    background: var(--surface2);
    color: var(--text2);
}

/* ── Players bar ── */
.players-bar { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.player-badge {
    background: var(--surface);
    padding: 0.4rem 0.65rem;
    border-radius: 8px;
    border: 1.5px solid transparent;
    min-width: 90px;
    position: relative;
    transition: border-color 0.15s;
}

.player-badge.active-turn { border-color: var(--green); }
.player-badge.is-me { background: var(--surface2); }
.player-badge.finished { opacity: 0.5; }
.player-badge.passed { opacity: 0.6; }

.player-badge-name { font-weight: 600; font-size: 0.78rem; margin-bottom: 2px; }

.player-badge-info { font-size: 0.68rem; color: var(--text2); display: flex; gap: 0.4rem; }

.badge-rank { color: var(--gold); font-weight: 700; }
.badge-passed { color: var(--red); font-weight: 500; }

.turn-indicator {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 8px;
    height: 8px;
    background: var(--green);
    border-radius: 50%;
    border: 2px solid var(--bg);
}

/* ── Pile ── */
.pile {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 1rem;
}

.pile-empty { color: var(--text2); font-size: 0.82rem; }

.pile-cards { display: flex; gap: 6px; }

/* ── Cards ── */
.card {
    width: 72px;
    height: 100px;
    background: var(--card-white);
    border-radius: 7px;
    position: relative;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,0,0,0.06);
    user-select: none;
    flex-shrink: 0;
}

.card:hover {
    transform: translateY(-10px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.35), 0 0 0 1px rgba(0,0,0,0.08);
}

.card.selected {
    transform: translateY(-18px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.45), 0 0 0 2px var(--accent);
}

.card.card-small {
    width: 60px;
    height: 84px;
    cursor: default;
}

.card.card-small:hover { transform: none; box-shadow: 0 1px 3px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,0,0,0.06); }

.card.red { color: #e03131; }
.card.black { color: #1a1a1a; }

.card-corner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.card-corner.top-left { top: 4px; left: 5px; }

.card-corner.bottom-right {
    bottom: 4px;
    right: 5px;
    transform: rotate(180deg);
}

.card-rank { font-size: 0.85rem; font-weight: 800; }
.card-suit { font-size: 0.65rem; margin-top: 1px; }

.card-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.6rem;
}

.card-small .card-rank { font-size: 0.72rem; }
.card-small .card-suit { font-size: 0.55rem; }
.card-small .card-center { font-size: 1.25rem; }

/* ── Hand ── */
.hand {
    display: flex;
    justify-content: center;
    padding: 0.5rem 0;
    min-height: 120px;
}

.hand .card { margin-left: -18px; }
.hand .card:first-child { margin-left: 0; }

/* ── Game controls ── */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.25rem 0;
    min-height: 44px;
}

.game-controls kbd {
    display: inline-block;
    font-family: inherit;
    font-size: 0.65rem;
    font-weight: 500;
    opacity: 0.5;
    margin-left: 0.25rem;
}

/* ── Exchange ── */
.exchange-banner {
    text-align: center;
    background: var(--surface2);
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: 10px;
}

.exchange-banner h2 {
    color: var(--accent-light);
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.exchange-banner p { color: var(--text2); font-size: 0.85rem; }

/* ── Scoreboard ── */
.scoreboard { max-width: 420px; width: 100%; text-align: center; }

.scoreboard h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    color: var(--text);
}

.rankings { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1.5rem; }

.ranking-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.65rem 0.85rem;
    background: var(--surface);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.ranking-row.me { border-color: var(--accent); }

.ranking-pos {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--gold);
    width: 1.75rem;
    text-align: center;
}

.ranking-row:first-child .ranking-pos { color: var(--gold); }
.ranking-row:nth-child(2) .ranking-pos { color: #adb5bd; }
.ranking-row:nth-child(3) .ranking-pos { color: #cd7f32; }

.ranking-title {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--accent-light);
    width: 110px;
    text-align: left;
}

.ranking-name { flex: 1; text-align: left; font-size: 0.88rem; }

.scoreboard-actions { display: flex; justify-content: center; gap: 0.6rem; }

/* ── Pile area (toast overlay container) ── */
.pile-area { position: relative; }

/* ── Toast ── */
.toast {
    text-align: center;
    padding: 0.5rem 1.25rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    animation: toastIn 0.25s ease-out, toastOut 0.3s ease-in 1.5s forwards;
    pointer-events: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    white-space: nowrap;
}

.toast-play {
    background: var(--green);
    color: #111;
}

.toast-bomb {
    background: var(--red);
    color: #fff;
    animation: toastIn 0.25s ease-out, toastShake 0.4s ease 0.25s, toastOut 0.3s ease-in 2s forwards;
}

.toast-pass {
    background: var(--surface3);
    color: var(--text2);
}

.toast-clear {
    background: var(--accent);
    color: #fff;
}

.toast-finish {
    background: var(--gold);
    color: #111;
}

@keyframes toastIn {
    from { opacity: 0; transform: translate(-50%, -50%) translateY(-8px); }
    to { opacity: 1; transform: translate(-50%, -50%) translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes toastShake {
    0%, 100% { transform: translate(-50%, -50%) translateX(0); }
    20% { transform: translate(-50%, -50%) translateX(-4px); }
    40% { transform: translate(-50%, -50%) translateX(4px); }
    60% { transform: translate(-50%, -50%) translateX(-3px); }
    80% { transform: translate(-50%, -50%) translateX(3px); }
}

/* ── Pile animations ── */
.pile-flash {
    animation: pileFlash 0.5s ease-out;
}

.pile-bomb {
    animation: pileBomb 0.6s ease-out;
}

.pile-clearing {
    animation: pileClear 0.5s ease-out;
}

@keyframes pileFlash {
    0% { box-shadow: 0 0 0 0 rgba(81, 207, 102, 0.5); }
    50% { box-shadow: 0 0 20px 4px rgba(81, 207, 102, 0.35); }
    100% { box-shadow: none; }
}

@keyframes pileBomb {
    0% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.6); transform: scale(1); }
    30% { box-shadow: 0 0 24px 6px rgba(255, 107, 107, 0.45); transform: scale(1.03); }
    100% { box-shadow: none; transform: scale(1); }
}

@keyframes pileClear {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0.5; transform: scale(0.97); }
}

/* ── Badge animations ── */
.badge-just-played {
    animation: badgePulse 0.5s ease-out;
}

.badge-just-passed {
    animation: badgeFade 0.4s ease-out;
}

.badge-just-bombed {
    animation: badgeBomb 0.6s ease-out;
}

.badge-just-finished {
    animation: badgeCelebrate 0.7s ease-out;
}

@keyframes badgePulse {
    0% { box-shadow: 0 0 0 0 rgba(81, 207, 102, 0.5); }
    50% { box-shadow: 0 0 12px 3px rgba(81, 207, 102, 0.35); }
    100% { box-shadow: none; }
}

@keyframes badgeFade {
    0% { opacity: 1; }
    50% { opacity: 0.4; }
    100% { opacity: 0.6; }
}

@keyframes badgeBomb {
    0% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.6); }
    50% { box-shadow: 0 0 14px 4px rgba(255, 107, 107, 0.4); }
    100% { box-shadow: none; }
}

@keyframes badgeCelebrate {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(252, 196, 25, 0.6); }
    40% { transform: scale(1.08); box-shadow: 0 0 16px 4px rgba(252, 196, 25, 0.4); }
    100% { transform: scale(1); box-shadow: none; }
}

/* ── Turn indicator pulse ── */
.turn-indicator {
    animation: turnPulse 1.5s ease-in-out infinite;
}

@keyframes turnPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(81, 207, 102, 0.4); }
    50% { box-shadow: 0 0 6px 2px rgba(81, 207, 102, 0.3); }
}

/* ── Turn banner pulse ── */
.turn-banner:not(.waiting) {
    animation: turnBannerPulse 2s ease-in-out infinite;
}

@keyframes turnBannerPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(81, 207, 102, 0.3); }
    50% { box-shadow: 0 0 10px 2px rgba(81, 207, 102, 0.2); }
}

/* ── Card dealing animation ── */
.hand-dealing .card {
    animation: cardDealIn 0.4s ease-out backwards;
}

@keyframes cardDealIn {
    from { opacity: 0; transform: translateY(40px) scale(0.85); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Card selection pop ── */
:not(.hand-dealing) > .card.selected {
    animation: cardSelectPop 0.2s ease-out;
}

@keyframes cardSelectPop {
    0% { transform: translateY(-18px) scale(1); }
    50% { transform: translateY(-20px) scale(1.08); }
    100% { transform: translateY(-18px) scale(1); }
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .main { padding: 1rem 0.75rem; }

    .card { width: 56px; height: 78px; }
    .card-center { font-size: 1.25rem; }
    .card-rank { font-size: 0.72rem; }
    .card-suit { font-size: 0.55rem; }
    .hand .card { margin-left: -14px; }

    .card-small { width: 46px; height: 64px; }
    .card-small .card-center { font-size: 1rem; }

    .players-bar { gap: 0.25rem; }
    .player-badge { min-width: 72px; padding: 0.3rem 0.45rem; }
    .player-badge-name { font-size: 0.7rem; }
    .player-badge-info { font-size: 0.62rem; }

    .pile { min-height: 90px; }

    .game-controls { gap: 0.4rem; }
    .btn-play, .btn-pass, .btn-fill, .btn-bomb, .btn-clear { padding: 0.5rem 1.25rem; font-size: 0.82rem; }

    .toast { font-size: 0.78rem; padding: 0.4rem 1rem; }

    .game-controls kbd { display: none; }
}
