/* AoE4 Coach — theme tokens follow the validated reference palette */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;   /* focus player */
  --series-2: #008300;   /* opponent */
  --series-3: #e87ba4;
  --series-4: #eda100;
  --series-5: #1baf7a;
  --series-6: #eb6834;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #008300;
    --series-3: #d55181;
    --series-4: #c98500;
    --series-5: #199e70;
    --series-6: #d95926;
    --series-7: #9085e9;
    --series-8: #e66767;
    --good: #0ca30c;
    --good-text: #0ca30c;
    --accent: #3987e5;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); }

.topbar {
  padding: 18px 24px 10px;
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
}
.brand { font-size: 22px; font-weight: 700; }
.tagline { color: var(--text-secondary); font-size: 13px; }

main { max-width: 1060px; margin: 0 auto; padding: 8px 20px 60px; }
footer {
  max-width: 1060px; margin: 0 auto; padding: 16px 20px 40px;
  color: var(--text-muted); font-size: 12.5px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin: 14px 0;
}
.card h2 { margin: 0 0 6px; font-size: 16px; }
.hint { color: var(--text-secondary); font-size: 13px; margin: 4px 0 12px; }
.hint code { background: var(--page); padding: 1px 5px; border-radius: 4px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
input[type="text"] {
  flex: 1; min-width: 240px;
  padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--baseline);
  background: var(--page); color: var(--text-primary);
  font-size: 15px;
}
input[type="text"]:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn {
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary);
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.5; cursor: default; }

.status {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 18px; font-size: 13.5px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.18);
}

/* search results / games list */
.result-row, .game-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px; border-top: 1px solid var(--grid);
  flex-wrap: wrap;
}
.result-row:first-child, .game-row:first-child { border-top: none; }
.result-row .who { flex: 1; min-width: 200px; }
.result-name { font-weight: 600; }
.result-meta, .game-meta { color: var(--text-secondary); font-size: 13px; }
.rank-chip {
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--page); border: 1px solid var(--grid); color: var(--text-secondary);
}

.game-row .mapname { font-weight: 600; min-width: 110px; }
.game-row .vs { flex: 1; min-width: 240px; font-size: 13.5px; }
.game-row .when { color: var(--text-muted); font-size: 12.5px; min-width: 90px; }
.res-win  { color: var(--good-text); font-weight: 700; }
.res-loss { color: var(--critical); font-weight: 700; }

#player-banner { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
#player-banner img { width: 40px; height: 40px; border-radius: 8px; }
#player-banner .pname { font-weight: 700; font-size: 16px; }
#player-banner .pmeta { color: var(--text-secondary); font-size: 13px; }
.share-btn { margin-left: auto; white-space: nowrap; }
.back-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.back-row .share-btn { margin-left: auto; }

/* ============ report ============ */
.report-header { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin: 4px 0 0; }
.report-header h2 { margin: 0; font-size: 20px; }
.verdict-badge {
  font-size: 13px; font-weight: 700; padding: 3px 12px; border-radius: 999px; color: #fff;
}
.verdict-badge.win { background: var(--good); }
.verdict-badge.loss { background: var(--critical); }
.report-sub { color: var(--text-secondary); font-size: 13.5px; margin: 2px 0 0; }

.tldr {
  border-left: 3px solid var(--accent);
  padding: 10px 16px; margin: 14px 0;
  background: var(--surface-1); border-radius: 0 10px 10px 0;
  font-size: 15px;
}

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin: 14px 0;
}
.stat-tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px;
}
.stat-tile .label { font-size: 12px; color: var(--text-secondary); }
.stat-tile .value { font-size: 24px; font-weight: 650; margin-top: 2px; }
.stat-tile .delta { font-size: 12.5px; margin-top: 2px; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--critical); }
.delta.flat { color: var(--text-muted); }

