:root {
  /* Palette inspired by Japanese Colours gradient — muted sage / slate-teal */
  --bg: #0f1513;
  --surface: #161e1b;
  --surface-2: #1e2825;
  --surface-3: #2a352f;
  --line: #2d3833;
  --text: #ecefe8;
  --muted: #8c968b;
  --muted-2: #5c665d;
  --accent: #aebd99;        /* sage */
  --on-accent: #142019;     /* dark text on accent */
  --accent-dim: #45564f;    /* slate-teal for banners */
  --ok: #8fb08a;
  --miss: #c67d6e;          /* muted clay */
  --progress: #c9b481;      /* muted gold */

  --push: #c68f6e;          /* clay */
  --pull: #7fa0b3;          /* slate blue */
  --lower: #a591b5;         /* mauve */
  --recovery: #8fae8a;      /* sage */
  --optional: #8c968b;      /* gray-green */

  --tap: 50px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { font-size: 16px; line-height: 1.4; }

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 14px) 16px 110px;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.02em; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.mt { margin-top: 18px; }
.mt-s { margin-top: 10px; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 14px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px; font-weight: 700;
  width: 100%;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: transparent; color: var(--miss); border: 1.5px solid var(--miss); }
.btn.ghost { background: var(--surface); border: 1px solid var(--line); }
.btn.sm { min-height: 42px; width: auto; padding: 0 14px; font-size: 14px; border-radius: 11px; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; }

