:root {
    --bg-dark: #0f1115;
    --card-bg: #1a1d24;
    --card-border: #2a2d35;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --up-color: #ef4444; /* Red for Korean market */
    --up-bg: rgba(239, 68, 68, 0.15);
    --down-color: #3b82f6;
    --down-bg: rgba(59, 130, 246, 0.15);
    --hover-bg: #2a2d35;
    --drawer-bg: #1e2128;
}

body.light-mode {
    --bg-dark: #f1f5f9;
    --card-bg: #ffffff;
    --card-border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #94a3b8;
    --hover-bg: #f8fafc;
    --drawer-bg: #ffffff;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s;
}

.text-up { color: var(--up-color); font-weight: 600; }
.text-down { color: var(--down-color); font-weight: 600; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-body { color: var(--text-secondary); line-height: 1.6; font-size: 0.95rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

.news-ticker-container { height: 24px; overflow: hidden; margin-top: 1rem; }
.news-ticker { list-style: none; animation: ticker 20s linear infinite; }
.news-ticker:hover { animation-play-state: paused; }
.news-ticker li { height: 24px; line-height: 24px; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.news-ticker li a { color: var(--text-primary); text-decoration: none; margin-right: 0.5rem; }
.news-ticker li a:hover { text-decoration: underline; color: var(--accent); }

@keyframes ticker {
    0% { transform: translateY(0); }
    100% { transform: translateY(-240px); /* 10 items * 24px */ }
}

.ml-2 { margin-left: 0.5rem; }

.top-nav {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 2rem; border-bottom: 1px solid var(--card-border);
    background: var(--bg-dark);
}
.logo { font-size: 1.25rem; font-weight: 800; display: flex; align-items: center; gap: 0.5rem; }
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, #a855f7, #ec4899); }
.logo-sub { font-size: 0.85rem; color: var(--text-muted); font-weight: 400; margin-left: 0.5rem; }

.btn-icon {
    background: var(--card-bg); border: 1px solid var(--card-border);
    color: var(--text-primary); padding: 0.5rem 1rem; border-radius: 6px;
    cursor: pointer; font-size: 0.9rem; transition: 0.2s;
}
.btn-icon:hover { background: var(--hover-bg); }

.warning-banner {
    background: rgba(234, 179, 8, 0.1); border: 1px solid rgba(234, 179, 8, 0.3);
    color: #facc15; padding: 0.75rem 2rem; font-size: 0.9rem;
    text-align: center; margin: 1rem 2rem 0; border-radius: 8px;
}
body.light-mode .warning-banner { color: #b45309; }

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

.card {
    background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem;
}

.summary-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; margin-bottom: 1.5rem; }
.summary-cards .card { margin-bottom: 0; }
.card-title { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.card-value { font-size: 2rem; font-weight: 700; margin-bottom: 0.25rem; }
.card-sub { font-size: 0.85rem; color: var(--text-muted); }

.period-bar { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; }
.period-chips { display: flex; gap: 0.5rem; align-items: center; }
.period-label { font-weight: 600; margin-right: 1rem; color: var(--text-secondary); }
.period-chips button {
    background: transparent; border: none; color: var(--text-muted);
    padding: 0.4rem 1rem; border-radius: 20px; cursor: pointer; font-weight: 500;
    transition: 0.2s;
}
.period-chips button:hover { color: var(--text-primary); background: var(--hover-bg); }
.period-chips button.active { background: var(--text-primary); color: var(--bg-dark); }
.period-note { font-size: 0.85rem; color: var(--text-muted); }

.section-header { margin-bottom: 1.5rem; }
.section-header h2 { font-size: 1.25rem; display: inline-block; margin-right: 0.5rem; }
.section-sub { font-size: 0.9rem; color: var(--text-muted); }

.heatmap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.heatmap-cell {
    padding: 1.25rem; border-radius: 8px; cursor: pointer; transition: 0.2s;
    color: white; border: 1px solid rgba(255,255,255,0.1);
}
.heatmap-cell:hover { transform: scale(1.02); z-index: 10; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3); }
.heatmap-cell.active { border: 2px solid white; }
.hm-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.5rem; opacity: 0.9; }
.hm-val { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.25rem; }
.hm-sub { font-size: 0.8rem; opacity: 0.7; }

.compare-actions { display: flex; gap: 0.5rem; }
.compare-actions select {
    background: var(--card-bg); border: 1px solid var(--card-border);
    color: var(--text-primary); padding: 0.5rem; border-radius: 6px; outline: none;
}
.compare-bars { display: flex; flex-direction: column; gap: 0.75rem; }
.compare-row { display: flex; align-items: center; cursor: pointer; padding: 0.5rem; border-radius: 6px; }
.compare-row:hover { background: var(--hover-bg); }
.c-name { width: 150px; font-size: 0.9rem; font-weight: 500; }
.c-code { color: var(--text-muted); font-size: 0.8rem; margin-left: 0.5rem; font-weight: 400;}
.c-bar-container { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; height: 12px; margin: 0 1.5rem; background: rgba(255,255,255,0.03); border-radius: 6px; }
.c-midline { position: absolute; left: 50%; top: -5px; bottom: -5px; width: 1px; background: rgba(255,255,255,0.1); }
.c-bar { height: 100%; border-radius: 4px; position: absolute; }
.c-bar.up { background: var(--up-color); right: 50%; transform-origin: right; }
.c-bar.down { background: var(--down-color); left: 50%; transform-origin: left; }
.c-val { width: 60px; text-align: right; font-weight: 600; font-size: 0.95rem; }

.table-controls { display: flex; gap: 1rem; margin-bottom: 1rem; align-items: center; }
.table-controls input, .table-controls select {
    background: var(--card-bg); border: 1px solid var(--card-border);
    color: var(--text-primary); padding: 0.6rem 1rem; border-radius: 8px; outline: none;
}
.table-controls input { flex: 1; max-width: 400px; }
.table-count { margin-left: auto; color: var(--text-muted); font-size: 0.9rem; }

.table-container { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 1rem 1.5rem; border-bottom: 1px solid var(--card-border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 500; font-size: 0.85rem; }
tbody tr { transition: 0.2s; cursor: pointer; }
tbody tr:hover { background: var(--hover-bg); }
.tag { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); padding: 0.25rem 0.5rem; border-radius: 4px; font-size: 0.8rem; color: var(--text-secondary); }
.star { color: var(--text-muted); cursor: pointer; font-size: 1.1rem; }
.star.active { color: #fbbf24; }

/* Drawer */
.drawer-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none; transition: 0.3s; z-index: 100;
}
.drawer-overlay.active { opacity: 1; pointer-events: auto; }
.drawer {
    position: fixed; top: 0; right: -500px; bottom: 0; width: 450px;
    background: var(--drawer-bg); box-shadow: -5px 0 25px rgba(0,0,0,0.5);
    transition: 0.3s; z-index: 101; display: flex; flex-direction: column;
    border-left: 1px solid var(--card-border);
}
.drawer.active { right: 0; }
.drawer-header { padding: 1.5rem 2rem; border-bottom: 1px solid var(--card-border); display: flex; justify-content: space-between; align-items: flex-start; }
.drawer-header h2 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.drawer-sub { font-size: 0.85rem; color: var(--text-muted); }
.btn-close { background: none; border: none; color: var(--text-muted); font-size: 1.25rem; cursor: pointer; }
.btn-close:hover { color: var(--text-primary); }
.drawer-content { padding: 1.5rem 2rem; overflow-y: auto; flex: 1; }
.d-price-section { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1rem; }
.d-price { font-size: 2rem; font-weight: 700; }
.d-change { font-size: 1.1rem; font-weight: 600; }
.chart-container { height: 150px; margin-bottom: 2rem; }

h3 { font-size: 1rem; color: var(--text-secondary); margin: 1.5rem 0 1rem; border-bottom: 1px solid var(--card-border); padding-bottom: 0.5rem; }
.returns-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.5rem; text-align: center; }
.ret-box { background: rgba(255,255,255,0.03); padding: 0.75rem 0; border-radius: 8px; border: 1px solid var(--card-border); }
.ret-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.ret-val { font-size: 0.9rem; font-weight: 600; }

.range-52w { margin: 2rem 0; }
.range-bar { height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; margin-top: 0.5rem; position: relative; }
.range-indicator { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); top: -3px; border: 2px solid var(--drawer-bg); transform: translateX(-50%); }

.fundamentals-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2rem; }
.f-box { border-bottom: 1px solid var(--card-border); padding-bottom: 0.5rem; }
.f-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.f-val { font-size: 1.1rem; font-weight: 600; }

.points-list { list-style-type: disc; padding-left: 1.5rem; color: var(--text-secondary); font-size: 0.95rem; }
.points-list li { margin-bottom: 0.5rem; }
