/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --bg: #0d1117;
    --bg-card: #161b22;
    --bg-hover: #1c2129;
    --bg-round: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-dim: #8b949e;
    --accent: #58a6ff;
    --green: #3fb950;
    --red: #f85149;
    --orange: #d29922;
    --yellow: #e3b341;
    --purple: #bc8cff;
    --severity-critical: #f85149;
    --severity-high: #f0883e;
    --severity-medium: #d29922;
    --severity-low: #58a6ff;
    --radius: 8px;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}
code { background: var(--bg-round); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.container { max-width: 100%; margin: 0 auto; padding: 20px; }

/* ── Setup Panel ── */
#setup-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
#setup-panel .container { max-width: 600px; width: 100%; }
#setup-panel h1 { font-size: 2.4em; margin-bottom: 8px; }
#setup-panel .subtitle { color: var(--text-dim); margin-bottom: 32px; }
.upload-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.upload-section h2 { font-size: 1.1em; margin-bottom: 12px; color: var(--accent); }
.form-row { display: flex; gap: 10px; }

/* ── Demo Grid ── */
.demo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.demo-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 12px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.demo-card:hover {
    border-color: var(--accent);
    background: rgba(88,166,255,0.05);
}
.demo-card.selected {
    border-color: var(--accent);
    background: rgba(88,166,255,0.08);
    box-shadow: 0 0 0 2px rgba(88,166,255,0.2);
}
.demo-card-icon { font-size: 1.8em; }
.demo-card-name {
    font-weight: 600;
    font-size: 0.85em;
    word-break: break-all;
    line-height: 1.3;
}
.demo-card-meta {
    font-size: 0.75em;
    color: var(--text-dim);
}
.new-demo-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: transparent;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px 12px;
    text-decoration: none;
    color: var(--text-dim);
    transition: border-color 0.2s, color 0.2s;
    min-height: 120px;
}
.new-demo-card:hover {
    border-color: #ff5858;
    color: var(--text);
}
.new-demo-icon {
    font-size: 2em;
    font-weight: 700;
    background: linear-gradient(135deg, #f857a6, #ff5858);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
}
.new-demo-text { font-weight: 600; font-size: 0.9em; }
.new-demo-sub { font-size: 0.75em; }

/* ── Empty State ── */
.empty-state .big-icon { font-size: 3em; margin-bottom: 12px; }
select, button {
    padding: 10px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-round);
    color: var(--text);
    font-size: 1em;
    cursor: pointer;
}
select { flex: 1; }
button { font-weight: 600; transition: background 0.15s; }
button:hover { background: var(--border); }
button.primary { background: #238636; border-color: #2ea043; }
button.primary:hover { background: #2ea043; }
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.hint { color: var(--text-dim); font-size: 0.85em; margin-top: 8px; }

/* ── Loading ── */
#loading-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 16px;
    color: var(--text-dim);
}
.loading-spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Results Layout ── */
.header-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.header-bar h1 { font-size: 1.5em; }
#player-label { color: var(--accent); font-weight: 400; }
#summary-stats { display: flex; gap: 20px; margin-left: auto; }
.stat { text-align: center; }
.stat-value { font-size: 1.4em; font-weight: 700; display: block; }
.stat-label { font-size: 0.75em; color: var(--text-dim); text-transform: uppercase; }
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }

.main-layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }

/* ── Sidebar ── */
.sidebar { 
    background: var(--bg-card); 
    border: 1px solid var(--border); 
    border-radius: var(--radius); 
    padding: 12px;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
}
.sidebar h3 { font-size: 0.85em; color: var(--text-dim); text-transform: uppercase; margin-bottom: 8px; letter-spacing: 0.05em; }
.round-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text);
    font-size: 0.95em;
    text-align: left;
    cursor: pointer;
    margin-bottom: 2px;
}
.round-btn:hover { background: var(--bg-hover); }
.round-btn.active { background: var(--bg-round); border: 1px solid var(--border); }
.round-num { font-weight: 700; min-width: 28px; }
.round-info { font-size: 0.8em; color: var(--text-dim); }
.round-fights { display: flex; gap: 4px; }
.round-fight-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.round-fight-dot.win { background: var(--green); }
.round-fight-dot.loss { background: var(--red); }
.round-fight-dot.trade { background: var(--orange); }

/* ── Content ── */
.content { min-width: 0; }

/* ── Fight Cards ── */
.fight-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: border-color 0.15s;
}
.fight-card:hover { border-color: var(--accent); }
.fight-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.fight-result {
    font-weight: 700;
    font-size: 0.85em;
    padding: 3px 10px;
    border-radius: 4px;
    text-transform: uppercase;
}
.fight-result.win { background: rgba(63,185,80,0.15); color: var(--green); }
.fight-result.loss { background: rgba(248,81,73,0.15); color: var(--red); }
.fight-result.trade { background: rgba(226,136,34,0.15); color: var(--orange); }
.fight-result.exchange { background: rgba(136,136,136,0.15); color: #999; }
.fight-opponent { font-weight: 600; }
.fight-meta { margin-left: auto; display: flex; gap: 16px; color: var(--text-dim); font-size: 0.9em; }
.aim-badge { font-size: 0.85em; font-weight: 600; padding: 2px 8px; border-radius: 4px; }
.aim-badge.aim-great { background: rgba(63,185,80,0.15); color: var(--green); }
.aim-badge.aim-avg { background: rgba(226,136,34,0.15); color: var(--orange); }
.aim-badge.aim-poor { background: rgba(248,81,73,0.15); color: var(--red); }
.aim-great { color: var(--green) !important; }
.aim-avg { color: var(--orange) !important; }
.aim-poor { color: var(--red) !important; }
.fight-tip-preview {
    font-size: 0.85em;
    color: var(--text-dim);
    border-top: 1px solid var(--border);
    padding-top: 8px;
    margin-top: 8px;
}
.fight-tip-count { color: var(--orange); font-weight: 600; }

/* ── Fight Detail ── */
.fight-detail {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}
.fight-detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.back-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
}
.back-btn:hover { background: var(--bg-hover); color: var(--text); }