/* ---- block banner ---- */
.banner {
  border-radius: 16px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--accent-dim), var(--surface-2));
  border: 1px solid var(--line);
  margin-bottom: 16px;
}
.banner .blk { font-size: 20px; font-weight: 800; }
.banner .sub { color: #cdd8bd; font-size: 13px; font-weight: 600; margin-top: 2px; }
.banner .wk { float: right; font-size: 13px; color: #cdd8bd; font-weight: 700; }

/* ---- calendar ---- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-nav { display: flex; gap: 8px; align-items: center; }
.iconbtn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 18px;
}
.toggle { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.toggle button { min-height: 40px; padding: 0 14px; border: none; background: transparent; color: var(--muted); font-weight: 700; font-size: 13px; }
.toggle button.on { background: var(--surface-3); color: var(--text); }

.dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.dow span { text-align: center; font-size: 11px; color: var(--muted-2); font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cell {
  position: relative;
  min-height: 62px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid transparent;
  padding: 5px 4px 4px;
  display: flex; flex-direction: column; gap: 3px;
  overflow: hidden;
}
.cell.empty { background: transparent; }
.cell.dim { opacity: 0.4; }
.cell.today { border-color: var(--accent); }
.cell .dnum { font-size: 12px; font-weight: 700; color: var(--muted); }
.cell.today .dnum { color: var(--accent); }

.pill {
  position: relative;
  font-size: 8px; font-weight: 800; line-height: 1; letter-spacing: -0.01em;
  padding: 4px 9px 4px 4px; border-radius: 7px;
  display: flex; align-items: center;
  color: #0e1413;
  overflow: hidden; white-space: nowrap;
}
.pill .lab { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.pill.completed { opacity: 0.55; }
.pill.missed { background: var(--surface-3) !important; color: var(--miss); border: 1px solid var(--miss); }
.pill.upcoming { opacity: 0.92; padding-right: 4px; }
.pill .st { position: absolute; top: 50%; right: 3px; transform: translateY(-50%); font-size: 7px; }

/* 2-week list view */
.wk-list { display: flex; flex-direction: column; gap: 8px; }
.wk-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 14px; padding: 12px 14px;
  border: 1px solid transparent; min-height: var(--tap);
}
.wk-row.today { border-color: var(--accent); }
.wk-row.rest { opacity: 0.55; }
.wk-date { width: 46px; text-align: center; }
.wk-date .d { font-size: 20px; font-weight: 800; line-height: 1; }
.wk-date .m { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.wk-tag { width: 8px; align-self: stretch; border-radius: 6px; }
.wk-body { flex: 1; min-width: 0; }
.wk-body .nm { font-weight: 700; }
.wk-body .sub { font-size: 12px; color: var(--muted); }
.wk-status { font-size: 20px; }

/* ---- workout detail ---- */
.wo-head { margin-bottom: 14px; }
.wo-head .crumb { color: var(--muted); font-weight: 700; font-size: 14px; }
.wo-head h1 { margin-top: 4px; }
.wo-meta { color: var(--muted); font-size: 13px; margin-top: 4px; display: flex; gap: 14px; flex-wrap: wrap; }
.statuschip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.statuschip.completed { background: rgba(143,176,138,0.16); color: var(--ok); }
.statuschip.in_progress { background: rgba(201,180,129,0.16); color: var(--progress); }
.statuschip.missed { background: rgba(198,125,110,0.16); color: var(--miss); }
.statuschip.upcoming { background: var(--surface-2); color: var(--muted); }

.prompt {
  background: rgba(201,180,129,0.1); border: 1px solid var(--progress);
  border-radius: 14px; padding: 14px; margin-bottom: 14px;
}
.prompt p { margin: 0 0 10px; font-size: 14px; }
.prompt .row { gap: 8px; }

.ex {
  background: var(--surface); border-radius: 16px; padding: 14px;
  margin-bottom: 12px; border: 1px solid var(--line);
}
.ex.done { border-color: var(--ok); }
.ex-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ex-head .nm { font-weight: 800; font-size: 16px; flex: 1; min-width: 0; }
.ex-head-right { display: flex; align-items: center; gap: 8px; flex: none; }
.ex-head .tgt { font-size: 12px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.ex-tag { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; display: inline-block; margin-bottom: 8px; }

.desc-toggle {
  width: 38px; height: 38px; min-width: 38px; flex: none;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--muted); display: flex; align-items: center; justify-content: center; padding: 0;
  transition: color 0.15s, background 0.15s;
}
.desc-toggle:active { transform: scale(0.94); }
.desc-toggle svg { transition: transform 0.22s ease; display: block; }
.desc-toggle.open { color: var(--accent); background: var(--surface-3); }
.desc-toggle.open svg { transform: rotate(180deg); }
.ex-desc {
  margin-top: 10px; padding: 12px 14px; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 13.5px; line-height: 1.55; color: var(--muted);
}
.ex-desc[hidden] { display: none; }

.set-grid-head, .set-row {
  display: grid; align-items: center; gap: 8px;
}
.set-row { grid-template-columns: 30px 1fr 1fr 52px; margin-top: 8px; }
.set-grid-head { grid-template-columns: 30px 1fr 1fr 52px; margin-top: 10px; }
.set-grid-head span { font-size: 11px; color: var(--muted-2); font-weight: 800; text-transform: uppercase; }
.set-grid-head .h-check { text-align: center; }

/* duration / checkbox layouts */
.set-row.dur { grid-template-columns: 30px 1fr 52px; }
.set-grid-head.dur { grid-template-columns: 30px 1fr 52px; }
.set-row.chk { grid-template-columns: 1fr 52px; }

.set-n { font-size: 14px; font-weight: 800; color: var(--muted); text-align: center; }
input.f {
  width: 100%; min-height: var(--tap); border-radius: 12px;
  background: var(--surface-2); border: 1.5px solid var(--line);
  color: var(--text); font-size: 18px; font-weight: 700; text-align: center;
  padding: 0 6px;
}
input.f::placeholder { color: var(--muted-2); font-weight: 600; }
input.f:focus { outline: none; border-color: var(--accent); }
.unit { font-size: 11px; color: var(--muted-2); font-weight: 700; }

.check {
  width: 52px; height: var(--tap); border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--surface-2);
  color: var(--muted-2); font-size: 22px; display: flex; align-items: center; justify-content: center;
}
.check.on { background: var(--ok); border-color: var(--ok); color: #0e1813; }

.chk-label { display: flex; align-items: center; font-weight: 700; }

.add-set { margin-top: 10px; background: transparent; border: 1.5px dashed var(--line); color: var(--muted); min-height: 42px; }
.note-in {
  width: 100%; margin-top: 8px; min-height: 40px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 8px 10px; font-size: 13px; font-family: inherit; resize: none;
}
.note-in::placeholder { color: var(--muted-2); }

.sticky-actions {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  max-width: 480px; margin: 0 auto;
  display: flex; gap: 10px; z-index: 30;
}

/* ---- progress ---- */
.search {
  width: 100%; min-height: var(--tap); border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  padding: 0 16px; font-size: 16px; margin-bottom: 14px;
}
.search:focus { outline: none; border-color: var(--accent); }
.ex-list-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-radius: 14px; padding: 14px 16px;
  margin-bottom: 8px; min-height: var(--tap); border: 1px solid var(--line);
}
.ex-list-item .meta { font-size: 12px; color: var(--muted); }
.chev { color: var(--muted-2); font-size: 20px; }

.chart-card { background: var(--surface); border-radius: 16px; padding: 16px; border: 1px solid var(--line); }
.stat-row { display: flex; gap: 12px; margin: 14px 0; }
.stat {
  flex: 1; background: var(--surface); border-radius: 14px; padding: 12px 14px; border: 1px solid var(--line);
}
.stat .v { font-size: 22px; font-weight: 800; }
.stat .k { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; }

/* ---- settings / setup ---- */
.field { margin-bottom: 18px; }
.field > label { display: block; font-size: 13px; font-weight: 800; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.03em; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; min-height: var(--tap); border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--muted); font-weight: 800; font-size: 16px;
}
.seg button.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
input.date {
  width: 100%; min-height: var(--tap); border-radius: 12px; background: var(--surface);
  border: 1.5px solid var(--line); color: var(--text); padding: 0 14px; font-size: 16px; font-family: inherit;
}
input.date:focus { outline: none; border-color: var(--accent); }

.daypat { display: flex; flex-direction: column; gap: 8px; }
.daypat .dp-row { display: flex; align-items: center; gap: 10px; }
.daypat .dp-lab { width: 92px; font-size: 13px; font-weight: 700; }
.dow-pick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; flex: 1; }
.dow-pick button {
  min-height: 40px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 800; padding: 0;
}
.dow-pick button.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.brand { text-align: center; padding: 30px 0 18px; }
.brand .logo { font-size: 40px; font-weight: 900; letter-spacing: -0.04em; }
.brand .logo b { color: var(--accent); }
.brand .tg { color: var(--muted); font-weight: 600; margin-top: 4px; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .big { font-size: 40px; margin-bottom: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  background: var(--surface-3); color: var(--text); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 700; z-index: 100; border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5); opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ---- tab bar ---- */
#tabbar[hidden] { display: none; }
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: rgba(16,16,20,0.92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 8px 0 calc(6px + var(--safe-b));
  max-width: 480px; margin: 0 auto;
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted-2); font-size: 11px; font-weight: 700; flex: 1; padding: 4px 0;
  min-height: 48px; justify-content: center;
}
.tab.on { color: var(--accent); }
.tab-ico { font-size: 18px; }

.divider { height: 1px; background: var(--line); margin: 18px 0; border: none; }
