/* The Basketball Lab – styles (RTL, phone first) */

:root {
  --bg: #F6F4EF;
  --card: #FFFFFF;
  --ink: #14213D;
  --muted: #5B6475;
  --line: #E4E0D7;
  --line-strong: #C9C4B8;
  --accent: #C2410C;
  --accent-ink: #9A3412;
  --accent-soft: #FBE7DC;
  --dark: #14213D;
  --dark-2: #22325A;
  --dark-soft: #C9D1E0;
  --good: #1F7A4D;   --good-bg: #E3F2EA;   --good-ink: #1F5C3C;
  --warn: #B7791F;   --warn-bg: #FFF1D6;   --warn-ink: #7A4A00;
  --danger: #9B1C1C; --danger-bg: #FDE4E0; --danger-line: #F0B9B0;
  --chip: #ECE9E2;
  --radius: 16px;
  --font: Heebo, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --display: Rubik, Heebo, system-ui, sans-serif;
  --tabbar-h: 68px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh;
  background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.45;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
code { background: var(--chip); padding: 1px 6px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Text helpers ---------- */
.muted { color: var(--muted); }
.soft { color: var(--dark-soft); }
.small { font-size: 13px; }
.big { font-family: var(--display); font-size: 22px; font-weight: 700; }
.text-danger { color: var(--danger); }
.pre { white-space: pre-wrap; }

/* ---------- Layout ---------- */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 4px; max-width: 760px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-weight: 700; font-size: 15px; }
.brand svg { color: var(--accent); width: 28px; height: 28px; }
.brand-lg { font-size: 18px; justify-content: center; margin-bottom: 8px; }
.brand-lg svg { width: 36px; height: 36px; }

.page {
  flex: 1; width: 100%; max-width: 760px; margin: 0 auto;
  padding: 8px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; outline: none;
}
.page-head { margin-top: 4px; }
.page-title { font-family: var(--display); font-size: 24px; font-weight: 700; }
.page-sub { margin-top: -6px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.loading { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(var(--tabs, 4), minmax(0, 1fr));
  padding: 6px 4px calc(10px + env(safe-area-inset-bottom));
}
.tab {
  min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 12px; font-weight: 500; text-decoration: none; border-radius: 12px;
}
.tab-on { color: var(--accent); font-weight: 700; }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (min-width: 760px) {
  .tabbar { max-width: 760px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}

/* ---------- Child switcher ---------- */
.switcher { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 0; max-width: 760px; width: 100%; margin: 0 auto; }
.chip {
  min-height: 40px; padding: 0 18px; border-radius: 20px; border: 1px solid #D6D3CB;
  background: var(--card); font-weight: 500; white-space: nowrap; cursor: pointer;
}
.chip-on { background: var(--dark); color: #fff; border-color: var(--dark); }

/* ---------- Cards ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.card-title { font-size: 16px; font-weight: 700; }
.card-dark { background: var(--dark); color: #fff; }
.card-dark .card-label { color: var(--dark-soft); }
.card-accent { border: 1px solid #F2C9A8; }
.card-danger { border: 1px solid var(--danger-line); }
.card-warn { border: 1px solid #EBC98A; background: #FFFBF2; }

.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--chip); }
.list-row:last-child { border-bottom: 0; }
.list-row-tap { padding: 0; }
.row-btn {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 0; background: none; border: 0; text-align: start; cursor: pointer;
}
.row-btn .end { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; font-size: 14px; }

.list-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list-card {
  display: flex; flex-direction: column; gap: 4px; width: 100%;
  background: var(--card); border: 1px solid transparent; border-radius: 14px; padding: 12px 16px;
  color: inherit; text-decoration: none; text-align: start; cursor: pointer;
}
.list-card:hover { border-color: var(--line); }
.list-card:focus-visible { outline: 2px solid var(--accent); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; }

.meter { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); border-radius: 4px; }

.empty { background: var(--card); border-radius: var(--radius); padding: 28px 16px; text-align: center; display: flex; flex-direction: column; gap: 6px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 10px;
  font-size: 12px; font-weight: 700; background: var(--chip); color: #3F4757; white-space: nowrap;
}
.badge-good   { background: var(--good-bg);   color: var(--good-ink); }
.badge-warn   { background: var(--warn-bg);   color: var(--warn-ink); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-accent { background: var(--accent);    color: #fff; }
.card-dark .badge-good { background: var(--good); color: #fff; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid #D6D3CB; background: var(--card); color: var(--ink);
  font-size: 15px; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-on-dark { background: transparent; border-color: #5A6A8C; color: #fff; }
.btn-ghost-danger { background: transparent; border-color: var(--danger-line); color: var(--danger); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-wide { width: 100%; }
.btn:focus-visible, .chip:focus-visible, .icon-btn:focus-visible, .link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; border: 0; background: var(--card);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 500; min-height: 44px; padding: 0 4px; cursor: pointer; }
.link-btn:disabled { color: var(--muted); cursor: default; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; min-height: 40px; font-size: 14px; }
.back svg { width: 18px; height: 18px; }

/* ---------- Segmented tabs ---------- */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--chip); border-radius: 12px; padding: 4px; }
.segmented a, .segmented label {
  min-height: 40px; display: flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 9px; color: #3F4757; text-decoration: none; font-weight: 500; cursor: pointer;
}
.segmented .seg-on, .seg-input label:has(input:checked) { background: var(--card); color: var(--ink); font-weight: 700; }
.seg-input input { accent-color: var(--accent); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-size: 14px; font-weight: 700; padding: 0; margin-bottom: 0; }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea, .search input {
  width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--card); padding: 10px 12px; font-size: 16px;
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .search input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field input[dir=ltr] { text-align: left; }
.code-input { font-size: 24px !important; letter-spacing: 6px; text-align: center !important; font-family: var(--display); }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 0 16px; }
.checks-scroll { max-height: 40vh; overflow-y: auto; flex-direction: column; flex-wrap: nowrap; }
.toolbar { display: flex; gap: 12px; align-items: center; }
.search { position: relative; flex: 1; display: block; }
.search svg { position: absolute; inset-inline-start: 12px; top: 15px; color: var(--muted); }
.search input { padding-inline-start: 38px; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 20px; padding: 28px 20px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { font-family: var(--display); font-size: 24px; text-align: center; }
.auth-card > .muted { text-align: center; }

/* ---------- Sheet (dialog) ---------- */
dialog.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--bg); color: var(--ink);
}
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: 20px; } }
dialog.sheet::backdrop { background: rgba(11, 20, 40, .45); }
.sheet-form { display: flex; flex-direction: column; max-height: 92dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; }
.sheet-head h2 { font-family: var(--display); font-size: 19px; }
.sheet-body { padding: 4px 16px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.sheet-foot { display: flex; gap: 8px; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.sheet-foot .btn-ghost-danger { flex: 0 0 auto; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; inset-inline: 16px; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { max-width: 480px; padding: 12px 16px; border-radius: 12px; background: var(--dark); color: #fff; font-weight: 500; box-shadow: 0 6px 24px rgba(11,20,40,.18); }
.toast-error { background: var(--danger); }
