* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

/* Safari 26+ derives its top/bottom chrome color from the page's
   background-color (it ignores the `theme-color` meta tag now; ref:
   nasedk.in/blog/ios26-safari-toolbar-colors). Set felt-mid here so the
   chrome reads as continuous-felt with the body's gradient edges below.
   In iOS PWA mode the same color covers the safe-area gutters. */
html { background-color: #14432a; }

:root {
    --felt-dark: #0d2818;
    --felt-mid: #14432a;
    --felt-light: #1a5c3a;
    --felt-highlight: #1f6b45;
    --gold-dark: #b8860b;
    --gold-mid: #d4af37;
    --gold-light: #f4d03f;
    --gold-glow: rgba(212, 175, 55, 0.3);
    --cream: #faf8f0;
    --cream-dim: #e8e4d4;
    --cream-dark: #c9c4b0;
    --chip-red: #c41e3a;
    --chip-blue: #1e4a7c;
    --danger: #9b2335;
    --success: #2d8659;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-hard: 0 2px 8px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 20px var(--gold-glow);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    /* Vertical gradient: felt-mid at the top and bottom EDGES (matches the
       Safari chrome color, no seam), felt-dark in the middle for visual
       depth. background-color stays felt-mid so the chrome inherits it. */
    background-color: var(--felt-mid);
    background-image: linear-gradient(180deg,
        var(--felt-mid) 0%,
        var(--felt-dark) 50%,
        var(--felt-mid) 100%);
    color: var(--cream);
    height: 100vh;
    height: 100dvh;
    user-select: none;
    overflow: hidden;
}

.container {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.screen { display: none; width: 100%; height: 100%; overflow: hidden; }
.screen.active { display: flex; flex-direction: column; }

/* Landing */
.landing {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 20px;
    text-align: center;
}

.logo {
    font-size: 72px;
    margin-bottom: 8px;
    color: var(--gold-mid);
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.app-title {
    font-family: 'Cinzel', serif;
    font-size: 28px;
    font-weight: 700;
    color: var(--gold-light);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 8px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.tagline {
    color: var(--cream-dark);
    margin-bottom: 48px;
    font-size: 14px;
    font-style: italic;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 280px;
}

button {
    background: linear-gradient(180deg, var(--gold-mid) 0%, var(--gold-dark) 100%);
    color: var(--felt-dark);
    border: none;
    padding: 16px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    min-height: 52px;
    touch-action: manipulation;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    box-shadow: var(--shadow-hard);
}

button:active { transform: scale(0.98); }
button:disabled { opacity: 0.7; cursor: not-allowed; }

button .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.secondary-btn {
    background: transparent;
    color: var(--cream);
    border: 2px solid var(--gold-mid);
}

/* Setup */
.setup-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 24px;
    height: 100vh;
    height: 100dvh;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.setup-screen .action-buttons {
    flex-direction: row;
    max-width: 100%;
}
.setup-screen .action-buttons button {
    flex: 1;
}

.setup-title {
    font-family: 'Cinzel', serif;
    text-align: center;
    font-size: 22px;
    margin-bottom: 36px;
    color: var(--gold-light);
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.form-group { margin-bottom: 24px; }
.custom-chips-input {
    margin-top: 12px;
    display: none;
}
.custom-chips-input.show {
    display: block;
}

label {
    display: block;
    margin-bottom: 10px;
    color: var(--cream-dim);
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

input, select {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--felt-highlight);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--cream);
    font-size: 16px;
    font-family: inherit;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--gold-mid);
    box-shadow: 0 0 0 3px var(--gold-glow);
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23d4af37' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
}

select option { background: var(--felt-dark); }

/* Game */
.game-screen {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: relative;
}

.game-header {
    background: rgba(0, 0, 0, 0.3);
    padding: 14px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid rgba(212, 175, 55, 0.2);
    flex-shrink: 0;
}

.room-info { text-align: center; }
.room-code { color: var(--gold-mid); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.15em; }
.player-name { font-family: 'Cinzel', serif; color: var(--cream); font-size: 18px; font-weight: 600; margin-top: 2px; }

/* Music Player */
.music-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.4);
    border-bottom: 1px solid rgba(212, 175, 55, 0.15);
}
.music-player-art {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold-mid) 100%);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.music-player-art i { color: var(--felt-dark); font-size: 16px; }
.music-player.playing .music-player-art { animation: pulse 2s ease-in-out infinite; }
.music-player-info { flex: 1; min-width: 0; }
.music-player-title {
    color: var(--cream);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.music-player-artist {
    color: var(--gold-mid);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
}
.music-player-controls { display: flex; gap: 4px; flex-shrink: 0; }
.music-ctrl-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--cream);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.music-ctrl-btn:hover { background: rgba(212, 175, 55, 0.2); }
.music-ctrl-btn:active { transform: scale(0.95); }
.music-play-btn {
    width: 42px;
    height: 42px;
    background: var(--gold-mid);
    color: var(--dark-bg);
    font-size: 16px;
}
.music-play-btn:hover { background: var(--gold-light); }
.music-player.playing .music-play-btn { background: rgba(212, 175, 55, 0.3); color: var(--gold-light); }

