:root {
    --bg:         #0d1117;
    --surface:    #161b22;
    --card:       #21262d;
    --border:     #30363d;
    --border-sub: #21262d;
    --text:       #e6edf3;
    --text-muted: #7d8590;
    --accent:     #58a6ff;
    --green:      #3fb950;
    --red:        #f85149;
    --yellow:     #d29922;
    --radius:     6px;
    --radius-lg:  10px;
    --font:       'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Layout ── */
#app {
    display: grid;
    grid-template-rows: 52px 1fr;
    grid-template-columns: 400px 1fr;
    grid-template-areas: "header header" "sidebar main";
    height: 100vh;
    overflow: hidden;
}

header {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
header h1 { font-size: 16px; font-weight: 600; letter-spacing: .5px; }

.btn-header {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 5px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    transition: border-color .15s, color .15s;
}
.btn-header:hover { border-color: var(--accent); color: var(--accent); }

#sidebar {
    grid-area: sidebar;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--surface);
}

#main {
    grid-area: main;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ── Sidebar sections ── */
.section { border-bottom: 1px solid var(--border); }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    font-size: 11px;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: var(--text-muted);
    transition: color .15s;
}
.section-header:hover { color: var(--text); }
.section-header .chevron { transition: transform .2s; font-size: 10px; }
.section.open .section-header .chevron { transform: rotate(90deg); }

.section-body {
    display: none;
    padding: 4px 16px 16px;
    flex-direction: column;
    gap: 12px;
}
.section.open .section-body { display: flex; }

/* ── Utility text ── */
.hint-text  { font-size: 11px; color: var(--text-muted); line-height: 1.5; }
.label-sub  { font-size: 11px; color: var(--text-muted); }
.catch-all-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* ── Form elements ── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12px; color: var(--text-muted); }

.btn-group {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.btn-group button {
    flex: 1;
    padding: 6px 4px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.btn-group button:not(:last-child) { border-right: 1px solid var(--border); }
.btn-group button.active { background: var(--accent); color: #fff; font-weight: 600; }
.btn-group button:hover:not(.active) { background: var(--card); color: var(--text); }

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.toggle-row > label:first-child { font-size: 13px; color: var(--text); }

.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
    position: absolute; inset: 0;
    background: var(--border);
    border-radius: 20px; cursor: pointer;
    transition: background .2s;
}
.toggle .slider::before {
    content: '';
    position: absolute; left: 3px; top: 3px;
    width: 14px; height: 14px;
    background: #fff; border-radius: 50%;
    transition: transform .2s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(16px); }

input[type="number"],
input[type="text"] {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 6px 10px;
    font-size: 13px;
    width: 100%;
    outline: none;
    transition: border-color .15s;
}
input[type="number"]:focus,
input[type="text"]:focus { border-color: var(--accent); }

input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }

.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type="range"] { flex: 1; }
.range-val { min-width: 56px; text-align: right; font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }

/* ── Small utility buttons ── */
.btn-sm {
    padding: 5px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    transition: border-color .15s, color .15s;
}
.btn-sm:hover         { border-color: var(--text-muted); color: var(--text); }
.btn-sm.btn-danger:hover  { border-color: var(--red);    color: var(--red); }
.btn-sm.btn-accent    { border-color: var(--accent); color: var(--accent); }
.btn-sm.btn-accent:hover { background: var(--accent); color: #fff; }

/* ── Profile select ── */
#profile-select {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 6px 8px;
    font-size: 13px;
    outline: none;
    cursor: pointer;
    width: 100%;
}
#profile-select:focus { border-color: var(--accent); }

/* ── Bet table ── */
#bet-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
#bet-table th {
    text-align: left;
    font-size: 11px;
    color: var(--text-muted);
    padding: 4px 4px;
    border-bottom: 1px solid var(--border);
    font-weight: 500;
}
#bet-table td {
    padding: 4px 2px;
    vertical-align: middle;
}
#bet-table select {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    outline: none;
    padding: 4px 4px;
    font-size: 12px;
    width: 100%;
}
.hands-grp { min-width: 72px; }
.hands-grp button { font-size: 12px; padding: 4px 2px; }

/* Bet cell: slider + number input side by side */
.bet-cell { min-width: 130px; }
.bet-cell-inner {
    display: flex;
    align-items: center;
    gap: 6px;
}
.bet-cell-inner input[type="range"] { flex: 1; min-width: 50px; }
.bet-cell-inner input[type="number"] { width: 58px; padding: 4px 6px; font-size: 12px; }

.del-row-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius);
    font-size: 16px;
    line-height: 1;
    transition: color .15s, background .15s;
}
.del-row-btn:hover { color: var(--red); background: rgba(248,81,73,.12); }

