:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-soft: #eef2ec;
  --ink: #18201b;
  --muted: #657066;
  --line: #dce4dc;
  --shadow: 0 16px 34px rgba(24, 32, 27, 0.1);
  --sleep: #111111;
  --eat: #f28c28;
  --exercise: #e53935;
  --work: #2276d2;
  --entertainment: #f5d547;
  --family: #35a853;
  --free: #d8ded7;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  background:
    linear-gradient(180deg, rgba(53, 168, 83, 0.08), transparent 270px),
    var(--bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  width: min(100%, 440px);
  min-height: 100vh;
  margin: 0 auto;
  overflow-x: clip;
  padding: calc(16px + env(safe-area-inset-top)) 14px calc(104px + env(safe-area-inset-bottom));
  touch-action: pan-y;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 54px;
  margin-bottom: 12px;
}

.title-stack {
  min-width: 0;
}

.eyebrow,
.section-heading p {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.2;
}

h1 {
  font-size: 2rem;
  line-height: 1;
}

h2 {
  font-size: 1.04rem;
  line-height: 1.2;
}

h3 {
  font-size: 1rem;
  line-height: 1.2;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 22px rgba(24, 32, 27, 0.08);
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
  overflow-x: clip;
  touch-action: pan-y;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  margin-bottom: 12px;
}

.section-heading.compact {
  min-height: 32px;
  margin-bottom: 10px;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
  white-space: nowrap;
}

.stats-overview,
.dial-area,
.timeline-area,
.current-block-area,
.schedule-area,
.settings-area,
.block-settings-area,
.health-input-area,
.chart-area,
.table-area {
  margin: 0 0 16px;
}

.stats-layout {
  display: grid;
  grid-template-columns: 154px 1fr;
  gap: 10px;
  align-items: center;
}

.donut-box {
  position: relative;
  width: 154px;
  aspect-ratio: 1;
}

#statsDonut {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 10px 20px rgba(24, 32, 27, 0.08));
}

.donut-center {
  position: absolute;
  inset: 41px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 50%;
  background: var(--surface);
  text-align: center;
}

.donut-center strong {
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
}

.donut-center span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.rank-list {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.rank-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-height: 25px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.rank-item strong,
.stat-table td:first-child {
  font-size: 0.9rem;
  font-weight: 850;
}

.rank-item span:last-child {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.dial-area {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 2px 0 4px;
}

.dial-wrap {
  position: relative;
  width: min(86vw, 342px);
  max-width: 100%;
  aspect-ratio: 1;
}

#timeDial {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.dial-face {
  fill: var(--surface);
  stroke: rgba(24, 32, 27, 0.1);
  stroke-width: 1;
}

.dial-segment {
  stroke: rgba(255, 255, 255, 0.52);
  stroke-width: 0.7;
}

.dial-number {
  fill: #1d2720;
  stroke: none;
  font-size: 14px;
  font-weight: 900;
}

.dial-tick {
  stroke: rgba(24, 32, 27, 0.24);
  stroke-width: 1.2;
}

.hour-hand {
  fill: #17201d;
  stroke: rgba(255, 255, 255, 0.86);
  stroke-width: 1.2;
  filter: drop-shadow(0 3px 3px rgba(24, 32, 27, 0.25));
}

.hand-pin {
  fill: #18201b;
  stroke: #ffffff;
  stroke-width: 2;
}

.dial-label {
  position: absolute;
  inset: 50% auto auto 50%;
  display: grid;
  place-items: center;
  min-width: 78px;
  border-radius: 999px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 18px rgba(24, 32, 27, 0.08);
  transform: translate(-50%, calc(-50% + var(--time-offset, 0px)));
  pointer-events: none;
}

.dial-label strong {
  font-variant-numeric: tabular-nums;
  font-size: 1.4rem;
  line-height: 1;
}

.dial-label span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.now-panel {
  width: 100%;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 13px 0;
}

.status-pill,
.template-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 0.74rem;
  font-weight: 850;
}

.now-panel h2 {
  margin: 10px 0 7px;
  font-size: 1.35rem;
}

.now-panel p {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.stat-bars {
  display: grid;
  gap: 10px;
}

.stat-bar-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 88px;
  align-items: center;
  gap: 10px;
}

.stat-bar-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.stat-bar-label strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.stat-bar-track {
  height: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.stat-bar-fill {
  display: block;
  height: 100%;
  min-width: 8px;
  border-radius: inherit;
}

.stat-bar-value {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-align: right;
  white-space: nowrap;
}

.timeline-horizontal-wrap {
  display: grid;
  gap: 8px;
  padding-top: 28px;
}

.timeline-track {
  position: relative;
  height: 56px;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.timeline-segment {
  position: absolute;
  top: 0;
  bottom: 0;
  min-width: 2px;
}

.timeline-segment.is-lane-1 {
  top: 29px;
  bottom: 0;
  border-top: 2px solid rgba(255, 255, 255, 0.75);
}

.timeline-progress {
  position: absolute;
  inset: 0 auto 0 0;
  background: rgba(255, 255, 255, 0.42);
  border-right: 2px solid rgba(24, 32, 27, 0.72);
  pointer-events: none;
}

.timeline-now {
  position: absolute;
  top: -30px;
  max-width: 54px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  background: #18201b;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 900;
  box-shadow: 0 0 0 4px rgba(24, 32, 27, 0.12);
}

.timeline-now::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid #18201b;
  transform: translateX(-50%);
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
}

.block-progress-list,
.schedule-list,
.block-settings-list,
.measure-grid,
.chart-area {
  display: grid;
  gap: 10px;
}

.progress-card,
.schedule-item,
.block-setting-row,
.measure-panel,
.chart-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.progress-card {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.progress-head strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
}

.progress-head span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 850;
  white-space: nowrap;
}

