:root {
  --bg: #0f1210;
  --surface: #1a1f1c;
  --surface-2: #242b27;
  --line: #2e3732;
  --text: #e8eee9;
  --muted: #8a968e;
  --accent: #3d8b7a;
  --accent-2: #4ea894;
  --good: #5cb88a;
  --warn: #c9a86b;
  --danger: #c96b6b;
  --rest: #3d6b8b;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 56px;
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  border: none;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0.65rem 1rem;
  cursor: pointer;
}

button:active { opacity: 0.85; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); color: #06120f; font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; color: var(--muted); }
button.danger { background: var(--danger); color: #1a0a0a; }
button.small { padding: 0.4rem 0.7rem; font-size: 0.8125rem; }
button.block { width: 100%; }

input, textarea, select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}

textarea { min-height: 72px; resize: vertical; }

label.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(15, 18, 16, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  font-size: 1.1rem;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.topbar .sub {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.main {
  flex: 1;
  padding: 1rem 1rem calc(var(--nav-h) + var(--safe-bottom) + 1rem);
  overflow-y: auto;
}

.view { display: none; }
.view.active { display: block; }

.nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 30;
}

.nav button {
  border-radius: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  font-size: 0.65rem;
  color: var(--muted);
  padding: 0.35rem;
}

.nav button.active { color: var(--accent-2); }
.nav .icon { font-size: 1.05rem; line-height: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
}

.card h2, .card h3 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.muted { color: var(--muted); font-size: 0.8125rem; }
.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.row.between { justify-content: space-between; }
.gap { gap: 0.5rem; }
.mt { margin-top: 0.75rem; }
.mb { margin-bottom: 0.75rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.chip.new { background: rgba(61, 139, 122, 0.2); color: var(--accent-2); }
.chip.kind { background: rgba(61, 107, 139, 0.25); color: #8eb8d4; }

.day-switch {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  margin-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
}
.day-switch button {
  flex: 0 0 auto;
  padding: 0.45rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 999px;
}
.day-switch button.active {
  background: var(--accent);
  color: #06120f;
  font-weight: 600;
}

.ex-list { list-style: none; }
.ex-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}
.ex-item:last-child { border-bottom: none; }
.ex-item .name { font-weight: 560; }
.ex-item .meta { font-size: 0.8rem; color: var(--muted); }

.set-row {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface-2);
  border-radius: 10px;
  margin-bottom: 0.4rem;
  border: 1px solid transparent;
}
.set-row.done {
  border-color: rgba(92, 184, 138, 0.45);
  opacity: 0.75;
}
.set-row .check {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  border: 2px solid var(--muted);
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  color: transparent;
  flex-shrink: 0;
}
.set-row.done .check {
  background: var(--good);
  border-color: var(--good);
  color: #0a1a10;
}
.set-row .set-meta { font-size: 0.8rem; color: var(--muted); }
.set-row .set-edit {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}
.set-row input.tiny {
  width: 3.2rem;
  padding: 0.3rem;
  text-align: center;
  font-size: 0.8rem;
}

.section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1rem 0 0.5rem;
}

.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0 0.75rem;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s;
}

.rest-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(8, 12, 10, 0.92);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
}
.rest-overlay.show { display: flex; }
.rest-overlay .label { color: var(--muted); margin-bottom: 0.5rem; }
.rest-overlay .clock {
  font-size: 5rem;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: #9fd4c8;
  line-height: 1;
  margin-bottom: 1.25rem;
}
.rest-overlay .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }

.meal-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}
.meal-row:last-child { border-bottom: none; }
.meal-row input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.15rem;
  accent-color: var(--accent);
}
.meal-row .label { font-weight: 560; margin-bottom: 0.2rem; }
.macros {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
  margin: 0.5rem 0;
}
.macro {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.5rem 0.35rem;
  text-align: center;
}
.macro .v { font-weight: 650; font-size: 0.95rem; }
.macro .k { font-size: 0.65rem; color: var(--muted); margin-top: 0.15rem; }

.hist-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.hist-item:last-child { border-bottom: none; }
.hist-item .t { font-weight: 560; }
.hist-detail { font-size: 0.8rem; color: var(--muted); margin-top: 0.35rem; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.form-grid .span2 { grid-column: 1 / -1; }

.ex-edit-card {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 1rem);
  transform: translateX(-50%) translateY(120%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 60;
  transition: transform 0.25s;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 55;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.show { display: flex; }
.modal {
  width: min(480px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 1rem 1rem calc(1rem + var(--safe-bottom));
}
.modal h3 { margin-bottom: 0.75rem; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
  font-size: 0.9rem;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}
.settings-row:last-child { border-bottom: none; }

.toggle {
  appearance: none;
  width: 44px;
  height: 26px;
  background: var(--line);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
}
.toggle:checked { background: var(--accent); }
.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s;
}
.toggle:checked::after { left: 21px; }
