:root {
    /* Mystical Theme Colors infused with Professional Utility */
    --bg-app: #0a0514; /* Deep mystic void */
    --bg-panel: rgba(26, 15, 38, 0.65); /* Dark purple glass */
    --bg-panel-hover: rgba(43, 25, 61, 0.8);
    
    /* Borders - Glowing yet subtle */
    --border-subtle: rgba(181, 147, 255, 0.15);
    --border-focus: rgba(181, 147, 255, 0.3);

    /* Text */
    --text-main: #f8fafc;
    --text-secondary: #c4b5fd; /* Soft purple-tinted silver */
    --text-tertiary: #8b5cf6; /* Deeper violet */

    /* Semantic Roles (Thematic) */
    --brand-primary: #9d4edd;      /* Mystic purple */
    --brand-accent: #ffd700;       /* Divine gold */
    
    --action-positive: #10b981;    /* Life/Start */
    --action-negative: #d90429;    /* Blood/Stop */
    
    /* System States */
    --state-won: #ffd700;          /* Gold */
    --state-lost: #64748b;         /* Slate */
    --state-purchased: #38bdf8;    /* Ethereal Blue */
    --state-pending: #f59e0b;      /* Amber */

    /* Typography */
    --font-heading: 'Cinzel', serif;
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-data: 'Outfit', 'Inter', monospace;
}

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

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    line-height: 1.5;
    position: relative;
    overflow-x: hidden;
}

/* Atmospheric Background Generation */
.dynamic-background {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}
.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.4;
    animation: float 20s infinite ease-in-out alternate;
}
.orb-1 { width: 300px; height: 300px; background: var(--brand-primary); top: -50px; left: -50px; }
.orb-2 { width: 400px; height: 400px; background: var(--brand-accent); bottom: -100px; right: -100px; animation-delay: -5s; opacity: 0.2; }
.orb-3 { width: 250px; height: 250px; background: var(--action-positive); top: 50%; left: 50%; transform: translate(-50%, -50%); animation-delay: -10s; opacity: 0.15; }

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(30px, -50px) scale(1.1); }
}

/* App Layout */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Header - System Status */
.sys-header {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-area i {
    font-size: 24px;
    color: var(--brand-primary);
}

.logo-area h1 {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--action-negative); box-shadow: 0 0 10px var(--action-negative); }
.dot.active { background: var(--action-positive); box-shadow: 0 0 10px var(--action-positive); animation: pulse 2s infinite; }

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 16px;
    align-items: start;
}

@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

/* Panels (Restored Glass with Controlled Padding) */
.panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-focus);
    padding-bottom: 12px;
    margin-bottom: 4px;
}

