/* ══════════════════════════════════════════
   Birthday Quest — Dark Theme with Glass UI
   ══════════════════════════════════════════ */

:root {
    --tg-bg: #0f0f1a;
    --tg-text: #ffffff;
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: rgba(255, 255, 255, 0.05);
    --bg-glass: rgba(255, 255, 255, 0.08);
    --border-glass: rgba(255, 255, 255, 0.12);
    --accent: #6c63ff;
    --accent-light: #8b83ff;
    --accent-glow: rgba(108, 99, 255, 0.3);
    --success: #4ade80;
    --error: #f87171;
    --warning: #fbbf24;
    --info: #60a5fa;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.35);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    min-height: 100vh;
    position: relative;
}

/* ─── Screens ─── */
.screen {
    min-height: 100vh;
    padding: 1rem;
    padding-bottom: 2rem;
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.3s ease;
}
.screen.active {
    opacity: 1;
    transform: translateX(0);
}
.slide-in {
    animation: slideIn 0.3s ease forwards;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ─── Map Header ─── */
.map-header {
    text-align: center;
    padding: 1.5rem 0 1rem;
}
.map-title {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, #6c63ff, #ff6b9d, #ffd93d);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.3rem;
}
.map-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ─── Progress Bar ─── */
.map-progress {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-top: 1rem;
    padding: 0 1rem;
}
.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-glass);
    border-radius: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #ff6b9d);
    border-radius: 4px;
    transition: width 0.5s ease;
}
.progress-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
}

/* ─── Stage Cards ─── */
.stages-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}
.stage-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.2rem;
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}
.stage-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 60%, rgba(108, 99, 255, 0.05));
    pointer-events: none;
}
.stage-card:active {
    transform: scale(0.98);
}
.stage-card.completed {
    border-color: rgba(74, 222, 128, 0.2);
    background: rgba(74, 222, 128, 0.05);
}
.stage-card.completed::before {
    background: linear-gradient(135deg, transparent 60%, rgba(74, 222, 128, 0.05));
}
.stage-icon {
    font-size: 2rem;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border-radius: 12px;
    flex-shrink: 0;
}
.stage-info {
    flex: 1;
}
.stage-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 2px;
}
.stage-desc {
    color: var(--text-secondary);
    font-size: 0.8rem;
}
.stage-arrow {
    color: var(--accent);
    font-size: 1.2rem;
    font-weight: 700;
}
.stage-check {
    color: var(--success);
    font-size: 1.2rem;
    font-weight: 700;
}

/* ─── Stage Header ─── */
.stage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0 1rem;
    gap: 0.5rem;
}
.stage-title {
    font-size: 1.2rem;
    font-weight: 700;
    text-align: center;
    flex: 1;
}
.stage-intro {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 0 0.5rem 1rem;
    line-height: 1.5;
}
.stage-content {
    padding-bottom: 2rem;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: white;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    box-shadow: 0 4px 15px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 6px 20px var(--accent-glow); }
.btn-secondary {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
}
.btn-danger {
    background: linear-gradient(135deg, #dc2626, #ef4444);
    box-shadow: 0 4px 15px rgba(220, 38, 38, 0.3);
}
.btn-big {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    width: 100%;
    border-radius: var(--radius);
}
.btn-back {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    font-weight: 600;
}
.btn-hint {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.3rem;
    filter: grayscale(0.3);
    transition: filter 0.2s;
}
.btn-hint:hover { filter: grayscale(0); }
.btn-icon {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-finale {
    margin-top: 1.5rem;
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6c63ff);
    background-size: 200% 200%;
    animation: gradientShift 3s ease infinite;
}
@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* ─── Puzzle Box ─── */
.puzzle-box {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
    text-align: center;
}
.puzzle-question {
    color: var(--text-secondary);
    margin-top: 1rem;
    line-height: 1.5;
}
.puzzle-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.8rem;
}

/* ─── HEX Display ─── */
.hex-display {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
    flex-wrap: wrap;
    margin: 1rem 0;
}
.hex-byte {
    font-family: 'Courier New', monospace;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-light);
    background: rgba(108, 99, 255, 0.1);
    border: 1px solid rgba(108, 99, 255, 0.3);
    border-radius: 10px;
    padding: 0.5rem 1rem;
    animation: pulse 2s ease-in-out infinite;
}
.hex-byte:nth-child(2) { animation-delay: 0.2s; }
.hex-byte:nth-child(3) { animation-delay: 0.4s; }
.hex-byte:nth-child(4) { animation-delay: 0.6s; }
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(108, 99, 255, 0.2); }
    50% { box-shadow: 0 0 20px 5px rgba(108, 99, 255, 0.15); }
}