.progress-bar {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.progress-fill {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
}

.progress-note {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.schedule-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.schedule-item {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content max-content;
  gap: 12px;
  align-items: center;
  min-height: 40px;
  padding: 8px 10px;
}

.schedule-item time {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.schedule-title {
  min-width: 0;
  font-size: 0.92rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.schedule-duration {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
  white-space: nowrap;
}

.vacation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.vacation-grid label,
.block-time-control,
.number-input {
  display: grid;
  gap: 7px;
}

.vacation-grid span,
.block-time-control span,
.number-input span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

input[type="time"],
input[type="text"],
input[type="number"],
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: var(--surface);
  color: var(--ink);
}

.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 850;
}

.icon-text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 850;
}

.icon-text-button.is-on {
  border-color: rgba(53, 168, 83, 0.46);
  background: var(--family);
}

.alarm-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.9);
}

.alarm-control div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.alarm-control > div span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.alarm-tone-picker {
  display: grid;
  flex: 1 0 100%;
  gap: 7px;
}

.alarm-tone-picker span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.block-setting-row {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.block-setting-head {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 9px;
  align-items: start;
}

.block-setting-head strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.block-setting-head small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
  line-height: 1.35;
}

.block-time-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.alarm-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.alarm-toggle input {
  appearance: none;
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  transition: background 0.18s ease, border-color 0.18s ease;
}

.alarm-toggle input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 3px 8px rgba(24, 32, 27, 0.18);
  transition: transform 0.18s ease;
}

.alarm-toggle input:checked {
  border-color: rgba(53, 168, 83, 0.42);
  background: var(--family);
}

.alarm-toggle input:checked::after {
  transform: translateX(20px);
}

.measure-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.measure-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.measure-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.measure-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.measure-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 8px;
}

.weight-icon {
  background: rgba(34, 118, 210, 0.12);
  color: var(--work);
}

.glucose-icon {
  background: rgba(229, 57, 53, 0.11);
  color: var(--exercise);
}

.photo-preview {
  width: 100%;
  max-height: 150px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.chart-panel {
  padding: 12px;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.chart-head span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  white-space: nowrap;
}

.line-chart {
  width: 100%;
  height: 170px;
  overflow: visible;
}

.chart-grid {
  stroke: rgba(24, 32, 27, 0.12);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  stroke: var(--surface);
  stroke-width: 2;
}

.chart-empty {
  fill: var(--muted);
  stroke: none;
  font-size: 13px;
  font-weight: 800;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 440px);
  min-height: calc(78px + env(safe-area-inset-bottom));
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
  touch-action: manipulation;
}

.alarm-banner {
  position: fixed;
  left: 50%;
  bottom: calc(94px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(calc(100% - 24px), 416px);
  min-height: 64px;
  border: 1px solid rgba(24, 32, 27, 0.16);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 44px rgba(24, 32, 27, 0.18);
  transform: translateX(-50%);
  backdrop-filter: blur(18px);
}

.alarm-banner[hidden] {
  display: none;
}

.alarm-banner div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.alarm-banner strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alarm-banner span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.alarm-stop {
  background: var(--ink);
  color: #ffffff;
}

.nav-item {
  display: grid;
  place-items: center;
  gap: 3px;
  min-width: 0;
  min-height: 59px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.nav-item svg {
  width: 23px;
  height: 23px;
}

.nav-item.is-active {
  background: var(--surface-soft);
  color: var(--ink);
}

.svg-sprite {
  display: none;
}

.color-sleep {
  background: var(--sleep);
}

.color-eat {
  background: var(--eat);
}

.color-exercise {
  background: var(--exercise);
}

.color-work {
  background: var(--work);
}

.color-entertainment {
  background: var(--entertainment);
}

.color-family {
  background: var(--family);
}

@media (max-width: 390px) {
  .app-shell {
    padding-inline: 12px;
  }

  .stats-layout {
    grid-template-columns: 140px 1fr;
    gap: 8px;
  }

  .donut-box {
    width: 140px;
  }

  .donut-center {
    inset: 38px;
  }

  .stat-bar-row {
    grid-template-columns: 72px minmax(0, 1fr) 82px;
    gap: 8px;
  }
}

@media (max-width: 350px) {
  .stats-layout,
  .measure-grid,
  .vacation-grid,
  .block-time-grid {
    grid-template-columns: 1fr;
  }

  .donut-box {
    justify-self: center;
    width: 170px;
  }
}
