/* BetterMove phone app. Brand from the icon: ink brown #583A18, parchment #ECDCB8, teal #14A096.
   Every colour is a token; the light and dark themes follow the phone. Camera screens are always
   dark (video fills the screen, dark glass panels, parchment text, teal live data). */
:root {
  --ink: #583A18;
  --parchment: #ECDCB8;
  --teal: #14A096;

  --bg: #F7F0E1;
  --surface: #FFFBF2;
  --surface-2: #EFE3C9;
  --fg: #2A1D0E;
  --muted: #74624A;
  --line: #E0D2B4;
  --accent: #0F7F77;
  --accent-fg: #FFFFFF;
  --brand: var(--ink);
  --good: #1F7A45;
  --ok: #9A6200;
  --work: #B3362A;
  --note-bg: #FBEFC9;
  --chip-good-bg: #DDF1E3;
  --chip-ok-bg: #F8EBC8;
  --chip-work-bg: #F8DCD6;
  --shadow: 0 1px 2px rgba(60, 40, 10, .12), 0 4px 14px rgba(60, 40, 10, .06);

  /* camera (always dark) */
  --cam-bg: #000;
  --glass: rgba(24, 17, 9, .72);
  --glass-strong: rgba(24, 17, 9, .88);
  --cam-fg: #ECDCB8;
  --cam-muted: #B5A685;
  --cam-live: #3FD1C3;
  --cam-good: #5BD48A;
  --cam-ok: #F2C14E;
  --cam-work: #FF7A68;
  --rec: #E5483B;

  --radius: 14px;
  --tap: 44px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17110A;
    --surface: #221A10;
    --surface-2: #2E2416;
    --fg: #F0E4C8;
    --muted: #B09D7C;
    --line: #3A2E1D;
    --accent: #3FC3B6;
    --accent-fg: #0C1F1D;
    --brand: var(--parchment);
    --good: #63CF8F;
    --ok: #E8B64A;
    --work: #F2806F;
    --note-bg: #3A2F1A;
    --chip-good-bg: #1D3826;
    --chip-ok-bg: #3D3017;
    --chip-work-bg: #44221D;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--fg); font: 16px/1.45 var(--font);
  min-height: 100vh; min-height: 100dvh; overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
body.camera-on { background: var(--cam-bg); overflow: hidden; }
#app { min-height: 100vh; min-height: 100dvh; }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 26px; margin: 0; }
h2 { font-size: 19px; margin: 28px 0 8px; }
h3 { font-size: 16px; margin: 20px 0 6px; }
a { color: var(--accent); }
.muted { color: var(--muted); font-weight: normal; }
.pad { padding: 16px; }
.num, .tabnum { font-variant-numeric: tabular-nums; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- page (home, review, progress, settings) ---------- */
.page {
  max-width: 760px; margin: 0 auto;
  padding: calc(12px + var(--safe-t)) calc(16px + var(--safe-r)) calc(28px + var(--safe-b)) calc(16px + var(--safe-l));
}
.page-head { display: flex; align-items: center; gap: 8px; min-height: var(--tap); margin-bottom: 8px; }
.page-head h1 { font-size: 22px; flex: 1; min-width: 0; }
.back {
  min-width: var(--tap); min-height: var(--tap); border: 0; background: transparent; color: var(--accent);
  font-size: 17px; padding: 0 8px 0 0; display: inline-flex; align-items: center; gap: 2px; cursor: pointer;
}
.brand { display: flex; align-items: center; gap: 14px; padding: 8px 0 18px; }
.brand img { width: 64px; height: 64px; border-radius: 15px; box-shadow: var(--shadow); }
.brand h1 { color: var(--brand); font-size: 30px; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.group-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 2px 8px; font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-height: 84px; padding: 14px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  text-align: left; cursor: pointer; text-decoration: none; color: var(--fg);
}
.tile:active { transform: scale(.98); }
.tile b { font-size: 17px; }
.tile span { font-size: 13px; color: var(--muted); line-height: 1.3; }
.tile .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--teal); margin-bottom: 2px; }
.list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.row-link {
  display: flex; align-items: center; justify-content: space-between; min-height: 52px; padding: 12px 14px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--fg);
  text-decoration: none; font-weight: 600; box-shadow: var(--shadow);
}
.row-link span { color: var(--muted); font-weight: normal; font-size: 14px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; box-shadow: var(--shadow); }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 16px; }
.field > label, .field > .label { font-weight: 600; font-size: 15px; }
.field .help { font-size: 13px; color: var(--muted); margin: 0; }
input[type=text], input[type=number], select {
  min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  padding: 8px 12px; width: 100%; font-size: 16px;
}
input[type=file] { min-height: var(--tap); max-width: 100%; font-size: 15px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  min-height: var(--tap); min-width: 56px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer; font-size: 15px;
}
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; font-weight: 600; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 10px 0 4px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.note { background: var(--note-bg); padding: 8px 12px; border-radius: 8px; margin: 8px 0; }
.err { color: var(--work); }

