:root {
  --paper: #fbf8f3;
  --ink: #221d1a;
  --muted: #7a7068;
  --line: #e4ddd2;
  --chip: #f1ebe2;
  --accent: #b4405e;
  --accent-soft: #f6dde3;
  --sab: var(--random-nav-h, env(safe-area-inset-bottom, 0px));
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.35 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#app { -webkit-user-select: none; user-select: none; } /* (a drag that strays off the view mustn't select the panel's words) */
#app input, #app textarea { -webkit-user-select: text; user-select: text; }
#app { position: fixed; inset: 0 0 var(--sab) 0; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 0; background: #e7e2da; }
#view, #aids, #sun { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#view { touch-action: none; outline: none; }
#aids, #sun { pointer-events: none; }
#sun[hidden] { display: none; }
/* a reference photo over the view, faint, to match a pose to (it lets every touch through to the figure) */
#ref { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; opacity: 0.45; }
#ref[hidden] { display: none; }
/* the points read from the photo, over it: the dots take a finger, the rest lets the view have it */
#ref-pts { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#ref-pts[hidden] { display: none; }
#ref-pts line { stroke: var(--accent); stroke-width: 2; opacity: 0.7; }
#ref-pts circle { fill: #fff; stroke: var(--accent); stroke-width: 3; pointer-events: all; cursor: grab; touch-action: none; }
#ref-pts circle.unsure { stroke-dasharray: 4 3; fill: #fff8; }
/* the line of action: drawn over the view while it's on, the last stroke left faintly in place */
#loa { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#loa[hidden] { display: none; }
#loa path { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
#loa path.done { opacity: 0.5; }
#loa-on[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.photo { margin: 6px 0 10px; }
.photo .note { margin: 0 0 8px; font-size: 14px; line-height: 1.4; }
.photo .chips button { font-size: 13px; flex: none; }
.photo .head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 2px 0 4px; }

