:root {
  --bg0: #e8f2ef;
  --bg1: #f3f7f5;
  --ink: #1a2e28;
  --ink-soft: #4a635c;
  --muted: #6f857d;
  --line: rgba(26, 46, 40, 0.1);
  --card: rgba(255, 255, 255, 0.72);
  --card-solid: #ffffff;
  --accent: #0f7a5f;
  --accent-2: #1fa37f;
  --accent-soft: rgba(15, 122, 95, 0.12);
  --warn: #b86a1c;
  --warn-soft: rgba(184, 106, 28, 0.12);
  --danger: #b42318;
  --taken: #8fa39b;
  --shadow: 0 12px 40px rgba(26, 46, 40, 0.08);
  --radius: 18px;
  --font: "DM Sans", "Noto Sans SC", "Source Han Sans SC", "PingFang SC", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg1);
}

body {
  position: relative;
}

.bg-wash {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 480px at 12% -10%, #c8e8dc 0%, transparent 55%),
    radial-gradient(700px 420px at 100% 8%, #d7ebe4 0%, transparent 50%),
    linear-gradient(180deg, var(--bg0), var(--bg1) 40%, #eef4f1);
  animation: washShift 18s ease-in-out infinite alternate;
}

@keyframes washShift {
  from { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(-8deg); }
}

.topbar {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.btn.compact {
  padding: 10px 14px;
  font-size: 0.85rem;
}

.create-course {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.course-list {
  display: grid;
  gap: 12px;
}

.course-card {
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  font: inherit;
  color: inherit;
  transition: transform 0.2s var(--ease), border-color 0.2s;
  display: grid;
  gap: 12px;
}

.course-card:hover {
  transform: translateY(-2px);
  border-color: rgba(15, 122, 95, 0.35);
}

.course-card.done {
  opacity: 0.72;
}

.course-enter {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.course-card h3 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.course-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.course-card p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.4;
}

.course-delete {
  justify-self: start;
  color: var(--danger) !important;
  border-color: rgba(180, 35, 24, 0.28) !important;
}

.status-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 8px;
  vertical-align: middle;
}

.status-pill.done {
  background: rgba(26, 46, 40, 0.08);
  color: var(--muted);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  flex: 1;
}

.brand-mark {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 12px;
  flex-shrink: 0;
  display: block;
  object-fit: cover;
  box-shadow: 0 6px 16px rgba(15, 122, 95, 0.28);
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
}

.brand-text {
  min-width: 0;
  flex: 1;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.3;
}

.achievement.compact {
  padding: 14px 16px;
  margin-bottom: 12px;
}

.meal-guide {
  margin: 0;
  padding: 12px 16px;
  background: rgba(15, 122, 95, 0.06);
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.meal-guide.compact {
  padding: 10px 16px;
}

.meal-guide strong {
  color: var(--accent);
}

.meal-guide .warn {
  color: var(--warn);
  margin-top: 4px;
}

.meal-phase-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 22px 16px;
  background: linear-gradient(180deg, rgba(15, 122, 95, 0.04), rgba(246, 241, 232, 0.9));
  border-bottom: 1px solid var(--line);
}

.meal-phase-line {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(15, 122, 95, 0.35), transparent);
}

.meal-phase-copy {
  text-align: center;
  min-width: 7.5rem;
}

.meal-phase-copy strong {
  display: block;
  font-size: clamp(1.45rem, 4.5vw, 1.85rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--ink);
  line-height: 1.15;
}

.meal-phase-copy span {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.meal-phase-divider[data-kind='done'] .meal-phase-copy strong {
  color: var(--accent);
}

.meal-phase-divider[data-kind='bed'] {
  background: linear-gradient(180deg, rgba(60, 70, 110, 0.05), rgba(246, 241, 232, 0.9));
}

.dose-done-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 4px 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.dose-done-sep::before,
.dose-done-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(26, 46, 40, 0.12);
}

.dose-done-sep span {
  flex-shrink: 0;
}

.dose-media {
  position: relative;
  flex-shrink: 0;
  width: 88px;
}

.dose-media .water-on-thumb {
  display: none;
}

.dose-dose {
  margin: 2px 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  line-height: 1.35;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.dose-dose-text {
  min-width: 0;
}

.water-badge {
  flex-shrink: 0;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  letter-spacing: 0.02em;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  line-height: 1.2;
  border: 1px solid transparent;
}

.water-inline {
  display: inline-flex;
  align-items: center;
}

.water-badge.warm {
  color: #9a4a12;
  background: #ffe8d2;
  border-color: rgba(154, 74, 18, 0.2);
}

.water-badge.hot {
  color: #a11616;
  background: #ffd9d6;
  border-color: rgba(161, 22, 22, 0.18);
}

.water-badge.cool {
  color: #1c5f8a;
  background: #d7ecff;
  border-color: rgba(28, 95, 138, 0.18);
}

.water-badge.any {
  color: var(--ink-soft);
  background: rgba(0, 0, 0, 0.05);
  border-color: var(--line);
}

.dose-body {
  min-width: 0;
}

.dose-ai-tip {
  margin-top: 6px;
  padding: 7px 9px;
  border-radius: 10px;
  background: rgba(15, 122, 95, 0.08);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
}

.dose-ai-mark {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  vertical-align: 1px;
}

.dose-timing {
  display: inline-block;
  margin-top: 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.nav-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(15, 122, 95, 0.28);
  background: rgba(15, 122, 95, 0.08);
  color: var(--accent);
  border-radius: 12px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.nav-toggle-bars {
  width: 16px;
  height: 12px;
  position: relative;
  display: inline-block;
}

.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.nav-toggle-bars::before {
  top: 0;
  box-shadow: 0 5px 0 currentColor;
}

.nav-toggle-bars::after {
  bottom: 0;
}

.nav-backdrop {
  display: none;
}

@keyframes navDrop {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.tabs,
.top-nav {
  max-width: 720px;
  width: calc(100% - 32px);
  margin: 0 auto 8px;
  padding: 4px 10px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(26, 46, 40, 0.05);
  position: relative;
  z-index: 40;
}

.tabs[hidden],
.top-nav[hidden] {
  display: none !important;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 600;
  font-size: 0.78rem;
  padding: 10px 4px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.timing-grid {
  grid-template-columns: 1.2fr 0.8fr;
}

.tab.active {
  background: var(--ink);
  color: #fff;
}

.tab:hover:not(.active) {
  background: var(--accent-soft);
  color: var(--accent);
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 4px 16px 40px;
}

.view {
  display: none;
  animation: viewIn 0.45s var(--ease);
}

.view.active {
  display: block;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.section-head {
  margin: 12px 0 18px;
}

.section-head.compact {
  margin-top: 28px;
}

.section-head h2 {
  margin: 0 0 6px;
  font-size: 1.25rem;
}

.section-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Calendar */
.calendar-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.month-label {
  font-weight: 700;
  letter-spacing: -0.02em;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--ink);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 18px;
}

.cal-dow {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  padding: 4px 0;
}

.cal-day {
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink-soft);
  cursor: pointer;
  position: relative;
  transition: transform 0.2s var(--ease), background 0.2s, border-color 0.2s;
}

.cal-day:hover {
  background: rgba(255, 255, 255, 0.7);
}

.cal-day.muted {
  opacity: 0.35;
}

.cal-day.today {
  border-color: rgba(15, 122, 95, 0.35);
}

.cal-day.selected {
  background: var(--ink);
  color: #fff;
  transform: translateY(-1px);
}

.cal-day .dot {
  position: absolute;
  left: 50%;
  bottom: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  transform: translateX(-50%);
  background: var(--accent);
}

.cal-day.selected .dot {
  background: #9fe0c8;
}

.cal-day.done .dot {
  background: var(--accent-2);
}

/* Achievement */
.achievement {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 18px 20px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  margin-bottom: 14px;
}

.ach-ring {
  position: relative;
  width: 96px;
  height: 96px;
  flex-shrink: 0;
}

.ach-ring svg {
  width: 100%;
  height: 100%;
  display: block;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: rgba(26, 46, 40, 0.08);
  stroke-width: 8;
}

.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 251.2;
  stroke-dashoffset: 251.2;
  transition: stroke-dashoffset 0.7s var(--ease);
}

.ach-pct {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.ach-date {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.ach-copy h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.ach-meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.tips {
  margin-bottom: 14px;
  display: grid;
  gap: 8px;
}

.tip {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--warn-soft);
  color: #7a4812;
  border: 1px solid rgba(184, 106, 28, 0.2);
  font-size: 0.9rem;
  animation: tipIn 0.4s var(--ease);
}

@keyframes tipIn {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: none; }
}

.day-board {
  display: grid;
  gap: 14px;
}

.meal-block {
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  overflow: hidden;
}

.meal-title {
  margin: 0;
  padding: 12px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.45);
}

.dose-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  transition: opacity 0.35s var(--ease), filter 0.35s var(--ease), background 0.35s;
  cursor: pointer;
  text-align: left;
  width: 100%;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  background: transparent;
  font: inherit;
  color: inherit;
}

.dose-item:last-child {
  border-bottom: 0;
}

.dose-item:hover {
  background: rgba(15, 122, 95, 0.04);
}

.meal-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
  padding: 6px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.meal-tab {
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 8px 4px;
  cursor: pointer;
  font: inherit;
  color: var(--ink-soft);
  text-align: center;
  transition: background 0.2s var(--ease), color 0.2s, transform 0.15s;
}

.meal-tab strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 750;
  letter-spacing: 0.02em;
  color: inherit;
}

.meal-tab span {
  display: block;
  margin-top: 2px;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.meal-tab:hover:not(.active) {
  background: var(--accent-soft);
  color: var(--accent);
}

.meal-tab.active {
  background: var(--ink);
  color: #fff;
  transform: translateY(-1px);
}

.meal-tab.active span {
  color: rgba(255, 255, 255, 0.72);
}

.meal-tab.empty-slot:not(.active) {
  opacity: 0.72;
}

.empty.compact {
  padding: 20px 16px;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.time-context strong {
  color: var(--accent);
}

.dose-item.deferred {
  opacity: 0.42;
  filter: grayscale(0.55);
  cursor: default;
  pointer-events: none;
}

.dose-item.deferred .dose-name,
.dose-item.deferred .dose-how {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.dose-item.missed {
  opacity: 0.55;
  filter: grayscale(0.35);
  cursor: default;
  pointer-events: none;
  border-left: 3px solid var(--danger);
}

.dose-item.missed .dose-badge {
  background: rgba(180, 35, 24, 0.12);
  color: var(--danger);
}

.dose-defer-tag {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.dose-defer-tag.soft {
  font-weight: 500;
  opacity: 0.9;
}

.dose-item.makeup {
  border-left: 3px solid var(--warn);
}

.dose-item.makeup .dose-badge {
  background: var(--warn-soft);
  color: #7a4812;
}

.check-field {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0 4px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.check-field input {
  margin-top: 3px;
  flex-shrink: 0;
}

.dose-timer {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #7a4812;
  background: var(--warn-soft);
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1.35;
}

.dose-timer.ready {
  color: var(--accent);
  background: var(--accent-soft);
}

.dose-timer em {
  font-style: normal;
  font-variant-numeric: tabular-nums;
}

.dose-item.waiting {
  border-left: 3px solid rgba(184, 106, 28, 0.55);
}

.dose-item.taken .dose-name,
.dose-item.taken .dose-how {
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.dose-thumb {
  width: 88px;
  height: 88px;
  border-radius: 16px;
  object-fit: cover;
  object-position: center;
  background: var(--accent-soft);
  box-shadow: 0 4px 12px rgba(26, 46, 40, 0.1);
  display: block;
}

.dose-thumb.placeholder {
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
}

.dose-name {
  margin: 0 0 4px;
  font-weight: 700;
  font-size: 1rem;
}

.dose-how {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.dose-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
  align-self: center;
}

.dose-item.taken .dose-badge {
  background: rgba(26, 46, 40, 0.08);
  color: var(--taken);
}

.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.4);
}

/* Med list */
.med-list {
  display: grid;
  gap: 12px;
}

.med-card {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  position: relative;
  align-items: start;
}

.med-card img,
.med-card .thumb-ph,
.med-thumb-wrap img,
.med-thumb-wrap .thumb-ph {
  width: 88px;
  height: 88px;
  max-width: 88px;
  border-radius: 18px;
  object-fit: cover;
  object-position: center;
  background: var(--accent-soft);
  display: block;
}

.med-thumb-wrap {
  position: relative;
  width: 88px;
  height: 88px;
  max-width: 88px;
  border-radius: 18px;
  overflow: hidden;
  flex-shrink: 0;
}

.med-card > div:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.med-thumb-edit {
  position: absolute;
  right: 4px;
  bottom: 4px;
  left: auto;
  border: 0;
  border-radius: 8px;
  padding: 2px 6px;
  font: inherit;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
  background: rgba(26, 46, 40, 0.7);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.med-card .thumb-ph {
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--accent);
}

.med-card h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.med-card p {
  margin: 0 0 4px;
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.4;
}

.med-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(26, 46, 40, 0.06);
  color: var(--ink-soft);
}

.chip.remain {
  background: var(--accent-soft);
  color: var(--accent);
}

.conflict-tip {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: #7a4812;
  font-size: 0.86rem;
  font-weight: 600;
}

.med-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
}

.med-actions button {
  border: 0;
  background: transparent;
  color: var(--danger);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.med-actions button[data-adapt] {
  color: var(--accent);
}

.med-actions button[data-edit-med] {
  color: var(--ink-soft);
}

/* Add / camera */
.recognize-form,
.confirm-form {
  display: grid;
  gap: 14px;
}

.camera-box {
  display: block;
  border-radius: 22px;
  overflow: hidden;
  border: 1px dashed rgba(15, 122, 95, 0.35);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.85), rgba(200, 232, 220, 0.45));
  min-height: 220px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.25s, transform 0.25s var(--ease);
}

.camera-box:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.camera-placeholder {
  min-height: 220px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--ink-soft);
}

.camera-placeholder strong {
  color: var(--ink);
  font-size: 1.05rem;
}

.camera-placeholder span:last-child {
  font-size: 0.85rem;
  color: var(--muted);
}

.cam-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--accent);
  margin-bottom: 6px;
  position: relative;
  box-shadow: 0 10px 24px rgba(15, 122, 95, 0.3);
}

