/* ==========================================================================
   Matchday — design system
   ========================================================================== */

:root {
  /* color */
  --bg: #171a19;
  --surface: #202421;
  --elevated: #282d29;
  --border: #353c36;
  --border-strong: #454d46;
  --text: #e8ece7;
  --text-2: #9aa49b;
  --text-3: #727b73;
  --accent: #b7d95c;
  --accent-hover: #c7e574;
  --accent-ink: #18200a;
  --accent-soft: #2b3320;
  --success: #86b37f;
  --warning: #d6aa5c;
  --warning-soft: #2f2a1e;
  --error: #d2766c;
  --error-soft: #33221f;
  --scrim: rgb(8 10 9 / 0.6);

  /* type */
  --font: "Inter", "SF Pro Text", -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --fs-title: 1.25rem;
  --fs-lg: 1.0625rem;
  --fs-md: 0.9375rem;
  --fs-sm: 0.8125rem;
  --fs-xs: 0.75rem;

  /* spacing (4px grid) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s8: 32px;

  /* shape */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --bw: 1px;

  /* layout */
  --content-w: 640px;
  --nav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --touch: 44px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body.has-sheet { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
.num, output { font-variant-numeric: tabular-nums; }
.icon { flex: none; display: block; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: var(--r-sm); z-index: 100; }
.skip-link:focus { left: 8px; }
.accent { color: var(--accent); }

/* ---------- layout ---------- */

.view {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + var(--s6));
  outline: none;
}
body.has-actionbar .view { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 84px); }

.content {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: var(--s2) var(--s4) var(--s4);
}

.boot {
  display: flex; align-items: center; justify-content: center; gap: var(--s3);
  min-height: 70dvh; color: var(--text-2); font-size: var(--fs-sm);
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s2);
  max-width: var(--content-w); margin: 0 auto;
  padding: calc(var(--safe-t) + var(--s3)) var(--s4) var(--s3);
  background: var(--bg);
}
.topbar-back { margin-left: calc(var(--s2) * -1); }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 {
  font-size: var(--fs-title); font-weight: 650; letter-spacing: -0.01em; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-title p { color: var(--text-2); font-size: var(--fs-sm); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: var(--s1); }

/* ---------- bottom navigation ---------- */

.nav {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: var(--bw) solid var(--border);
}
.nav ul { list-style: none; margin: 0 auto; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); height: 100%; max-width: 480px; }
.nav-item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--nav-h);
  color: var(--text-3); font-size: 0.6875rem; font-weight: 550; letter-spacing: 0.01em;
  transition: color 0.15s;
}
.nav-item::before {
  content: ""; position: absolute; top: -1px; left: 50%; width: 28px; height: 2px; margin-left: -14px;
  background: var(--accent); border-radius: 0 0 2px 2px; transform: scaleX(0); transition: transform 0.2s var(--ease);
}
.nav-item.is-active { color: var(--accent); }
.nav-item.is-active::before { transform: scaleX(1); }
.nav-item:not(.is-active):hover { color: var(--text-2); }

/* ---------- action bar (sticky primary actions above nav) ---------- */

