:root {
  --bg: #eef2f0; --surface: #ffffff; --ink: #13201c; --muted: #55655f; --faint: #c3cdc8; --line: #d5ddd9;
  --green: #0c6b58; --green-dark: #084c3f; --green-soft: #dcefe8; --mid: #7dbfab;
  --red: #a8372b; --red-soft: #f6e3df; --amber: #7a4e00; --amber-soft: #f7ecd3;
  --serif: "Iowan Old Style", "Palatino Linotype", Charter, "Bitstream Charter", "Source Serif 4", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, "Helvetica Neue", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1614; --surface: #18211e; --ink: #e6eeea; --muted: #9aaba4; --faint: #3a4743; --line: #2a3632;
    --green: #58c9ad; --green-dark: #8fdcc8; --green-soft: #17342c; --mid: #2f7a67;
    --red: #e58a7c; --red-soft: #3a1f1b; --amber: #e0b05a; --amber-soft: #3a2e14;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); }
:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
[hidden] { display: none !important; }
.loading { padding: 40px 20px; color: var(--muted); }
.wrap { max-width: 640px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.page { flex: 1; padding-bottom: calc(88px + var(--safe-b)); }

/* type */
.serif { font-family: var(--serif); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
h1.title { margin: 2px 0 0; font: 600 30px/1.15 var(--serif); }
.pagehead { padding: 28px 20px 16px; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.pagehead .date { margin: 0; font-size: 14px; color: var(--muted); }
.pill { margin: 0 0 4px; padding: 6px 12px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 14px; font-weight: 600; white-space: nowrap; }
.pill.lap { background: var(--amber-soft); color: var(--amber); }
.sectionhead { padding: 26px 20px 10px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.sectionhead h2 { margin: 0; font-size: 17px; font-weight: 600; }
.sectionhead p { margin: 0; font-size: 14px; color: var(--muted); }

/* panels */
.panel { margin: 0 16px; padding: 20px 18px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat b { display: block; font: 600 38px/1 var(--serif); }
.stat b small { font-size: 18px; }
.stat span { display: block; margin-top: 6px; font-size: 14px; color: var(--muted); }
.note { margin: 0; font-size: 14px; color: var(--muted); text-align: center; }
.callout { margin: 12px 16px 0; padding: 14px 18px; background: var(--green-soft); border-radius: 16px; color: var(--green-dark); display: flex; gap: 12px; align-items: center; font-size: 15px; }
.callout.warn { background: var(--amber-soft); color: var(--amber); }
.callout p { margin: 0; }
.callout svg { flex-shrink: 0; }

/* buttons */
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 15px 18px; font-weight: 600; font-size: 17px; text-align: center; background: var(--green); color: #fff; text-decoration: none; }
@media (prefers-color-scheme: dark) { .btn { color: #06241d; } }
.btn.quiet { background: var(--surface); color: var(--ink); border: 1px solid var(--line); font-size: 16px; padding: 14px 18px; }
.btn.small { display: inline-block; width: auto; padding: 8px 14px; font-size: 15px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--green); text-decoration: underline; font-size: inherit; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* deck list */
.list { list-style: none; margin: 0 16px; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.deckrow { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; column-gap: 12px; row-gap: 6px; align-items: center; padding: 12px 16px; min-height: 44px; cursor: pointer; }
.deckrow input { width: 20px; height: 20px; margin: 0; accent-color: var(--green); grid-row: 1 / 3; }
.deckrow .name { font-weight: 500; }
.deckrow .meta { font-size: 14px; color: var(--muted); white-space: nowrap; }
.deckrow.off .name { color: var(--muted); }
.deckrow.off .bar { opacity: .45; }
.deckrow.locked { cursor: default; }
.bar { grid-column: 2 / 4; display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line); }
.bar span:first-child { background: var(--green); }
.bar span:last-child { background: var(--mid); }
.bar.big { height: 12px; border-radius: 6px; grid-column: auto; }
.legend { margin: 10px 20px 0; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 16px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; background: var(--line); }
.key.known { background: var(--green); } .key.learning { background: var(--mid); }
.progrow { padding: 12px 16px; display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; row-gap: 6px; align-items: baseline; }
.progrow .name { font-weight: 500; }
.progrow .meta { font-size: 14px; color: var(--muted); white-space: nowrap; }
.progrow .bar { grid-column: 1 / 3; }
.legend3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; font-size: 14px; }
.legend3 p { margin: 0; }
.legend3 span { color: var(--muted); }
.ontrack { margin: 0; padding-top: 14px; border-top: 1px solid var(--line); font-size: 15px; }
.ontrack strong { color: var(--green); }
.ontrack.behind strong { color: var(--amber); }

/* forecast */
.forecast { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; align-items: end; height: 132px; }
.forecast div { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.forecast b { font-size: 13px; }
.forecast i { width: 100%; background: var(--mid); border-radius: 4px 4px 0 0; min-height: 2px; }
.forecast div:first-child i { background: var(--green); }
.forecast span { font-size: 13px; color: var(--muted); }

/* bottom navigation */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); z-index: 5; }
.tabs div { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tabs button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 4px 11px; border: 0; border-top: 3px solid transparent; margin-top: -1px; background: none; color: var(--muted); font-size: 13px; }
.tabs button[aria-current="page"] { border-top-color: var(--green); color: var(--green); font-weight: 600; }

/* study session */
.session { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.sbar { padding: 10px 12px 6px 8px; display: flex; align-items: center; gap: 8px; }
.iconbtn { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; background: none; color: var(--muted); border-radius: 10px; }
.track { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.track b { display: block; height: 100%; background: var(--green); }
.sbar p { margin: 0 8px 0 4px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.card { flex: 1; padding: 20px 20px 20px; display: flex; flex-direction: column; }
.kind { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.question { margin: 0; font: 600 26px/1.25 var(--serif); text-wrap: balance; }
.revealed .question { font-size: 21px; line-height: 1.3; }
.hint { margin: 14px 0 0; font-size: 15px; color: var(--muted); }
.answer { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); overflow-wrap: anywhere; -webkit-user-select: none; user-select: none; }
.answer h4 { margin: 18px 0 6px; font: 700 13px/1.3 var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--green); }
.answer h4:first-child { margin-top: 0; }
.answer p { margin: 0 0 8px; }
.answer ul, .answer ol { margin: 0 0 14px; padding-left: 20px; }
.answer li { margin: 4px 0; }
.answer li > ul, .answer li > ol { margin: 4px 0 0; }
.answer .tablewrap { overflow-x: auto; margin: 0 0 12px; }
.answer table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.answer th, .answer td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; min-width: 7em; }
.answer th { background: var(--green-soft); }
.answer blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--line); }
.cardmeta { margin: 20px 0 0; font-size: 14px; color: var(--muted); }
.mynote { margin: 16px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--amber-soft); font-size: 15px; white-space: pre-wrap; }
.mynote strong { display: block; font-size: 13px; color: var(--amber); }
.watermark { margin: auto 0 0; padding-top: 16px; text-align: center; font-size: 13px; letter-spacing: .04em; color: var(--faint); -webkit-user-select: none; user-select: none; }
.dock { position: sticky; bottom: 0; padding: 12px 16px calc(20px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line); }
.dock .ask { margin: 0 0 10px; font-size: 14px; color: var(--muted); text-align: center; }
.rate { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.rate button { display: flex; flex-direction: column; align-items: center; padding: 10px 4px 9px; border-radius: 12px; border: 1.5px solid; font-weight: 600; font-size: 16px; }
.rate button span { font-size: 13px; font-weight: 400; }
.rate button span:last-child { margin-top: 4px; font-weight: 600; }
.rate .r1 { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.rate .r2 { border-color: var(--amber); background: var(--amber-soft); color: var(--amber); }
.rate .r3 { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.more { margin-top: 10px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.more button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px; padding: 6px 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 13px; font-weight: 500; }
.more button:disabled { opacity: .45; cursor: default; }
.keys { font-size: 12px; color: var(--muted); text-align: center; margin: 8px 0 0; }
@media (hover: none) { .keys { display: none; } }
kbd { font: inherit; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; background: var(--surface); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + var(--safe-b)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }

/* summary */
.split { display: flex; gap: 3px; height: 12px; }
.split i { display: block; border-radius: 2px; }
.split i.g { background: #2f8f78; } .split i.h { background: #e3b860; } .split i.f { background: #a8372b; }
.split i:first-child { border-radius: 6px 2px 2px 6px; } .split i:last-child { border-radius: 2px 6px 6px 2px; }
.key.g { background: #2f8f78; } .key.h { background: #e3b860; } .key.f { background: #a8372b; }
.plainrow { padding: 12px 16px; }
.plainrow p { margin: 0; }
.plainrow .q { font-weight: 500; }
.footer { padding: 18px 16px calc(20px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; }

/* forms */
.field { margin: 0 0 18px; }
.field label, .field .label { display: block; font-weight: 600; margin: 0 0 6px; }
.field input[type=date], .field input[type=search], .field input[type=email], .field input[type=password], textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 16px; }
textarea { min-height: 110px; resize: vertical; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.seg button { border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 6px; font-weight: 600; }
.seg button span { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.seg button[aria-pressed="true"] { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.content { padding: 0 16px; }
.error { color: var(--red); background: var(--red-soft); border-radius: 10px; padding: 10px 12px; margin: 12px 0 0; }
.signin { max-width: 400px; margin: 10vh auto 0; padding: 0 20px; }
.signin h1 { margin: 0 0 4px; font: 600 30px/1.15 var(--serif); }
.signin p { color: var(--muted); }
.signin .btn { margin-top: 8px; }

/* search */
.results { list-style: none; margin: 0 16px; padding: 0; }
.results > li { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 8px; overflow: hidden; }
.results summary { padding: 12px 14px; cursor: pointer; list-style: none; }
.results summary::-webkit-details-marker { display: none; }
.results summary .q { font-weight: 600; display: block; }
.results summary .m { font-size: 13px; color: var(--muted); }
.results .answer { margin: 0 14px; padding-top: 12px; }
.results .rowactions { padding: 8px 14px 12px; font-size: 14px; color: var(--muted); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.results .locked { padding: 0 14px 12px; font-size: 14px; color: var(--muted); }

dialog { border: 1px solid var(--line); border-radius: 16px; padding: 22px 20px; width: min(440px, calc(100% - 32px)); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 20, 16, .4); }
dialog h2 { margin: 0 0 6px; font: 600 20px/1.3 var(--serif); }
dialog p { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.dialog-actions .btn { width: auto; font-size: 16px; padding: 10px 16px; }
.dialog-actions .btn.danger { background: var(--red); }
