/* ========================
   PREMIUM DARK THEME TOKENS
======================== */
:root {
    --bg-primary: #0F1226;
    --bg-secondary: #0A0D1B;
    --bg-card: #1A1F3A;
    --bg-glass: rgba(26, 31, 58, 0.6);
    --border-glass: rgba(108, 92, 231, 0.2);
    --border-glow: rgba(108, 92, 231, 0.4);
    
    --accent: #6C5CE7;
    --accent-glow: #A29BFE;
    --accent-dim: #4B41A6;
    
    --success: #00E676;
    --success-glow: rgba(0, 230, 118, 0.4);
    --error: #FF5252;
    --error-glow: rgba(255, 82, 82, 0.4);
    --warning: #FDCB6E;
    
    --text-primary: #FFFFFF;
    --text-secondary: #AAB0D6;
    --text-dim: #646E99;
    
    --font-main: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --radius: 14px;
    --radius-sm: 8px;
    --radius-pill: 50px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================
   RESET & BASE
======================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden; /* Prevent body scroll, handle inside containers */
    touch-action: manipulation;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* Background gradient animation */
.bg-fx {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: radial-gradient(circle at 50% 0%, rgba(108, 92, 231, 0.15), transparent 60%),
                radial-gradient(circle at 100% 100%, rgba(26, 31, 58, 0.8), transparent 50%);
    pointer-events: none;
}

/* ========================
   SCREENS
======================== */
.screen {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 10;
    flex-direction: column;
}
.screen.active {
    display: flex;
}

/* ========================
   TYPOGRAPHY & UTILS
======================== */
.label {
    font-size: 0.65rem;
    color: var(--text-dim);
    letter-spacing: 2px;
    text-transform: uppercase;
    font-weight: 700;
}
.value {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ========================
   START SCREEN
======================== */
#start-screen {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    justify-content: center;
    align-items: center;
}
.start-content {
    text-align: center;
    z-index: 2;
}
.start-logo {
    font-size: 4rem;
    margin-bottom: 0.5rem;
    animation: bounce 2s ease infinite;
}
.start-title {
    font-size: 3.5rem;
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: -1px;
}
.panic-text {
    background: linear-gradient(135deg, var(--accent-glow), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: block;
    font-size: 4.5rem;
    text-shadow: 0 4px 30px rgba(108, 92, 231, 0.3);
}
.start-subtitle {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin: 1rem 0 2rem;
    letter-spacing: 4px;
    text-transform: uppercase;
}

/* Input Styles */
.player-setup {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}
.input-wrapper {
    position: relative;
    width: 280px;
}
.input-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.2rem;
    opacity: 0.5;
}
#player-name-input {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    padding: 1rem 1rem 1rem 3rem;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 1.1rem;
    font-weight: 600;
    outline: none;
    transition: var(--transition);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}
#player-name-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--border-glow), inset 0 2px 4px rgba(0,0,0,0.2);
    background: rgba(108, 92, 231, 0.05);
}
.lifetime-stats {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: rgba(0,0,0,0.3);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-pill);
    border: 1px solid rgba(255,255,255,0.05);
}
.lifetime-stats span {
    color: var(--success);
    font-weight: 700;
}
.lifetime-stats.hidden { display: none; }

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    color: #FFF;
    font-family: var(--font-main);
    font-weight: 800;
    font-size: 1.1rem;
    padding: 1rem 2.5rem;
    border: none;
    border-radius: var(--radius-pill);
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.btn-primary:active { transform: scale(0.95); }
.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.5);
    background: linear-gradient(135deg, var(--accent-glow), var(--accent));
}
.btn-primary:disabled {
    background: var(--text-dim);
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}
.start-hint {
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-dim);
}

/* ========================
   STATION SELECT SCREEN
======================== */
#station-select-screen {
    background: var(--bg-primary);
}
.select-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    position: relative;
    z-index: 2;
}
.select-header {
    text-align: center;
    padding: 2rem 1rem 1rem;
}
.select-title {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--text-primary);
}
.select-desc {
    color: var(--text-secondary);
    margin-top: 0.5rem;
}
.selection-container {
    flex: 1;
    display: flex;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
    min-height: 0;
    overflow: hidden;
}