.actionbar {
  position: fixed; z-index: 25; left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b));
  background: var(--bg);
  border-top: var(--bw) solid var(--border);
}
.actionbar-inner {
  max-width: var(--content-w); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) var(--s4);
}
.actionbar-left { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.actionbar-info { color: var(--text-2); font-size: var(--fs-sm); }
.actionbar-info b { color: var(--text); font-size: var(--fs-lg); font-weight: 650; margin-right: 2px; font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--touch); padding: 0 var(--s4);
  border-radius: var(--r-md); border: var(--bw) solid transparent;
  font-size: var(--fs-md); font-weight: 600; line-height: 1; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn--secondary { background: var(--elevated); border-color: var(--border); color: var(--text); }
.btn--secondary:hover:not(:disabled) { border-color: var(--border-strong); }
.btn--ghost { color: var(--text-2); padding: 0 var(--s2); }
.btn--ghost:hover { color: var(--text); }
.btn--danger { background: var(--error-soft); border-color: #4a2c28; color: var(--error); }
.btn--sm { min-height: 36px; padding: 0 var(--s3); font-size: var(--fs-sm); gap: 6px; }
.btn--lg { min-height: 52px; padding: 0 var(--s5); font-size: var(--fs-lg); }
.btn--wide { min-width: 200px; }
.btn--square { width: var(--touch); padding: 0; }
.btn--icon-text { padding: 0 var(--s3); }
.btn.is-busy { opacity: 0.85; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  width: var(--touch); height: var(--touch); flex: none;
  border-radius: var(--r-md); color: var(--text-2);
  transition: background-color 0.15s, color 0.15s;
}
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--surface); }
.icon-btn:disabled { opacity: 0.3; }
.icon-btn--sm { width: 36px; height: 36px; border-radius: var(--r-sm); }
.icon-btn.has-dot::after {
  content: ""; position: absolute; top: 10px; right: 10px; width: 7px; height: 7px;
  background: var(--accent); border-radius: 50%; box-shadow: 0 0 0 2px var(--surface);
}

.link-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 var(--s1);
  color: var(--accent); font-size: var(--fs-sm); font-weight: 600;
}
.link-btn:hover { color: var(--accent-hover); }
.link-btn--block { margin-top: var(--s3); color: var(--text-2); font-weight: 500; }
.link-btn--block:hover { color: var(--text); }

.spinner {
  width: 16px; height: 16px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- sections, panels, lists ---------- */

.section { margin-top: var(--s6); }
.section--first { margin-top: var(--s2); }
.section--tight { margin-top: var(--s5); }
.section-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s2); }
.section-row .section-title { margin-bottom: 0; }
.section-title {
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); letter-spacing: 0.01em;
  margin-bottom: var(--s2);
}
.section-meta { font-size: var(--fs-xs); color: var(--text-3); }
.section-hint { color: var(--text-3); font-size: var(--fs-sm); margin: var(--s2) 0; }
.section-hint b { color: var(--text-2); font-weight: 600; }
.section-hint--in { margin: var(--s3) 0 0; }

.panel {
  background: var(--surface);
  border: var(--bw) solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s1) var(--s4);
}
.panel--flush { padding: 0; }
.panel--mt { margin-top: var(--s3); }
.panel-empty { color: var(--text-3); font-size: var(--fs-sm); padding: var(--s4); }

