:root {
  --bg: #fff4f6;
  --surface: #ffffff;
  --surface-soft: #fbe6ec;
  --ink: #3d2230;
  --muted: #7d5566;
  --line: #f0cfd9;
  --rose: #c9486f;
  --rose-deep: #a32350;
  --rose-dry: #c98a9b;
  --danger: #b3261e;
  --radius: 16px;
  --shadow: 0 4px 14px rgba(163, 35, 80, .1);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 18px; color: var(--rose-deep); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }

input, select, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=color]), select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
input[type=time] { display: block; min-width: 0; }
input[type=color] {
  width: 100%;
  height: 44px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
:focus-visible { outline: 2px solid var(--rose); outline-offset: 2px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 16px;
  color: var(--ink);
}
label.check input { width: 22px; height: 22px; accent-color: var(--rose); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--rose-dry);
  border-radius: 14px;
  color: var(--rose-deep);
  font-weight: 600;
  font-size: 16px;
  text-align: center;
  cursor: pointer;
}
.btn.primary { background: var(--rose); border-color: var(--rose); color: #fff; }
.btn.danger { border-color: transparent; background: transparent; color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: linear-gradient(170deg, #fbdde5, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 360px;
  display: grid;
  gap: 14px;
  padding: 28px 22px;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card label { text-align: left; }
.login-card h1 { color: var(--rose-deep); font-size: 26px; }
.login-card p { margin: 0; }
.login-heart { font-size: 42px; line-height: 1; color: var(--rose); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
  background: var(--bg);
}
.topbar h1 { font-size: 24px; color: var(--rose-deep); }
.progress { color: var(--muted); font-size: 14px; }

main { padding-bottom: calc(env(safe-area-inset-bottom) + 84px); }
.view { display: grid; gap: 12px; padding: 0 16px; }
#view-program { padding: 0; }

.day-chips {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 52px);
  z-index: 4;
  display: flex;
  gap: 6px;
  padding: 2px 16px 8px;
  overflow-x: auto;
  background: var(--bg);
  scrollbar-width: none;
}
.day-chips::-webkit-scrollbar { display: none; }
.day-chip {
  flex: 1 0 auto;
  min-width: 44px;
  min-height: 40px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.day-chip.today { border-color: var(--rose); color: var(--rose-deep); }
.day-chip.active { background: var(--rose); border-color: var(--rose); color: #fff; }

.days {
  display: flex;
  align-items: flex-start;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.days::-webkit-scrollbar { display: none; }
.day {
  flex: 0 0 100%;
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 4px 16px;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}
.day h2 { font-size: 17px; }

.block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  border-left: 5px solid var(--color, var(--rose-dry));
  box-shadow: var(--shadow);
}
.block.done { background: var(--surface-soft); box-shadow: none; }
.block.done .block-name { text-decoration: line-through; color: var(--muted); }
.block-body {
  min-width: 0;
  padding: 10px 2px 6px 12px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}
.done-btn {
  grid-column: 1 / -1;
  min-height: 44px;
  margin: 0 8px 8px;
  background: var(--surface-soft);
  border: 0;
  border-radius: 12px;
  color: var(--rose-deep);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.block.done .done-btn { background: var(--rose); color: #fff; }
.block-name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.block-meta { display: block; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--rose-dry);
  font-size: 22px;
  cursor: pointer;
}
.icon-btn.on { color: var(--rose); }
.bell { font-size: 18px; }
.bell.off { filter: grayscale(1); opacity: .4; }

.add-block {
  min-height: 46px;
  background: none;
  border: 1.5px dashed var(--rose-dry);
  border-radius: var(--radius);
  color: var(--rose-deep);
  font-weight: 600;
  cursor: pointer;
}

.card {
  display: grid;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card p { margin: 0; }
.hint { padding: 10px 12px; background: var(--surface-soft); border-radius: 12px; font-size: 14px; }
.upload { position: relative; color: var(--rose-deep); font-size: 16px; }

.list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: left;
}
.list-item > .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
button.list-item { cursor: pointer; }
.swatch { flex: none; width: 20px; height: 20px; border-radius: 50%; background: var(--color); }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar button {
  display: grid;
  justify-items: center;
  gap: 1px;
  min-height: 56px;
  padding: 6px 0;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.tabbar button span { font-size: 19px; line-height: 1.2; }
.tabbar button.active { color: var(--rose-deep); font-weight: 700; }

.sheet {
  width: min(480px, calc(100vw - 24px));
  max-height: 88vh;
  padding: 20px 16px;
  background: var(--surface);
  border: 0;
  border-radius: 22px;
  color: var(--ink);
}
.sheet::backdrop, .viewer::backdrop { background: rgba(61, 34, 48, .45); }
.sheet form, .sheet-body { display: grid; gap: 12px; }
.sheet-body { text-align: center; }
.sheet-body p { margin: 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }

.viewer {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  background: var(--bg);
  border: 0;
  color: var(--ink);
}
.viewer[open] { display: flex; flex-direction: column; }
.viewer header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.viewer header strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-pages {
  flex: 1;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.pdf-pages canvas { display: block; width: 100%; height: auto; background: #fff; border-radius: 6px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 72px);
  z-index: 20;
  max-width: 420px;
  margin: 0 auto;
  padding: 12px 16px;
  background: var(--ink);
  border-radius: 14px;
  color: #fff;
  text-align: center;
}

.program-top { display: grid; gap: 8px; padding: 0 16px 8px; }
.note-card {
  padding: 12px 14px;
  background: var(--surface-soft);
  border-radius: var(--radius);
}
.note-card p { margin: 0; }
.note-title { margin-bottom: 4px; font-size: 15px; }
#daily-note { color: var(--ink); font-size: 16px; }
#streak-line { margin-top: 4px; color: var(--rose-deep); font-weight: 600; }
.review-banner {
  min-height: 44px;
  padding: 8px 14px;
  background: var(--rose);
  border: 0;
  border-radius: 14px;
  color: #fff;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat {
  display: grid;
  justify-items: center;
  padding: 12px 4px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.stat strong { color: var(--rose-deep); font-size: 26px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.small-btn { flex: none; min-height: 40px; padding: 6px 12px; font-size: 14px; }

.badges { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.badge {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 1px;
  padding: 10px 4px;
  background: var(--bg);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.badge.earned { background: var(--surface-soft); color: var(--ink); }
.badge-heart { color: var(--rose-dry); font-size: 22px; line-height: 1.1; }
.badge.earned .badge-heart { color: var(--rose); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
th { color: var(--muted); font-weight: 600; }
th:first-child, td:first-child { text-align: left; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: var(--surface-soft); border-radius: 12px; }
.segmented button {
  min-height: 38px;
  background: none;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.segmented button.active { background: var(--surface); color: var(--rose-deep); }

.chart svg { display: block; width: 100%; height: auto; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; }
.chart-line { fill: none; stroke: var(--rose); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--rose); stroke: var(--surface); stroke-width: 2; }
.chart-hit { fill: transparent; cursor: pointer; }
.chart-value { fill: var(--ink); font-size: 12px; font-weight: 700; }

.topic-groups { display: grid; gap: 8px; }
details {
  padding: 0 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
details[open] { padding-bottom: 12px; }
summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  font-weight: 600;
  cursor: pointer;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "›"; color: var(--rose-dry); font-size: 20px; }
details[open] summary::after { transform: rotate(90deg); }
.grow-text { flex: 1; min-width: 0; }
.topic-list { margin: 0 0 8px; padding: 0; list-style: none; }
.topic {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 124px 36px;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}
.topic-name { display: grid; overflow-wrap: anywhere; font-size: 15px; }
.topic select { min-height: 40px; padding: 6px 8px; font-size: 14px; }
.topic-done .topic-name > span:first-child { color: var(--rose-deep); font-weight: 600; }
.topic-review .block-meta { color: var(--rose-deep); }
.topic .icon-btn { width: 36px; font-size: 15px; }
.add-block.wide { width: 100%; }

.row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.exam-sections { display: grid; gap: 8px; }
fieldset { margin: 0; padding: 8px 10px 10px; border: 1px solid var(--line); border-radius: 12px; }
legend { padding: 0 4px; color: var(--rose-deep); font-size: 14px; font-weight: 600; }
.sheet { overflow-y: auto; }

@media (min-width: 1100px) {
  main { max-width: 1400px; margin: 0 auto; }
  .day-chips { display: none; }
  .days { overflow: visible; }
  .day { flex: 1 1 0; padding: 4px 6px; }
  #view-subjects, #view-pdf, #view-settings, #view-track, #view-topics { max-width: 560px; margin: 0 auto; }
  .program-top { max-width: 700px; width: 100%; margin: 0 auto; }
}
