/* Badminton H2H — mobile-first, one thumb, bright sunlight. */

:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eff1ee;
  --text: #14181a;
  --muted: #626d72;
  --border: #dfe3e0;
  --accent: #0d7a68;
  --accent-soft: #d9f0ea;
  --on-accent: #ffffff;
  --accent-ink: #075a4d;
  --up: #10704f;
  --up-bg: #dff2ea;
  --down: #a33a4a;
  --down-bg: #fae4e7;
  --even: #6b6257;
  --even-bg: #f0ece5;
  --warn-bg: #fdf3dc;
  --warn-ink: #7a5610;
  --danger: #b3402f;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 26, .06), 0 4px 14px rgba(20, 24, 26, .05);
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

/* Dark tokens apply when the system asks for dark, unless the viewer has
   explicitly chosen light; an explicit dark choice wins either way. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1416;
    --surface: #191f21;
    --surface-2: #222a2d;
    --text: #e7ecec;
    --muted: #94a3a5;
    --border: #2c3538;
    --accent: #3ec5a8;
    --accent-soft: #16302c;
    --on-accent: #06211c;
    --accent-ink: #8fe5d2;
    --up: #57c99f;
    --up-bg: #163028;
    --down: #e08a97;
    --down-bg: #33191e;
    --even: #b8ab99;
    --even-bg: #2b2721;
    --warn-bg: #33290f;
    --warn-ink: #e8c882;
    --danger: #e0705c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1416;
  --surface: #191f21;
  --surface-2: #222a2d;
  --text: #e7ecec;
  --muted: #94a3a5;
  --border: #2c3538;
  --accent: #3ec5a8;
  --accent-soft: #16302c;
  --on-accent: #06211c;
  --accent-ink: #8fe5d2;
  --up: #57c99f;
  --up-bg: #163028;
  --down: #e08a97;
  --down-bg: #33191e;
  --even: #b8ab99;
  --even-bg: #2b2721;
  --warn-bg: #33290f;
  --warn-ink: #e8c882;
  --danger: #e0705c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(64px + var(--safe-b));
  overscroll-behavior-y: contain;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; letter-spacing: -.02em; }
h2 { font-size: .95rem; margin: 0; letter-spacing: -.01em; }
p { margin: .5rem 0; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: .82rem; line-height: 1.4; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.num { text-align: right; }
.footnote { margin-top: 1rem; }

/* ---------- shell ---------- */

#appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; padding: .7rem 1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; letter-spacing: -.02em; font-size: .95rem; }
.appbar-right { display: flex; align-items: center; gap: .6rem; }

.theme-toggle {
  display: flex; gap: 2px; padding: 2px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px;
}
.theme-btn {
  width: 30px; height: 26px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted);
  display: grid; place-items: center; font-size: .8rem; line-height: 1;
}
.theme-btn.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.theme-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.brand-accent { color: var(--accent); }

#view { padding: 1rem; max-width: 720px; margin: 0 auto; }
.view-body { display: flex; flex-direction: column; gap: 1rem; }
.view-head h1 { margin-bottom: .2rem; }
.back { margin-bottom: .4rem; }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .5rem 0 .55rem; text-decoration: none; color: var(--muted);
  font-size: .68rem; font-weight: 550; letter-spacing: .01em;
}
.tab.on { color: var(--accent); }
.tab-icon { font-size: 1.1rem; line-height: 1.1; }

/* ---------- cards ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .6rem;
}
.card-head-actions { display: flex; gap: .35rem; }
.empty-state { text-align: center; padding: 2rem 1rem; }
.empty-state h2 { font-size: 1.05rem; margin-bottom: .35rem; }

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

.btn {
  min-height: var(--tap); padding: 0 1rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font-weight: 560; font-size: .9rem;
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  transition: transform .06s ease, background .12s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .42; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.btn.sm { min-height: 36px; padding: 0 .7rem; font-size: .8rem; border-radius: 8px; }
.btn.block { width: 100%; margin-top: .75rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.file-btn { position: relative; overflow: hidden; }

.icon-btn {
  flex: none; width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  font-size: 1.25rem; line-height: 1; display: grid; place-items: center;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:disabled { opacity: .25; pointer-events: none; }

/* ---------- segmented control ---------- */