.list {
  background: var(--surface);
  border: var(--bw) solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.list--plain { background: none; border: 0; border-radius: 0; margin: 0 calc(var(--s4) * -1); }

.row {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; min-height: 60px; padding: var(--s2) var(--s4);
  text-align: left;
  border-top: var(--bw) solid var(--border);
  transition: background-color 0.12s;
}
.list > .row:first-child, .list > :first-child .row, .panel > .row:first-child { border-top: 0; }
.list--plain > .row:first-child { border-top: 0; }
a.row:hover, button.row:hover, label.row:hover { background: var(--elevated); }
a.row:active, button.row:active { background: #2e342f; }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 1px; }
.row-title { font-weight: 560; font-size: var(--fs-md); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: var(--text-2); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta--accent { color: var(--accent); }
.row-aside { display: inline-flex; align-items: center; gap: 4px; color: var(--text-3); font-size: var(--fs-xs); white-space: nowrap; }
.row .chev { color: var(--text-3); }
.row > .icon:first-child { color: var(--text-2); }
.row.is-current { background: var(--accent-soft); }
.row--menu { min-height: 52px; }
.row--menu.is-danger, .row--menu.is-danger > .icon { color: var(--error); }
.row--add { min-height: 52px; color: var(--accent); font-weight: 600; font-size: var(--fs-sm); gap: var(--s2); }
.row--add:hover { background: var(--elevated); }
label.row { cursor: pointer; }

.count { font-family: var(--mono); font-size: var(--fs-sm); color: var(--text); }

/* avatar */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--elevated); border: var(--bw) solid var(--border);
  color: var(--text-2); font-size: 0.75rem; font-weight: 650; letter-spacing: 0.02em;
}
.avatar--sm { width: 28px; height: 28px; font-size: 0.6875rem; }
.avatar--lg { width: 56px; height: 56px; font-size: 1.0625rem; color: var(--text); }

/* foosball rod glyph */
.rods { flex: none; }
.rods .rod-on { fill: var(--accent); }
.rods .rod-off { fill: var(--border-strong); }

/* ---------- inputs ---------- */

.form { display: flex; flex-direction: column; gap: var(--s4); }
.form-hint { color: var(--text-3); font-size: var(--fs-sm); }
.field { display: flex; flex-direction: column; gap: 6px; padding: var(--s3) 0; flex: 1; min-width: 0; }
.field-label { font-size: var(--fs-sm); color: var(--text-2); font-weight: 500; }
.field-row { display: flex; gap: var(--s4); flex-wrap: wrap; border-top: var(--bw) solid var(--border); }
.field-row .field { min-width: 140px; }
.panel > .field + .field { border-top: var(--bw) solid var(--border); }
.input {
  width: 100%; min-height: var(--touch); padding: 0 var(--s3);
  background: var(--bg); border: var(--bw) solid var(--border); border-radius: var(--r-sm);
  font-size: 1rem; /* ≥16px prevents iOS zoom */
  transition: border-color 0.15s;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--accent); }
.input[type="date"] { color-scheme: dark; }

/* segmented control */
.seg {
  display: flex; gap: 2px; padding: 3px;
  background: var(--bg); border: var(--bw) solid var(--border); border-radius: var(--r-md);
}
.seg-btn {
  flex: 1; min-height: 38px; padding: 0 var(--s2);
  border-radius: 7px; color: var(--text-2); font-size: var(--fs-sm); font-weight: 560; white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-checked="true"] { background: var(--elevated); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.seg--sm .seg-btn { min-height: 34px; font-size: var(--fs-xs); padding: 0 6px; }

/* switch row */
.row--toggle { min-height: 64px; }
.switch {
  position: relative; flex: none; width: 44px; height: 26px; border-radius: 13px;
  background: var(--border); transition: background-color 0.18s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--text-2); transition: transform 0.18s var(--ease), background-color 0.18s;
}
[aria-checked="true"] > .switch { background: var(--accent); }
[aria-checked="true"] > .switch::after { transform: translateX(18px); background: var(--accent-ink); }
.row--toggle .row-meta { white-space: normal; }

/* stepper */
.row--stepper { min-height: 64px; }
.row--stepper .row-meta { white-space: normal; }
.stepper { display: flex; align-items: center; gap: 2px; flex: none; }
.stepper .icon-btn { width: 40px; height: 40px; background: var(--elevated); border: var(--bw) solid var(--border); }
.stepper .icon-btn:hover:not(:disabled) { background: var(--elevated); border-color: var(--border-strong); }
.row--stepper .row-title { white-space: normal; }
.stepper output { min-width: 72px; text-align: center; font-weight: 600; font-size: var(--fs-sm); }

/* ---------- slider ---------- */

.slider { padding: var(--s4) 0 var(--s3); }
.slider + .slider { border-top: var(--bw) solid var(--border); }
.slider-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: 2px; }
.slider-head label { font-weight: 560; display: inline-flex; align-items: center; gap: 6px; }
.slider-head output { color: var(--accent); font-size: var(--fs-sm); font-weight: 600; text-align: right; }
.slider-ends { display: flex; justify-content: space-between; color: var(--text-3); font-size: var(--fs-xs); margin-top: -2px; }
.slider-ends--strong { color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; }
.slider-hint { color: var(--text-3); font-size: var(--fs-xs); margin-top: var(--s1); }
.mark { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }

.range {
  --v: 50;
  --thumb: 24px;
  --track: 4px;
  --fill: var(--accent);
  --rest: var(--border);
  --pos: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--v) / 100);
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; height: var(--touch); margin: 0;
  background: transparent; cursor: pointer; touch-action: pan-y;
}
.range:focus { outline: none; }
.range::-webkit-slider-runnable-track {
  height: var(--track); border-radius: 2px;
  background: linear-gradient(to right, var(--fill) 0 var(--pos), var(--rest) var(--pos) 100%);
}
.range::-moz-range-track {
  height: var(--track); border-radius: 2px;
  background: linear-gradient(to right, var(--fill) 0 var(--pos), var(--rest) var(--pos) 100%);
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: var(--thumb); height: var(--thumb); margin-top: calc((var(--track) - var(--thumb)) / 2);
  border-radius: 50%; background: var(--text); border: 0;
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px var(--border-strong);
  transition: transform 0.12s var(--ease);
}
.range::-moz-range-thumb {
  width: var(--thumb); height: var(--thumb); border-radius: 50%; background: var(--text); border: 0;
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px var(--border-strong);
}
.panel .range::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--surface), 0 0 0 5px var(--border-strong); }
.panel .range::-moz-range-thumb { box-shadow: 0 0 0 4px var(--surface), 0 0 0 5px var(--border-strong); }
.range:active::-webkit-slider-thumb { transform: scale(1.1); }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px var(--accent); }
.range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px var(--accent); }

/* bipolar: fills from the centre (chemistry) */
.chem .range, .slider--bipolar .range {
  --mid: calc(var(--thumb) / 2 + (100% - var(--thumb)) / 2);
  --a: min(var(--mid), var(--pos));
  --b: max(var(--mid), var(--pos));
}
.chem .range::-webkit-slider-runnable-track, .slider--bipolar .range::-webkit-slider-runnable-track {
  background: linear-gradient(to right, var(--rest) 0 var(--a), var(--fill) var(--a) var(--b), var(--rest) var(--b) 100%);
}
.chem .range::-moz-range-track, .slider--bipolar .range::-moz-range-track {
  background: linear-gradient(to right, var(--rest) 0 var(--a), var(--fill) var(--a) var(--b), var(--rest) var(--b) 100%);
}

.range--lg { --thumb: 28px; --track: 6px; height: 52px; }

/* ---------- team & profile ---------- */

.profile { display: flex; align-items: center; gap: var(--s4); padding: var(--s2) 0 var(--s2); }
.profile-main { min-width: 0; }
.profile-summary { font-weight: 560; }
.profile-stats { color: var(--text-3); font-size: var(--fs-sm); margin-top: 2px; }

.chem { padding: var(--s3) var(--s4) var(--s2); border-top: var(--bw) solid var(--border); }
.chem:first-child { border-top: 0; }
.chem-head { display: flex; align-items: center; gap: var(--s3); }
.chem-name { flex: 1; font-weight: 560; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chem-head output { color: var(--accent); font-size: var(--fs-sm); font-weight: 600; }
.chem-head .icon-btn { margin-right: calc(var(--s2) * -1); }
.chem-back { color: var(--text-3); font-size: var(--fs-xs); margin: var(--s1) 0 var(--s1); }

/* ---------- empty / start ---------- */

.empty, .start {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s3);
  padding: var(--s6) var(--s5);
  background: var(--surface); border: var(--bw) solid var(--border); border-radius: var(--r-md);
  margin-top: var(--s2);
}
.empty h2, .start h2 { font-size: var(--fs-lg); font-weight: 650; }
.empty p, .start p { color: var(--text-2); font-size: var(--fs-md); max-width: 46ch; }
.empty .btn, .start .btn { margin-top: var(--s2); }