.line-selector {
    width: 220px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.pill {
    padding: 1rem 1.5rem;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-pill);
    cursor: pointer;
    text-align: left;
    font-weight: 700;
    transition: var(--transition);
    font-size: 1rem;
}
.pill.active {
    background: var(--bg-card);
    border-color: var(--border-glow);
    color: var(--accent-glow);
    box-shadow: 0 0 15px rgba(108, 92, 231, 0.1);
}
.pill:hover:not(.active):not(.disabled) {
    background: rgba(255,255,255,0.03);
    color: var(--text-primary);
}
.pill.disabled { opacity: 0.3; cursor: not-allowed; }

/* Grid Cards (Replaces old station list) */
.grid-cards {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    align-content: start;
    overflow-y: auto;
    padding-right: 0.5rem;
}
.grid-cards::-webkit-scrollbar { width: 6px; }
.grid-cards::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 4px; }
.grid-cards::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 4px; }

.station-item {
    padding: 1rem;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 600;
    transition: var(--transition);
    text-align: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.station-item:hover {
    transform: translateY(-2px);
    background: rgba(108, 92, 231, 0.1);
    border-color: var(--border-glass);
    box-shadow: 0 6px 12px rgba(0,0,0,0.2);
}
.station-item.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    color: #FFF;
    border-color: transparent;
    font-weight: 800;
    box-shadow: 0 4px 15px var(--border-glow);
}

.sticky {
    padding: 1.5rem;
    background: var(--bg-card);
    border-top: 1px solid rgba(255,255,255,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.5);
}
.select-chosen { display: flex; flex-direction: column; gap: 0.3rem; }
.card {
    background: rgba(0,0,0,0.2);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    border: 1px solid rgba(255,255,255,0.02);
}

/* ========================
   GAME SCREEN UI
======================== */
#game-screen {
    z-index: 2;
}

#top-bar {
    display: flex;
    justify-content: space-around;
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 5;
}
.bar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}
.bar-section.left { align-items: flex-start; }
.bar-section.right { align-items: flex-end; }
.name-badge { color: var(--accent-glow); }
.lifetime-badge { color: var(--success); font-size: 1rem; }

/* Glassmorphism Chat Area */
#chat-area {
    padding: 1.5rem;
    display: flex;
    justify-content: center;
    pointer-events: none; /* Let clicks pass through if empty space */
}
.glass {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.chat-bubble {
    display: flex;
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
    border-radius: 20px;
    max-width: 800px;
    position: relative;
    pointer-events: auto;
}
.chat-enter {
    animation: slideUpFade 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.avatar-wrapper { position: relative; }
.chat-avatar { width: 64px; height: 64px; }
.customer-badge {
    position: absolute;
    bottom: -5px;
    right: -5px;
    background: rgba(0,0,0,0.6);
    padding: 2px 4px;
    border-radius: 8px;
    font-size: 1rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
}
.customer-badge.hidden { display: none; }

.chat-content { display: flex; flex-direction: column; justify-content: center; flex: 1; }
.chat-message {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.patience-bar {
    height: 6px;
    background: rgba(0,0,0,0.4);
    border-radius: 3px;
    margin-top: 0.75rem;
    overflow: hidden;
}
.gradient-bar {
    height: 100%;
    width: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--success), var(--warning), var(--error));
    background-size: 200% 100%;
    transition: width 0.1s linear, background-position 1s ease;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
}
.pulse-warn {
    animation: dangerPulse 0.5s infinite alternate;
}

.tip-indicator {
    position: absolute;
    top: -12px;
    right: 20px;
    background: var(--warning);
    color: #000;
    font-weight: 900;
    padding: 0.3rem 0.8rem;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    box-shadow: 0 4px 15px rgba(253, 203, 110, 0.4);
    animation: bounce 1s ease infinite;
}
.tip-indicator.hidden { display: none; }

/* Main Game Layout */
#game-main {
    flex: 1;
    display: flex;
    padding: 0 1.5rem 1.5rem;
    gap: 1.5rem;
    min-height: 0;
}