/* report tables (progress + review): scroll inside the table, never the page */
.report table { border-collapse: collapse; width: 100%; overflow-x: auto; display: block; -webkit-overflow-scrolling: touch; }
.report th, .report td {
  text-align: left; padding: 6px 12px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top;
  font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 14px;
}
.report td:nth-child(5), .report td:nth-child(6) { white-space: normal; min-width: 140px; }
.report th { color: var(--muted); font-weight: 500; }
.report .up, .report .good { color: var(--good); }
.report .down, .report .work { color: var(--work); }
.report .work { font-weight: 600; }
.report .ok { color: var(--ok); }
.report svg { color: var(--accent); display: block; }
.report .strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.report figure { margin: 0; flex: 0 0 auto; }
.report figure img { height: 200px; border-radius: 8px; display: block; }
.report figcaption { font-size: 13px; color: var(--muted); text-align: center; }
.report h1 { font-size: 22px; margin: 4px 0; }

/* ---------- camera screen (always dark) ----------
   Top bar, then the picture (.stage: always the whole camera view, never under the sheet), then
   the sheet. The sheet's bottom strip (.foot: the big line + the record button) stays put; the
   details open above it. --sheet-px is the sheet's height, kept up to date by camera.js. */
.cam {
  position: fixed; inset: 0; background: var(--cam-bg); color: var(--cam-fg); overflow: hidden; touch-action: manipulation;
  --bar: calc(52px + var(--safe-t)); --sheet-px: 150px;
}
.cam .stage { position: absolute; left: 0; right: 0; top: var(--bar); bottom: var(--sheet-px); }
.cam .stage video, .cam .stage canvas.overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
/* hand modes with the numbers open: fill the space (the middle of the picture), not a thin strip */
.cam:not(.is-bb):not(.compact) .stage video, .cam:not(.is-bb):not(.compact) .stage canvas.overlay { object-fit: cover; }
.cam video.mirror { transform: scaleX(-1); }
.cam .topbar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3; display: flex; align-items: center; gap: 6px; height: var(--bar);
  padding: calc(4px + var(--safe-t)) calc(6px + var(--safe-r)) 4px calc(6px + var(--safe-l));
  background: var(--glass-strong);
}
.cam .topbar .title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.cam .topbar .title b { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam .topbar .fps { font-size: 12px; color: var(--cam-muted); font-variant-numeric: tabular-nums; }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border-radius: 22px; border: 0; background: rgba(236, 220, 184, .14); color: var(--cam-fg);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 15px; padding: 0 12px; font-weight: 600;
  white-space: nowrap;
}
.icon-btn[aria-pressed=true] { background: var(--cam-live); color: #0C1F1D; }
.icon-btn:disabled { opacity: .45; }
.icon-btn svg { width: 22px; height: 22px; }
.cam .status {
  position: absolute; z-index: 3; left: 50%; transform: translateX(-50%); top: calc(var(--bar) + 8px);
  background: var(--glass-strong); padding: 6px 12px; border-radius: 16px; font-size: 14px; max-width: calc(100% - 24px);
  text-align: center; font-variant-numeric: tabular-nums;
}
.cam .status.rec { color: #fff; background: var(--rec); font-weight: 700; }
.rec-btn {
  width: 68px; height: 68px; border-radius: 50%; border: 4px solid var(--cam-fg); background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0; flex: 0 0 auto;
}
.rec-btn::after { content: ""; width: 50px; height: 50px; border-radius: 50%; background: var(--rec); transition: all .15s; }
.rec-btn.on::after { width: 26px; height: 26px; border-radius: 6px; }
.rec-btn:disabled { opacity: .4; }
.sheet {
  position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; height: 44%; display: flex; flex-direction: column;
  background: #1C140B; border-radius: 18px 18px 0 0; border-top: 5px solid transparent;
  padding: 0 calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
  font-size: 14px; font-variant-numeric: tabular-nums;
}
.cam.is-bb .sheet { height: 62%; }
.cam.compact .sheet { height: auto; }
/* the colour of the big line runs along the top of the sheet: readable from across a room */
.sheet[data-tone=good] { border-top-color: var(--cam-good); }
.sheet[data-tone=ok] { border-top-color: var(--cam-ok); }
.sheet[data-tone=work] { border-top-color: var(--cam-work); }
.sheet[data-tone=live] { border-top-color: var(--cam-live); }
.grab-hit {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 30px; flex: 0 0 auto;
  background: none; border: 0; padding: 0; cursor: pointer; color: var(--cam-muted); font-size: 12px; font-weight: 600;
}
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--cam-muted); opacity: .6; display: block; }
.sheet .details { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
.cam.compact .sheet .details { display: none; }
.sheet .foot { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; min-height: 72px; }
.cam.is-bb .sheet .foot { min-height: 116px; }
.cam:not(.compact) .sheet .foot { border-top: 1px solid rgba(236, 220, 184, .14); padding-top: 8px; }
.sheet .controls { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.sheet .headline[hidden] + .controls { margin: 0 auto; }
.headline { flex: 1 1 auto; min-width: 0; }
.headline .hl-big {
  font-size: clamp(34px, 11vw, 46px); font-weight: 800; line-height: 1.02; letter-spacing: -.01em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; color: var(--cam-live);
}
/* a long line (a pitch grip name, OVER THE LIMIT) wraps to two lines instead of being cut off */
.headline.long .hl-big {
  font-size: clamp(22px, 6.8vw, 30px); white-space: normal; overflow-wrap: break-word; display: -webkit-box;
  -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}
.headline .hl-sub {
  font-size: 17px; font-weight: 600; line-height: 1.22; margin-top: 4px; color: var(--cam-fg);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; min-height: 3.66em;
}
.headline.hl-good .hl-big { color: var(--cam-good); }
.headline.hl-ok .hl-big { color: var(--cam-ok); }
.headline.hl-work .hl-big { color: var(--cam-work); }
/* phone on its side: the picture on the left, the sheet as a panel on the right, details always open */
@media (orientation: landscape) and (max-height: 540px) {
  .cam .stage { bottom: 0; right: 44%; }
  .cam .sheet, .cam.is-bb .sheet, .cam.compact .sheet {
    left: auto; top: var(--bar); bottom: 0; width: 44%; height: auto; border-radius: 0; border-top: 0; border-left: 5px solid transparent;
  }
  .sheet[data-tone=good] { border-left-color: var(--cam-good); }
  .sheet[data-tone=ok] { border-left-color: var(--cam-ok); }
  .sheet[data-tone=work] { border-left-color: var(--cam-work); }
  .sheet[data-tone=live] { border-left-color: var(--cam-live); }
  .cam.compact .sheet .details { display: block; }
  .grab-hit { display: none; }
  .sheet .details { padding-top: 8px; }
}
.sheet .blk { margin: 0 0 12px; }
.sheet .blk-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; color: var(--cam-fg); letter-spacing: .02em; }
.sheet .big { font-size: 30px; font-weight: 800; line-height: 1.1; color: var(--cam-live); }
.sheet .line { margin: 2px 0; }
.sheet table { border-collapse: collapse; width: 100%; }
.sheet th { color: var(--cam-muted); font-weight: 500; text-align: right; padding: 1px 6px; font-size: 12px; }
.sheet th:first-child, .sheet td:first-child { text-align: left; padding-left: 0; }
.sheet td { text-align: right; padding: 1px 6px; color: var(--cam-live); }
.sheet td:first-child { color: var(--cam-fg); }
.sheet .two { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 4px 16px; }
.c-good { color: var(--cam-good) !important; } .c-ok { color: var(--cam-ok) !important; } .c-work { color: var(--cam-work) !important; }
.c-muted { color: var(--cam-muted) !important; } .c-live { color: var(--cam-live) !important; } .c-fg { color: var(--cam-fg) !important; }
.metric { padding: 6px 0; border-bottom: 1px solid rgba(236, 220, 184, .12); }
.metric .m-top { display: flex; align-items: baseline; gap: 8px; }
.metric .m-label { flex: 1; min-width: 0; }
.metric .m-val { font-weight: 700; color: var(--cam-live); white-space: nowrap; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 10px; font-weight: 700; white-space: nowrap; }
.chip.good { background: rgba(91, 212, 138, .2); color: var(--cam-good); }
.chip.ok { background: rgba(242, 193, 78, .2); color: var(--cam-ok); }
.chip.work { background: rgba(255, 122, 104, .22); color: var(--cam-work); }
.metric .m-sub { font-size: 12px; color: var(--cam-muted); }
.metric .m-cue { font-size: 13px; margin-top: 2px; }
.page .chip.good { background: var(--chip-good-bg); color: var(--good); }
.page .chip.ok { background: var(--chip-ok-bg); color: var(--ok); }
.page .chip.work { background: var(--chip-work-bg); color: var(--work); }
.cam .cam-msg {
  position: absolute; z-index: 5; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; gap: 12px; background: rgba(0, 0, 0, .7);
}
.cam .cam-msg p { max-width: 420px; margin: 0; }
.cam .cam-msg .btn { background: var(--glass-strong); color: var(--cam-fg); border-color: rgba(236, 220, 184, .3); }
.toast {
  position: fixed; z-index: 50; left: 50%; transform: translateX(-50%); bottom: calc(28px + var(--safe-b)); max-width: calc(100% - 32px);
  background: var(--glass-strong); color: var(--cam-fg); padding: 10px 16px; border-radius: 12px; font-size: 15px; text-align: center;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .3);
}
/* on the camera screen the bottom belongs to the record button and the big line */
body.camera-on .toast { bottom: auto; top: calc(100px + var(--safe-t)); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
