/* Tapo Fitness v1.0.0. Dark by default (it is his own app). Colours are tokens; nothing loads from another site. */
:root {
  --bg: #0e1116; --surface: #171b22; --raised: #1f252e; --line: #2c3440;
  --text: #f1f3f5; --muted: #a3adb8; --ember: #ff8a4c; --ember-ink: #1c0d04; --ok: #58c996; --warn: #f3c969;
  --r: 14px; --tap: 46px;
  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.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(72px + env(safe-area-inset-bottom)); }
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1 { font-size: 1.15rem; letter-spacing: .01em; }
h2 { font-size: 1.3rem; margin-bottom: 10px; }
h3 { font-size: 1.02rem; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ember); outline-offset: 2px; border-radius: 6px; }

#top, #app { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0 10px; }
.sub { color: var(--muted); font-size: .9rem; }
#status { font-size: .82rem; color: var(--muted); min-height: 1.2em; text-align: right; }
#status[data-s="ok"] { color: var(--ok); }
#status[data-s="retry"], #status[data-s="badkey"] { color: var(--warn); }

.cycle-h { color: var(--muted); font-size: .92rem; margin-bottom: 8px; }
.cycle-h strong { color: var(--text); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 10px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 10px 0; padding: 0; }
.chip { flex: 0 0 auto; min-height: var(--tap); padding: 6px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  text-align: left; cursor: pointer; font-size: .92rem; max-width: 200px; }
.chip-k { display: block; font-size: .72rem; color: var(--muted); }
.chip[aria-pressed="true"] { border-color: var(--ember); box-shadow: inset 0 0 0 1px var(--ember); background: var(--raised); }
.chip.done .chip-k { color: var(--ok); }
.chip.small { min-height: 38px; padding: 4px 12px; border-radius: 999px; }