.date-chip {
  display: flex; flex-direction: column; align-items: center; justify-content: center; flex: none;
  width: 48px; height: 44px; border-radius: var(--r-sm);
  background: var(--bg); border: var(--bw) solid var(--border); line-height: 1.1;
}
.date-chip b { font-family: var(--mono); font-size: var(--fs-sm); font-weight: 600; }
.date-chip span { font-family: var(--mono); font-size: 0.625rem; color: var(--text-3); }

/* ---------- matchday stepper ---------- */

.steps ol { list-style: none; margin: 0; padding: 0; }
.sticky-head { position: sticky; top: 0; z-index: 20; background: var(--bg); }
.sticky-head .topbar { position: static; }
nav.steps {
  max-width: var(--content-w); margin: 0 auto;
  padding: 0 var(--s4) var(--s3);
  background: var(--bg);
}
nav.steps ol { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s1); }
.step {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  width: 100%; padding: 0 0 2px; text-align: left;
  color: var(--text-3); font-size: var(--fs-xs); font-weight: 560;
}
.step::before {
  content: ""; display: block; width: 100%; height: 3px; border-radius: 2px; background: var(--border);
  transition: background-color 0.2s;
}
.step-no { display: none; }
.step.is-done { color: var(--text-2); }
.step.is-done::before { background: #5d6b42; }
.step.is-current { color: var(--text); }
.step.is-current::before { background: var(--accent); }
.step:disabled { opacity: 0.55; }
.step:not(:disabled):not(.is-current):hover { color: var(--text); }

/* player selection */
.row--select { padding: 0 var(--s2) 0 0; gap: 0; }
.select-hit { display: flex; align-items: center; gap: var(--s3); flex: 1; min-width: 0; min-height: 60px; padding: var(--s2) var(--s2) var(--s2) var(--s4); text-align: left; }
.check {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 24px; height: 24px; border-radius: var(--r-sm);
  border: 1.5px solid var(--border-strong); color: transparent;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.row--select.is-selected .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.row--select:not(.is-selected) .row-title { color: var(--text-2); font-weight: 500; }
.row--select:hover { background: var(--elevated); }

/* choices */
.choice { padding: var(--s3) var(--s4) var(--s4); border-top: var(--bw) solid var(--border); }
.choice:first-child { border-top: 0; }
.choice-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }

.plan-summary {
  display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3);
  margin-top: var(--s3); color: var(--text-2); font-size: var(--fs-sm); font-variant-numeric: tabular-nums;
}
.plan-summary span + span::before { content: "·"; margin-right: var(--s3); color: var(--text-3); }
.plan-summary--top { margin: var(--s1) 0 var(--s4); }

/* balance control */
.balance { padding: var(--s5) var(--s4) var(--s4); }
.balance-head { min-height: 88px; }
.balance-title { font-size: var(--fs-lg); font-weight: 650; color: var(--accent); }
.balance-text { color: var(--text-2); font-size: var(--fs-sm); margin-top: var(--s1); max-width: 44ch; }
.balance .range { margin-top: var(--s2); --rest: #3d4a2c; --fill: #3d4a2c; }
.factors { list-style: none; margin: var(--s5) 0 0; padding: var(--s4) 0 0; border-top: var(--bw) solid var(--border); display: grid; gap: 10px; }
.factors li { display: grid; grid-template-columns: minmax(0, 1fr) 40%; align-items: center; gap: var(--s3); font-size: var(--fs-sm); color: var(--text-2); }
.bar { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--text-3); border-radius: 3px; transition: width 0.2s var(--ease); }

/* ---------- lineup ---------- */

.lineup-head .row-meta { white-space: normal; }
.lineup-head {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--surface); border: var(--bw) solid var(--border); border-radius: var(--r-md);
}
.fit { display: flex; flex-direction: column; align-items: flex-end; flex: none; line-height: 1.15; }
.fit b { font-family: var(--mono); font-size: var(--fs-lg); color: var(--accent); font-weight: 600; }
.fit span { font-size: var(--fs-xs); color: var(--text-3); }
.fit.is-low b { color: var(--warning); }

