:root {
  --seam: #111111;
  --ink: #111111;
  --sub: #4A4A48;
  --paper: #F0EFEC;
  --light: #DCDBD7;
  --mid: #A8A7A3;
  --dark: #1C1C1C;
  --on-dark: #F0EFEC;
  --on-dark-sub: #B5B4B0;
  --white: #FFFFFF;
  --orange: #F05A0A;
  --orange-press: #D04C06;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --sans: 'Barlow', system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--seam); }
body {
  font-family: var(--sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
button, input, select { font: inherit; color: inherit; }
input, textarea { -webkit-user-select: text; user-select: text; }

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; }

/* ---------- tile grid ---------- */
.screen {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 2px;
  background: var(--seam);
  min-height: 100dvh;
  align-content: start;
  padding-bottom: var(--safe-b);
}
.screen.fill { height: 100dvh; min-height: 0; align-content: stretch; overflow: hidden; }

.tile {
  min-width: 0;
  min-height: 0;
  background: var(--paper);
  color: var(--ink);
  border: 0;
  border-radius: 0;
  margin: 0;
  padding: 0;
  position: relative;
  text-align: left;
  display: flex;
  flex-direction: column;
}
.settled .tile, .settled .strip { animation: none; }

/* ---------- motion ---------- */
:root {
  --ease-out: cubic-bezier(0.2, 0, 0, 1);        /* emphasized decelerate */
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --spring: cubic-bezier(0.2, 0.9, 0.3, 1.25);  /* slight overshoot */
}
@keyframes tileIn {
  from { opacity: 0; transform: translateY(16px) scale(0.985); }
  55% { opacity: 1; }
}
/* Tiles are physical keys: they sink when pressed and spring back. */
button.tile, label.tile { cursor: pointer; transition: transform 0.22s var(--spring), filter 0.22s ease; }
button.tile:active, label.tile:active { transform: scale(0.955); filter: brightness(0.9); transition-duration: 0.07s; }
button.tile:disabled { cursor: default; }
button.tile:disabled:active { transform: none; filter: none; }

/* Leaving tiles are pinned here while they slide off the board. */
.motion-layer {
  position: fixed !important; inset: 0 !important; z-index: 15; pointer-events: none;
  background: transparent !important; display: block !important;
  height: 0 !important; min-height: 0 !important; padding: 0 !important; overflow: visible !important;
}
.motion-layer > * { z-index: 1; }

/* Segments fill like a wipe; rating bars charge up one by one. */
@keyframes wipe { from { transform: scaleX(0); } }
@keyframes charge { from { transform: scaleY(0.2); opacity: 0.3; } }
.segs > span.now { transform-origin: left; animation: wipe 0.5s var(--ease-out); }
.picked .bars > span.on { transform-origin: bottom; animation: charge 0.28s var(--spring) both; animation-delay: calc(var(--b, 0) * 45ms); }
.clock .dg { display: inline-block; }
@keyframes cellPop { from { transform: scale(0.2); } 60% { transform: scale(1.15); } }
.fresh { animation: cellPop 0.5s var(--spring) both; }
/* A swapped exercise flips over like a split-flap card. */
@keyframes flipIn { from { transform: perspective(500px) rotateX(-90deg); opacity: 0.2; } }
.settled .tile.flip, .tile.flip { animation: flipIn 0.5s var(--spring) both; transform-origin: center top; }
button.tile:focus-visible, .tile :focus-visible { outline: 3px solid var(--orange); outline-offset: -3px; }
.dark button.tile:focus-visible, button.tile.orange:focus-visible { outline-color: var(--ink); }

.s1 { grid-column: span 1; } .s2 { grid-column: span 2; } .s3 { grid-column: span 3; }
.s4 { grid-column: span 4; } .s5 { grid-column: span 5; } .s6 { grid-column: span 6; }

.paper { background: var(--paper); }
.light { background: var(--light); }
.mid { background: var(--mid); }
.white { background: var(--white); }
.dark { background: var(--dark); color: var(--on-dark); }
.orange { background: var(--orange); color: var(--ink); }
button.orange:active { background: var(--orange-press); filter: none; }

.pad { padding: 12px 16px; }
.pad-s { padding: 8px 10px; }
.center { align-items: center; justify-content: center; text-align: center; }
.between { justify-content: space-between; }
.end { justify-content: flex-end; }
.row { display: flex; flex-direction: row; align-items: center; gap: 10px; }
.top { padding-top: calc(var(--safe-t) + 12px) !important; }
.gap { gap: 6px; }

/* subgrid row of equal tiles inside a tile slot */
.strip { display: grid; gap: 2px; background: var(--seam); grid-column: span 6; }
.strip > * { animation: none; }
.subgrid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 2px; grid-column: span 6; }

/* ---------- type ---------- */
.lbl { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sub); }
.dark .lbl { color: var(--on-dark-sub); }
.orange .lbl, .mid .lbl { color: var(--ink); }
.cond { font-family: var(--cond); font-weight: 600; text-transform: uppercase; line-height: 0.95; }
.h-xxl { font-family: var(--cond); font-weight: 700; font-size: clamp(120px, 44vw, 200px); line-height: 0.8; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.h-xl { font-family: var(--cond); font-weight: 700; font-size: 64px; line-height: 0.85; text-transform: uppercase; font-variant-numeric: tabular-nums; }
.h-l { font-family: var(--cond); font-weight: 600; font-size: 40px; line-height: 0.95; text-transform: uppercase; }
.h-m { font-family: var(--cond); font-weight: 600; font-size: 26px; line-height: 1; text-transform: uppercase; }
.h-s { font-family: var(--cond); font-weight: 600; font-size: 19px; line-height: 1.05; text-transform: uppercase; letter-spacing: 0.02em; }
.copy { font-size: 15px; line-height: 1.4; }
.copy-s { font-size: 13px; line-height: 1.35; }
.big-copy { font-size: 17px; line-height: 1.35; font-weight: 500; }
.sub { color: var(--sub); }
.dark .sub { color: var(--on-dark-sub); }
.accent { color: var(--orange); }
.mono-num { font-variant-numeric: tabular-nums; }

/* ---------- bits ---------- */
.ico { display: inline-flex; line-height: 0; }
.bars { display: inline-flex; gap: 2px; }
.bars > span { width: 7px; height: 11px; background: rgba(17, 17, 17, 0.16); }
.bars > span.on { background: var(--ink); }
.dark .bars > span { background: #3A3A38; }
.dark .bars > span.on { background: var(--orange); }

.segs { display: grid; gap: 2px; background: var(--seam); grid-column: span 6; height: 14px; animation: none; }
.segs > span { background: var(--light); }
.segs > span.done { background: var(--sub); }
.segs > span.now { background: var(--orange); }

.pbar { height: 4px; background: rgba(17, 17, 17, 0.18); }
.pbar > span { display: block; height: 100%; background: var(--ink); width: 100%; transform-origin: left; }
.dark .pbar { background: #3A3A38; }
.dark .pbar > span { background: var(--orange); }

.fig { width: 100%; height: 100%; display: block; }
.figbox { padding: 6px; align-items: center; justify-content: center; overflow: hidden; }
.figbox .fig { max-height: 100%; }

.swatch { width: 14px; height: 14px; display: inline-block; border: 2px solid var(--ink); flex-shrink: 0; }
.dot { width: 8px; height: 8px; display: inline-block; background: var(--orange); }

.list { margin: 0; padding-left: 18px; }
.list li { margin: 3px 0; }

.selected { background: var(--dark) !important; color: var(--on-dark) !important; }
.selected .lbl { color: var(--on-dark-sub); }
.picked { background: var(--orange) !important; color: var(--ink) !important; }
.muted { opacity: 0.45; }

input.field, select.field {
  width: 100%;
  border: 0;
  border-bottom: 2px solid var(--ink);
  background: transparent;
  padding: 6px 0;
  font-size: 17px;
  border-radius: 0;
  outline: none;
}
input.field:focus { border-bottom-color: var(--orange); }
input[type='color'].colorpick { width: 100%; height: 100%; min-height: 44px; border: 0; padding: 0; background: none; }

/* LED calendar */
.leds { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.leds > span { aspect-ratio: 1; background: var(--light); position: relative; }
.leds > span.on { background: var(--orange); }
.leds > span.today { outline: 2px solid var(--ink); outline-offset: -2px; }
.leds > span.p::after { content: ''; position: absolute; right: 2px; bottom: 2px; width: 4px; height: 4px; background: var(--ink); }
.leds > span.future { background: transparent; }

/* ---------- player ---------- */
.player { grid-template-rows: auto 14px minmax(150px, 30dvh) 60px 64px minmax(110px, 1fr) 52px 72px calc(52px + var(--safe-b)); padding-bottom: 0; }
.player.rest { grid-template-rows: auto 14px 108px 36px 78px minmax(140px, 1fr) 52px 72px calc(52px + var(--safe-b)); }
.player .mode-row > * { padding-bottom: var(--safe-b); }
.player .timer { padding: 12px 18px 14px; justify-content: space-between; }
.player .clock { font-family: var(--cond); font-weight: 700; line-height: 0.8; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; font-size: clamp(110px, 40vw, 190px); }
.player.rest .clock { font-size: 92px; color: var(--orange); }
.player .ready { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { background: var(--orange); color: var(--ink); } }


/* sheet overlay (exercise info during a workout) */
.sheet { position: fixed; inset: 0; z-index: 20; overflow-y: auto; background: var(--seam); max-width: 560px; margin: 0 auto; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 16px); transform: translateX(-50%);
  background: var(--dark); color: var(--on-dark); padding: 12px 18px; font-weight: 600; font-size: 14px;
  z-index: 30; animation: toastIn 0.36s var(--spring) both; max-width: calc(100% - 32px);
}
@keyframes toastIn { from { transform: translate(-50%, 24px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .tile, .strip, .toast, .segs > span, .bars > span { animation: none !important; }
  button.tile, label.tile { transition: none; }
  .player .ready { animation: none; background: var(--orange); color: var(--ink); }
}
.dragging { z-index: 2; cursor: grabbing; }
