:root {
  color-scheme: light;
  --ground: #f7f8f7;
  --surface: #fff;
  --subtle: #f0f2ef;
  --hover: #e9ede8;
  --ink: #222622;
  --muted: #526057;
  --line: #dbdfda;
  --control-line: #9aa79b;
  --accent: #b8d8ae;
  --accent-hover: #a8cda0;
  --accent-ink: #173928;
  --accent-track: #47764e;
  --accent-text: #285c39;
  --next-surface: #eaf2e8;
  --next-line: #d3e3d0;
  --brand: #174737;
  --error: #932f29;
  --error-surface: #f9ecea;
  --overlay: #10171180;
  --elevation: #10171127;
  font: 400 100%/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--ground);
  -webkit-tap-highlight-color: transparent;
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --ground: #181a19;
  --surface: #222524;
  --subtle: #2c302d;
  --hover: #353a36;
  --ink: #f3f5f1;
  --muted: #b5c1b7;
  --line: #3c433e;
  --control-line: #77847a;
  --accent: #bad9ae;
  --accent-hover: #c9e3bf;
  --accent-ink: #163020;
  --accent-track: #a5cf9a;
  --accent-text: #bcdfb5;
  --next-surface: #242f27;
  --next-line: #3d5042;
  --brand: #f0f5ef;
  --error: #f6b7ae;
  --error-surface: #412a27;
  --overlay: #080a09b8;
  --elevation: #080a0966;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