.tally { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--s3) 0 0; }
.tally-item {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 var(--s2);
  border: var(--bw) solid var(--border); border-radius: var(--r-sm);
  font-size: var(--fs-xs); color: var(--text-2);
}
.tally-item b { font-family: var(--mono); color: var(--text); font-weight: 600; }
.tally-item.is-zero { border-color: #5a4a2c; color: var(--warning); }
.tally-item.is-zero b { color: var(--warning); }

.notice, .game-warn { list-style: none; margin: 0; padding: 0; }
.notice { margin-top: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r-sm); background: var(--warning-soft); }
.notice li, .game-warn li { display: flex; align-items: flex-start; gap: 6px; color: var(--warning); font-size: var(--fs-xs); line-height: 1.4; }
.notice .icon, .game-warn .icon { margin-top: 1px; }

.swaphint { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--text-2); line-height: 1.3; }
.swaphint b { color: var(--text); }
.swaphint .icon { color: var(--accent); }

.half { margin-top: var(--s5); }
.half-title {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-2);
  padding: 0 0 var(--s2); border-bottom: var(--bw) solid var(--border);
}
.half-count { font-weight: 500; color: var(--text-3); font-size: var(--fs-xs); }

.games { list-style: none; margin: 0; padding: 0; }
.game {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: var(--s2);
  padding: var(--s2) 0 var(--s3);
  border-bottom: var(--bw) solid var(--border);
}
.game-no, .game-no--inline {
  font-family: var(--mono); font-size: var(--fs-md); font-weight: 600; color: var(--text-3);
  padding-top: 4px; letter-spacing: -0.02em;
}
.game-no--inline { padding-top: 0; flex: none; min-width: 28px; }
.game.is-locked .game-no { color: var(--accent); }
.game-head { display: flex; align-items: center; gap: var(--s2); min-height: 28px; }
.game-side { display: flex; align-items: flex-start; }
.game-type { font-size: var(--fs-xs); font-weight: 650; color: var(--text-2); letter-spacing: 0.04em; text-transform: uppercase; }
.game--singles .game-type, .game--goalie .game-type { color: var(--text-3); }
.game-tag { font-size: var(--fs-xs); color: var(--text-3); padding: 1px 6px; border: var(--bw) solid var(--border); border-radius: 4px; white-space: nowrap; }
.lock { color: var(--text-3); }
.lock.is-on { color: var(--accent); }