.game-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.pot-area { flex: 1; display: flex; justify-content: center; align-items: center; padding: 20px; overflow: hidden; }
.pots-scroll-container { display: flex; align-items: flex-end; overflow-x: auto; overflow-y: hidden; padding: 20px calc(50% - 80px); max-width: 100%; -webkit-overflow-scrolling: touch; scrollbar-width: none; scroll-snap-type: x mandatory; gap: 10px; }
.pots-scroll-container::-webkit-scrollbar { display: none; }
.pot-wrapper { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; scroll-snap-align: center; scroll-snap-stop: always; position: relative; transition: transform 0.1s ease-out, opacity 0.1s ease-out; }
.pot-wrapper.unfocused { transform: scale(0.5); opacity: 0.6; }
.pot-wrapper.focused { transform: scale(1); opacity: 1; }
.pot-container { transition: none; }
.delete-pot-btn { position: absolute; top: 5px; right: 5px; background: #e74c3c; border: none; color: #fff; font-size: 12px; line-height: 1; cursor: pointer; opacity: 0; padding: 0; width: 24px; height: 24px; max-width: 24px; max-height: 24px; min-width: 24px; min-height: 24px; border-radius: 12px; display: flex; align-items: center; justify-content: center; transition: opacity 0.1s; box-shadow: 0 2px 6px rgba(0,0,0,0.3); pointer-events: none; box-sizing: border-box; }
.delete-pot-btn i { display: block; width: 12px; height: 12px; line-height: 12px; text-align: center; }
.pot-wrapper.focused .delete-pot-btn { opacity: 1; pointer-events: auto; }
.delete-pot-btn:active { transform: scale(1.1); }
.add-pot-slot { width: 160px; height: 160px; border-radius: 50%; background: rgba(0, 0, 0, 0.2); border: 3px dashed var(--gold-mid); display: flex; justify-content: center; align-items: center; cursor: pointer; color: var(--gold-mid); font-size: 32px; opacity: 0.5; transition: opacity 0.1s, border-color 0.1s; }
.pot-wrapper.focused .add-pot-slot { opacity: 1; border-color: var(--gold-light); }

.pot-container {
    position: relative;
    background: radial-gradient(ellipse at center, var(--felt-highlight) 0%, var(--felt-mid) 60%, var(--felt-dark) 100%);
    border: 4px solid var(--gold-mid);
    border-radius: 50%;
    width: 160px;
    height: 160px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: var(--shadow-soft), inset 0 0 40px rgba(0, 0, 0, 0.3);
}

.pot-label { font-family: 'Cinzel', serif; color: var(--gold-mid); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.2em; }
.pot-amount { font-family: 'Cinzel', serif; color: var(--cream); font-size: 28px; font-weight: 700; }

.player-area { padding: 16px 20px; flex-shrink: 0; }

.player-chips {
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.4);
    border: 3px solid var(--gold-mid);
    border-radius: 16px;
    padding: 14px;
    cursor: pointer;
    touch-action: manipulation;
    height: 68px;
}

.chips-content { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chips-label { color: var(--gold-mid); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.15em; }
.chips-amount { font-family: 'Cinzel', serif; color: var(--cream); font-size: 24px; font-weight: 700; }

.bottom-actions {
    background: rgba(0, 0, 0, 0.4);
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    border-top: 1px solid rgba(212, 175, 55, 0.15);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.action-btn {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(212, 175, 55, 0.25);
    color: var(--cream-dim);
    padding: 10px 8px;
    border-radius: 10px;
    font-size: 11px;
    cursor: pointer;
    flex: 1;
    margin: 0 5px;
    text-align: center;
    height: 52px;
    touch-action: manipulation;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.action-btn i { font-size: 16px; margin-bottom: 4px; color: var(--gold-mid); }
.action-btn span { font-size: 10px; font-weight: 500; text-transform: uppercase; }

/* Disconnected state - grey out interactive elements */
.game-screen.disconnected .pot-container,
.game-screen.disconnected .player-chips {
    opacity: 0.5;
    pointer-events: none;
}
.game-screen.disconnected .action-btn:not(.always-enabled) {
    opacity: 0.5;
    pointer-events: none;
}

/* Connection status indicator */
.connection-status {
    position: absolute;
    top: 14px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: var(--cream-dark);
    opacity: 0.7;
}
.connection-status .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}
.connection-status.reconnecting .status-dot {
    background: var(--gold-mid);
    animation: pulse 1s ease-in-out infinite;
}
.connection-status.disconnected .status-dot {
    background: var(--danger);
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Chip movement animation */
.chip-animation {
    position: fixed;
    pointer-events: none;
    z-index: 1;
    font-size: 28px;
    color: var(--gold-light);
    text-shadow: 0 0 12px var(--gold-mid), 0 2px 8px rgba(0, 0, 0, 0.6);
}

.chip-animation.to-pot {
    animation: chipToPot 1s ease-in-out forwards;
}
.chip-animation.from-pot {
    animation: chipFromPot 1s ease-in-out forwards;
}
@keyframes chipToPot {
    0% { opacity: 1; transform: translate(0, 0) scale(1); }
    40% { opacity: 1; transform: translate(var(--dx), calc(var(--dy) * 0.15)) scale(1); }
    75% { opacity: 1; transform: translate(var(--dx), calc(var(--dy) * 0.85)) scale(1.1); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.7); }
}
@keyframes chipFromPot {
    0% { opacity: 1; transform: translate(0, 0) scale(1); }
    30% { opacity: 1; transform: translate(var(--dx), calc(var(--dy) * 0.35)) scale(1); }
    70% { opacity: 1; transform: translate(var(--dx), calc(var(--dy) * 0.65)) scale(1.1); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.7); }
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.show { display: flex; }

.modal {
    background: linear-gradient(180deg, var(--felt-mid) 0%, var(--felt-dark) 100%);
    border: 2px solid var(--gold-mid);
    border-radius: 20px;
    padding: 28px;
    width: 90%;
    max-width: 380px;
    text-align: center;
}

.modal-title {
    font-family: 'Cinzel', serif;
    color: var(--gold-light);
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    text-transform: uppercase;
}

.modal-input {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--felt-highlight);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.4);
    color: var(--cream);
    font-size: 20px;
    font-family: 'Cinzel', serif;
    text-align: center;
    margin-bottom: 20px;
}