.cam-icon::before {
  content: "";
  position: absolute;
  inset: 16px;
  border: 2px solid #fff;
  border-radius: 8px;
}

.cam-icon::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9fe0c8;
}

#photo-preview {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  display: block;
  background: rgba(26, 46, 40, 0.04);
}

#photo-preview[hidden] {
  display: none !important;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  font-weight: 600;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stepper button {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

.stepper input {
  width: 52px;
  text-align: center;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field input,
.field textarea,
.field select {
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  resize: vertical;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.slots {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 0;
  background: var(--card);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.slots legend {
  padding: 0 6px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.slots label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s var(--ease), box-shadow 0.2s, opacity 0.2s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 122, 95, 0.28);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  color: var(--ink);
}

.auto-summary {
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
}

.auto-summary h3 {
  margin: 0;
  font-size: 1.15rem;
}

.auto-summary p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.45;
}

.auto-summary .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.stock-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid rgba(15, 122, 95, 0.18);
}

.stock-remain {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.95rem;
  line-height: 1.35;
  padding-bottom: 10px;
}

@media (max-width: 560px) {
  .stock-row {
    grid-template-columns: 1fr;
  }
}

.edit-details {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px 14px;
  background: rgba(255, 255, 255, 0.45);
}

.edit-details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--muted);
  padding: 12px 0;
  list-style: none;
}

