:root {
  --bg: #ffffff;
  --fg: #0a0a0a;
  --muted: #6b6b6b;
  --line: #e4e4e4;
  --soft: #f4f4f4;
  --accent: #0a0a0a;
  --on-accent: #ffffff;
  --danger: #c62828;
  --ok: #1b6e2a;
  --warn: #a35f00;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --fg: #f2f2f2;
    --muted: #9a9a9a;
    --line: #262626;
    --soft: #161616;
    --accent: #f2f2f2;
    --on-accent: #0a0a0a;
    --danger: #ef5350;
    --ok: #66bb6a;
    --warn: #ffb74d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.05rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
h3 { font-size: 1.05rem; font-weight: 800; }
p { margin: .4rem 0; }
code { background: var(--soft); padding: 1px 6px; border-radius: 4px; }
[hidden] { display: none !important; }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.danger { color: var(--danger) !important; }
.pad { padding: 12px 0; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; color: var(--fg); }
.logo { height: 26px; width: auto; display: block; }
.nav { display: flex; align-items: center; gap: 4px; overflow-x: auto; scrollbar-width: none; margin-left: auto; }
.nav::-webkit-scrollbar { display: none; }
.nav a, .nav .linkish { padding: 6px 10px; border-radius: 8px; text-decoration: none; white-space: nowrap; font-size: .92rem; font-weight: 600; }
.nav a:hover, .nav .linkish:hover { background: var(--soft); }
.nav form { margin: 0; }

/* Cards & lists */
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h1, .card-head h2 { margin: 0; }
.hello { margin: 4px 0 16px; }
.crumb { margin: 0 0 8px; font-size: .9rem; }
.crumb a { text-decoration: none; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list > li > a, .list > li > details > summary, .list > li > .li-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; text-decoration: none; width: 100%;
}
.list > li { display: block; }
.list > li:has(> .li-main) { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; }
.li-main { display: flex; flex-direction: column; min-width: 0; }
.li-main a { text-decoration: none; }
.list li.off { opacity: .45; }
.list details > summary { cursor: pointer; list-style: none; }
.list details > summary::-webkit-details-marker { display: none; }
.list details[open] { padding-bottom: 12px; }
.li-btn { background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; flex-direction: column; align-items: flex-start !important; }

details.card > summary { cursor: pointer; font-weight: 700; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "+"; float: right; color: var(--muted); }
details.card[open] > summary::after { content: "–"; }
details.card[open] > summary { margin-bottom: 12px; }
details.card > summary.btn::after { content: none; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-bottom: 8px; }
.tile { display: block; padding: 16px 12px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; font-weight: 700; }
.tile:hover { background: var(--soft); }

.badges { display: inline-flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.badge-on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.badge-off { color: var(--muted); }
.badge-warn { color: var(--warn); border-color: currentColor; }

.chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }
.chip { padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-weight: 600; font-size: .9rem; }
.chip.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--fg); font-weight: 500; font-size: .95rem; }
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--fg); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
input[type=search] { margin-bottom: 12px; }
select[size] { padding: 4px; }
select[size] option { padding: 8px; border-radius: 6px; }
textarea { resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  background: var(--accent); color: var(--on-accent); border: 1px solid var(--accent);
  border-radius: 8px; padding: 11px 18px; min-height: 44px;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; }
.linkish { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.actions form { margin: 0; }
.list .actions { margin: 0; flex-wrap: nowrap; }
.icon-btn { background: none; border: 1px solid var(--line); color: var(--fg); border-radius: 6px; width: 32px; height: 32px; cursor: pointer; font-size: .9rem; flex: 0 0 auto; }
.icon-btn:hover { background: var(--soft); }

.sticky-bar { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); margin-top: 8px; }

.flash { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--line); font-weight: 600; }
.flash-ok { border-color: var(--ok); color: var(--ok); }
.flash-err { border-color: var(--danger); color: var(--danger); }
.notice { border-color: var(--warn); }
.danger-zone { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }

/* Auth */
.auth { max-width: 360px; margin: 10vh auto 0; }
.auth-brand { text-align: center; margin-bottom: 28px; }
.auth-brand .logo { height: 56px; margin: 0 auto; }
.auth-brand p { margin: 12px 0 0; font-size: .78rem; letter-spacing: .35em; font-weight: 600; }