.segmented {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.seg {
  flex: 1; min-height: 42px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font-weight: 600; font-size: .88rem;
}
.seg.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented.small .seg { min-height: 32px; font-size: .78rem; white-space: nowrap; padding: 0 .5rem; }

/* ---------- session ---------- */

.session-bar {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
}
.date-input {
  border: 0; background: transparent; padding: 0;
  font-size: 1.15rem; font-weight: 650; letter-spacing: -.02em;
}

.court { display: flex; flex-direction: column; gap: .4rem; }

.side {
  width: 100%; text-align: left;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: .8rem .9rem;
  display: flex; flex-direction: column; gap: .5rem;
  transition: border-color .15s ease, background .15s ease, transform .06s ease;
}
.side:disabled { cursor: default; }
.side.armed {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft), var(--surface) 70%);
}
.side.armed:active { transform: scale(.985); }
.side-label {
  font-size: .7rem; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.side.armed .side-label { color: var(--accent); }
.side-cta {
  font-size: .78rem; font-weight: 650; color: var(--accent);
  display: flex; align-items: center; gap: .3rem;
}
.side-cta::before { content: "▲"; font-size: .6rem; }

.slots { display: flex; flex-wrap: wrap; gap: .4rem; }
.slot {
  flex: 1 1 44%; min-height: 52px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 .5rem 0 .75rem; gap: .4rem;
}
.slot.filled {
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 600; font-size: 1rem;
}
.slot.empty {
  border: 1.5px dashed var(--border); background: transparent;
  justify-content: center;
}
.slot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-x { color: var(--muted); font-size: 1.2rem; line-height: 1; padding: 0 .2rem; }
.slot-hint { color: var(--muted); font-size: .8rem; }

.vs-row { display: flex; align-items: center; justify-content: center; gap: .75rem; }
.vs {
  font-size: .72rem; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted);
}

.picker-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .5rem; min-height: 36px;
}

.chip-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .45rem;
}
.chip {
  min-height: 54px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: center; padding: 0 .4rem;
  font-weight: 560; font-size: .92rem; text-align: center;
  transition: transform .06s ease, opacity .12s ease;
}
.chip:active { transform: scale(.96); }
.chip-initials {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2); color: var(--muted);
  display: grid; place-items: center; font-size: .72rem; font-weight: 700;
}
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.on {
  border-color: var(--accent); background: var(--accent);
  color: var(--on-accent); font-weight: 650;
}
.chip.on .chip-initials { background: var(--accent); color: var(--on-accent); }
.chip.placed { opacity: .32; }

.attendance .chip-grid { margin-top: .5rem; }

/* ---------- session blocks ---------- */

.session-blocks { display: flex; flex-direction: column; }
.session-block { border-top: 1px solid var(--border); }
.session-block:first-child { border-top: 0; }
.session-block > summary {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem 0; cursor: pointer; list-style: none;
  font-size: .88rem; font-weight: 600;
}
.session-block > summary::-webkit-details-marker { display: none; }
.session-block > summary::before {
  content: "›"; color: var(--muted); font-size: 1.15rem; line-height: 1;
  transition: transform .18s ease; flex: none;
}
.session-block[open] > summary::before { transform: rotate(90deg); }
.session-block > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sb-date { flex: none; }
.sb-tag {
  font-size: .62rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent-ink);
  padding: .15rem .35rem; border-radius: 5px;
}
.session-block .game-list { padding-bottom: .4rem; }
.sb-count { margin-left: auto; color: var(--muted); font-weight: 400; font-size: .82rem; }

/* ---------- game list ---------- */

.game-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.game-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .55rem 0; border-bottom: 1px solid var(--border); font-size: .88rem;
}
.game-row:last-child { border-bottom: 0; }
.game-text { flex: 1; min-width: 0; }
.tag {
  flex: none; font-size: .62rem; font-weight: 750; letter-spacing: .05em;
  padding: .18rem .38rem; border-radius: 5px;
  background: var(--surface-2); color: var(--muted);
}
.tag-S { background: var(--accent-soft); color: var(--accent-ink); }
.tag-U { background: var(--warn-bg); color: var(--warn-ink); }
.result { font-weight: 750; }
.result.win { color: var(--up); }
.result.loss { color: var(--down); }

/* ---------- matrix ---------- */