.modal-buttons { display: flex; gap: 12px; }
.modal-btn { flex: 1; padding: 14px 16px; border-radius: 10px; font-size: 13px; font-weight: 600; min-height: 48px; }
.all-btn { background: linear-gradient(180deg, var(--chip-red) 0%, #8b0000 100%); color: var(--cream); border: none; }
.cancel-btn { background: transparent; color: var(--cream-dim); border: 1px solid rgba(255, 255, 255, 0.2); }
.leave-btn { background: linear-gradient(180deg, var(--danger) 0%, #6b1a26 100%) !important; }

.players-modal .modal, .activity-log-modal .modal { max-height: 80vh; overflow-y: auto; }
.players-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }

.activity-log {
    max-height: 350px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    text-align: left;
}

.log-entry { padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.1); font-size: 13px; color: var(--cream-dim); }
.log-entry:last-child { border-bottom: none; }
.log-entry .log-time { color: var(--cream-dark); font-size: 11px; }
.log-entry .log-action { color: var(--success); font-weight: 600; margin-top: 2px; }
.log-entry.pot-action .log-action { color: var(--gold-mid); }
.log-entry.join-action .log-action { color: var(--chip-blue); }

.player-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 16px;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-item.me { background: rgba(212, 175, 55, 0.15); border: 2px solid var(--gold-mid); }
.player-item-name { font-family: 'Cinzel', serif; font-size: 16px; font-weight: 600; }
.player-item-chips { font-family: 'Cinzel', serif; font-size: 18px; color: var(--gold-light); font-weight: 700; }

.leave-text { margin-bottom: 24px; color: var(--cream-dim); font-size: 14px; }

.status-toast {
    position: fixed;
    top: 155px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(180deg, var(--success) 0%, #1d6b45 100%);
    color: var(--cream);
    padding: 14px 28px;
    border-radius: 30px;
    font-weight: 600;
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s;
}

.status-toast.show { opacity: 1; }
.status-toast.error { background: linear-gradient(180deg, var(--danger) 0%, #6b1a26 100%); }

/* Recent rooms */
.recent-rooms {
    margin-top: 32px;
    width: 100%;
    max-width: 280px;
}
.recent-rooms-title {
    font-size: 11px;
    color: var(--cream-dark);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 12px;
    text-align: center;
}
.recent-room-item {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
}
.recent-room-item:active {
    transform: scale(0.98);
    background: rgba(0, 0, 0, 0.4);
}
.recent-room-info {
    text-align: left;
    flex: 1;
    cursor: pointer;
}
.recent-room-code {
    font-family: 'Cinzel', serif;
    font-size: 14px;
    color: var(--gold-mid);
    font-weight: 600;
    letter-spacing: 0.05em;
}
.recent-room-name {
    font-size: 12px;
    color: var(--cream-dim);
    margin-top: 2px;
}
.recent-room-arrow {
    color: var(--gold-mid);
    font-size: 14px;
}
.recent-room-delete {
    color: var(--cream-dim);
    font-size: 14px;
    padding: 8px;
    margin: -8px;
    margin-left: 8px;
    opacity: 0.6;
    transition: opacity 0.2s, color 0.2s;
}
.recent-room-delete:active {
    opacity: 1;
    color: #e74c3c;
}

@media (max-width: 400px) {
    .pot-container { width: 150px; height: 150px; }
    .pot-amount { font-size: 26px; }
    .chips-amount { font-size: 22px; }
    .app-title { font-size: 24px; }
}
