/* Karthik's Dojo — calm athletic, phone-first. */
:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #e9eef2;
  --text: #13202b;
  --muted: #4d5d6b;
  --line: #c9d3dc;
  --brand: #14324a;
  --brand-ink: #ffffff;
  --accent: #b86e00;
  --focus: #1f6feb;
  --hard: #9b2c2c;
  --hard-bg: #fbe9e9;
  --moderate: #7a4a00;
  --moderate-bg: #fff1d6;
  --easy: #1d5e3a;
  --easy-bg: #e3f4ea;
  --warn-bg: #fff4dc;
  --warn-line: #d9a23b;
  --error: #a4161a;
  --error-bg: #fde8e8;
  --ok: #1d5e3a;
  --chart-1: #1b5e9a;
  --chart-2: #c27a00;
  --radius: 12px;
  --tap: 44px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f171e;
    --surface: #17222c;
    --surface-2: #1f2d39;
    --text: #e8eef3;
    --muted: #a9b8c4;
    --line: #34485a;
    --brand: #9ec9ec;
    --brand-ink: #0f171e;
    --accent: #f0b54d;
    --focus: #7ab7ff;
    --hard: #ffb3b3;
    --hard-bg: #3a1d1f;
    --moderate: #ffd08a;
    --moderate-bg: #372a12;
    --easy: #9be0b7;
    --easy-bg: #13301f;
    --warn-bg: #33290f;
    --warn-line: #a07a2b;
    --error: #ffb4b4;
    --error-bg: #3a1a1a;
    --ok: #9be0b7;
    --chart-1: #7ab7ff;
    --chart-2: #f0b54d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin-top: 1.5rem; }
h3, .h3 { font-size: 1.05rem; margin: 0; }
.h4 { font-size: 1rem; margin: 0; }
p { margin: 0 0 .6rem; }
a { color: var(--brand); text-underline-offset: 2px; }
@media (prefers-color-scheme: dark) { a { color: var(--brand); } }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .6rem 1rem; z-index: 100; }
.skip-link:focus { left: .5rem; top: .5rem; }

/* Layout */
.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 16px calc(var(--nav-h) + 2rem + env(safe-area-inset-bottom));
}
.page:focus { outline: none; }
.auth-page { padding-bottom: 2rem; }
.stack > * + * { margin-top: .9rem; }
.stack-s > * + * { margin-top: .5rem; }
.row { display: flex; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; gap: .5rem; }
.row.end { justify-content: flex-end; align-items: flex-end; }
.gap-s { gap: .5rem; }
.center { text-align: center; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: .75rem; grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 560px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}
ul.plain, ol.plain { list-style: none; padding: 0; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.subtitle { color: var(--muted); margin-top: -.25rem; }

/* Header + nav */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem 16px; padding-top: calc(.5rem + env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.brand { color: inherit; font-weight: 700; text-decoration: none; font-size: 1.05rem; margin-right: auto; }
.brand-title { color: var(--brand); }
.badge { font-size: .78rem; padding: .25rem .6rem; border-radius: 999px; text-decoration: none; max-width: 48vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-local { background: var(--warn-bg); color: var(--text); border: 1px solid var(--warn-line); }
.badge-cloud { background: var(--easy-bg); color: var(--easy); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); color: inherit; border-radius: 10px; }
.icon-btn[aria-current="page"] { background: rgba(255,255,255,.15); }
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--nav-h); color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 600;
}
.nav-item[aria-current="page"] { color: var(--brand); box-shadow: inset 0 3px 0 var(--accent); }
@media (min-width: 900px) {
  .bottom-nav { max-width: 720px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 14px 14px 0 0; }
}

.save-status { max-width: 720px; margin: 0 auto; padding: 0 16px; font-size: .85rem; min-height: 0; }
.save-status:empty { display: none; }
.save-status[data-state="saving"] { color: var(--muted); padding-top: .4rem; }
.save-status[data-state="saved"] { color: var(--ok); padding-top: .4rem; }
.save-status[data-state="error"] { color: var(--error); font-weight: 600; padding-top: .4rem; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
fieldset.card { margin: 0; }
legend { font-weight: 700; padding: 0 .25rem; }
.session-card { border-left: 5px solid var(--line); }
.kind-judo { border-left-color: var(--brand); }
.kind-gym { border-left-color: var(--chart-1); }
.kind-park { border-left-color: var(--easy); }
.kind-recovery { border-left-color: var(--easy); }
.is-rest { opacity: .75; }
.time { font-weight: 700; color: var(--muted); font-size: .9rem; margin: 0; font-variant-numeric: tabular-nums; }
.focus { margin: .5rem 0; }
.logged { color: var(--ok); font-weight: 600; }
.actions { margin-top: .75rem; }
.phase { background: var(--surface-2); }
.empty { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1rem; color: var(--muted); text-align: center; }
.notice { background: var(--surface-2); border-left: 4px solid var(--brand); padding: .6rem .8rem; border-radius: 8px; }
.notice.warn { background: var(--warn-bg); border-left-color: var(--warn-line); }
.notice.error, .error-card { background: var(--error-bg); border-left: 4px solid var(--error); }
.form-error { color: var(--error); font-weight: 600; min-height: 0; margin: 0; }
.form-error:empty { display: none; }

/* Chips */
.chip { display: inline-block; font-size: .78rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.chip-hard { background: var(--hard-bg); color: var(--hard); }
.chip-moderate { background: var(--moderate-bg); color: var(--moderate); }
.chip-easy { background: var(--easy-bg); color: var(--easy); }
.chip-fixed { background: var(--brand); color: var(--brand-ink); }
.status-completed { background: var(--easy-bg); color: var(--easy); }
.status-partial { background: var(--moderate-bg); color: var(--moderate); }
.status-skipped { background: var(--surface-2); color: var(--muted); }

/* Buttons + forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: var(--tap); padding: .5rem 1rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--error); border-color: var(--error); }
.btn.small { min-height: 40px; padding: .3rem .75rem; font-size: .9rem; }
.btn.icon { width: 40px; padding: 0; font-size: 1.2rem; }
.btn:disabled { opacity: .6; cursor: progress; }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: .5rem; }
label { font-weight: 600; font-size: .92rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: .55rem .65rem; min-height: var(--tap); width: 100%;
}
.field.inline select { width: auto; }
textarea { min-height: 4.5rem; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--focus); }
.radio { display: flex; gap: .5rem; align-items: center; font-weight: 500; min-height: var(--tap); }
.radio input { width: 22px; height: 22px; min-height: 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; }
.sticky-actions {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  background: var(--bg); padding: .6rem 0; border-top: 1px solid var(--line); z-index: 5;
}

/* Exercise details */
details > summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-weight: 600; }
.session-details { margin-top: .5rem; }
.block { margin-top: .5rem; }
.block-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: .6rem 0 .2rem; }
.exercise { border-bottom: 1px solid var(--line); }
.exercise summary { justify-content: space-between; }
.ex-name { font-weight: 600; }
.ex-target { font-weight: 500; color: var(--muted); font-size: .9rem; }
.ex-detail { padding: .25rem 0 .75rem; }
.ex-detail ol { padding-left: 1.25rem; margin: .4rem 0; }
.cautions { padding-left: 1.25rem; color: var(--hard); }
.purpose { margin-top: .25rem; }