.top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; gap: 8px; align-items: flex-start; pointer-events: none; }
.top > * { pointer-events: auto; }
.figs { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.figs button {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid #fff; padding: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.figs button[aria-selected="true"] { outline: 3px solid var(--accent); outline-offset: 1px; }
.tools { display: flex; gap: 6px; }
.icon {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(251, 248, 243, 0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); display: grid; place-items: center;
}
.icon svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon:disabled svg { stroke: #bdb4aa; }
.hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); margin: 0; max-width: calc(100% - 24px);
  background: rgba(34, 29, 26, 0.82); color: #fff; padding: 6px 12px; border-radius: 99px; font-size: 13px; text-align: center;
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
.hint.on { opacity: 1; }

.sheet { background: var(--paper); border-top: 1px solid var(--line); flex: none; }
.panel { display: none; padding: 10px 12px 4px; max-height: 38vh; overflow-y: auto; }
@media (min-height: 760px) { .panel { max-height: 40vh; } }
.sheet[data-open="pose"] .panel[data-tab="pose"], .sheet[data-open="joint"] .panel[data-tab="joint"], .sheet[data-open="body"] .panel[data-tab="body"],
.sheet[data-open="scene"] .panel[data-tab="scene"], .sheet[data-open="draw"] .panel[data-tab="draw"] { display: block; }
.tabs { display: flex; border-top: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; padding: 11px 0 12px; font-weight: 600; color: var(--muted); position: relative; }
.tabs button[aria-selected="true"] { color: var(--accent); }
.tabs button[aria-selected="true"]::before { content: ""; position: absolute; top: -1px; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 6px; margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips button, .small, .seg button {
  border: 1px solid var(--line); background: var(--chip); border-radius: 99px; padding: 6px 12px; white-space: nowrap; font-size: 14px;
}
.chips button[aria-pressed="true"], .seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.small.go { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
/* (hidden means hidden, whatever display a class gives: a row shown only sometimes) */
[hidden] { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.lbl { color: var(--muted); font-size: 13px; min-width: 4.5em; }
.seg { display: inline-flex; gap: 4px; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }
.tog { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 0; }
.tog input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.muted { color: var(--muted); font-size: 13px; margin: 6px 0; }

.jhead { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.jhead strong { font-size: 16px; }
.spacer { flex: 1; }
.slide { display: grid; grid-template-columns: 6.6em 1fr 3.2em; align-items: center; gap: 8px; margin: 4px 0; }
.slide span { color: var(--muted); font-size: 13px; }
.slide output { font-variant-numeric: tabular-nums; font-size: 13px; text-align: right; }
.slide.ends { grid-template-columns: 6.6em auto 1fr auto; }
.slide.ends small { color: var(--muted); font-size: 11px; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; }
.woods { margin: 6px 0 2px; }
.woods .lbl { display: block; margin-bottom: 4px; }
.woods button { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px 4px 4px; }
.woods i { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
.woods button[aria-pressed="true"] i { box-shadow: 0 0 0 2px #fff; }

.gesture { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.gesture > * { pointer-events: auto; }
.gesture[hidden] { display: none; }
.clock { font: 700 28px/1 ui-monospace, "SF Mono", Menlo, monospace; background: rgba(251, 248, 243, 0.9); padding: 6px 14px; border-radius: 12px; font-variant-numeric: tabular-nums; }
.gbtns { display: flex; gap: 6px; }
.gbtns button { border: 0; border-radius: 99px; padding: 7px 14px; background: rgba(34, 29, 26, 0.8); color: #fff; }
.gbtns button[aria-pressed="true"] { background: var(--accent); }
.gstage { font: 600 13px/1.2 system-ui, sans-serif; background: rgba(251, 248, 243, 0.9); padding: 4px 10px; border-radius: 99px; }
.gstage:empty { display: none; }
.seg.wrap { flex-wrap: wrap; }
input.text { flex: 1; min-width: 0; font: inherit; font-size: 15px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
#app.gesturing .sheet, #app.gesturing .top { display: none; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(380px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3); }
dialog::backdrop { background: rgba(34, 29, 26, 0.4); }
dialog form { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog button[data-out] { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 12px; font-weight: 600; display: flex; flex-direction: column; }
dialog button[data-out] small { font-weight: 400; color: var(--muted); font-size: 12px; }
dialog .print { display: flex; gap: 8px; align-items: stretch; }
dialog .print button { flex: 1; }
dialog .print label { display: flex; flex-direction: column; justify-content: center; font-size: 12px; color: var(--muted); gap: 2px; }
#link-text { border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 13px; background: #fff; }
dialog select { border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }
dialog .close { border: 0; background: var(--accent); color: #fff; border-radius: 12px; padding: 10px; font-weight: 600; margin-top: 4px; }

@media (min-width: 760px) and (min-height: 520px) {
  #app { flex-direction: row; }
  .sheet { width: 360px; border-top: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column-reverse; justify-content: flex-end; }
  .tabs { border-top: 0; border-bottom: 1px solid var(--line); }
  .panel { max-height: none; flex: 1; }
}

/* the pose library: a category, then its poses as cards to tap, each a picture of the pose */
.library { margin: 4px 0 2px; }
.libhead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.libhead .lbl { min-width: 0; flex: none; }
/* (the categories scroll sideways on a narrow screen rather than squeezing the label) */
.libhead .seg { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.libhead .seg::-webkit-scrollbar { display: none; }
.libhead .seg button { flex: none; }
/* a row whose label sits above it on a phone, so its buttons keep to one line */
@media (max-width: 480px) { .row.stack > .lbl { flex-basis: 100%; } }
.cards { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 0 12px 4px; }
.cards::-webkit-scrollbar { display: none; }
.cards button { flex: none; width: 78px; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: #e7e2da; overflow: hidden; display: flex; flex-direction: column; }
.cards img { width: 78px; height: 104px; object-fit: cover; display: block; }
.cards span { font-size: 11.5px; line-height: 1.2; padding: 5px 4px 6px; background: var(--paper); text-align: center; min-height: 34px; display: flex; align-items: center; justify-content: center; }
.cards button[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
#lib-note { min-height: 2.6em; margin: 4px 0 0; }
/* beside the view (a computer, a tablet), a category's poses all in sight, four across, rather than a strip to scroll */
@media (min-width: 760px) and (min-height: 520px) {
  .cards { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0 0 4px; }
  .cards button { width: calc((100% - 24px) / 4); }
  .cards img { width: 100%; height: auto; aspect-ratio: 3 / 4; }
}

/* the daily exercise: today's date on the view (filled once drawn), its card, and the steps while it runs */
.today { flex: none; width: 46px; height: 50px; border-radius: 12px; border: 0; background: rgba(251, 248, 243, 0.92); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; line-height: 1; }
.today small { font-size: 9.5px; font-weight: 800; letter-spacing: 0.06em; color: var(--accent); }
.today b { font-size: 21px; font-weight: 800; margin-top: 2px; }
.today.done { background: var(--accent); color: #fff; }
.today.done small { color: #fff; opacity: 0.85; }
.today[hidden] { display: none; }
.todaycard { border: 0; border-radius: 18px; padding: 16px; width: min(380px, calc(100vw - 28px)); background: var(--paper); color: var(--ink); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); }
.todaycard::backdrop { background: rgba(34, 29, 26, 0.35); }
.todaycard .lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.todaycard h2 { font-size: 21px; line-height: 1.15; margin: 0; }
.tc-head { display: flex; gap: 12px; align-items: center; margin: 8px 0 4px; }
.tc-head img { width: 64px; height: 86px; border-radius: 10px; object-fit: cover; background: #e7e2da; border: 1px solid var(--line); flex: none; }
.tc-head .sub { color: var(--muted); font-size: 14px; }
.tc-head p { margin: 4px 0 0; font-size: 13px; }
.tc-steps { display: grid; grid-template-columns: 22px 1fr auto; gap: 6px 8px; font-size: 14px; margin: 12px 0; align-items: center; }
.tc-steps i { width: 20px; height: 20px; border-radius: 50%; background: var(--chip); display: grid; place-items: center; font-size: 12px; font-weight: 700; font-style: normal; }
.tc-steps small { color: var(--muted); }
.tc-month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 6px 0 4px; }
.tc-month > * { aspect-ratio: 1; border-radius: 6px; background: var(--chip); position: relative; overflow: hidden; border: 0; padding: 0; font: inherit; color: inherit; }
.tc-month > * b { position: absolute; left: 3px; bottom: 2px; font-size: 9px; font-weight: 600; color: var(--muted); }
.tc-month > .done { background: #d9cfc2; }
.tc-month > .today { outline: 2px solid var(--accent); outline-offset: 1px; }
.tc-month > .later { opacity: 0.4; }
.tc-month > .blank { visibility: hidden; }
.tc-month img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tc-month > :has(img) b { color: #fff; text-shadow: 0 0 3px #000; }
.tc-month button { cursor: pointer; }
.tc-big { margin: 6px 0; }
.tc-big img { width: 100%; max-height: 50vh; object-fit: contain; border-radius: 10px; background: #e7e2da; display: block; }
.tc-big figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; }
.tc-note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.tc-btns { display: flex; gap: 8px; margin-top: 14px; }
.tc-btns button { flex: 1; border: 0; border-radius: 12px; padding: 11px; font-weight: 700; background: var(--chip); }
.tc-btns button.go, .todaycard .wide.go { background: var(--accent); color: #fff; }
.todaycard .wide { width: 100%; border: 0; border-radius: 12px; padding: 12px; font-weight: 700; background: var(--chip); margin-top: 4px; }
.stepper { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; max-width: 460px; margin: 0 auto; background: rgba(251, 248, 243, 0.94); border-radius: 16px; padding: 10px 12px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12); }
.stepper[hidden], .stepbar[hidden] { display: none; }
.track { display: flex; align-items: center; }
.track b { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; background: var(--chip); color: var(--muted); flex: none; }
.track b.done { background: var(--accent); color: #fff; }
.track b.now { background: #fff; color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.track i { flex: 1; height: 2px; background: var(--line); margin: 0 4px; }
.track i.done { background: var(--accent); }
.track .clock { font: 700 20px/1 ui-monospace, "SF Mono", Menlo, monospace; margin-left: 12px; background: none; padding: 0; font-variant-numeric: tabular-nums; }
.track .clock.over { color: var(--accent); }
.stepper .what { font-weight: 700; margin-top: 8px; }
.stepper .how { font-size: 13px; color: var(--muted); }
.stepbar { position: absolute; left: 12px; right: 12px; bottom: 14px; max-width: 460px; margin: 0 auto; display: flex; gap: 8px; }
.stepbar button { border: 0; border-radius: 12px; padding: 12px 14px; font-weight: 700; background: rgba(251, 248, 243, 0.94); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); }
.stepbar .go { flex: 1; background: var(--accent); color: #fff; }
.stepbar .go.nudge { animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { box-shadow: 0 0 0 6px rgba(180, 64, 94, 0.25); } }
@media (prefers-reduced-motion: reduce) { .stepbar .go.nudge { animation: none; outline: 3px solid rgba(180, 64, 94, 0.35); } }

/* the picked prop's Remove button, kept over the prop as the view turns */
.prop-remove { position: absolute; transform: translate(-50%, -100%); white-space: nowrap; display: flex; align-items: center; gap: 6px; border: 0; border-radius: 99px; padding: 7px 12px 7px 9px; background: rgba(34, 29, 26, 0.86); color: #fff; font-size: 13px; font-weight: 600; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); }
.prop-remove svg { width: 15px; height: 15px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; }
.prop-remove[hidden] { display: none; }
/* beside the view, the sideways strips wrap onto rows instead: a mouse wheel scrolls up and down, and a strip only it can't move
   is hard to use */
@media (min-width: 760px) and (min-height: 520px) {
  .chips.scroll { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0 0 6px; }
  .libhead { flex-wrap: wrap; align-items: flex-start; }
  .libhead .seg { flex-wrap: wrap; overflow: visible; }
}

/* the context menu: a long press or a right-click on a figure, a prop or the floor */
.ctx { position: absolute; z-index: 5; min-width: 180px; background: var(--paper); border-radius: 14px; padding: 6px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22); display: flex; flex-direction: column; }
.ctx[hidden] { display: none; }
.ctx p { margin: 2px 10px 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.ctx button { border: 0; background: none; text-align: left; padding: 10px 12px; border-radius: 9px; font-size: 15px; }
.ctx button:hover, .ctx button:focus-visible { background: var(--chip); outline: none; }
.ctx button.danger { color: var(--accent); }
.ctx button:disabled { color: #bdb4aa; }
#view { -webkit-touch-callout: none; }