.edit-details summary::-webkit-details-marker {
  display: none;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-row .btn.primary {
  flex: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s var(--ease);
  max-width: min(90vw, 420px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.app-dialog {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.app-dialog[hidden] {
  display: none !important;
}

.app-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 46, 40, 0.42);
  animation: dialogFade 0.2s ease both;
}

.app-dialog-sheet {
  position: relative;
  width: min(100%, 440px);
  max-height: min(82vh, 560px);
  margin: 0;
  padding: 10px 18px calc(16px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: #fff;
  box-shadow: 0 -12px 40px rgba(26, 46, 40, 0.18);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: dialogUp 0.28s var(--ease) both;
  overflow: hidden;
}

.app-dialog-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(26, 46, 40, 0.14);
  margin: 2px auto 4px;
  flex-shrink: 0;
}

.app-dialog-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.app-dialog-body {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.55;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre-wrap;
  word-break: break-word;
}

.app-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 4px;
  flex-shrink: 0;
}

.app-dialog-actions .btn {
  min-height: 46px;
  font-weight: 700;
}

.app-dialog-actions .btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.app-dialog.is-closing .app-dialog-backdrop {
  animation: dialogFadeOut 0.18s ease both;
}

.app-dialog.is-closing .app-dialog-sheet {
  animation: dialogDown 0.18s ease both;
}

@keyframes dialogFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes dialogFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes dialogUp {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

@keyframes dialogDown {
  from { transform: none; opacity: 1; }
  to { transform: translateY(28px); opacity: 0; }
}

@media (min-width: 721px) {
  .app-dialog {
    align-items: center;
    padding: 24px;
  }

  .app-dialog-sheet {
    border-radius: 20px;
    padding: 22px 22px 18px;
    max-height: min(70vh, 480px);
    animation-name: dialogPop;
  }

  .app-dialog-handle {
    display: none;
  }

  .app-dialog.is-closing .app-dialog-sheet {
    animation-name: dialogPopOut;
  }
}

@keyframes dialogPop {
  from { transform: scale(0.96) translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes dialogPopOut {
  from { transform: none; opacity: 1; }
  to { transform: scale(0.96) translateY(8px); opacity: 0; }
}

.photo-edit-row {
  display: flex;
  gap: 8px;
  margin: -4px 0 12px;
  flex-wrap: wrap;
}

.crop-dialog {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.crop-dialog[hidden] {
  display: none !important;
}

.crop-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 46, 40, 0.5);
}

.crop-dialog-sheet {
  position: relative;
  width: min(100%, 480px);
  max-height: min(94vh, 720px);
  margin: 0;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: #fff;
  box-shadow: 0 -12px 40px rgba(26, 46, 40, 0.2);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.crop-hint {
  margin: -4px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.crop-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 16px;
  overflow: hidden;
  background: #111;
  touch-action: none;
  user-select: none;
}

#crop-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.crop-zoom-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.crop-zoom-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.crop-zoom-row .crop-rotate-deg {
  min-width: 2.6rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.75rem;
}

.crop-rotate-row {
  grid-template-columns: auto 1fr auto;
}

.crop-step {
  min-width: 36px;
  padding: 6px 0 !important;
}

.crop-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.edit-med-sheet {
  max-height: min(92vh, 760px);
}

.edit-med-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  max-height: calc(92vh - 88px);
}

.edit-med-form .field span {
  font-size: 0.78rem;
}

.edit-med-form .app-dialog-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent, #fff 28%);
  padding-top: 10px;
  margin-top: 4px;
}

@media (min-width: 721px) {
  .crop-dialog {
    align-items: center;
    padding: 24px;
  }

  .crop-dialog-sheet {
    border-radius: 20px;
    padding: 18px 20px 16px;
  }

  .edit-med-form {
    max-height: min(70vh, 620px);
  }
}

.time-context {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.35;
}

/* —— 移动端：压缩顶栏与打卡区 —— */
@media (max-width: 900px) {
  .field-grid { grid-template-columns: 1fr; }

  body {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .topbar {
    max-width: none;
    padding: 6px 10px 4px;
    padding-top: calc(6px + env(safe-area-inset-top));
    gap: 8px;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(243, 247, 245, 0.96);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(26, 46, 40, 0.06);
    min-height: 48px;
  }

  .brand { gap: 8px; min-width: 0; flex: 1; align-items: center; }

  .brand-mark {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 9px;
    box-shadow: 0 3px 10px rgba(15, 122, 95, 0.28);
  }

  .brand-text { min-width: 0; flex: 1; }

  .brand h1 {
    font-size: 0.98rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-sub {
    margin-top: 1px;
    font-size: 0.66rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
  }

  #btn-back-courses {
    display: inline-flex !important;
    align-items: center;
    padding: 6px 10px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    border: 1px solid rgba(15, 122, 95, 0.28);
    background: rgba(15, 122, 95, 0.08);
    border-radius: 999px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  #btn-back-courses[hidden] { display: none !important; }

  #app-title { cursor: pointer; }

  .btn.compact { padding: 6px 10px; font-size: 0.75rem; }

  /* 移动端：顶部导航折叠成菜单 */
  .nav-toggle {
    display: inline-flex !important;
  }

  .nav-toggle[hidden] {
    display: none !important;
  }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(26, 46, 40, 0.35);
  }

  .nav-backdrop[hidden] {
    display: none !important;
  }

  .tabs,
  .top-nav {
    position: fixed;
    left: 10px;
    right: 10px;
    top: calc(56px + env(safe-area-inset-top));
    width: auto;
    max-width: none;
    margin: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 8px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: #fff;
    box-shadow: 0 16px 40px rgba(26, 46, 40, 0.18);
    transform-origin: top center;
    animation: navDrop 0.18s ease both;
  }

  .tabs[hidden],
  .top-nav[hidden] {
    display: none !important;
  }

  body.nav-open .tabs:not([hidden]),
  body.nav-open .top-nav:not([hidden]) {
    display: grid !important;
  }

  body:not(.nav-open) .tabs:not([hidden]),
  body:not(.nav-open) .top-nav:not([hidden]) {
    display: none !important;
  }

  .tab {
    font-size: 0.95rem;
    padding: 14px 12px;
    border-radius: 12px;
    text-align: left;
  }

  main { padding: 4px 8px 24px; }

  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }

  .achievement,
  .achievement-today {
    flex-direction: row !important;
    text-align: left !important;
    gap: 8px;
    padding: 6px 8px;
    margin-bottom: 6px;
    border-radius: 12px;
  }

  .ach-ring { width: 40px; height: 40px; }
  .ring-bg, .ring-fg { stroke-width: 10; }
  .ach-pct { font-size: 0.62rem; }
  .ach-date { margin: 0; font-size: 0.65rem; }
  .ach-copy h2 {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .ach-meta { display: none; }

  .time-context {
    margin-bottom: 4px;
    padding: 4px 8px;
    font-size: 0.68rem;
    border-radius: 8px;
  }

  .meal-tabs {
    margin-bottom: 6px;
    padding: 3px;
    gap: 2px;
    border-radius: 10px;
  }
  .meal-tab { padding: 5px 2px 4px; border-radius: 8px; }
  .meal-tab strong { font-size: 0.78rem; }
  .meal-tab span { display: none; }

  .tips { margin-bottom: 4px; gap: 4px; }
  .tip { padding: 5px 8px; font-size: 0.7rem; border-radius: 8px; line-height: 1.3; }

  .day-board { gap: 6px; }
  .meal-block { border-radius: 12px; }
  .view-today .meal-title { display: none; }

  .meal-title { padding: 6px 10px; font-size: 0.72rem; }
  .meal-guide,
  .meal-guide.compact { padding: 6px 10px; font-size: 0.72rem; line-height: 1.35; }

  .meal-phase-divider { padding: 8px 6px; gap: 8px; }
  .meal-phase-copy { min-width: 5rem; }
  .meal-phase-copy strong { font-size: 1.05rem; letter-spacing: 0.06em; }
  .meal-phase-copy span { display: none; }

  .dose-item {
    display: grid;
    grid-template-columns: 118px 1fr;
    grid-template-areas:
      "media body"
      "media action";
    gap: 10px 12px;
    padding: 12px;
    align-items: start;
  }

  .dose-media {
    grid-area: media;
    width: 118px;
  }

  .dose-thumb {
    width: 118px;
    height: 118px;
    border-radius: 18px;
    display: block;
  }

  .water-inline {
    display: none !important;
  }

  .dose-media .water-on-thumb {
    display: block;
    position: absolute;
    left: 50%;
    bottom: 8px;
    transform: translateX(-50%);
    z-index: 2;
    max-width: calc(100% - 12px);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.92rem;
    font-weight: 900;
    padding: 7px 14px;
    border-radius: 999px;
    letter-spacing: 0.08em;
    border-width: 2px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
    white-space: nowrap;
  }

  .water-badge.hot {
    color: #fff;
    background: linear-gradient(135deg, #ff6b4a, #d62828);
    border-color: rgba(255, 255, 255, 0.35);
  }

  .water-badge.warm {
    color: #fff;
    background: linear-gradient(135deg, #ffb347, #e67e22);
    border-color: rgba(255, 255, 255, 0.35);
  }

  .water-badge.cool {
    color: #fff;
    background: linear-gradient(135deg, #5dade2, #2874a6);
    border-color: rgba(255, 255, 255, 0.35);
  }

  .water-badge.any {
    color: #fff;
    background: linear-gradient(135deg, #7f8c8d, #566573);
    border-color: rgba(255, 255, 255, 0.35);
  }

  .dose-body {
    grid-area: body;
    min-width: 0;
  }

  .dose-name {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    line-height: 1.3;
  }

  .dose-dose {
    margin: 4px 0 0;
    font-size: 0.8rem;
  }

  .dose-meta-row { display: none; }

  .dose-ai-tip {
    margin-top: 8px;
    padding: 8px 10px;
    font-size: 0.78rem;
    border-radius: 10px;
    line-height: 1.4;
  }

  .dose-ai-mark {
    font-size: 0.66rem;
    padding: 1px 6px;
    margin-right: 4px;
  }

  .dose-defer-tag { margin-top: 4px; font-size: 0.72rem; }
  .dose-defer-tag.soft { display: block; }

  .dose-how {
    margin-top: 6px;
    font-size: 0.74rem;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .dose-timer { margin-top: 6px; font-size: 0.72rem; padding: 5px 8px; border-radius: 8px; }

  .dose-badge {
    grid-area: action;
    justify-self: end;
    align-self: end;
    font-size: 0.88rem;
    font-weight: 800;
    padding: 10px 16px;
    border-radius: 999px;
    min-width: 4.5rem;
    text-align: center;
  }

  .empty.compact { padding: 12px 8px; font-size: 0.8rem; }

  .section-head { margin: 4px 0 8px; }
  .section-head h2 { font-size: 1.05rem; }
  .section-head p { font-size: 0.74rem; margin: 2px 0 0; }

  .med-card { grid-template-columns: 72px minmax(0, 1fr); gap: 10px; padding: 10px; }
  .med-card img,
  .med-card .thumb-ph,
  .med-thumb-wrap,
  .med-thumb-wrap img,
  .med-thumb-wrap .thumb-ph {
    width: 72px;
    height: 72px;
    max-width: 72px;
    border-radius: 16px;
  }

  .med-thumb-edit {
    right: 3px;
    bottom: 3px;
    padding: 2px 5px;
    font-size: 0.58rem;
    border-radius: 6px;
  }
}