/* ─── Math Formula ─── */
.math-formula {
    margin: 1rem 0;
}
.formula-block {
    margin-bottom: 1rem;
}
.formula-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    display: block;
    margin-bottom: 0.5rem;
}
.formula-display {
    font-family: 'Courier New', monospace;
    font-size: 1.4rem;
    color: var(--accent-light);
    padding: 1rem;
    background: rgba(108, 99, 255, 0.08);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(108, 99, 255, 0.2);
}

/* ─── Answer Input ─── */
.answer-box {
    display: flex;
    gap: 0.6rem;
    margin-top: 1rem;
}
.answer-input {
    flex: 1;
    padding: 0.8rem 1rem;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}
.answer-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.answer-input.shake {
    animation: shake 0.5s ease;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

/* ─── Calculator ─── */
.calculator-container {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}
.calc-section {
    margin-bottom: 0.8rem;
}
.calc-section h4 {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.calc-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.calc-input {
    width: 80px;
    padding: 0.5rem 0.6rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    outline: none;
}
.calc-input:focus { border-color: var(--accent); }
.calc-input.calc-wide { width: 160px; }
.calc-input.calc-small { width: 60px; }
.calc-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
}
.calc-op {
    color: var(--accent);
    font-weight: 700;
    font-size: 1.1rem;
}
.calc-result {
    color: var(--success);
    font-family: 'Courier New', monospace;
    font-weight: 700;
    font-size: 1rem;
    min-width: 50px;
}

/* ─── Terminal ─── */
.terminal-window {
    background: #0a0a0a;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.terminal-header {
    background: #1e1e1e;
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.terminal-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}
.terminal-dot.red { background: #ff5f57; }
.terminal-dot.yellow { background: #febc2e; }
.terminal-dot.green { background: #28c840; }
.terminal-title {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    margin-left: 0.5rem;
}
.terminal-body {
    padding: 0.8rem;
    min-height: 250px;
    max-height: 400px;
    overflow-y: auto;
    font-family: 'Courier New', 'Menlo', monospace;
    font-size: 0.85rem;
    color: #00ff41;
    line-height: 1.4;
}
.terminal-line {
    white-space: pre-wrap;
    word-break: break-word;
    margin-bottom: 2px;
}
.terminal-input-line {
    display: flex;
    align-items: center;
    padding: 0 0.8rem 0.8rem;
    font-family: 'Courier New', 'Menlo', monospace;
    font-size: 0.85rem;
}
.terminal-prompt {
    color: #00ff41;
    white-space: nowrap;
    flex-shrink: 0;
}
.terminal-input {
    flex: 1;
    background: none;
    border: none;
    color: #00ff41;
    font-family: 'Courier New', 'Menlo', monospace;
    font-size: 0.85rem;
    outline: none;
    caret-color: #00ff41;
}

/* ─── Team Game ─── */
.team-lobby, .team-waiting, .team-round, .team-round-complete, .team-complete {
    text-align: center;
    padding: 1rem;
}
.team-lobby h3, .team-waiting h3, .team-round h3, .team-round-complete h3, .team-complete h3 {
    margin-bottom: 0.8rem;
}
.team-buttons {
    margin: 1.5rem 0;
}
.team-join {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}
.team-input {
    flex: 1;
    padding: 0.7rem 1rem;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    text-align: center;
}
.team-input:focus { border-color: var(--accent); }
.room-code {
    font-family: 'Courier New', monospace;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-light);
    letter-spacing: 4px;
    background: rgba(108, 99, 255, 0.1);
    padding: 0.3rem 1rem;
    border-radius: 8px;
}
.team-share {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.3rem;
}
.team-players {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
}
.team-player {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
}
.team-player.disconnected { opacity: 0.4; }
.player-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.player-dot.online { background: var(--success); }
.player-dot.offline { background: var(--error); }
.team-count {
    color: var(--text-muted);
    font-size: 0.8rem;
}
.team-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
    margin-top: 0.5rem;
}
.team-number-display {
    margin: 1.5rem 0;
}
.team-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
}
.team-number {
    font-size: 3rem;
    font-weight: 800;
    color: var(--accent-light);
    text-shadow: 0 0 30px var(--accent-glow);
}
.team-formula {
    background: rgba(108, 99, 255, 0.1);
    border: 1px solid rgba(108, 99, 255, 0.2);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1rem 0;
}
.team-formula-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-light);
    margin: 0.5rem 0;
}
.team-formula-desc {
    color: var(--text-muted);
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}
.team-task {
    color: var(--text-secondary);
    margin: 1rem 0;
    line-height: 1.5;
}
.team-answer-section {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
}
.team-answer-reveal {
    font-size: 2rem;
    font-weight: 700;
    color: var(--success);
    margin: 1rem 0;
}
.team-confetti {
    font-size: 2rem;
    margin: 1rem 0;
    animation: bounce 1s ease infinite;
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* ─── Toasts ─── */
#toast-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 10px;
    pointer-events: none;
}
.toast {
    padding: 0.7rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    transform: translateY(-30px);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: auto;
    max-width: 90%;
    text-align: center;
    backdrop-filter: blur(10px);
}
.toast.show {
    transform: translateY(0);
    opacity: 1;
}
.toast-success {
    background: rgba(74, 222, 128, 0.15);
    border: 1px solid rgba(74, 222, 128, 0.3);
    color: var(--success);
}
.toast-error {
    background: rgba(248, 113, 113, 0.15);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--error);
}
.toast-warning {
    background: rgba(251, 191, 36, 0.15);
    border: 1px solid rgba(251, 191, 36, 0.3);
    color: var(--warning);
}
.toast-info {
    background: rgba(96, 165, 250, 0.15);
    border: 1px solid rgba(96, 165, 250, 0.3);
    color: var(--info);
}

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    backdrop-filter: blur(4px);
}
.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    overflow: hidden;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-glass);
    font-weight: 600;
}
.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
}
.modal-body {
    padding: 1.2rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* ─── Finale ─── */
.finale-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.finale-content {
    position: relative;
    z-index: 2;
}
.finale-title {
    font-size: 3rem;
    animation: bounce 1s ease infinite;
}
.finale-message {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6c63ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 1rem 0;
}
.finale-stars {
    font-size: 1.5rem;
    margin: 0.5rem 0;
    animation: twinkle 2s ease-in-out infinite;
}
@keyframes twinkle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; transform: scale(1.1); }
}
.finale-subtitle {
    color: var(--text-secondary);
    margin: 1rem 0 1.5rem;
}
.finale-cert-placeholder {
    color: var(--text-muted);
    font-style: italic;
    margin-top: 1rem;
}
.finale-fireworks {
    font-size: 2rem;
    margin-top: 1.5rem;
    animation: bounce 1.5s ease infinite;
}

