:root {
  --bg: #f6f1e7; --card: #fffdf8; --ink: #262a33; --muted: #6b7080; --line: #e6dfd1; --soft: #ece6da;
  --acc: #3d5a80; --acc-ink: #fff; --sage: #5f8f72; --warm: #c9783f; --danger: #b3261e;
  --serif: Georgia, "Noto Serif", "Times New Roman", serif;
  --sans: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181e; --card: #1e222a; --ink: #ece8e0; --muted: #a0a5b2; --line: #2e333d; --soft: #262b35;
    --acc: #8fb0dc; --acc-ink: #10141a; --sage: #8cc2a0; --warm: #e8a070; --danger: #f2877c; color-scheme: dark;
  }
}
[hidden] { display: none !important; }   /* .sheet/.layer set display, which beats the attribute */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); }
body { min-height: 100dvh; overscroll-behavior-y: none; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
img { display: block; }

/* Shell */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: baseline; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.brand { font: italic 700 25px var(--serif); color: var(--acc); text-decoration: none; }
.topdate { font-size: 13px; color: var(--muted); font-weight: 600; }
main { max-width: 760px; margin: 0 auto; padding: 6px 16px calc(96px + env(safe-area-inset-bottom)); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
.tabs a { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; text-decoration: none;
  font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.tabs a span { font-size: 21px; line-height: 1.25; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--acc); }
.tabs a.on span { filter: none; opacity: 1; }

h1.page { font: 700 30px/1.15 var(--serif); margin: 4px 0 4px; }
h2.sec { font: 700 20px var(--serif); margin: 26px 0 10px; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; cursor: pointer; background: var(--soft); text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--acc); color: var(--acc-ink); }
.btn.ghost { background: none; color: var(--acc); padding-left: 6px; padding-right: 6px; }
.btn.danger { background: none; color: var(--danger); }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }

/* Today */
.hello { font: 700 27px/1.2 var(--serif); margin: 6px 0 2px; }
.course { display: flex; gap: 12px; align-items: center; text-decoration: none; background: linear-gradient(135deg, var(--acc), color-mix(in srgb, var(--acc) 70%, var(--sage)));
  color: #fff; border-radius: 18px; padding: 14px 16px; margin: 14px 0; }
@media (prefers-color-scheme: dark) { .course { color: #10141a; } }
.course .ic { font-size: 30px; }
.course .k { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .85; }
.course .t { font: 700 18px var(--serif); }
.course .go { margin-left: auto; font-weight: 800; font-size: 20px; }
.moods { display: flex; justify-content: space-between; gap: 6px; }
.moods button { flex: 1; border: 2px solid transparent; background: var(--soft); border-radius: 14px; padding: 8px 0 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; font-size: 11px; font-weight: 700; color: var(--muted); }
.moods button span { font-size: 28px; line-height: 1.2; filter: grayscale(.6); opacity: .8; }
.moods button.on { border-color: var(--acc); background: var(--card); color: var(--ink); }
.moods button.on span { filter: none; opacity: 1; }
.feel { margin-top: 12px; }
.feel .lbl { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 0 6px; }
.prompt { font: italic 21px/1.35 var(--serif); margin: 2px 0 10px; }
.plabel { font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--sage); }
.write { width: 100%; min-height: 220px; border: 0; outline: none; resize: none; font: 19px/32px var(--serif); padding: 0; margin-top: 4px;
  /* Ruled paper drawn on the textarea itself, so the lines scroll with the words. */
  background: repeating-linear-gradient(transparent 0 31px, color-mix(in srgb, var(--line) 85%, transparent) 31px 32px); background-attachment: local; }
.page-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px 18px; margin-bottom: 14px; }
.wbar { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.wbar .sp { flex: 1; }
.timer { border: 1px solid var(--line); background: var(--soft); border-radius: 999px; padding: 6px 12px; font-weight: 700; cursor: pointer; font-size: 13px; font-variant-numeric: tabular-nums; }
.timer.run { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.photo-slot { display: flex; gap: 10px; }
.photo-slot img { width: 100%; max-height: 420px; object-fit: cover; border-radius: 14px; }
.photo-wrap { position: relative; }
.photo-wrap .x { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; cursor: pointer; }
.addph { flex: 1; border: 2px dashed var(--line); background: none; border-radius: 14px; padding: 18px 8px; color: var(--muted); font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
.addph b { font-size: 24px; }
.done-bar { display: flex; gap: 10px; align-items: center; background: color-mix(in srgb, var(--sage) 16%, var(--card)); border: 1px solid color-mix(in srgb, var(--sage) 40%, var(--line));
  border-radius: 16px; padding: 12px 14px; margin-bottom: 14px; }
.done-bar .t { flex: 1; font-weight: 600; }
.saved { transition: opacity .3s; }

/* Learn */
.lessons { display: flex; flex-direction: column; gap: 10px; }
.lesson { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; text-decoration: none; }
.lesson .n { width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: var(--soft); }
.lesson.done .n { background: color-mix(in srgb, var(--sage) 25%, var(--card)); }
.lesson.next { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc); }
.lesson.locked { opacity: .5; }
.lesson .t { font: 700 17px var(--serif); }
.lesson .m { font-size: 13px; color: var(--muted); }
.lesson .st { margin-left: auto; font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.lesson.done .st { color: var(--sage); }
.lesson.next .st { color: var(--acc); }
.progress { height: 8px; border-radius: 6px; background: var(--soft); overflow: hidden; margin: 4px 0 16px; }
.progress i { display: block; height: 100%; background: var(--sage); border-radius: 6px; }
.lesson-page .big { font-size: 54px; }
.lesson-page h1 { font: 700 30px/1.15 var(--serif); margin: 4px 0 12px; }
.lesson-page .why { font: 18px/1.6 var(--serif); }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 10px 0 16px; }
.steps li { counter-increment: s; position: relative; padding: 8px 0 8px 40px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 6px; width: 28px; height: 28px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; font-weight: 800; font-size: 14px; color: var(--acc); }
.tip { background: color-mix(in srgb, var(--warm) 13%, var(--card)); border-radius: 14px; padding: 12px 14px; margin-bottom: 18px; }
.styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.styles button { text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 12px; cursor: pointer; font-weight: 600; }
.styles button.on { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc); }
details.faq { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; }
details.faq summary { font-weight: 700; cursor: pointer; }
details.faq p { margin: 8px 0 0; color: var(--muted); }

/* Journal */
.monthbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.monthbar b { font: 700 20px var(--serif); }
.monthbar button { border: 0; background: var(--soft); width: 38px; height: 38px; border-radius: 50%; font-size: 18px; cursor: pointer; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 16px; }
.cal .dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); padding-bottom: 2px; }
.cal a, .cal span.d { aspect-ratio: 1; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; font-size: 13px; font-weight: 600; color: var(--muted); }
.cal a.has { background: var(--card); border: 1px solid var(--line); color: var(--ink); }
.cal a.today { box-shadow: inset 0 0 0 2px var(--acc); }
.cal a i { width: 8px; height: 8px; border-radius: 50%; margin-top: 3px; background: var(--line); }
.cal a .f { font-size: 15px; line-height: 1; margin-top: 1px; }
.otd { background: color-mix(in srgb, var(--acc) 10%, var(--card)); border: 1px solid color-mix(in srgb, var(--acc) 30%, var(--line)); border-radius: 16px; padding: 14px; margin-bottom: 16px; text-decoration: none; display: block; }
.otd .k { font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--acc); }
.otd .q { font: italic 17px/1.5 var(--serif); margin-top: 4px; }
.entries { display: flex; flex-direction: column; gap: 10px; }
.entry { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; text-decoration: none; }
.entry .d { flex: none; width: 46px; text-align: center; }
.entry .d b { display: block; font: 700 22px/1 var(--serif); }
.entry .d small { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.entry .x { flex: 1; min-width: 0; }
.entry .p { font-size: 13px; color: var(--muted); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .s { font: 16px/1.45 var(--serif); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entry img { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; }
.entry .mf { font-size: 22px; }
.read .q { font: italic 19px/1.4 var(--serif); color: var(--muted); margin: 10px 0; }
.read .body { font: 19px/1.75 var(--serif); white-space: pre-wrap; }
.read img { width: 100%; border-radius: 16px; margin: 12px 0; }
.tagline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.pill { background: var(--soft); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; }

/* Me / insights */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat b { display: block; font: 700 28px/1.1 var(--serif); }
.stat span { font-size: 13px; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar { display: grid; grid-template-columns: 90px 1fr 26px; gap: 8px; align-items: center; font-size: 14px; }
.bar i { height: 10px; border-radius: 6px; background: var(--acc); display: block; min-width: 4px; }
.bar em { font-style: normal; color: var(--muted); text-align: right; }
.field { margin-bottom: 14px; }
.field label, .lbl { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.in { width: 100%; min-width: 0; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px; outline: none; }
.in:focus { border-color: var(--acc); }

/* Onboarding & lock (full-screen layers) */
.layer { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; overflow-y: auto;
  padding: calc(28px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom)); }
.ob { max-width: 460px; width: 100%; margin: auto; display: flex; flex-direction: column; gap: 14px; }
.ob .art { font-size: 64px; }
.ob h1 { font: 700 32px/1.15 var(--serif); margin: 0; }
.ob p { font: 18px/1.6 var(--serif); margin: 0; color: var(--muted); }
.ob ul { list-style: none; padding: 0; margin: 4px 0; display: flex; flex-direction: column; gap: 12px; }
.ob li { display: flex; gap: 12px; align-items: flex-start; }
.ob li span { font-size: 24px; }
.ob .dots { display: flex; gap: 6px; justify-content: center; margin-top: 8px; }
.ob .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.ob .dots i.on { background: var(--acc); }
.goal { display: flex; flex-direction: column; gap: 8px; }
.goal button { text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 12px 14px; cursor: pointer; }
.goal button b { display: block; }
.goal button small { color: var(--muted); }
.goal button.on { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc); }
.lock { z-index: 55; align-items: center; justify-content: center; text-align: center; }
.lock h2 { font: 700 24px var(--serif); margin: 10px 0 4px; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0 22px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--acc); }
.pin-dots i.on { background: var(--acc); }
.pin-dots.bad { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; justify-content: center; }
.keypad button { width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--soft); font-size: 26px; font-weight: 600; cursor: pointer; }
.keypad button.blank { background: none; }

/* Sheet & toast */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { position: relative; background: var(--bg); width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; border-radius: 22px 22px 0 0;
  padding: 22px 16px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 760px) { .sheet { align-items: center; } .sheet-card { border-radius: 22px; } }
.sheet .close { position: sticky; top: 0; float: right; margin: -8px -4px 0 8px; border: 0; background: var(--soft); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; z-index: 2; }
.sheet h2 { font: 700 22px var(--serif); margin: 0 0 12px; }
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.install-bar { position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 15; display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 10px 10px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: 520px; margin: 0 auto; }
.install-bar img { width: 36px; height: 36px; border-radius: 9px; }
.install-bar .txt { flex: 1; min-width: 0; font-size: 14px; line-height: 1.3; }
.install-bar .go { border: 0; background: var(--acc); color: var(--acc-ink); font-weight: 700; border-radius: 10px; padding: 9px 14px; }
.install-bar .no { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 4px 6px; }