.slots { display: flex; flex-direction: column; }
.slot {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; min-height: 38px; padding: 0 var(--s2);
  margin-left: calc(var(--s2) * -1); width: calc(100% + var(--s2));
  border-radius: var(--r-sm); text-align: left;
}
.slot--edit { transition: background-color 0.12s; }
.slot--edit:hover { background: var(--surface); }
.slot--edit:active { background: var(--elevated); }
.slot-name { flex: 1; min-width: 0; font-size: var(--fs-lg); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-name.is-empty { color: var(--text-3); font-weight: 500; font-style: italic; }
.slot-role { font-size: var(--fs-xs); color: var(--text-3); }
.slot.is-source { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.game--doubles .slot + .slot { border-top: 0; }
.game-warn { margin-top: var(--s1); display: grid; gap: 2px; }

.lineup.is-fresh .game { animation: rise 0.28s var(--ease) both; }
.lineup.is-fresh .game:nth-child(2) { animation-delay: 0.02s; }
.lineup.is-fresh .game:nth-child(3) { animation-delay: 0.04s; }
.lineup.is-fresh .game:nth-child(4) { animation-delay: 0.06s; }
.lineup.is-fresh .game:nth-child(n + 5) { animation-delay: 0.08s; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- statistics ---------- */

.stat-table { font-size: var(--fs-sm); }
.stat-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 40px 28px 28px 28px 36px; align-items: start; gap: var(--s2);
  padding: var(--s3) var(--s4); border-top: var(--bw) solid var(--border);
}
.stat-row--head { border-top: 0; padding-top: var(--s3); padding-bottom: var(--s2); color: var(--text-3); font-size: var(--fs-xs); font-weight: 600; }
.stat-row > :not(:first-child) { text-align: right; }
.stat-row .num { font-family: var(--mono); color: var(--text-2); }
.stat-row .num--strong { color: var(--text); font-weight: 600; }
.stat-name { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-weight: 560; }
.stat-row > .stat-sub { grid-column: 1 / -1; text-align: left; font-size: var(--fs-xs); color: var(--text-3); margin-top: -2px; }
.stat-bar { display: block; height: 4px; border-radius: 2px; background: var(--bg); overflow: hidden; max-width: 160px; }
.stat-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.stat-bar--lg { height: 6px; max-width: none; }
.meter { padding: var(--s3) 0 var(--s1); }
.meter-head { display: flex; justify-content: space-between; margin-bottom: var(--s2); font-size: var(--fs-sm); color: var(--text-2); }
.meter-head b { font-family: var(--mono); color: var(--text); font-weight: 600; }
.panel > .section-hint--in:last-child { padding-bottom: var(--s3); }

details.more { margin-top: var(--s2); }
details.more summary { cursor: pointer; color: var(--accent); font-size: var(--fs-sm); font-weight: 600; padding: var(--s2) var(--s1); list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more .list { margin-top: var(--s2); }

/* ---------- settings: format editor ---------- */

.fmt-row { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s2) var(--s3) var(--s4); border-top: var(--bw) solid var(--border); }
.fmt-row:first-child { border-top: 0; }
.fmt-row .game-no--inline { padding-top: 9px; }
.fmt-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--s2); }
.fmt-sub { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-xs); color: var(--text-3); }
.fmt-sub .seg { flex: 1; max-width: 200px; }
.fmt-row > .icon-btn { margin-top: 1px; }

/* ---------- sheet ---------- */

.sheet-root { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.sheet-root:empty { display: none; }
.sheet-backdrop {
  position: absolute; inset: 0; background: var(--scrim);
  opacity: 0; transition: opacity 0.2s; pointer-events: auto;
}
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--surface); border-top: var(--bw) solid var(--border);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  transform: translateY(100%); transition: transform 0.24s var(--ease);
  pointer-events: auto;
}
.sheet-root.is-open .sheet-backdrop { opacity: 1; }
.sheet-root.is-open .sheet { transform: none; }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s2) var(--s2) var(--s2) var(--s4); flex: none; }
.sheet-head h2 { font-size: var(--fs-lg); font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body {
  overflow-y: auto; overscroll-behavior: contain;
  padding: 0 var(--s4) calc(var(--s4) + var(--safe-b));
}
.sheet-text { color: var(--text-2); font-size: var(--fs-sm); margin-bottom: var(--s2); }
.sheet-actions {
  display: flex; gap: var(--s3); justify-content: flex-end;
  position: sticky; bottom: calc(var(--s4) * -1 - var(--safe-b));
  margin: var(--s5) calc(var(--s4) * -1) calc(var(--s4) * -1 - var(--safe-b));
  padding: var(--s3) var(--s4) calc(var(--s3) + var(--safe-b));
  background: var(--surface); border-top: var(--bw) solid var(--border);
}
.sheet-actions .btn { flex: 1; }
.sheet-tools { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s3); }
.sheet .slider + .slider { border-top: 0; }
.sheet .slider { padding: var(--s2) 0 var(--s2); }
.sheet .range::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--surface), 0 0 0 5px var(--border-strong); }
.sheet .range::-moz-range-thumb { box-shadow: 0 0 0 4px var(--surface), 0 0 0 5px var(--border-strong); }
.sheet .panel { background: var(--bg); }
.sheet .stepper .icon-btn { background: var(--surface); }