/* ─── Confetti ─── */
.confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}
.confetti-particle {
    position: absolute;
    top: -20px;
    left: var(--x);
    width: var(--size);
    height: var(--size);
    background: var(--color);
    border-radius: 2px;
    animation: confettiFall var(--duration) ease-in var(--delay) infinite;
}
@keyframes confettiFall {
    0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ─── Admin ─── */
.admin-content {
    padding: 0.5rem 0;
}
.admin-section {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.8rem;
}
.admin-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.8rem;
}
.admin-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.admin-input {
    flex: 1;
    min-width: 100px;
    padding: 0.5rem 0.7rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
}
.admin-input:focus { border-color: var(--accent); }
.admin-player-card {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 0.7rem;
    margin-bottom: 0.5rem;
}
.admin-stages {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.3rem;
}
.admin-stages span {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
}
.admin-stages .done {
    background: rgba(74, 222, 128, 0.2);
    color: var(--success);
}
.admin-stages .pending {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}
.badge-done {
    font-size: 0.75rem;
    color: var(--success);
}

/* ─── Map Footer ─── */
.map-footer {
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    margin-top: 1.5rem;
    padding-bottom: 1rem;
}

/* ─── Responsive ─── */
@media (min-width: 500px) {
    .stages-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}
@media (min-width: 768px) {
    #app {
        max-width: 500px;
        margin: 0 auto;
    }
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
