:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --border: #e3e6ea;
    --text: #1f2937;
    --muted: #6b7280;
    --accent: #2563eb;
    --pos: #16a34a;
    --neg: #dc2626;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}
header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0.9rem 1.5rem;
    display: flex;
    align-items: baseline;
    gap: 1rem;
}
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); }
.tagline { color: var(--muted); font-size: 0.9rem; }
.nav { margin-left: auto; display: flex; gap: 1.1rem; }
.nav a { text-decoration: none; color: var(--accent); font-weight: 600; font-size: 0.9rem; }
.nav a:hover { text-decoration: underline; }
main { max-width: 1000px; margin: 1.5rem auto; padding: 0 1rem; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.section-head h2, .section-head h3 { margin: 0; }
.btn-secondary {
    text-decoration: none; border: 1px solid var(--border); border-radius: 6px;
    padding: 0.35rem 0.8rem; font-size: 0.85rem; font-weight: 600; color: var(--text); background: #fff;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-tiny {
    border: 1px solid var(--border); border-radius: 5px; background: #fff; cursor: pointer;
    padding: 0.25rem 0.55rem; font-size: 0.8rem; font-weight: 600; color: var(--accent); white-space: nowrap;
}
.btn-tiny:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.beat-row { background: rgba(22,163,74,0.06); }

.heatmap-wrap { overflow-x: auto; }
table.heatmap { border-collapse: collapse; font-size: 0.82rem; }
table.heatmap th, table.heatmap td { border: 1px solid var(--border); padding: 0.4rem 0.55rem; text-align: center; min-width: 48px; }
table.heatmap thead th, table.heatmap tbody th { background: #f3f4f6; font-weight: 700; color: var(--muted); }
table.heatmap td { font-variant-numeric: tabular-nums; font-weight: 600; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}
.card h2 { margin-top: 0; }

.alert {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.9rem;
}
label { display: flex; flex-direction: column; font-size: 0.85rem; font-weight: 600; gap: 0.3rem; }
input, select {
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 400;
}
input[readonly] { background: #f3f4f6; color: var(--muted); }
.hint { color: var(--muted); font-weight: 400; font-size: 0.78rem; }

.presets { margin-bottom: 1.1rem; padding-bottom: 0.9rem; border-bottom: 1px solid var(--border); }
.preset-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.preset-label { font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; min-width: 120px; }
.preset-buttons { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip {
    background: #fff; border: 1px solid var(--border); border-radius: 999px;
    padding: 0.3rem 0.85rem; font-size: 0.85rem; font-weight: 600; cursor: pointer; color: var(--text);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.scenario-select { min-width: 320px; max-width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; }
.scenario-note { margin: 0.1rem 0 0; font-style: italic; }

.ticker-confirm { margin: 0.6rem 0 0; font-size: 0.88rem; font-weight: 600; min-height: 1.2em; }
.ticker-confirm.ok { color: var(--pos); }
.ticker-confirm.warn { color: var(--neg); }
.ticker-confirm.loading { color: var(--muted); font-weight: 400; font-style: italic; }
.company { font-weight: 400; font-size: 1rem; color: var(--muted); }

.advanced { margin: 1rem 0; border: 1px dashed var(--border); border-radius: 8px; padding: 0.5rem 0.9rem; }
.advanced summary { cursor: pointer; font-weight: 600; }
.advanced .grid { margin-top: 0.8rem; }

button[type=submit] {
    margin-top: 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.6rem 1.4rem;
    border-radius: 7px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
button[type=submit]:hover { background: #1d4ed8; }

table.runs { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.runs th, table.runs td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
table.runs th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f9fafb; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.small { font-size: 0.82rem; }
.muted { color: var(--muted); }
.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }

.link-danger { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; }
.link-danger:hover { color: var(--neg); }
.back { text-decoration: none; color: var(--accent); font-weight: 600; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin: 1.2rem 0; }
.metric { border: 1px solid var(--border); border-radius: 8px; padding: 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.2rem; }
.metric.highlight { border-color: var(--accent); background: #eff6ff; }
.metric .label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.metric .value { font-size: 1.5rem; font-weight: 700; }
.metric .sub { font-size: 0.85rem; color: var(--muted); }

table.params { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 0.5rem; }
table.params td { padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--border); }
table.params td:nth-child(odd) { color: var(--muted); }

.trade-scroll { max-height: 360px; overflow-y: auto; }
.action-buy, .action-initial { color: var(--pos); font-weight: 600; }
.action-sell, .action-target_exit { color: var(--neg); font-weight: 600; }

canvas { max-width: 100%; }