/* ---------- toast ---------- */

.toast-root {
  position: fixed; z-index: 60; left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b) + var(--s3));
  display: flex; justify-content: center; pointer-events: none; padding: 0 var(--s4);
}
body.has-actionbar .toast-root { bottom: calc(var(--nav-h) + var(--safe-b) + 80px); }
.toast {
  max-width: 420px; padding: var(--s3) var(--s4);
  background: var(--elevated); border: var(--bw) solid var(--border-strong); border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: 560;
  opacity: 0; transform: translateY(6px); transition: opacity 0.18s, transform 0.18s var(--ease);
}
.toast.is-in { opacity: 1; transform: none; }
.toast--success { border-color: #4a5a2a; }
.toast--success::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: var(--s2); vertical-align: middle; }
.toast--error { border-color: #5a3430; color: #f0c8c2; }

/* ---------- larger screens ---------- */

@media (min-width: 720px) {
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%; width: min(520px, calc(100vw - 48px));
    max-height: min(80dvh, 760px);
    border: var(--bw) solid var(--border); border-radius: var(--r-lg);
    transform: translate(-50%, calc(-50% + 12px)); opacity: 0;
    transition: transform 0.2s var(--ease), opacity 0.2s;
  }
  .sheet-root.is-open .sheet { transform: translate(-50%, -50%); opacity: 1; }
  .sheet-grip { display: none; }
  .sheet-body { padding-bottom: var(--s4); }
  .sheet-actions { bottom: calc(var(--s4) * -1); margin-bottom: calc(var(--s4) * -1); padding-bottom: var(--s3); }
}

@media (min-width: 960px) {
  :root { --rail: 96px; }
  .nav {
    top: 0; bottom: 0; right: auto; width: var(--rail); height: auto;
    border-top: 0; border-right: var(--bw) solid var(--border); padding: var(--s6) 0;
  }
  .nav ul { grid-template-columns: 1fr; grid-auto-rows: 72px; height: auto; gap: var(--s2); }
  .nav-item { height: 72px; }
  .nav-item::before { top: 50%; left: 0; width: 2px; height: 28px; margin: -14px 0 0; border-radius: 0 2px 2px 0; transform: scaleY(0); }
  .nav-item.is-active::before { transform: scaleY(1); }
  .view { margin-left: var(--rail); padding-bottom: var(--s8); }
  body.has-actionbar .view { padding-bottom: 104px; }
  .actionbar { left: var(--rail); bottom: 0; }
  .toast-root { left: var(--rail); bottom: var(--s6); }
  body.has-actionbar .toast-root { bottom: 92px; }
  .topbar { padding-top: var(--s6); }
}

@media (hover: none) {
  a.row:hover, button.row:hover, label.row:hover, .row--select:hover, .slot--edit:hover { background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .spinner { animation: spin 1.4s linear infinite !important; }
}

/* ---------- login ---------- */

.login-page { display: flex; justify-content: center; }
.login {
  width: 100%; max-width: 400px;
  padding: calc(var(--safe-t) + 14dvh) var(--s4) var(--s8);
}
.login-brand h1 { font-size: 1.5rem; font-weight: 650; letter-spacing: -0.01em; margin-top: var(--s4); }
.login-brand p { color: var(--text-2); margin-top: var(--s2); }
.login-mark .rod-on { fill: var(--accent); }
.login-mark .rod-off { fill: var(--border-strong); }
.login-form {
  display: flex; flex-direction: column; gap: var(--s3);
  margin-top: var(--s6); padding: var(--s2) var(--s4) var(--s4);
  background: var(--surface); border: var(--bw) solid var(--border); border-radius: var(--r-md);
}
.login-form .btn { width: 100%; }
.login-form .input[aria-invalid="true"] { border-color: var(--error); }
.login-error { color: var(--error); font-size: var(--fs-sm); margin-top: calc(var(--s2) * -1); }
