:root {
  color-scheme: light;
  --background: #f4f1e8;
  --card: #fbfaf6;
  --field: #f0eee7;
  --text: #2d332f;
  --muted: #7b817c;
  --line: #deddd6;
  --green: #5d7f6d;
  --green-soft: #dce9df;
  --nav-background: rgba(251, 250, 246, 0.96);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-theme="eye-care"] {
  --background: #e7eadf;
  --card: #f2f3ec;
  --field: #e9ece3;
  --text: #31352f;
  --muted: #777d73;
  --line: #d5d9cf;
  --green: #647565;
  --green-soft: #dfe5da;
  --nav-background: rgba(242, 243, 236, 0.96);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  background: var(--background);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body { min-width: 320px; min-height: 100vh; margin: 0; color: var(--text); background: var(--background); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 10px calc(68px + env(safe-area-inset-bottom));
}

.topbar, .section-heading, .dialog-heading, .record-row, .period-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
}

.topbar { min-height: 32px; margin: 0 1px 4px; }
h1 { margin: 0; font-size: 1.08rem; letter-spacing: -0.03em; }
h2 { margin: 0; font-size: 0.78rem; }
h3 { margin: 0 0 7px; font-size: 0.76rem; }
p { margin: 0; }

.icon-button, .nav-arrow {
  border: 1px solid var(--line);
  background: transparent;
}
.icon-button { width: 30px; height: 30px; border-radius: 9px; font-size: 0.92rem; }

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

.period-nav {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.nav-arrow { width: 32px; height: 32px; border-radius: 9px; font-size: 1.15rem; }
.period-title { min-height: 32px; border: 0; background: transparent; text-align: center; }
.period-title strong, .period-title span { display: block; }
.period-title strong { font-size: 0.8rem; }
.period-title span { margin-top: 1px; color: var(--muted); font-size: 0.58rem; }

.compact-stack { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 5px; }
.plan-card, .review-card { grid-column: 1 / -1; }
.section-card, .period-summary-card, .record-list {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
}
.section-card, .period-summary-card { padding: 9px; }
.section-label { display: block; margin-bottom: 5px; font-size: 0.78rem; font-weight: 700; }

textarea, input[type="time"], .headline-input, .habit-editor input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  outline: none;
  background: var(--field);
}
textarea { display: block; padding: 7px 8px; resize: none; overflow-y: hidden; font-size: 0.73rem; line-height: 1.45; }
textarea:focus, input:focus { border-color: var(--green); }
.headline-input { min-height: 31px; padding: 5px 7px; font-size: 0.71rem; }
.detail-label { margin-top: 8px; }
.large-textarea { min-height: clamp(124px, calc(100dvh - 500px), 340px); }
.period-textarea { min-height: 112px; }

.time-grid { display: grid; grid-template-columns: 1fr; gap: 5px; margin-top: 6px; }
.time-grid label { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 5px; color: var(--muted); font-size: 0.62rem; }
input[type="time"] { min-width: 0; min-height: 30px; padding: 3px 5px; font-size: 0.7rem; }