/* Tables */
.table-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; }
.maxes th, .maxes td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.maxes thead th { font-size: .75rem; color: var(--muted); font-weight: 700; }
.maxes th:first-child { text-align: left; position: sticky; left: 0; background: var(--bg); padding-left: 0; }
.maxes tbody th a { text-decoration: none; font-weight: 600; }
.maxes tr:last-child th, .maxes tr:last-child td { border-bottom: 0; }
.pr { margin-left: 2px; }
.plain th, .plain td { text-align: left; padding: 9px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.plain thead th { font-size: .75rem; color: var(--muted); }

.stats { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 12px; }
.stats div { display: flex; flex-direction: column; }
.stats strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 12px; }
.chart .line { fill: none; stroke: var(--fg); stroke-width: 2.5; stroke-linejoin: round; }
.chart .dot { fill: var(--bg); stroke: var(--fg); stroke-width: 2; }

/* WOD view */
.wod { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; }
.wod-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.wod-head h3 { margin: 0; text-transform: uppercase; letter-spacing: .03em; }
.wrows { list-style: none; margin: 0; padding: 0; }
.wrow { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.wrow:first-child { border-top: 0; }
.wrow .lbl { font-weight: 800; color: var(--muted); }
.wrow .what { display: flex; flex-direction: column; }
.wrow .kg { text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.wrow .kg strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wtext { display: block; color: var(--muted); font-style: italic; }
.wod-notes { color: var(--muted); font-size: .92rem; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.kg-input { width: 84px; text-align: right; font-weight: 700; padding: 8px; }
.wod-foot { display: flex; flex-direction: column; gap: 10px; margin: -4px 0 18px; }
.comment { white-space: pre-line; border-left: 3px solid var(--line); padding-left: 10px; }
.note-item { padding: 10px 14px; background: var(--soft); border-radius: var(--radius); margin: 0 0 12px; }

/* QR */
.qr-box { text-align: center; margin-bottom: 12px; }
#qr { display: inline-block; padding: 12px; background: #fff; border-radius: 8px; }
#qr img, #qr canvas { width: 240px; height: 240px; display: block; }
.print-only { display: none; }

/* Editor */
.ed-wod { display: flex; flex-direction: column; gap: 8px; }
.ed-line { display: flex; gap: 6px; align-items: center; }
.w-type { flex: 0 0 auto; width: auto; font-weight: 700; }
.w-param { flex: 1; }
.ed-rows { display: flex; flex-direction: column; gap: 6px; }
.ed-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; background: var(--soft); }
.ed-row input, .ed-row select, .ed-row textarea { padding: 8px; background: var(--bg); }
.ed-row-text { flex-direction: row; align-items: flex-start; }
.ed-row-text textarea { flex: 1; }
.w-label { flex: 0 0 44px; text-align: center; font-weight: 800; }
.w-reps { flex: 0 0 64px; }
.picker { position: relative; flex: 1; min-width: 0; }
.picker-list { position: absolute; z-index: 20; left: 0; min-width: min(260px, 80vw); top: calc(100% + 4px); max-height: 240px; overflow-y: auto; list-style: none; margin: 0; padding: 4px; background: var(--bg); border: 1px solid var(--fg); border-radius: 8px; }
.picker-list li { padding: 9px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; }
.picker-list li:hover { background: var(--soft); }
.picker-list small { color: var(--muted); font-weight: 700; font-size: .7rem; }
.ed-sub { flex-wrap: wrap; }
.w-pct { flex: 0 0 64px; text-align: right; }
.w-rm { flex: 0 0 auto; width: auto; }
.w-note { flex: 1 1 100px; }
.ed-sub .ed-tools { margin-left: auto; }
.ed-tools { display: flex; gap: 4px; flex: 0 0 auto; }
.ed-add { display: flex; gap: 8px; flex-wrap: wrap; }
.ed-add-main { justify-content: center; padding: 8px 0; }
.ed-item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.ed-item-head strong { text-transform: uppercase; letter-spacing: .05em; font-size: .85rem; }
.ed-item-foot { margin-top: 10px; text-align: right; }
.ed-note { background: var(--soft); }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5); display: flex; align-items: flex-end; justify-content: center; }
.modal-panel { background: var(--bg); width: 100%; max-width: 560px; max-height: 80vh; overflow-y: auto; border-radius: 14px 14px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .modal { align-items: center; } .modal-panel { border-radius: 14px; } }

@media (max-width: 480px) {
  h1 { font-size: 1.4rem; }
  .row2 { grid-template-columns: 1fr; }
  .nav a:first-child { display: none; }
  .top { gap: 8px; }
  .ed-line .ed-tools .icon-btn { width: 28px; }
  .w-reps { flex-basis: 54px; }
}

@media print {
  body { background: #fff; color: #000; }
  .top, .crumb, .card-head, .actions, .no-print, .flash, .sticky-bar { display: none !important; }
  .print-area { border: 0; padding: 0; }
  .print-area h2 { display: none; }
  .print-only { display: block; }
  .print-title { font-size: 22pt; font-weight: 800; margin-bottom: 20px; }
  #qr img, #qr canvas { width: 12cm; height: 12cm; margin: 0 auto; }
}
