:root {
  --navy: #0b3a6a;
  --navy-deep: #072a4e;
  --navy-mid: #124a82;
  --ice: #eaf6ff;
  --ice-2: #f7fbff;
  --sky: #cfeeff;
  --white: #ffffff;
  --green: #1f9d55;
  --green-2: #22b35f;
  --green-dark: #167a41;
  --yellow: #ffd54a;
  --yellow-deep: #f5c518;
  --yellow-text: #3b2d00;
  --red: #e03131;
  --red-dark: #b42318;
  --muted: #6b8196;
  --line: #d7e6f2;
  --shadow: 0 10px 24px rgba(11, 58, 106, 0.12);
  --radius: 22px;
  --font: "Segoe UI", "Noto Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--ice);
  color: var(--navy-deep);
  font-family: var(--font);
}
body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 0 28px;
}

/* Header */
.nav, .home-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--navy);
  color: var(--white);
  padding: 12px 12px 12px 8px;
  min-height: 56px;
}
.nav h1, .home-bar h1 {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 800;
}
.nav-back, .nav-test, .btn-testmode {
  border: 0;
  background: transparent;
  color: var(--white);
  min-height: 40px;
  min-width: 40px;
  font-size: 1.6rem;
  font-weight: 700;
  border-radius: 12px;
}
.nav-test, .btn-testmode {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  font-weight: 800;
  background: var(--yellow);
  color: var(--yellow-text);
  padding: 7px 8px;
  min-width: auto;
  line-height: 1.1;
}
.nav-test.active, .btn-testmode.active { box-shadow: 0 0 0 2px #fff; }
.test-banner {
  background: var(--yellow);
  color: var(--yellow-text);
  text-align: center;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 8px 12px;
}
.test-banner span { display: block; font-size: 0.78rem; letter-spacing: 0; margin-top: 2px; }

/* Home */
.home-hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(#f4fbff 0%, #d8f1ff 58%, #bfe6fb 100%);
  padding: 18px 18px 78px;
  text-align: center;
}
.home-hero::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 72px;
  background:
    radial-gradient(120px 46px at 18% 100%, #fff 0 70%, transparent 71%),
    radial-gradient(160px 54px at 55% 100%, #f7fbff 0 72%, transparent 73%),
    radial-gradient(130px 48px at 88% 100%, #fff 0 70%, transparent 71%);
}
.brand-mark { display: flex; justify-content: center; align-items: flex-start; gap: 6px; }
.snowflake { font-size: 2rem; color: #7ec8ea; line-height: 1; }
.brand-mark img {
  width: 108px;
  height: 108px;
  border-radius: 28px;
  box-shadow: 0 10px 20px rgba(11, 58, 106, 0.18);
}
.home-hero .btn-testmode { margin-bottom: 6px; }
.home-hero h2 {
  margin: 10px 0 0;
  font-size: 1.7rem;
  line-height: 1.15;
}
.home-hero .sub { margin: 6px 0 0; color: var(--navy-mid); font-weight: 700; font-size: 0.95rem; }
.home-menu { padding: 8px 16px 0; display: grid; gap: 12px; }
.menu-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--white);
  border: 0;
  border-radius: 18px;
  padding: 14px 14px;
  min-height: 74px;
  box-shadow: var(--shadow);
  color: var(--navy-deep);
}
.menu-card:disabled { opacity: 0.45; }
.menu-ico {
  width: 42px; height: 42px; flex: none;
  border-radius: 12px;
  background: var(--ice);
  display: grid; place-items: center;
  color: var(--navy);
}
.menu-card strong { display: block; font-size: 1.05rem; }
.menu-card small { color: var(--muted); font-weight: 600; }
.chevron { margin-left: auto; color: #9db4c7; font-size: 1.6rem; font-weight: 300; }
.resume-card { border: 2px solid var(--green); }

/* Cards and fields */
.wrap { padding: 14px 16px 0; }
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px 0;
}
.round-title { text-align: center; margin: 10px 0 12px; font-size: 1.35rem; }
.row-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.row-field:last-child { border-bottom: 0; }
.row-field .ico { width: 28px; text-align: center; color: var(--navy-mid); flex: none; }
.row-field label { flex: 1; font-weight: 700; font-size: 0.95rem; }
.row-field input, .row-field select {
  width: 148px;
  min-height: 40px;
  border: 0;
  background: var(--ice);
  border-radius: 12px;
  padding: 6px 10px;
  text-align: right;
  font-weight: 700;
  color: var(--navy-deep);
}
.value-group {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--ice);
  border-radius: 12px;
  padding-right: 10px;
}
.value-group input {
  width: 72px;
  background: transparent;
}
.unit {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: 28px;
  padding: 12px 16px;
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--white);
  background: var(--navy-mid);
}
.btn:disabled { opacity: 0.4; }
.btn-green { background: var(--green-2); box-shadow: 0 8px 16px rgba(31, 157, 85, 0.28); }
.btn-red { background: var(--red); }
.btn-yellow { background: var(--yellow); color: var(--yellow-text); }
.btn-pink { background: #e85d8c; box-shadow: 0 8px 16px rgba(232, 93, 140, 0.28); }
.btn-log { background: #2f7fb8; }
.btn-chemo {
  min-height: 64px;
  font-size: 1.12rem;
  letter-spacing: 0.03em;
  margin-top: 4px;
}
.time-facts {
  margin: 8px 16px 0;
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}
.time-facts div { display: grid; gap: 2px; }
.time-facts small { color: var(--muted); font-weight: 700; font-size: 0.75rem; }
.time-facts span { font-weight: 800; color: var(--navy); }
.sched-row.actual { background: #e7f8ee; }
.sched-row.estimate { background: #eef7ff; }
.sched-row.planned { background: #fff6d6; }
.overlay .field { display: grid; gap: 6px; font-weight: 700; margin: 10px 0; }
.overlay .field input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: var(--ice-2);
  font-weight: 700;
}
.btn-ghost, .btn-secondary {
  background: var(--white);
  color: var(--navy);
  border: 1px solid var(--line);
  box-shadow: none;
  min-height: 48px;
}
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.cta-wrap { padding: 16px; }

/* Schedule */
.date-chip {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--navy); font-weight: 800; margin: 8px 0 12px;
}
.sched { overflow: hidden; }
.sched-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  padding: 12px 14px;
  font-weight: 700;
}
.sched-row:nth-child(odd) { background: #eef7ff; }
.sched-row:nth-child(even) { background: var(--white); }
.sched-row .t { color: var(--navy); }
.sched-row .d { color: #35536d; font-weight: 650; }
.info-box {
  margin: 12px 0 0;
  background: #e7f4ff;
  border-radius: 16px;
  padding: 12px 14px;
  color: var(--navy-mid);
  font-weight: 650;
  line-height: 1.4;
}
.info-box ul { margin: 8px 0 0; padding-left: 18px; }

/* Settings toggles */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  width: 100%;
  background: transparent;
  border-left: 0; border-right: 0; border-top: 0;
  text-align: left;
  color: inherit;
}
.toggle-row:disabled { opacity: 0.45; }
.toggle-copy { flex: 1; }
.toggle-copy strong { display: block; }
.toggle-copy small { color: var(--muted); font-weight: 600; }
.switch {
  width: 50px; height: 30px; flex: none;
  border-radius: 999px;
  background: #d5dee6;
  position: relative;
}
.switch { transition: background 0.15s ease; }
.switch.on { background: #34c759; }
.switch i {
  position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: left 0.15s ease;
}
.switch.on i { left: 23px; }
.volume-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 16px;
}
.volume-row .toggle-copy { flex: 1 1 180px; }
.volume-row input[type="range"] {
  flex: 1 1 160px;
  min-height: 32px;
  accent-color: var(--navy);
}
#alarm-volume-label {
  font-weight: 800;
  color: var(--navy);
  min-width: 3.2em;
  text-align: right;
}
.seq { counter-reset: step; }
.seq-item { display: flex; gap: 10px; margin: 8px 0; }
.seq-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--navy); color: #fff;
  display: grid; place-items: center; font-size: 0.78rem; font-weight: 800; flex: none;
}