#add-bet-row {
    margin-top: 4px;
    background: none;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px 10px;
    font-size: 12px;
    width: 100%;
    transition: border-color .15s, color .15s;
}
#add-bet-row:hover { border-color: var(--accent); color: var(--accent); }

/* ── Run button ── */
#run-section {
    padding: 16px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}
#run-btn {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
}
#run-btn:hover    { opacity: .85; }
#run-btn:disabled { opacity: .4; cursor: not-allowed; }
#cancel-btn {
    display: none;
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    transition: border-color .15s, color .15s;
}
#cancel-btn:hover { border-color: var(--red); color: var(--red); }

/* ── Main panel ── */
.placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-muted);
    text-align: center;
}
.placeholder .icon { font-size: 48px; opacity: .25; }
.placeholder p { max-width: 320px; line-height: 1.6; }

/* ── Progress ── */
#progress-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.progress-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
}
.progress-stats { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.progress-bar-track { height: 6px; background: var(--border); border-radius: 6px; overflow: hidden; }
.progress-bar-fill  { height: 100%; background: var(--accent); border-radius: 6px; transition: width .3s; width: 0%; }

/* Worker tiles */
#worker-detail { margin-top: 4px; }
.worker-detail-summary {
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    padding: 2px 0;
    list-style: none;
    transition: color .15s;
}
.worker-detail-summary::-webkit-details-marker { display: none; }
.worker-detail-summary::before { content: '› '; }
#worker-detail[open] .worker-detail-summary::before { content: '⌄ '; }
.worker-detail-summary:hover { color: var(--text); }
#worker-tiles {
    display: grid;
    gap: 6px;
    margin-top: 8px;
}
.worker-tile {
    background: var(--bg);
    border: 1px solid var(--border-sub);
    border-radius: var(--radius);
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.worker-tile-header {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.worker-tile-label { font-weight: 600; }
.worker-tile-track { height: 3px; background: var(--border); border-radius: 3px; overflow: hidden; }
.worker-tile-fill  { height: 100%; background: var(--green); border-radius: 3px; transition: width .25s; width: 0%; }

/* ── Playing strategy / deviation section ── */
.dev-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    padding: 3px 0;
    line-height: 1.4;
}
.dev-item input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    cursor: pointer;
}

/* ── Summary cards ── */
#summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
}
.stat-card .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat-card .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .sub   { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.val-pos     { color: var(--green);  }
.val-neg     { color: var(--red);    }
.val-warn    { color: var(--yellow); }
.val-neutral { color: var(--text);   }

/* ── Charts ── */
.chart-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
}
.chart-panel h3 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: .6px;
}
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Outcome table ── */
#outcome-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
#outcome-panel summary {
    padding: 13px 18px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .6px;
    user-select: none;
    transition: color .15s;
}
#outcome-panel summary:hover { color: var(--text); }
.outcome-scroll { overflow-x: auto; }
#outcome-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 700px; }
#outcome-table th {
    padding: 7px 10px; text-align: right;
    color: var(--text-muted); border-bottom: 1px solid var(--border);
    font-weight: 500; white-space: nowrap;
}
#outcome-table th:first-child { text-align: left; }
#outcome-table td { padding: 5px 10px; text-align: right; border-bottom: 1px solid var(--border-sub); font-variant-numeric: tabular-nums; }
#outcome-table td:first-child { text-align: left; color: var(--text-muted); }
#outcome-table tr:last-child td { border-bottom: none; }
#outcome-table tr:hover td { background: rgba(255,255,255,.025); }

/* ── Coffee button ── */
.btn-coffee {
    text-decoration: none;
    color: var(--text-muted);
    border-color: var(--border);
}
.btn-coffee:hover { border-color: var(--yellow); color: var(--yellow); }

/* ── About modal ── */
#about-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
#about-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    max-width: 480px;
    width: calc(100% - 40px);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
#about-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#about-header h2 { font-size: 18px; font-weight: 700; letter-spacing: .5px; }
#about-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    transition: color .15s;
}
#about-close:hover { color: var(--text); }
#about-modal p { font-size: 14px; line-height: 1.6; color: var(--text-muted); }
#about-modal p a { color: var(--accent); text-decoration: none; }
#about-modal p a:hover { text-decoration: underline; }
.about-license { font-size: 13px !important; }
#about-footer {
    margin-top: 4px;
    display: flex;
    justify-content: center;
}
.btn-coffee-lg {
    display: inline-block;
    padding: 9px 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: border-color .15s, color .15s;
}
.btn-coffee-lg:hover { border-color: var(--yellow); color: var(--yellow); }

/* ── Scrollbar ── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 960px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: 52px auto 1fr;
        grid-template-areas: "header" "sidebar" "main";
        height: auto; overflow: visible;
    }
    #sidebar { max-height: none; overflow: visible; }
    #main    { overflow: visible; }
    #summary-cards { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .chart-row     { grid-template-columns: 1fr; }
}