::selection { color: var(--accent-ink); background: var(--accent); }
button, input, a { font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent-track); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.19rem; line-height: 1.25; letter-spacing: -.025em; font-weight: 650; }
h3 { font-size: 1rem; line-height: 1.25; font-weight: 650; }
p { color: var(--muted); }
.frame { width: min(1080px, 100% - max(48px, env(safe-area-inset-left) + env(safe-area-inset-right))); margin-inline: auto; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.top-inner { min-height: 68px; display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 16px; }
.brand { display: inline-flex; min-height: 44px; align-items: center; gap: 9px; color: var(--brand); white-space: nowrap; text-decoration: none; font: 750 1.43rem/1 ui-rounded, 'Trebuchet MS', system-ui, sans-serif; letter-spacing: -.045em; }
.brand, .theme-picker { justify-self: start; }
.theme-picker { justify-self: end; }
.brand img { display: block; border-radius: 8px; }
.main-nav { display: flex; align-items: center; gap: 5px; }
.main-nav a, .main-nav button { display: flex; align-items: center; min-height: 44px; padding: 6px 11px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; text-decoration: none; font-size: .94rem; font-weight: 600; }
.main-nav button[aria-expanded='true'] { color: var(--ink); background: var(--subtle); }
.theme-picker { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--subtle); }
.theme-picker button { min-height: 44px; padding: 6px 11px; border-radius: 7px; border: 1px solid transparent; background: transparent; color: var(--muted); font-size: .875rem; line-height: 1.1; font-weight: 550; }
.theme-picker button[aria-pressed='true'] { background: var(--surface); color: var(--ink); border-color: var(--line); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 8px 14px; border: 1px solid var(--control-line); border-radius: 8px; color: var(--ink); background: var(--surface); font-size: .91rem; line-height: 1.15; text-align: center; font-weight: 650; }
.button.primary { color: var(--accent-ink); background: var(--accent); border-color: transparent; }
.button.secondary { border-color: var(--line); }
.button.danger { color: var(--error); background: var(--error-surface); border-color: var(--error); }
.button.small { padding-inline: 10px; }
.plus { width: 14px; height: 14px; position: relative; display: inline-block; font-size: 0; }
.plus::before, .plus::after { content: ''; position: absolute; inset: 6px 0 auto; height: 2px; border-radius: 2px; background: currentColor; }
.plus::after { transform: rotate(90deg); }
.bullet-check { display: inline-block; width: 12px; height: 7px; border: solid currentColor; border-width: 0 0 2px 2px; transform: rotate(-45deg) translateY(-2px); }
main { padding-top: 39px; }
.title-row { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
h1 { font-size: 2rem; letter-spacing: -.039em; line-height: 1.15; font-weight: 690; }
.page-date { margin-top: 6px; }
.dashboard { display: grid; grid-template-columns: minmax(0, 2.25fr) minmax(0, 1fr); align-items: start; gap: 18px; }
.journal, .side { display: grid; gap: 14px; min-width: 0; }
.panel { min-width: 0; padding: 18px 21px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); scroll-margin-block-start: 16px; }
.treatments { grid-column: 1 / -1; }
.section-bar { display: flex; align-items: center; justify-content: space-between; min-height: 30px; gap: 10px; }
.section-bar > span, .day-heading > span { color: var(--muted); font-size: .88rem; text-align: right; }
.week-panel { padding-block: 11px 13px; }
.week-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.week-heading h2 { font-size: 1rem; }
.week-controls { display: flex; align-items: center; gap: 2px; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day-arrow, .day, .close { display: grid; place-content: center; min-width: 0; min-height: 44px; padding: 0; border: 0; border-radius: 7px; color: var(--ink); background: transparent; }
.day-arrow { min-width: 44px; }
.day-arrow span { display: block; width: 8px; height: 8px; border: solid currentColor; border-width: 0 0 2px 2px; transform: rotate(45deg); }
.day-arrow[data-action='next'] span { transform: rotate(225deg); }
.close { min-width: 44px; font-size: 1.6rem; line-height: 1; }
.day { min-height: 65px; justify-items: center; gap: 2px; padding: 5px 0; line-height: 1.3; }
.day[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }
.day[aria-current='date'] .day-number { text-decoration: underline; text-underline-offset: 4px; }
.day-name { color: var(--muted); font-size: .82rem; }
.day[aria-pressed='true'] .day-name { color: inherit; }
.day-number { font-size: 1.06rem; font-variant-numeric: tabular-nums; font-weight: 650; }
.day-marker { width: 5px; height: 5px; border-radius: 50%; }
.day[data-doses='planned'] .day-marker { background: currentColor; opacity: .53; }
.day[data-doses='complete'] .day-marker { width: 8px; height: 5px; border: solid var(--accent-text); border-width: 0 0 2px 2px; border-radius: 0; transform: rotate(-45deg); }
.day[aria-pressed='true'][data-doses='complete'] .day-marker { border-color: currentColor; }
.day-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.day-heading h2 { min-width: 0; }
#day-progress { display: block; appearance: none; width: 100%; height: 7px; margin-top: 14px; border: 0; border-radius: 5px; background: var(--subtle); color: var(--accent-track); }
#day-progress::-webkit-progress-bar { border-radius: 5px; background: var(--subtle); }
#day-progress::-webkit-progress-value { border-radius: 5px; background: var(--accent-track); }
#day-progress::-moz-progress-bar { border-radius: 5px; background: var(--accent-track); }
#dose-list { margin-top: 13px; }
.empty { display: grid; align-content: center; min-height: 68px; gap: 4px; padding: 8px 0; }
.empty strong { font-weight: 600; }
.start { justify-items: start; gap: 7px; min-height: 170px; padding: 18px 0 8px; }
.start strong { font-size: 1.13rem; }
.start p { max-width: 42ch; }
.start .button { margin-top: 6px; }
.next { background: var(--next-surface); border-color: var(--next-line); }
.next-slot { display: flex; flex-wrap: wrap; align-items: baseline; gap: 5px 8px; margin: 12px 0 5px; }
.next-time { color: var(--accent-text); font-size: 2rem; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.035em; }
.next-day { font-size: .875rem; }
.next-name { color: var(--ink); font-weight: 650; overflow-wrap: anywhere; }
.reminders p, .setting p { margin-top: 7px; }
.reminders button, .setting button, #history-more { margin-top: 10px; }
.dose-row, .plan-row, .history-row { display: grid; align-items: center; gap: 12px; padding: 10px 0; }
.dose-row { grid-template-columns: 5ch minmax(0, 1fr) auto; column-gap: 23px; min-height: 54px; border-top: 1px solid var(--line); }
.dose-time::after { content: ''; position: absolute; top: 50%; left: calc(100% + 7px); width: 7px; height: 7px; border: 1px solid var(--control-line); border-radius: 50%; transform: translateY(-50%); }
.due .dose-time::after { background: var(--accent-track); border-color: var(--accent-track); }
.recorded .dose-time::after { border-color: var(--accent-track); }
.dose-row:last-child, .plan-row:last-child, .history-row:last-child { padding-bottom: 0; }
.plan-row, .history-row { grid-template-columns: minmax(0, 1fr) auto; }
.plan-row + .plan-row, .history-row + .history-row { border-top: 1px solid var(--line); }
.dose-time { position: relative; align-self: center; font-weight: 650; font-variant-numeric: tabular-nums; }
.row-title { display: block; overflow-wrap: anywhere; font-weight: 650; }
.meta { overflow-wrap: anywhere; color: var(--muted); font-size: .875rem; }
.status { font-size: .84rem; color: var(--muted); }
.status.done { display: inline-flex; align-items: center; gap: 7px; color: var(--accent-text); font-weight: 650; }
.row-actions { display: flex; flex-wrap: wrap; gap: 5px 9px; justify-content: end; align-items: center; }
.text-action { min-height: 44px; padding: 4px 5px; border: 0; border-radius: 6px; color: var(--accent-text); background: transparent; font-size: .9rem; font-weight: 650; text-align: left; text-decoration: underline; text-underline-offset: .18em; }
footer { padding: 19px 0 calc(25px + env(safe-area-inset-bottom)); color: var(--muted); font-size: .875rem; }
.auth-frame { display: grid; justify-items: center; padding-block: clamp(32px, 8vw, 84px); }
.auth-card { width: min(100%, 450px); padding: 25px; }
.auth-card > p, .auth-card form { margin-top: 12px; }
.auth-card form > .button { width: 100%; margin-top: 16px; }
.auth-actions { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; }
.account-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; overflow-wrap: anywhere; }
#account-email { color: var(--ink); font-weight: 650; }
.import-panel { margin-bottom: 16px; }
.import-panel p { margin-block: 6px 10px; }
dialog { width: min(520px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: 20px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--surface); overflow: auto; overscroll-behavior: contain; }
dialog::backdrop { background: var(--overlay); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.dialog-heading h2 { font-size: 1.35rem; }
label { display: block; min-width: 0; font-size: .94rem; font-weight: 650; }
form > label + label, .form-grid { margin-top: 13px; }
.first-dose { min-width: 0; margin: 14px 0 0; padding: 5px 12px 12px; border: 1px solid var(--line); border-radius: 9px; }
.first-dose legend { padding-inline: 4px; color: var(--muted); font-size: .875rem; }
.first-dose .form-grid { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
input { display: block; width: 100%; min-width: 0; min-height: 44px; margin-top: 5px; padding: 7px 10px; border: 1px solid var(--control-line); border-radius: 8px; color: var(--ink); background: var(--surface); font-size: 1rem; }
.optional, .help { color: var(--muted); font-size: .875rem; font-weight: 400; }
form > .help, .form-preview, .error { margin-top: 9px; }
.form-preview, .error { padding: 9px 11px; border-radius: 8px; background: var(--subtle); font-size: .91rem; }
.error { color: var(--error); background: var(--error-surface); }
#storage-error { margin: 0 0 14px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 8px; margin-top: 17px; }
.record-medicine { color: var(--ink); font-weight: 650; overflow-wrap: anywhere; }
.record-actions .remove-record { margin-right: auto; color: var(--error); }
.delete-plan { color: var(--error); }
#delete-calendar-note { margin-top: 9px; }
.setting + .setting { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.notice { position: fixed; z-index: 2; bottom: calc(16px + env(safe-area-inset-bottom)); right: 16px; width: min(370px, calc(100% - 32px)); display: flex; align-items: start; justify-content: space-between; gap: 8px; padding: 9px 9px 9px 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: var(--surface); box-shadow: 0 7px 22px var(--elevation); overflow-wrap: anywhere; }
#notice-body { padding-top: 8px; }
#notice-body p + p { margin-top: 5px; }
button:not(:disabled):active { filter: brightness(.91); }
@media (hover: hover) and (pointer: fine) {
  .button:not(:disabled):hover, .day-arrow:hover, .day:not([aria-pressed='true']):hover, .close:hover, .text-action:hover, .main-nav a:hover, .main-nav button:hover, .theme-picker button:not([aria-pressed='true']):hover { background: var(--hover); }
  .button.primary:not(:disabled):hover { background: var(--accent-hover); }
}
@media (max-width: 900px) {
  .dashboard { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .frame { width: calc(100% - 32px); }
  .top-inner { grid-template-columns: 1fr auto; gap: 0 10px; padding-block: 5px 0; }
  .brand { font-size: 1.32rem; gap: 6px; }
  .brand img { width: 32px; height: 32px; }
  .main-nav { grid-column: 1 / -1; grid-row: 2; gap: 2px; margin-top: 2px; }
  .main-nav a:first-child { padding-left: 0; }
  main { padding-top: 24px; }
  h1 { font-size: 1.72rem; }
  .title-row { align-items: start; margin-bottom: 14px; }
  .add-detail { display: none; }
  .page-date { font-size: .9rem; }
  .panel { padding: 13px 14px; border-radius: 12px; }
  .week-panel { padding-block: 6px 9px; }
  .week { gap: 3px; }
  .day { min-height: 53px; }
  .day-name { font-size: .75rem; }
  .side { grid-template-columns: 1fr; }
  .dose-row { column-gap: 18px; }
  .dose-time::after { left: calc(100% + 4px); }
  .row-actions { gap: 0 6px; }
  .dose-row.recorded, .dose-row.due { grid-template-columns: 5ch minmax(0, 1fr); row-gap: 2px; }
  .dose-row.recorded .row-actions, .dose-row.due .row-actions { grid-column: 2 / -1; justify-content: start; gap: 2px 9px; }
  .dose-row .row-actions .text-action { padding-right: 0; }
  .dose-row .button { padding-inline: 8px; }
  .plan-row { grid-template-columns: 1fr; gap: 4px; }
  .plan-row .row-actions { justify-content: start; }
  dialog { padding: 14px; }
}
@media (max-width: 355px) {
  .frame { width: calc(100% - 24px); }
  .day-name { font-size: .72rem; }
  .form-grid { grid-template-columns: 1fr; }
  .day-heading > span { white-space: nowrap; }
  .dose-row { grid-template-columns: 5ch minmax(0, 1fr); row-gap: 2px; }
  .dose-row .row-actions { grid-column: 2 / -1; justify-content: start; }
}