#figure { position: relative; height: 300px; margin: 4px 0 6px; border-radius: var(--r);
  background: radial-gradient(120% 90% at 50% 100%, #2a1d14 0%, #151a21 55%, var(--bg) 100%); overflow: hidden; }
#figure[hidden] { display: none; }
#figure-canvas, #figure-canvas canvas { width: 100%; height: 100%; display: block; }
#figure-canvas canvas { cursor: grab; }
#figure-label { position: absolute; left: 12px; right: 12px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.mus { background: #0e1116; border: 1px solid var(--ember); color: var(--text); border-radius: 999px; padding: 2px 10px; font-size: .8rem; }
.mus.off { border-color: var(--line); color: var(--muted); }
#figure.flat { height: auto; background: none; }
#figure.flat #figure-canvas { display: none; }
#figure.flat #figure-label { position: static; }

.day h2 { margin-top: 14px; }
.ex, .card, .tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.ex header { margin-bottom: 10px; }
.last, .hint, .ctx { color: var(--muted); font-size: .86rem; }
.hint { margin: 6px 0 10px; }
.sets { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.sets li { display: flex; align-items: center; gap: 6px; background: var(--raised); border-radius: 10px; padding: 2px 4px 2px 10px; font-variant-numeric: tabular-nums; }
.sets .n { color: var(--ok); font-weight: 700; font-size: .8rem; }
.x, .ico { width: 38px; height: 38px; border: 0; background: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; border-radius: 8px; }
.ico { border: 1px solid var(--line); background: var(--raised); flex: 0 0 auto; }
.ico:disabled { opacity: .35; cursor: default; }
.entry { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.entry .log { grid-column: 1 / -1; }
.stepper { display: flex; align-items: center; background: var(--raised); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper button { width: var(--tap); height: var(--tap); border: 0; background: none; font-size: 1.4rem; cursor: pointer; flex: 0 0 auto; }
.stepper button:active { background: var(--line); }
.stepper input { flex: 1 1 0; min-width: 0; width: 100%; border: 0; background: none; text-align: right; font-size: 1.15rem; font-weight: 650; font-variant-numeric: tabular-nums; padding: 0 2px; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.unit { color: var(--muted); font-size: .8rem; padding: 0 4px 0 3px; }
.stepper.wide { justify-content: space-between; }
.stepper.wide .val { font-size: 1.15rem; font-weight: 650; }

.btn { min-height: var(--tap); padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--raised); cursor: pointer; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn.primary { background: var(--ember); border-color: var(--ember); color: var(--ember-ink); }
.btn:active { transform: translateY(1px); }
.big-btn { width: 100%; min-height: 56px; font-size: 1.05rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.row .btn { flex: 1 1 140px; }
.addrow { display: flex; gap: 8px; margin: 10px 0; }
.addrow input { flex: 1 1 auto; min-width: 0; }
input[type="text"], input[type="number"], select, textarea { min-height: var(--tap); background: var(--raised); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.stepper input[type="number"] { min-height: 0; border: 0; background: none; border-radius: 0; padding: 0 2px; }
textarea { width: 100%; resize: vertical; }
.field { display: block; margin: 10px 0; }
.field > span:first-child { display: block; color: var(--muted); font-size: .86rem; margin-bottom: 4px; }
.field select, .field input { width: 100%; }
.field.inline { display: flex; align-items: center; gap: 8px; }
.field.inline > span:first-child { flex: 1 1 auto; margin: 0; color: var(--text); font-size: 1rem; }
.field.inline input { width: 110px; flex: 0 0 auto; text-align: right; }
.total { margin: 12px 0; color: var(--muted); }
.total strong { color: var(--text); }
.empty { color: var(--muted); padding: 14px 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 18px; }
.tile { margin: 0; }
.big { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.big small { font-size: .86rem; font-weight: 400; color: var(--muted); }
.meter { height: 8px; border-radius: 99px; background: var(--raised); margin: 8px 0; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ember); border-radius: 99px; }
.cardio { display: grid; grid-template-columns: 1.2fr 1fr 1fr auto; gap: 6px; margin-top: 10px; }
.cardio input, .cardio select { min-width: 0; width: 100%; padding: 8px; }
.finish { margin: 20px 0 8px; }
.finished { color: var(--ok); font-weight: 650; margin-bottom: 8px; }

.plan-h { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.plan-h .n { color: var(--muted); font-size: .8rem; flex: 1 1 auto; }
.plan-h input { order: 3; flex: 1 1 100%; min-width: 0; font-weight: 650; }
.exlist li { display: grid; grid-template-columns: 1fr 1fr auto auto auto; gap: 6px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.exlist li > input[type="text"] { grid-column: 1 / -1; }
.exlist select { min-width: 0; padding: 8px; }
.step { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .8rem; grid-column: 1 / 3; }
.step input { width: 84px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; }
.stat p:last-child { color: var(--muted); font-size: .8rem; }
.stat .big { font-size: 1.3rem; }
.chart { width: 100%; height: auto; display: block; margin: 6px 0 10px; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--ember); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--bg); stroke: var(--ember); stroke-width: 2.5; cursor: pointer; }
.chart .pt.on { fill: var(--ember); }
.sessions li { padding: 10px 0; border-top: 1px solid var(--line); }
.sessions li.on { border-left: 3px solid var(--ember); padding-left: 10px; }
.when { color: var(--muted); font-size: .84rem; }
.what { font-variant-numeric: tabular-nums; font-weight: 600; }
.note { font-style: italic; margin-top: 2px; }

#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; background: #12161c; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
#tabs button { flex: 1 1 0; max-width: 190px; min-height: 58px; border: 0; background: none; color: var(--muted); font-weight: 600; cursor: pointer; }
#tabs button[aria-current="page"] { color: var(--ember); box-shadow: inset 0 3px 0 var(--ember); }

#toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #f1f3f5; color: #11151a;
  border-radius: 12px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px); z-index: 20; font-weight: 600; }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { border: 0; background: none; color: #a13a00; font-weight: 800; min-height: 36px; cursor: pointer; }

#overlay { position: fixed; inset: 0; background: rgba(8, 10, 13, .9); display: grid; place-items: center; z-index: 30; padding: 24px; }
#overlay[hidden] { display: none; }
.cele { text-align: center; max-width: 420px; position: relative; isolation: isolate; }
.cele-k { color: var(--ember); font-weight: 700; letter-spacing: .04em; }
.cele h2 { font-size: clamp(2.2rem, 10vw, 3.4rem); line-height: 1.05; margin: 10px 0 14px; }
.cele-s { color: var(--muted); margin-bottom: 22px; }
.burst { z-index: -1; position: absolute; left: 50%; top: 40%; width: 10px; height: 10px; border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 0 0 var(--ember), 0 0 0 0 var(--ok), 0 0 0 0 var(--warn); animation: burst 1.6s ease-out 1 both; }
@keyframes burst {
  0% { box-shadow: 0 0 0 0 rgba(255, 138, 76, .9), 0 0 0 0 rgba(88, 201, 150, .7), 0 0 0 0 rgba(243, 201, 105, .6); }
  100% { box-shadow: 0 0 0 190px rgba(255, 138, 76, 0), 0 0 0 290px rgba(88, 201, 150, 0), 0 0 0 400px rgba(243, 201, 105, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .burst { animation: none; display: none; }
  #toast { transition: none; }
  .btn:active { transform: none; }
}
@media (min-width: 700px) {
  #figure { height: 380px; }
  .entry { grid-template-columns: 1fr 1fr auto; }
  .entry .log { grid-column: auto; min-width: 150px; }
  .stats { grid-template-columns: repeat(6, 1fr); }
}
