:root {
    --bg: #08090a;
    --bg-panel: #0f1011;
    --bg-surface: #191a1b;
    --text-primary: #f7f8f8;
    --text-secondary: #d0d6e0;
    --text-tertiary: #8a8f98;
    --text-muted: #62666d;
    --border-subtle: rgba(255,255,255,0.05);
    --border-default: rgba(255,255,255,0.08);
    --accent: #5e6ad2;
    --accent-hover: #7170ff;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

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

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}
.page::before {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: url('/images/bg-static.webp') center/cover no-repeat;
    opacity: 0.10;
    z-index: 0;
    pointer-events: none;
}
.nav, .container, footer { position: relative; z-index: 1; }

.container { max-width: 1120px; margin: 0 auto; padding: 0 2rem; }

/* Nav */
.nav { position: sticky; top: 0; z-index: 100; background: rgba(8,9,10,0.8); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border-subtle); }
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.nav-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-primary); }
.nav-logo { width: 28px; height: 28px; border-radius: var(--radius-sm); object-fit: cover; }
.nav-name { font-size: 14px; font-weight: 510; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-link { color: var(--text-secondary); text-decoration: none; font-size: 13px; font-weight: 510; padding: 6px 12px; border-radius: var(--radius-sm); transition: all 0.15s; }
.nav-link:hover { color: var(--text-primary); background: rgba(255,255,255,0.04); }
.nav-link.active { color: var(--text-primary); background: rgba(255,255,255,0.06); }

/* Main */
.main { flex: 1; padding: 2rem 2rem 4rem; }

/* Card */
.card { background: var(--bg-panel); border: 1px solid var(--border-default); border-radius: var(--radius-lg); padding: 2rem; max-width: 640px; margin: 0 auto 1.5rem; text-align: center; }

/* Loading */
.loading-spinner { margin-bottom: 16px; }
.spinner { display: inline-block; width: 32px; height: 32px; border: 3px solid rgba(255,255,255,0.1); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 14px; color: var(--text-secondary); margin-bottom: 16px; }

/* Log Container */
.log-container { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: 12px; max-height: 200px; overflow-y: auto; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; line-height: 1.6; text-align: left; }
.log-line { color: var(--text-muted); padding: 2px 0; }
.log-line:last-child { color: var(--text-tertiary); }
.log-line::before { content: '› '; color: var(--accent); }

/* Error */
.error-text { color: #f87171; font-size: 14px; }

/* Profile */
.profile-card { flex: 0 0 auto; min-width: 280px; }
.profile-header { display: flex; align-items: center; gap: 20px; text-align: left; }
.profile-icon { width: 112px; height: 112px; border-radius: var(--radius-md); object-fit: cover; flex-shrink: 0; display: none; }
.profile-info { flex: 1; }
.profile-name { font-size: 32px; font-weight: 600; letter-spacing: -0.5px; margin-bottom: 8px; }
.profile-rating { font-size: 56px; font-weight: 600; background: linear-gradient(135deg, var(--accent), #7170ff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; letter-spacing: -2px; }

/* Dashboard layout */
#dashboard { max-width: 800px; margin: 0 auto; }
.dashboard-top { display: flex; gap: 16px; align-items: stretch; margin-bottom: 16px; }
.dashboard-top .card { max-width: none; }

/* Search */
.search-card { text-align: left; padding: 1.5rem 2rem; flex: 1; }
.search-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.search-input-wrap { position: relative; }
.search-input { width: 100%; padding: 10px 14px; font-size: 14px; font-family: inherit; background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: var(--radius-md); color: var(--text-primary); outline: none; transition: border-color 0.15s; }
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

/* Suggestions dropdown */
.suggestions { position: absolute; top: 100%; left: 0; right: 0; z-index: 50; background: var(--bg-surface); border: 1px solid var(--border-default); border-top: none; border-radius: 0 0 var(--radius-md) var(--radius-md); max-height: 300px; overflow-y: auto; }
.suggestion-item { padding: 10px 14px; font-size: 14px; cursor: pointer; transition: background 0.1s; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; gap: 8px; }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: rgba(94, 106, 210, 0.15); }

/* Score Results */
.score-loading { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.score-card { text-align: left; padding: 1.5rem 2rem; max-width: 480px; }
.score-header { display: flex; gap: 16px; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border-subtle); }
.score-jacket { width: 100px; height: 100px; border-radius: var(--radius-md); object-fit: cover; flex-shrink: 0; }
.score-song-info { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.score-title { font-size: 20px; font-weight: 600; letter-spacing: -0.3px; }
.score-genre { font-size: 13px; color: var(--text-muted); }
.version-icon { height: 18px; vertical-align: middle; margin-left: 6px; }

/* Score table */
.score-table { display: flex; flex-direction: column; gap: 12px; }
.score-row { display: flex; gap: 16px; background: var(--bg-surface); border-radius: var(--radius-md); padding: 14px 16px; align-items: center; }
.score-diff { min-width: 90px; padding-left: 10px; }
.diff-name { font-size: 13px; font-weight: 600; display: block; }
.diff-level { font-size: 12px; color: var(--text-muted); display: block; margin-top: 2px; }
.score-data { flex: 1; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.score-rank { font-size: 20px; font-weight: 700; min-width: 52px; text-align: center; padding: 4px 8px; border-radius: var(--radius-sm); }
.score-rank-row { display: flex; align-items: center; gap: 8px; }
.fcap-badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: var(--radius-sm); text-transform: uppercase; letter-spacing: 0.5px; }
.fcap-fc, .fcap-fcplus { background: rgba(105, 240, 174, 0.15); color: #69f0ae; }
.fcap-ap { background: rgba(255, 109, 0, 0.15); color: #ff6d00; }
.fcap-applus { background: rgba(255, 64, 129, 0.15); color: #ff4081; }

/* Internal level badge */
.internal-badge { 
    font-size: 11px; 
    font-weight: 600; 
    padding: 2px 6px; 
    border-radius: var(--radius-sm); 
    background: rgba(124, 179, 255, 0.15); 
    color: #7cb3ff; 
    margin-left: 6px;
    cursor: help;
}

/* Chart type badge (STD/DX) */
.chart-type-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: var(--radius-sm);
    margin-left: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.chart-type-std {
    background: rgba(105, 240, 174, 0.15);
    color: #69f0ae;
}
.chart-type-dx {
    background: rgba(255, 109, 0, 0.15);
    color: #ff6d00;
}

/* Rank colors */
.rank-sssplus { color: #ff4081; }
.rank-sss { color: #ff6d00; }
.rank-ssplus { color: #ffab00; }
.rank-ss { color: #ffd600; }
.rank-splus { color: #c6ff00; }
.rank-s { color: #69f0ae; }
.rank-aaa { color: #40c4ff; }
.rank-aa { color: #448aff; }
.rank-a { color: #7c4dff; }
.rank-bbb, .rank-b { color: var(--text-muted); }

.score-pct { font-size: 18px; font-weight: 600; color: var(--text-primary); min-width: 95px; }
.score-notes { font-size: 12px; color: var(--text-tertiary); }
.score-meta { width: 100%; display: flex; gap: 16px; font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Button */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 20px; font-size: 14px; font-weight: 500; font-family: inherit; border: none; border-radius: var(--radius-md); cursor: pointer; transition: all 0.15s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.hidden { display: none !important; }

/* Footer */
.footer { border-top: 1px solid var(--border-subtle); padding: 1.5rem 0; }
.footer-text { font-size: 12px; color: var(--text-muted); text-align: center; }

/* ===== TABS ===== */
.tabs { display: flex; gap: 4px; margin-bottom: 1.5rem; background: var(--bg-panel); border: 1px solid var(--border-default); border-radius: var(--radius-lg); padding: 4px; }
.tab { flex: 1; padding: 10px 16px; font-size: 13px; font-weight: 510; font-family: inherit; background: transparent; border: none; border-radius: var(--radius-md); color: var(--text-secondary); cursor: pointer; transition: all 0.15s; }
.tab:hover { color: var(--text-primary); background: rgba(255,255,255,0.04); }
.tab.active { color: var(--text-primary); background: rgba(255,255,255,0.08); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== BROWSE ===== */
.browse-card { text-align: left; max-width: none; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.browse-filters { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-group label { font-size: 12px; font-weight: 510; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.5px; }
.filter-select { padding: 8px 12px; font-size: 13px; font-family: inherit; background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: var(--radius-md); color: var(--text-primary); outline: none; cursor: pointer; min-width: 160px; }
.filter-select:focus { border-color: var(--accent); }
.browse-mode-toggle, .diff-toggle { display: flex; gap: 4px; }
.cat-btn, .diff-btn { padding: 6px 14px; font-size: 12px; font-weight: 510; font-family: inherit; background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: var(--radius-sm); color: var(--text-secondary); cursor: pointer; transition: all 0.15s; }
.cat-btn:hover, .diff-btn:hover { color: var(--text-primary); border-color: var(--accent); }
.cat-btn.active, .diff-btn.active { color: var(--text-primary); background: var(--accent); border-color: var(--accent); }

/* ===== KEYBOARD ACCESSIBILITY ===== */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:focus-visible, .tab:focus-visible, .cat-btn:focus-visible, .diff-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.filter-select:focus-visible { border-color: var(--accent); outline: none; }

/* Browse Summary */
.browse-summary { max-width: none; text-align: left; }
.summary-stats { display: flex; gap: 24px; flex-wrap: wrap; }
.stat-item { display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: 24px; font-weight: 600; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* Browse Grid */
.browse-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: 12px; margin-top: 16px; }
.browse-item { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); cursor: pointer; transition: all 0.15s; text-align: left; overflow: hidden; }
.browse-item:hover { border-color: var(--accent); transform: translateY(-2px); }
.browse-jacket { width: 100%; height: 120px; object-fit: cover; display: block; }
.browse-item-info { padding: 10px 14px 0; }
.browse-item-name { font-size: 13px; font-weight: 510; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; margin-bottom: 4px; cursor: default; }
.browse-item-name:hover { white-space: normal; overflow: visible; position: relative; z-index: 10; background: var(--bg-surface); padding: 4px 8px; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.browse-item-level { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.browse-item-score { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.browse-item-rank { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-sm); display: inline-block; }

/* Difficulty Group */
.diff-group { margin-top: 20px; }
.diff-group-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--bg-surface); border-radius: var(--radius-md); margin-bottom: 12px; font-weight: 600; font-size: 15px; }
.diff-group-count { font-size: 13px; font-weight: 400; color: var(--text-muted); }

/* ===== STATISTICS ===== */
.stats-profile { max-width: none; text-align: left; }
.stats-profile-header { display: flex; gap: 20px; margin-bottom: 20px; }
.stats-profile-name { font-size: 28px; font-weight: 600; }
.stats-profile-rating { font-size: 48px; font-weight: 600; background: linear-gradient(135deg, var(--accent), #7170ff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.stats-summary { display: flex; gap: 24px; flex-wrap: wrap; }

/* Rank Bars */
.rank-bars, .level-bars { display: flex; flex-direction: column; gap: 10px; }
.rank-bar-row, .level-bar-row { display: flex; align-items: center; gap: 12px; }
.rank-bar-label, .level-bar-label { font-size: 13px; font-weight: 600; min-width: 50px; text-align: right; }
.rank-bar-track, .level-bar-track { flex: 1; height: 24px; background: var(--bg-surface); border-radius: var(--radius-sm); overflow: hidden; }
.rank-bar-fill, .level-bar-fill { height: 100%; border-radius: var(--radius-sm); transition: width 0.5s ease; }
.level-bar-fill { background: var(--accent); }
.rank-bar-count, .level-bar-count { font-size: 13px; font-weight: 500; min-width: 30px; }

/* Coverage Bar */
.coverage-stats { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 16px; }
.coverage-bar { height: 20px; background: var(--bg-surface); border-radius: var(--radius-sm); overflow: hidden; }
.coverage-fill { height: 100%; background: linear-gradient(90deg, #69f0ae, #00e676); border-radius: var(--radius-sm); transition: width 0.5s ease; }

/* Rating List */
.rating-list { display: flex; flex-direction: column; gap: 8px; }
.rating-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--bg-surface); border-radius: var(--radius-md); }
.rating-rank { font-size: 14px; font-weight: 600; color: var(--text-muted); min-width: 24px; }
.rating-name { font-size: 13px; font-weight: 510; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rating-level { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.rating-score { font-size: 14px; font-weight: 600; min-width: 90px; text-align: right; }
.rating-gap { font-size: 12px; color: var(--text-tertiary); min-width: 60px; text-align: right; }

/* ===== MODAL ===== */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
.modal-content { position: relative; z-index: 1; background: var(--bg-panel); border: 1px solid var(--border-default); border-radius: var(--radius-lg); padding: 2rem; max-width: 600px; width: 90%; max-height: 80vh; overflow-y: auto; }
.modal-close { position: absolute; top: 12px; right: 16px; background: none; border: none; color: var(--text-secondary); font-size: 24px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); }
.modal-close:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }

/* ===== MULTI-LEVEL SELECT ===== */
.multi-select-wrap { position: relative; }
.multi-select-toggle { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: var(--radius-md); cursor: pointer; min-width: 180px; }
.multi-select-toggle:hover { border-color: var(--accent); }
.dropdown-arrow { font-size: 10px; color: var(--text-muted); }
.multi-select-dropdown { position: absolute; top: 100%; left: 0; z-index: 50; background: var(--bg-panel); border: 1px solid var(--border-default); border-radius: var(--radius-md); margin-top: 4px; max-height: 400px; overflow-y: auto; min-width: 320px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.multi-select-options { padding: 8px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; }
.multi-select-options label { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; white-space: nowrap; transition: background 0.15s; }
.multi-select-options label:hover { background: var(--bg-surface); }
.multi-select-options input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* ===== MOST PLAYED GRID ===== */
.most-played-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 12px; margin-top: 16px; }
.most-played-item { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg-surface); border-radius: var(--radius-md); cursor: pointer; transition: all 0.2s ease; position: relative; }
.most-played-item:hover { background: var(--bg-panel); border-color: var(--accent); transform: translateY(-2px); }
.most-played-rank { position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 700; color: var(--text-muted); background: var(--bg-panel); padding: 2px 6px; border-radius: var(--radius-sm); }
.most-played-jacket { width: 64px; height: 64px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; }
.most-played-info { flex: 1; min-width: 0; }
.most-played-name { font-size: 14px; font-weight: 500; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.most-played-count { font-size: 13px; color: var(--text-tertiary); }
@keyframes badgePulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.score-rank { display: inline-block; animation: badgePulse 2s ease-in-out infinite; }

/* ===== ANIMATED CHARTS ===== */
@keyframes barGrow { from { width: 0; } }
.rank-bar-fill { animation: barGrow 0.8s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.browse-item, .most-played-item { animation: fadeIn 0.3s ease-out; }

/* ===== RESPONSIVE GRID ===== */
.browse-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: 12px; }
@media (min-width: 1200px) { .browse-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }
@media (min-width: 1600px) { .browse-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); } }

@media (max-width: 640px) {
    .container { padding: 0 1rem; }
    .dashboard-top { flex-direction: column; }
    .tabs { flex-wrap: wrap; }
    .tab { font-size: 12px; padding: 8px 12px; }
    .browse-filters { flex-direction: column; }
    .browse-grid { grid-template-columns: 1fr; }
    .summary-stats { gap: 16px; }
    .stat-value { font-size: 20px; }
    .profile-rating { font-size: 40px; }
    .profile-name { font-size: 24px; }
}

/* ===== ADMIN PANEL ===== */
.admin-card { max-width: 640px; text-align: left; }
.admin-section { margin-bottom: 24px; }
.admin-section:last-child { margin-bottom: 0; }
.section-title { font-size: 14px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; }
.admin-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.btn-secondary { background: var(--bg-surface); color: var(--text-secondary); border: 1px solid var(--border-default); }
.btn-secondary:hover { color: var(--text-primary); border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.scrape-progress { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 12px; background: var(--bg-surface); border-radius: var(--radius-md); }
.scrape-progress .loading-spinner { margin-bottom: 0; }
.scrape-progress .spinner { width: 20px; height: 20px; }
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.status-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--bg-surface); border-radius: var(--radius-md); }
.status-label { font-size: 12px; color: var(--text-muted); }
.status-value { font-size: 14px; font-weight: 600; }
.text-green { color: #69f0ae; }
.text-red { color: #f87171; }
.text-yellow { color: #ffab00; }
.profile-mini { padding: 12px; background: var(--bg-surface); border-radius: var(--radius-md); font-size: 14px; }