.matrix-wrap {
  overflow: auto; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); -webkit-overflow-scrolling: touch;
}
.matrix { border-collapse: separate; border-spacing: 0; font-size: .8rem; }
.matrix th, .matrix td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.matrix .corner {
  position: sticky; left: 0; top: 0; z-index: 3;
  background: var(--surface-2); min-width: 92px;
}
.matrix .col-head {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2);
  padding: .5rem .25rem; font-size: .7rem; font-weight: 700; color: var(--muted);
  min-width: 68px;
}
.matrix .row-head {
  position: sticky; left: 0; z-index: 1; background: var(--surface-2);
  text-align: left; padding: .4rem .5rem; font-weight: 600; min-width: 92px; max-width: 92px;
}
.row-initials { display: none; }
.row-name {
  display: block; font-size: .78rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.matrix td { padding: 0; text-align: center; }
.cell-btn {
  width: 100%; min-height: 46px; padding: 0 .2rem; border: 0; background: transparent;
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: .74rem; font-weight: 600; color: inherit;
  white-space: nowrap; letter-spacing: -.02em;
}
.matrix .self { background: repeating-linear-gradient(45deg, var(--surface-2) 0 5px, transparent 5px 10px); }
.matrix .none { color: var(--muted); opacity: .45; }
.matrix .up { background: var(--up-bg); color: var(--up); }
.matrix .down { background: var(--down-bg); color: var(--down); }
.matrix .even { background: var(--even-bg); color: var(--even); }
.matrix .thin { color: var(--muted); opacity: .55; font-weight: 500; }

.legend { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .75rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.sw { width: 13px; height: 13px; border-radius: 4px; display: inline-block; border: 1px solid var(--border); }
.sw.up { background: var(--up-bg); }
.sw.down { background: var(--down-bg); }
.sw.even { background: var(--even-bg); }
.sw.thin { background: var(--surface-2); opacity: .6; }

/* ---------- pair detail ---------- */

.pair-title { font-size: 1.25rem; }
.headline { text-align: center; }
.big-record {
  font-family: var(--mono); font-size: 2.6rem; font-weight: 700;
  letter-spacing: -.03em; line-height: 1.1;
}
.splits { display: flex; flex-direction: column; }
.split {
  display: flex; align-items: center; justify-content: space-between;
  padding: .5rem 0; border-bottom: 1px solid var(--border);
}
.split:last-child { border-bottom: 0; }
.split.empty { opacity: .45; }
.split-label { font-size: .88rem; }
.split-value { font-family: var(--mono); font-weight: 650; }
.mix-list { margin: 0; padding-left: 1.1rem; font-size: .88rem; }
.mix-list li { margin-bottom: .3rem; }
.warn-inline { color: var(--warn-ink); font-weight: 600; }

/* ---------- tables ---------- */

.data-table {
  width: 100%; border-collapse: collapse; font-size: .88rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.data-table th {
  text-align: left; font-size: .7rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); padding: .6rem .75rem;
  background: var(--surface-2);
}
.data-table td { padding: .6rem .75rem; border-top: 1px solid var(--border); }
.data-table tr.thin td { opacity: .5; }
.stats-body { display: flex; flex-direction: column; gap: 1rem; }

/* ---------- filter bar + cards ---------- */

.filter-bar { display: flex; flex-direction: column; gap: .5rem; }
.filter-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; min-height: 34px;
}
.filter-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.fchip {
  min-height: 38px; padding: 0 .7rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: .85rem; font-weight: 550; color: var(--text);
  transition: transform .06s ease, background .14s ease, border-color .14s ease;
}
.fchip:active { transform: scale(.95); }
.fchip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.fchip.full { opacity: .32; }
.fchip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.result-count { margin: .1rem 0 0; }
.empty-line { padding: 1.5rem 0; text-align: center; }

.card-list { display: flex; flex-direction: column; gap: .6rem; }

.pcard {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .8rem .9rem;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .55rem;
  transition: border-color .14s ease, transform .06s ease;
}
.pcard:active { transform: scale(.995); }
.pcard.thin { opacity: .62; }

.h2h-row { display: flex; align-items: center; gap: .5rem; }
.h2h-side { flex: 1; min-width: 0; display: flex; align-items: center; gap: .45rem; }
.h2h-side:last-of-type { flex-direction: row-reverse; text-align: right; }
.h2h-avatar {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-2); color: var(--muted);
  display: grid; place-items: center; font-size: .68rem; font-weight: 700;
}
.h2h-side.lead .h2h-avatar { background: var(--accent); color: var(--on-accent); }
.h2h-name {
  flex: 1; min-width: 0; font-size: .92rem; font-weight: 560;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.h2h-score {
  flex: none; font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em;
}
.h2h-side.lead .h2h-score { color: var(--accent); }
.h2h-v {
  flex: none; font-size: .68rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); padding: 0 .1rem;
}

.h2h-bar { height: 5px; border-radius: 3px; background: var(--down-bg); overflow: hidden; }
.h2h-bar-a { display: block; height: 100%; background: var(--up); border-radius: 3px; }

.pcard-foot {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .6rem; font-size: .78rem; color: var(--muted);
}
.pcard-meta { flex: none; font-family: var(--mono); font-variant-numeric: tabular-nums; }

.pt-row { display: flex; align-items: center; gap: .55rem; }
.pt-avatars { flex: none; display: flex; }
.pt-avatars .h2h-avatar:last-child { margin-left: -9px; border: 2px solid var(--surface); }
.pt-names {
  flex: 1; min-width: 0; font-size: .92rem; font-weight: 560;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pt-record {
  flex: none; font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em;
}

/* ---------- forms ---------- */

.field-label {
  display: block; font-size: .72rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin: 1rem 0 .4rem;
}
.text-input, .num-input, .name-input, .textarea {
  width: 100%; min-height: 44px; padding: .5rem .7rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg);
}
.textarea { min-height: 96px; resize: vertical; font-size: .9rem; }
.num-input { width: 88px; }
.inline-field { display: flex; align-items: center; gap: .6rem; }
.bulk-add { margin-bottom: .75rem; }