.panel-header h2 {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.panel-header h2 i { color: var(--brand-accent); }

/* Controls */
.control-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    color: #fff;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(255,255,255,0.05) !important;
    border-color: rgba(255,255,255,0.1) !important;
    box-shadow: none !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--brand-primary), #4c1d95);
    box-shadow: 0 4px 15px rgba(157, 78, 221, 0.4);
}
.btn-primary:not(:disabled):hover {
    background: linear-gradient(135deg, #7b2cbf, #3b0764);
    box-shadow: 0 6px 20px rgba(157, 78, 221, 0.6);
    transform: translateY(-2px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--action-negative), #991b1b);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}
.btn-danger:not(:disabled):hover {
    background: linear-gradient(135deg, #dc2626, #7f1d1d);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.6);
    transform: translateY(-2px);
}

.btn-outline {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-focus);
    color: var(--text-main);
}
.btn-outline:hover {
    background: rgba(255,255,255,0.1);
    border-color: var(--text-main);
}

.sys-msg {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 4px;
    font-style: italic;
}

/* Stats Section */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

.stat-box {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-box.full-width { grid-column: 1 / -1; }

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.stat-value {
    font-family: var(--font-data);
    font-variant-numeric: tabular-nums;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
}
.stat-value.highlight {
    color: var(--brand-accent);
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
}

/* Table Design - Dense & Data Focused but slightly ethereal */
.table-container { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

.data-table th {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-focus);
    white-space: nowrap;
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--bg-panel-hover); }

.text-right { text-align: right; }
.text-center { text-align: center; }
.num-data { font-family: var(--font-data); font-variant-numeric: tabular-nums; }

/* Badges */
.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    letter-spacing: 0.5px;
}

.badge-pending { background: rgba(245, 158, 11, 0.2); color: var(--state-pending); }
.badge-purchased { background: rgba(14, 165, 233, 0.2); color: var(--state-purchased); }
.badge-won { background: rgba(255, 215, 0, 0.2); color: var(--state-won); border: 1px solid rgba(255, 215, 0, 0.4); }
.badge-lost { background: rgba(255, 255, 255, 0.05); color: var(--state-lost); }

/* Utility */
.cursor-pointer { cursor: pointer; }
.loading-text { color: var(--text-tertiary); font-style: italic; font-size: 13px; }

/* --- Newspaper / Race Details (馬柱) --- */
.horse-row { display: flex; flex-direction: column; gap: 4px; }

.horse-primary { display: flex; align-items: baseline; gap: 8px; }

.h-num {
    display: inline-block; width: 26px; height: 26px; line-height: 26px;
    text-align: center; background: rgba(255,255,255,0.1);
    color: #fff; border-radius: 4px; font-weight: 700; font-size: 14px;
}

.h-name { font-size: 16px; color: var(--text-main); font-weight: 700; letter-spacing: -0.5px; }

.h-meta { font-size: 12px; color: var(--text-secondary); display: flex; gap: 12px; }
.h-meta span { display: flex; align-items: center; gap: 4px; }

.signal-row { font-size: 13px; color: var(--text-secondary); }
.signal-row strong { color: var(--text-main); font-family: var(--font-data); font-size: 14px; }
.ev-high { color: var(--brand-accent) !important; text-shadow: 0 0 10px rgba(255,215,0,0.4); }

/* Past Races (Sideways Scroll) */
.past-races-row {
    display: flex; gap: 8px; margin-top: 8px; flex-wrap: nowrap;
    overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.past-races-row::-webkit-scrollbar { height: 6px; }
.past-races-row::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 3px; }
.past-races-row::-webkit-scrollbar-thumb { background: var(--border-focus); border-radius: 3px; }

.past-race-card {
    background: rgba(0,0,0,0.25); border: 1px solid var(--border-subtle);
    border-radius: 6px; padding: 10px; font-size: 12px;
    min-width: 175px; max-width: 185px; flex: 0 0 auto;
    display: flex; flex-direction: column; gap: 6px; color: var(--text-secondary);
}

.pr-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px dashed var(--border-focus); padding-bottom: 4px; }

.pr-rank { font-weight: 700; color: var(--text-main); }
.pr-rank.rank-1 { color: var(--state-won); }
.pr-rank.rank-2 { color: #cbd5e1; }
.pr-rank.rank-3 { color: #cd7f32; }

.pr-course { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
.pr-body { display: flex; flex-direction: column; gap: 4px; }
.pr-row { display: flex; justify-content: space-between; align-items: center; white-space: nowrap; }
.pr-icon { opacity: 0.6; margin-right: 4px; }

/* Responsive Table (Netkeiba-style mobile list) */
@media (max-width: 900px) {
    .data-table, .data-table tbody { display: block; width: 100%; }
    .data-table thead { display: none; }
    
    .data-table tr {
        display: flex; flex-direction: column;
        background: rgba(0,0,0,0.2); border: 1px solid var(--border-subtle);
        border-radius: 8px; margin-bottom: 8px; padding: 12px; gap: 8px;
    }
    
    .data-table td {
        display: flex; padding: 0; border: none; align-items: center; justify-content: space-between;
    }
    
    .data-table td::before { content: attr(data-label); font-size: 11px; color: var(--text-tertiary); font-weight: 600; }
    
    .race-horse-row { gap: 6px !important; }
    .race-horse-row td { justify-content: flex-start; }
    .race-horse-row td::before { display: none; }
    .col-status { width: 100%; justify-content: flex-end; }
}

/* Toast System Updates */
.toast {
    position: fixed; bottom: -100px; left: 50%; transform: translateX(-50%);
    background: var(--bg-panel); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-focus); padding: 12px 24px; border-radius: 30px;
    color: #fff; font-size: 14px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 100;
}