/* Log editor */
.entry .planned { margin: 0 0 .25rem; }
.entry .label { display: inline-block; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); padding: .05rem .4rem; border-radius: 4px; margin-right: .25rem; }
table.sets { width: 100%; border-collapse: collapse; margin: .5rem 0; table-layout: fixed; }
table.sets th, table.sets td { padding: .2rem; text-align: left; font-size: .85rem; }
table.sets th[scope="row"] { width: 2rem; }
table.sets td:last-child, table.sets th:last-child { width: 44px; }
table.sets input, table.sets select { padding: .4rem; }
.entry-list li { margin: .1rem 0; }
.item-edit { border-bottom: 1px solid var(--line); padding-bottom: .5rem; }

/* Plan week */
.week-nav { margin-bottom: .5rem; }
.week { display: grid; gap: .75rem; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; }
.day.is-today { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; }
.day-title { font-size: 1rem; margin: 0 0 .4rem; }
.slot { border-left: 4px solid var(--line); padding: .25rem 0 .25rem .6rem; }
.small-actions { margin-top: .35rem; }

/* Tabs */
.tabs { display: flex; gap: .25rem; overflow-x: auto; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tab { padding: .6rem .8rem; min-height: var(--tap); white-space: nowrap; text-decoration: none; color: var(--muted); font-weight: 600; }
.tab[aria-current="page"] { color: var(--brand); box-shadow: inset 0 -3px 0 var(--accent); }
.video-list { padding-left: 1.1rem; }
.video-list li { margin: .5rem 0; }
.use-class { background: var(--surface-2); }
.use-solo { background: var(--easy-bg); color: var(--easy); }
.use-watch { background: var(--surface-2); color: var(--muted); }
.use-coach-first { background: var(--moderate-bg); color: var(--moderate); }

/* Stats + charts */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; display: flex; flex-direction: column; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-wrap { margin: .5rem 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; }
.chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-tick { fill: var(--muted); font-size: 10px; }
.chart-line { fill: none; stroke: var(--chart-1); stroke-width: 2.5; }
.chart-line2 { fill: none; stroke: var(--chart-2); stroke-width: 2; stroke-dasharray: 5 4; }
.chart-dot { fill: var(--chart-1); }
.chart-ref { stroke: var(--muted); stroke-dasharray: 2 3; }
.chart-ref-label { fill: var(--muted); font-size: 10px; }
.legend { font-size: .8rem; color: var(--muted); display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.key { display: inline-block; width: 16px; height: 3px; }
.key-1 { background: var(--chart-1); }
.key-2 { background: var(--chart-2); }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: .45rem .4rem; border-bottom: 1px solid var(--line); text-align: left; }
.table-scroll { overflow-x: auto; max-width: 100%; }
.consistency td.bar-col { width: 25%; min-width: 60px; }
@media (max-width: 380px) { .consistency .bar-col { display: none; } }
abbr[title] { text-decoration: none; }
.bar { display: block; width: 100%; height: 10px; background: var(--surface-2); border-radius: 5px; }
.bar-done { fill: var(--easy); }
.bar-partial { fill: var(--chart-2); }

/* Toasts + dialog */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom)); z-index: 50; display: grid; gap: .5rem; width: min(92vw, 480px); }
.toast { padding: .75rem 1rem; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast-error { background: var(--error); color: #fff; }
@media (prefers-color-scheme: dark) { .toast-error { color: #2a0000; } }
.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(92vw, 480px); padding: 1.25rem; }
.dialog::backdrop { background: rgba(10, 20, 30, .55); }
.dialog-body { margin: .5rem 0 1rem; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .2s ease-out; }
  @keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
}
/* Headings receive focus on navigation for screen readers; no visual ring needed. */
main h1[tabindex="-1"]:focus { outline: none; }