.switch { display: inline-flex; align-items: center; gap: .45rem; font-size: .85rem; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.switch.tight span { display: none; }

.toolbar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.roster-list { list-style: none; margin: 0; padding: 0; }
.roster-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .4rem 0; border-bottom: 1px solid var(--border);
}
.roster-row:last-child { border-bottom: 0; }
.roster-row.inactive .name-input { opacity: .5; }
.name-input { flex: 1; min-width: 0; }

/* ---------- roster + weights ---------- */

.roster-row { flex-wrap: wrap; }
.roster-actions { display: flex; align-items: center; gap: .4rem; flex: none; }
.state-btn {
  min-height: 34px; padding: 0 .65rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: .76rem; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.state-btn.on {
  background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent-ink);
}
.state-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.remove-btn {
  min-height: 34px; padding: 0 .6rem; border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  background: transparent; color: var(--danger);
  font-size: .76rem; font-weight: 600; white-space: nowrap;
}
.roster-count {
  font-size: .74rem; color: var(--muted); white-space: nowrap;
  font-variant-numeric: tabular-nums; padding: 0 .3rem;
}
.legend-note { margin-top: .8rem; padding-top: .7rem; border-top: 1px solid var(--border); }
.legend-note p { margin: 0 0 .5rem; }
.legend-note p:last-child { margin-bottom: 0; }

.wtable {
  display: flex; flex-direction: column; margin: .8rem 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden;
}
.wrow {
  display: grid; grid-template-columns: 1fr auto; gap: .1rem .6rem;
  padding: .6rem .75rem; border-top: 1px solid var(--border);
  background: var(--surface);
}
.wrow:first-child { border-top: 0; }
.wrow-label { font-size: .85rem; font-weight: 600; }
.wrow-value {
  grid-row: 1; grid-column: 2; justify-self: end;
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 1rem; font-weight: 700; color: var(--accent);
}
.wrow-note { grid-column: 1 / -1; }

/* ---------- notices ---------- */

.notice {
  background: var(--warn-bg); color: var(--warn-ink);
  border-radius: var(--radius-sm); padding: .65rem .8rem;
  font-size: .82rem; line-height: 1.45; margin: .75rem 0 0;
}
.thin-notice { text-align: left; }

.banner {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .6rem .8rem;
  font-size: .82rem; display: flex; align-items: center;
  justify-content: space-between; gap: .6rem; flex-wrap: wrap;
  margin-bottom: 1rem;
}
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.banner-btn {
  border: 1px solid currentColor; background: transparent; color: inherit;
  border-radius: 7px; padding: .25rem .6rem; font-size: .78rem; font-weight: 600;
}

/* ---------- sync dot ---------- */

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; display: inline-block; }
.dot.ok { background: var(--up); }
.dot.syncing { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.dot.error { background: var(--danger); }
.dot.offline, .dot.readonly, .dot.local { background: var(--warn-ink); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.sync-status { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }

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

#toast {
  position: fixed; left: 50%; bottom: calc(74px + var(--safe-b));
  transform: translate(-50%, 20px); z-index: 60;
  max-width: min(560px, calc(100vw - 2rem));
  display: flex; align-items: center; gap: .75rem;
  background: #16201f; color: #f2f6f5;
  padding: .7rem .8rem .7rem 1rem; border-radius: 12px;
  font-size: .85rem; box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast-msg { flex: 1; min-width: 0; }
.toast-action {
  flex: none; border: 0; background: transparent; color: #6fe0c4;
  font-weight: 700; font-size: .82rem; padding: .3rem .5rem; text-transform: uppercase;
  letter-spacing: .05em;
}

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 80; background: rgba(10, 14, 15, .55);
  display: grid; place-items: center; padding: 1.5rem;
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  padding: 1.25rem; max-width: 380px; width: 100%; box-shadow: var(--shadow);
}
.modal p { margin: 0 0 1rem; font-size: .92rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; }

/* ---------- narrow phones ---------- */

@media (max-width: 380px) {
  .chip-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .matrix .row-head, .matrix .corner { min-width: 44px; max-width: 44px; }
  .row-name { display: none; }
  .row-initials { display: block; font-size: .78rem; }
}

.link-btn {
  border: 0; background: transparent; color: inherit; padding: 0;
  font: inherit; font-weight: 700; text-decoration: underline;
}