.small-button { padding: 3px 5px; border: 0; color: var(--muted); background: transparent; font-size: 0.62rem; }
.habit-list { display: grid; grid-template-columns: 1fr; gap: 4px; margin-top: 6px; }
.habit-item {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 29px;
  padding: 4px 6px;
  border-radius: 8px;
  background: var(--field);
  cursor: pointer;
  user-select: none;
}
.habit-item input { width: 15px; height: 15px; margin: 0; flex: 0 0 auto; accent-color: var(--green); }
.habit-item span { overflow: hidden; font-size: 0.69rem; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { padding: 4px 0; color: var(--muted); font-size: 0.65rem; }

.add-plan-button { color: var(--green); }
.plan-list { display: grid; gap: 4px; margin-top: 6px; }
.plan-empty { padding: 5px 1px 2px; color: var(--muted); font-size: 0.65rem; }
.plan-item {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 20px 22px;
  align-items: center;
  gap: 4px;
  min-height: 31px;
  padding: 3px 4px;
  border-radius: 8px;
  background: var(--field);
}
.plan-number { color: var(--muted); text-align: right; font-size: 0.65rem; }
.plan-item input[type="text"] { min-width: 0; padding: 4px 2px; border: 0; outline: none; background: transparent; font-size: 0.71rem; }
.plan-item input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--green); }
.plan-item.completed input[type="text"] {
  color: #626c66;
  text-decoration-line: line-through;
  text-decoration-color: #454b47;
  text-decoration-thickness: 2px;
}
.delete-plan { width: 22px; height: 22px; padding: 0; border: 0; color: #aaa; background: transparent; font-size: 0.8rem; }

.period-summary-card { margin-bottom: 5px; }
.period-stats { justify-content: flex-start; margin-bottom: 7px; color: var(--muted); font-size: 0.62rem; }
.period-stats span + span::before { content: "·"; margin-right: 7px; color: #b2b4af; }

.record-list { overflow: hidden; }
.record-row { width: 100%; min-height: 44px; padding: 7px 9px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
.record-row:last-child { border-bottom: 0; }
.record-date { flex: 0 0 54px; color: var(--muted); font-size: 0.64rem; }
.record-content { min-width: 0; flex: 1; }
.record-content strong, .record-content span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-content strong { font-size: 0.71rem; font-weight: 600; }
.record-content span { margin-top: 2px; color: var(--muted); font-size: 0.6rem; }
.record-meta { flex: 0 0 auto; color: var(--muted); font-size: 0.6rem; }
.record-arrow { color: var(--muted); font-size: 0.9rem; }
.record-empty { padding: 18px 10px; color: var(--muted); text-align: center; font-size: 0.67rem; }
.month-row .record-date { flex-basis: 30px; }
.week-row .record-date { flex-basis: 68px; }

.bottom-nav {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 620px);
  min-height: calc(52px + env(safe-area-inset-bottom));
  margin: auto;
  padding: 5px 8px max(5px, env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  background: var(--nav-background);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.bottom-nav button { border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: 0.7rem; }
.bottom-nav button.active { color: var(--green); background: var(--green-soft); font-weight: 700; }
.bottom-nav span { display: block; }

dialog {
  width: min(calc(100% - 20px), 450px);
  max-height: calc(100vh - 30px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  color: var(--text);
  background: var(--card);
  box-shadow: 0 24px 70px rgba(38, 45, 40, 0.2);
}
dialog::backdrop { background: rgba(35, 40, 37, 0.35); }
.dialog-panel { padding: 13px; }
.dialog-heading { margin-bottom: 12px; }
.dialog-section { padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--line); }
.dialog-heading + .dialog-section { padding-top: 0; margin-top: 0; border-top: 0; }
.theme-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.theme-option {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--field);
  font-size: 0.7rem;
}
.theme-option[aria-checked="true"] { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); font-weight: 700; }
.theme-swatch { width: 18px; height: 18px; border: 1px solid rgba(45, 51, 47, 0.12); border-radius: 50%; }
.normal-swatch { background: #f4f1e8; }
.eye-care-swatch { background: #e7eadf; }
.cloud-section .section-heading { margin-bottom: 7px; }
.cloud-section h3 { margin: 0; }
.cloud-status { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 0.62rem; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #a4aaa5; }
.cloud-status[data-status="syncing"] .status-dot { background: #c69b54; }
.cloud-status[data-status="synced"] .status-dot { background: var(--green); }
.cloud-status[data-status="offline"] .status-dot,
.cloud-status[data-status="error"] .status-dot { background: #a96b62; }
.cloud-auth { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cloud-auth .settings-actions { grid-column: 1 / -1; }
.cloud-auth input {
  min-width: 0;
  min-height: 34px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  outline: none;
  background: var(--field);
  font-size: 0.7rem;
}
.cloud-auth input:focus { border-color: var(--green); }
.cloud-account { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cloud-account > span { min-width: 0; overflow: hidden; color: var(--muted); font-size: 0.67rem; text-overflow: ellipsis; white-space: nowrap; }
.habit-editor { display: grid; gap: 6px; }
.habit-edit-row { display: grid; grid-template-columns: 1fr 32px; gap: 6px; }
.habit-editor input { min-height: 34px; padding: 5px 7px; font-size: 0.72rem; }
.delete-habit { border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: transparent; }
.secondary-button { display: inline-grid; place-items: center; min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); font-size: 0.7rem; }
.full-button { width: 100%; margin-top: 7px; }
.settings-actions { display: flex; gap: 6px; }
.file-button { position: relative; overflow: hidden; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.import-message { min-height: 1em; margin-top: 6px; color: var(--green); font-size: 0.65rem; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(62px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px); max-width: calc(100% - 28px); padding: 8px 11px; border-radius: 999px; color: white; background: rgba(45, 51, 47, 0.94); font-size: 0.66rem; opacity: 0; pointer-events: none; transition: 150ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Keep every mobile label and control readable and prevent iOS focus zoom. */
@media (max-width: 767px) {
  body,
  body * {
    font-size: 16px !important;
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="time"],
  textarea {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