.panel-card {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}
.shadow { box-shadow: 0 8px 30px rgba(0,0,0,0.4); }

#selection-area { flex: 1; }
.selection-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.line-tabs { display: flex; gap: 0.5rem; }
.line-tab {
    background: rgba(255,255,255,0.05);
    color: var(--text-secondary);
    border: none;
    padding: 0.4rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1px;
}
.line-tab.active { background: var(--accent); color: #FFF; }

.inner-scroll { padding: 1rem; }

/* Ticket Form */
#ticket-form { width: 380px; display: flex; flex-direction: column; }
.form-card { padding: 1.5rem; height: 100%; }
.form-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1.5rem; color: var(--text-primary); }
.form-group { margin-bottom: 1.25rem; }

.pill-group { display: flex; gap: 0.5rem; flex-wrap: wrap; background: rgba(0,0,0,0.2); padding: 0.3rem; border-radius: 12px; }
.pill-group .option-btn {
    flex: 1;
    padding: 0.65rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--transition);
}
.pill-group .option-btn.active {
    background: var(--bg-card);
    color: var(--accent-glow);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.btn-print {
    margin-top: auto;
    width: 100%;
    padding: 1.25rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    color: #FFF;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 800;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    transition: var(--transition);
    box-shadow: 0 4px 15px var(--border-glow);
    letter-spacing: 1px;
}
.btn-print:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(108, 92, 231, 0.6); }
.btn-print:active { transform: scale(0.97); }

/* ========================
   MACRO-INTERACTIONS & ANIMATIONS
======================== */

.screen-flash {
    position: fixed;
    inset: 0;
    z-index: 99;
    pointer-events: none;
    opacity: 0;
}
.flash-success { animation: flashSuccess 0.4s ease-out; }
.flash-error { animation: flashError 0.4s ease-out; }

@keyframes flashSuccess {
    0% { opacity: 0; }
    10% { opacity: 1; background: radial-gradient(circle, var(--success-glow), transparent 70%); }
    100% { opacity: 0; }
}
@keyframes flashError {
    0% { opacity: 0; }
    10% { opacity: 1; background: radial-gradient(circle, var(--error-glow), transparent 70%); }
    100% { opacity: 0; }
}

#floating-text-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
}
.floating-text {
    position: absolute;
    font-family: var(--font-mono);
    font-weight: 900;
    font-size: 2rem;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
    animation: floatUp 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.float-pos { color: var(--success); text-shadow: 0 0 15px var(--success-glow); }
.float-neg { color: var(--error); text-shadow: 0 0 15px var(--error-glow); }

@keyframes floatUp {
    0% { opacity: 0; transform: translateY(20px) scale(0.8); }
    20% { opacity: 1; transform: translateY(0px) scale(1.1); }
    80% { opacity: 1; transform: translateY(-30px) scale(1); }
    100% { opacity: 0; transform: translateY(-50px) scale(0.9); }
}

@keyframes slideUpFade {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes dangerPulse {
    0% { transform: scale(1); filter: drop-shadow(0 0 5px var(--error)); }
    100% { transform: scale(1.02); filter: drop-shadow(0 0 15px var(--error)); }
}

@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.shake { animation: shake 0.3s ease; }

/* RESPONSIVE */
@media (max-width: 1000px) {
    #top-bar { flex-wrap: wrap; gap: 0.5rem; }
    .bar-section { min-width: 90px; }
}
@media (max-width: 900px) {
    #game-main { flex-direction: column; overflow-y: auto; padding-bottom: 2rem; }
    #ticket-form { width: 100%; order: 1; }
    #selection-area { height: 400px; order: 2; margin-top: 1rem; flex: none; }
    .select-layout { flex-direction: column; }
    .line-selector { width: 100%; flex-direction: row; overflow-x: auto; padding-bottom: 1rem; }
}