.playback-link-btn {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    transition: background 0.15s;
}
.playback-link-btn:hover {
    background: var(--accent);
    color: var(--bg-card);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.detail-item {
    background: var(--bg-round);
    padding: 12px;
    border-radius: 6px;
}
.detail-label { font-size: 0.75em; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.detail-value { font-size: 1.2em; font-weight: 700; margin-top: 4px; }

/* ── Timeline ── */
.timeline {
    border-left: 2px solid var(--border);
    margin-left: 12px;
    padding-left: 20px;
    margin-bottom: 24px;
}
.timeline-event {
    position: relative;
    padding: 10px 14px;
    background: var(--bg-round);
    border-radius: 6px;
    margin-bottom: 8px;
}
.timeline-event::before {
    content: '';
    position: absolute;
    left: -27px;
    top: 14px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
}
.timeline-event.kill::before { background: var(--red); }
.timeline-event .time-stamp { color: var(--text-dim); font-family: monospace; font-size: 0.85em; margin-right: 8px; }
.timeline-event.damage-by-target { border-left: 3px solid var(--green); }
.timeline-event.damage-by-opponent { border-left: 3px solid var(--red); }
.timeline-event .hitgroup { color: var(--orange); font-weight: 600; }

/* ── Tips Section ── */
.tips-section h3 { margin-bottom: 12px; }
.tip-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 4px solid var(--severity-medium);
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 10px;
}
.tip-card.severity-critical { border-left-color: var(--severity-critical); }
.tip-card.severity-high { border-left-color: var(--severity-high); }
.tip-card.severity-medium { border-left-color: var(--severity-medium); }
.tip-card.severity-low { border-left-color: var(--severity-low); }
.tip-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tip-severity {
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 3px;
}
.tip-severity.critical { background: rgba(248,81,73,0.15); color: var(--severity-critical); }
.tip-severity.high { background: rgba(240,136,62,0.15); color: var(--severity-high); }
.tip-severity.medium { background: rgba(210,153,34,0.15); color: var(--severity-medium); }
.tip-severity.low { background: rgba(88,166,255,0.15); color: var(--severity-low); }
.tip-title { font-weight: 600; font-size: 1.05em; }
.tip-block { margin-bottom: 8px; }
.tip-block-label { font-size: 0.8em; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 2px; }
.tip-block.what-happened { color: var(--text); }
.tip-block.what-to-do { color: var(--green); }

/* ── Tabs ── */
.tab-bar { display: flex; gap: 4px; margin-top: 8px; }
.tab {
    padding: 6px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px 6px 0 0;
    color: var(--text-dim);
    font-size: 0.9em;
    cursor: pointer;
    font-weight: 600;
}
.tab:hover { background: var(--bg-hover); }
.tab.active { background: var(--bg-card); color: var(--text); border-bottom-color: var(--bg-card); }
.tab-content { margin-top: 0; }

/* ── Round Tips (utility/economy/teamwork) ── */
.round-tips {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}
.round-tips h4 { margin-bottom: 10px; font-size: 0.9em; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }
.round-tip-inline {
    background: var(--bg-round);
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 6px;
    border-left: 3px solid var(--severity-medium);
}
.round-tip-inline.severity-critical { border-left-color: var(--severity-critical); }
.round-tip-inline.severity-high { border-left-color: var(--severity-high); }
.round-tip-inline.severity-medium { border-left-color: var(--severity-medium); }
.round-tip-inline.severity-low { border-left-color: var(--severity-low); }
.round-tip-inline .tip-category {
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(88,166,255,0.1);
    color: var(--accent);
    margin-right: 8px;
}
.round-tip-inline .tip-inline-title { font-weight: 600; }

/* ── Habits Page ── */
#habits-content { max-width: 100%; }
.habits-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}
.habits-col {
    min-width: 0;
}
.habit-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--severity-medium);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.habit-card.severity-high { border-left-color: var(--severity-high); }
.habit-card.severity-medium { border-left-color: var(--severity-medium); }
.habit-card.severity-low { border-left-color: var(--severity-low); }
.habit-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.habit-severity {
    font-size: 0.75em; font-weight: 700; text-transform: uppercase;
    padding: 2px 8px; border-radius: 3px;
}
.habit-severity.high { background: rgba(248,81,73,0.15); color: var(--severity-high); }
.habit-severity.medium { background: rgba(210,153,34,0.15); color: var(--severity-medium); }
.habit-severity.low { background: rgba(88,166,255,0.15); color: var(--severity-low); }
.habit-title { font-size: 1.15em; font-weight: 700; }
.habit-section { margin-bottom: 10px; }
.habit-section-label { font-size: 0.8em; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.habit-pattern { color: var(--text); }
.habit-impact { color: var(--orange); }
.habit-recommendation { color: var(--green); }
.habit-rounds { font-size: 0.85em; color: var(--text-dim); margin-top: 8px; }
.habit-rounds span {
    display: inline-block;
    background: var(--bg-round);
    padding: 2px 8px;
    border-radius: 4px;
    margin: 2px 4px 2px 0;
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .main-layout { grid-template-columns: 1fr; }
    .sidebar { max-height: none; }
    #summary-stats { margin-left: 0; }
    .header-bar { flex-direction: column; align-items: flex-start; }
    .habits-columns { grid-template-columns: 1fr; }
}