.finding {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 4px; border-top: 1px solid var(--grid);
}
.finding:first-of-type { border-top: none; }
.finding .sev {
  flex: 0 0 auto; margin-top: 3px;
  width: 10px; height: 10px; border-radius: 50%;
}
.sev.major { background: var(--critical); }
.sev.moderate { background: var(--serious); }
.sev.minor { background: var(--warning); }
.sev.positive { background: var(--good); }
.finding h4 { margin: 0 0 3px; font-size: 14.5px; }
.finding p { margin: 0; font-size: 13.5px; color: var(--text-secondary); }
.finding .evidence { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.plan-item {
  border-top: 1px solid var(--grid); padding: 12px 4px;
  display: flex; gap: 12px;
}
.plan-item:first-of-type { border-top: none; }
.plan-num {
  flex: 0 0 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center; margin-top: 1px;
}
.plan-item h4 { margin: 0 0 3px; font-size: 14.5px; }
.plan-item p { margin: 0; font-size: 13.5px; color: var(--text-secondary); }
.plan-item .drill { margin-top: 5px; font-size: 13px; }
.plan-item .drill strong { color: var(--text-primary); }

/* comparison table */
table.compare { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.compare th, table.compare td {
  padding: 7px 10px; text-align: right;
  border-top: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
table.compare th { color: var(--text-secondary); font-weight: 600; }
table.compare td:first-child, table.compare th:first-child { text-align: left; font-variant-numeric: normal; }
table.compare thead th { border-top: none; font-size: 12.5px; }
td.better { color: var(--good-text); font-weight: 650; }
td.worse { color: var(--critical); }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 860px) { .charts-grid { grid-template-columns: 1fr; } }
.chart-card { overflow: hidden; }
.chart-card h3 { margin: 0 0 2px; font-size: 14px; }
.chart-card .sub { color: var(--text-muted); font-size: 12px; margin-bottom: 6px; }

/* build order timeline */
.bo-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bo-table td { padding: 4px 10px; border-top: 1px solid var(--grid); }
.bo-table td.t { color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.age-marker { font-weight: 700; color: var(--accent); }

.finding-group {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin: 18px 0 4px; border-bottom: 1px solid var(--grid);
  padding-bottom: 4px;
}
.finding-group:first-of-type { margin-top: 8px; }
.prio-num {
  flex: 0 0 22px; height: 22px; border-radius: 50%;
  background: var(--critical); color: #fff; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center; margin-top: 1px;
}
.follows { margin: 0 0 4px !important; font-size: 12.5px !important; color: var(--text-muted) !important; font-style: italic; }
.recommend { margin-top: 6px; color: var(--text-secondary); }

/* fight cards */
.fight { border-top: 1px solid var(--grid); padding: 16px 4px; }
.fight:first-of-type { border-top: none; }
.fight-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; margin-bottom: 10px; }
.fight-time { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.fight-outcome { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; }
.fight-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 4px 0; }
@media (max-width: 700px) { .fight-grid { grid-template-columns: 1fr; } }

.fside-top { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; font-size: 14px; }
.fval { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.fbar { display: block; height: 8px; background: var(--page); border: 1px solid var(--grid); border-radius: 4px; margin: 6px 0 4px; overflow: hidden; }
.fbar i { display: block; height: 100%; border-radius: 3px; }
.fbar.mini { display: inline-block; width: 90px; height: 6px; margin: 0 0 0 6px; vertical-align: middle; }
.fbar.mini i { background: var(--critical); }
.floss { color: var(--text-secondary); margin-bottom: 2px; }

.uchips { margin: 6px 0 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.uchip {
  display: inline-block; padding: 1px 9px; border: 1px solid var(--grid);
  border-radius: 999px; font-size: 12px; background: var(--page);
  color: var(--text-secondary); white-space: nowrap;
}
.uchip.r.ok { border-color: var(--good); color: var(--good-text); }
.uchip.r.bad { border-color: var(--critical); color: var(--critical); }

.fnotes { margin-top: 10px; border-top: 1px dashed var(--grid); padding-top: 8px; }
.fnote { display: flex; gap: 10px; font-size: 13px; margin: 5px 0; align-items: baseline; }
.fnote-tag { flex: 0 0 130px; font-weight: 650; color: var(--text-primary); }
.fnote > span:last-child { color: var(--text-secondary); }
@media (max-width: 700px) { .fnote { flex-direction: column; gap: 1px; } .fnote-tag { flex: none; } }

.frec {
  margin-top: 10px; padding: 9px 13px; background: var(--page);
  border: 1px solid var(--grid); border-radius: 10px;
}
.frec-title { font-size: 12.5px; font-weight: 650; margin-bottom: 2px; }

.back-row { margin: 10px 0; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