/* Timer */
.progress {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  padding: 12px 10px 4px;
  text-align: center;
  position: relative;
}
.progress::before {
  content: "";
  position: absolute;
  left: 18%; right: 18%; top: 22px;
  height: 4px; background: #d3e4f2; border-radius: 4px;
}
.progress b {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: #c5d8e8;
  position: relative; z-index: 1;
}
.progress .on b { background: #3d9be8; }
.progress .done b { background: var(--green); }
.progress .done b::after {
  content: "✓";
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1;
}
.progress span { display: block; font-size: 0.72rem; font-weight: 800; margin-top: 6px; color: var(--muted); }
.progress .on span, .progress .done span { color: var(--navy); }

.treat-chip-row {
  display: flex;
  justify-content: flex-end;
  padding: 6px 12px 0;
  pointer-events: none;
}
.treat-chip {
  pointer-events: auto;
  border: 0;
  background: var(--navy);
  color: var(--white);
  border-radius: 14px;
  padding: 6px 10px;
  min-width: 86px;
  min-height: 44px;
  text-align: center;
  line-height: 1.15;
  box-shadow: var(--shadow);
}
.treat-chip small {
  display: block;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.treat-chip .t {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  font-weight: 800;
}
.treat-chip.post { background: var(--navy-mid); }
.treat-chip.done {
  background: var(--yellow);
  color: var(--yellow-text);
}
.treat-panel h4 {
  margin: 12px 0 6px;
  font-size: 0.92rem;
  color: var(--navy);
}
.sched-row.overdue { background: #fde7ea; }

.alert-card {
  margin: 10px 16px 0;
  border-radius: 26px;
  padding: 18px 16px 16px;
  text-align: center;
  color: var(--white);
  box-shadow: var(--shadow);
}
.alert-card.yellow { background: linear-gradient(#ffe56a, #f5c400); color: var(--yellow-text); }
.alert-card.red { background: linear-gradient(#ff5a5a, #d61f1f); }
.alert-card.navy { background: linear-gradient(#1a4f86, #0b3a6a); }
.alert-card.ice-next {
  background: linear-gradient(#ffffff, #e8f5ff);
  color: var(--navy-deep);
}
.alert-card.ice-next .bar { background: #d3e4f2; }
.alert-card.ice-next .bar > i { background: #3d9be8; }
.alert-kicker { font-size: 0.95rem; font-weight: 800; letter-spacing: 0.04em; }
.alert-title { font-size: 1.45rem; font-weight: 800; margin: 6px 0 2px; letter-spacing: 0.03em; }
.alert-sub { font-weight: 700; opacity: 0.92; }
.time-xl {
  font-variant-numeric: tabular-nums;
  font-size: clamp(3.6rem, 18vw, 5.4rem);
  font-weight: 800;
  line-height: 0.95;
  margin: 8px 0 6px;
}
.bar {
  height: 10px; border-radius: 999px; background: rgba(255,255,255,.35);
  overflow: hidden; margin: 8px 8px 0;
}
.bar > i { display: block; height: 100%; background: #fff; width: 0; }
.alert-card.yellow .bar > i { background: #c98900; }
.alert-card.navy .bar > i { background: #3cdb7a; }
.cap-line {
  text-align: center;
  font-weight: 800;
  margin: 12px 0 4px;
  color: var(--navy);
}
.until { font-weight: 700; opacity: 0.9; }

.temp-card {
  margin: 12px 16px 0;
  background: var(--white);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12px;
}
.temp-card h3 { margin: 0 0 8px; font-size: 0.95rem; }
.temp-stat {
  background: var(--ice);
  border-radius: 12px;
  padding: 8px 10px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--navy);
}
.temp-row { display: flex; gap: 8px; align-items: center; }
.temp-row input {
  flex: 1; min-height: 44px; border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 10px; background: var(--ice-2); font-weight: 700;
}
.temp-row .btn { width: auto; min-height: 44px; padding: 8px 12px; border-radius: 12px; }
.warn { background: #fde7ea; color: var(--red-dark); border-radius: 12px; padding: 8px 10px; font-weight: 700; margin: 8px 0; }
.okmsg { background: #e7f8ee; color: var(--green-dark); border-radius: 12px; padding: 8px 10px; font-weight: 700; margin: 8px 0; }
.err { background: #fde7ea; color: var(--red-dark); border-radius: 12px; padding: 10px 12px; font-weight: 700; margin: 10px 16px 0; }
.notice {
  background: #fff6d6; color: var(--yellow-text);
  border-radius: 12px; padding: 10px 12px; font-weight: 700; margin: 10px 16px 0; line-height: 1.35;
}
.help { color: var(--muted); font-size: 0.92rem; line-height: 1.4; }
.footer-note { color: var(--muted); font-size: 0.82rem; line-height: 1.4; padding: 16px 18px 8px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 700; margin-top: 8px; }
.check input { width: 22px; height: 22px; flex: none; }
.list-btn {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; background: var(--white); border: 0; border-radius: 16px;
  min-height: 62px; padding: 12px 14px; box-shadow: var(--shadow);
  font-weight: 800; color: var(--navy); margin-bottom: 10px; text-align: left;
}
.plan li { margin: 0 0 10px; line-height: 1.4; }
.overlay {
  margin: 12px 16px 0;
  background: var(--white);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12px;
}
.schedule { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.schedule th, .schedule td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.hidden { display: none; }
.stack { display: grid; gap: 10px; }
.paused-tag { display: inline-block; background: #fff; color: var(--navy); border-radius: 999px; padding: 2px 10px; font-size: 0.75rem; font-weight: 800; }

@media (min-width: 720px) {
  .app { max-width: 980px; padding-bottom: 36px; }
  .home-shell { display: grid; grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr); min-height: 100vh; }
  .home-hero { min-height: 100%; display: flex; flex-direction: column; justify-content: center; }
  .home-menu { padding: 24px; align-content: start; }
  .timer-stage {
    display: grid;
    grid-template-columns: minmax(320px, 1.1fr) minmax(280px, 0.9fr);
    gap: 12px;
    align-items: start;
    padding: 0 12px;
  }
  .timer-stage .cap-line,
  .timer-stage .cta-wrap,
  .timer-stage .time-facts,
  .timer-stage .overlay { grid-column: 1 / -1; }
  .alert-card { max-width: 560px; width: 100%; margin-left: auto; margin-right: auto; }
  .time-xl { font-size: 6rem; }
  .wrap, .cta-wrap { max-width: 640px; margin-left: auto; margin-right: auto; }
  .timer-stage .cta-wrap { max-width: none; }
}

@media (max-width: 380px) {
  .time-xl { font-size: 3.2rem; }
  .row-field input { width: 120px; }
  .value-group input { width: 64px; }
  .home-hero h2 { font-size: 1.4rem; }
  .alert-card { margin: 8px 10px 0; padding: 14px 12px 12px; }
  .temp-card { margin: 10px 10px 0; }
  .cta-wrap { padding: 12px 10px 16px; }
  .treat-chip-row { padding: 4px 8px 0; }
  .treat-chip { min-width: 78px; padding: 5px 8px; }
  .treat-chip .t { font-size: 0.86rem; }
  .nav-test, .btn-testmode { font-size: 0.62rem; padding: 6px 6px; }
}
