/*
  Sentence Notebook

  Idea: an English exercise book. The English sentence is always set on
  four-line ruled lines (the 四线三格 paper Chinese schoolchildren practise
  English handwriting on), with the baseline in red. That is the one loud
  thing. Everything else stays plain paper and ink.

  Colour   paper #f5f8fc, ink #18233f, rule blue #9fb5db, seal red #c23b30, accent ink-blue #2748a8
  Type     Atkinson Hyperlegible (made for unambiguous letterforms, which suits learners), system CJK for Chinese
  Layout   one column, left aligned, bottom tab bar on phones
*/

@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  ascent-override: 95%;
  descent-override: 29%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  ascent-override: 95%;
  descent-override: 29%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-hyperlegible-latin-400-italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  --paper: #f5f8fc;
  --sheet: #ffffff;
  --ink: #18233f;
  --ink-soft: #55617c;
  --line: #d3deee;
  --rule: #9fb5db;
  --seal: #c23b30;
  --accent: #2748a8;
  --accent-ink: #ffffff;
  --good: #1f7a60;
  --focus: #2748a8;
  --shadow: 0 1px 2px rgba(24, 35, 63, 0.06), 0 12px 28px -16px rgba(24, 35, 63, 0.28);
  --font: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', 'Noto Sans SC', 'Source Han Sans SC',
    'WenQuanYi Micro Hei', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #0f1729;
    --sheet: #17213a;
    --ink: #e7edfb;
    --ink-soft: #9aa8c7;
    --line: #2b3a5e;
    --rule: #41588f;
    --seal: #f0867a;
    --accent: #8fb2ff;
    --accent-ink: #0d1630;
    --good: #6fd1b6;
    --focus: #8fb2ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px -16px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --paper: #0f1729;
  --sheet: #17213a;
  --ink: #e7edfb;
  --ink-soft: #9aa8c7;
  --line: #2b3a5e;
  --rule: #41588f;
  --seal: #f0867a;
  --accent: #8fb2ff;
  --accent-ink: #0d1630;
  --good: #6fd1b6;
  --focus: #8fb2ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px -16px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.55 var(--font);
  -webkit-text-size-adjust: 100%;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.shell {
  max-width: 42rem;
  margin-inline: auto;
  padding-inline: 1rem;
  padding-block: 0 6.5rem;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- bilingual labels */

.bi {
  display: inline-flex;
  gap: 0.4em;
  align-items: baseline;
}
.bi-en {
  font-size: 0.85em;
  opacity: 0.75;
}

/* ---------------------------------------------------------------- header and navigation */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding-block: 1rem 0.75rem;
}
.brand {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--sheet);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav a {
  display: flex;
  justify-content: center;
  padding: 0.55rem 0.25rem 0.6rem;
  color: var(--ink-soft);
  text-decoration: none;
}
.nav a[aria-current='page'] {
  color: var(--accent);
  font-weight: 700;
  box-shadow: inset 0 2px 0 var(--accent);
}
.nav .bi {
  flex-direction: column;
  align-items: center;
  gap: 0;
  line-height: 1.25;
}
.nav .bi-en {
  font-size: 0.72rem;
}

@media (min-width: 40rem) {
  .nav {
    position: static;
    display: flex;
    gap: 0.15rem;
    border: 0;
    background: none;
    padding: 0;
  }
  .nav a {
    padding: 0.3rem 0.65rem;
    border-radius: 0.4rem;
  }
  .nav a[aria-current='page'] {
    box-shadow: inset 0 -2px 0 var(--accent);
  }
  .shell {
    padding-block-end: 3rem;
  }
}

/* ---------------------------------------------------------------- page structure */

main {
  display: block;
}
main > section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
main > .review,
main > .build {
  gap: 1rem;
}

.label {
  margin: 0 0 0.5rem;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.quiet {
  margin: 0;
  color: var(--ink-soft);
}
.notice {
  margin: 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--seal);
  border-radius: 0.5rem;
}
.block-group {
  min-width: 0;
}
.links,
.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ---------------------------------------------------------------- the ruled sentence */

/* Lines sit at fixed fractions of a 2.6em line box: top 0.61em, x-height 1.11em, baseline 1.61em (red), descender 2.11em. */
.en-face {
  --ruled-size: clamp(1.4rem, 5.4vw, 1.9rem);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.ruled {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: var(--ruled-size);
  line-height: 2.6em;
  overflow-wrap: anywhere;
  background-image:
    linear-gradient(to bottom, transparent 0.61em, var(--rule) 0.61em, var(--rule) calc(0.61em + 1px), transparent calc(0.61em + 1px)),
    linear-gradient(to bottom, transparent 1.11em, var(--line) 1.11em, var(--line) calc(1.11em + 1px), transparent calc(1.11em + 1px)),
    linear-gradient(to bottom, transparent 1.61em, var(--seal) 1.61em, var(--seal) calc(1.61em + 1.5px), transparent calc(1.61em + 1.5px)),
    linear-gradient(to bottom, transparent 2.11em, var(--rule) 2.11em, var(--rule) calc(2.11em + 1px), transparent calc(2.11em + 1px));
  background-size: 100% 2.6em;
  background-repeat: repeat-y;
}
.en-face .icon-btn {
  margin-top: calc((2.6 * var(--ruled-size) - 2.75rem) / 2);
}

.zh-face {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.5;
  font-weight: 500;
}
.today .zh-face {
  margin-top: 0.25rem;
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--ink-soft);
}
.prompt {
  margin: 0 0 0.75rem;
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

/* ---------------------------------------------------------------- buttons, chips, tiles */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.6rem 1.1rem;
  font: inherit;
  color: var(--ink);
  text-decoration: none;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  cursor: pointer;
}
.btn:hover:not(:disabled) {
  border-color: var(--rule);
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.btn.primary {
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border-color: transparent;
}
.btn.block {
  width: 100%;
}
.btn.danger {
  color: var(--accent-ink);
  background: var(--seal);
  border-color: transparent;
}
.btn.danger-outline {
  color: var(--seal);
  border-color: var(--seal);
}
.quiet-btn {
  color: var(--ink-soft);
}
.file-btn {
  position: relative;
}

.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  color: var(--accent);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--line);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.chip {
  min-height: 2.25rem;
  padding: 0.3rem 0.9rem;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.chip[aria-pressed='true'] {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
}

.tile {
  padding: 0.5rem 0.8rem;
  font: inherit;
  font-size: 1.15rem;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 0.4rem;
  cursor: pointer;
}
.tile.wrong {
  border-color: var(--seal);
  box-shadow: inset 0 -3px 0 var(--seal);
}

/* ---------------------------------------------------------------- home */

.stats {
  display: flex;
  gap: 2rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.stat {
  display: flex;
  flex-direction: column;
}
.stat .num {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat .lbl {
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.lv-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr 3.5rem;
  align-items: center;
  gap: 0.75rem;
  padding-block: 0.3rem;
}
.lv-name {
  font-weight: 700;
}
.lv-count {
  font-size: 0.875rem;
  text-align: end;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.bar {
  position: relative;
  height: 0.6rem;
  overflow: hidden;
  background: var(--line);
  border-radius: 999px;
}
.bar .seen,
.bar .learned {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
}
.bar .seen {
  background: var(--rule);
}
.bar .learned {
  background: var(--good);
}
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  margin: 0.6rem 0 0;
  font-size: 0.8125rem;
  color: var(--ink-soft);
}
.swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
}
.swatch.seen {
  background: var(--rule);
}
.swatch.learned {
  background: var(--good);
}
.swatch + .bi,
.swatch + span {
  margin-inline-end: 0.5rem;
}

/* ---------------------------------------------------------------- review and build */

.progress {
  height: 0.3rem;
  overflow: hidden;
  background: var(--line);
  border-radius: 999px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
}
.meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}
.meta .left {
  margin-inline-start: auto;
  font-variant-numeric: tabular-nums;
}
.tag-new {
  font-weight: 700;
  color: var(--accent);
}

.sheet {
  padding: 1.25rem 1rem;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
}
.answer {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.note {
  margin: 0;
  padding: 0.6rem 0.8rem;
  font-size: 0.9375rem;
  color: var(--ink-soft);
  background: var(--paper);
  border-radius: 0.4rem;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.tag {
  padding: 0.1rem 0.6rem;
  font-size: 0.8125rem;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.tag .bi {
  gap: 0.3em;
}

.grades {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}
.btn.grade {
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.55rem 0.15rem;
  border-bottom-width: 3px;
}
.btn.grade .bi {
  flex-direction: column;
  align-items: center;
  gap: 0;
  line-height: 1.25;
}
.grade .delay {
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.grade[data-grade='0'] {
  border-bottom-color: var(--seal);
}
.grade[data-grade='1'] {
  border-bottom-color: var(--rule);
}
.grade[data-grade='2'] {
  border-bottom-color: var(--good);
}
.grade[data-grade='3'] {
  border-bottom-color: var(--accent);
}

.answer-zone {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 4.25rem;
  padding: 0.75rem;
  background: var(--sheet);
  border: 1.5px dashed var(--rule);
  border-radius: 0.5rem;
}
.answer-zone .placeholder {
  align-self: center;
  color: var(--ink-soft);
}
.bank {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.feedback {
  margin: 0;
  font-weight: 700;
}
.feedback.good {
  color: var(--good);
}
.feedback.bad {
  color: var(--seal);
}
.done {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.done h2 {
  margin: 0;
  font-size: 1.3rem;
}
.tally {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.score {
  margin: 0;
  font-size: 1.2rem;
}

/* ---------------------------------------------------------------- browse */

.filters {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}
.filter-row .input {
  flex: 1 1 12rem;
  width: auto;
}
.input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font: inherit;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.check input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
}
.count {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}
.rows {
  margin: 0;
  padding: 0;
  list-style: none;
}
.row {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}
.row-main {
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
}
.row-en {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 500;
  text-align: start;
  color: var(--ink);
  background: none;
  border: 0;
  cursor: pointer;
}
.row .zh {
  margin: 0;
  color: var(--ink-soft);
}
.reveal-zh {
  padding: 0.25rem 0.6rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink-soft);
  background: none;
  border: 1px dashed var(--rule);
  border-radius: 0.4rem;
  cursor: pointer;
}
.detail {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

/* ---------------------------------------------------------------- settings */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
  margin: 0;
  padding: 1rem 0;
  border: 0;
  border-bottom: 1px solid var(--line);
}
.field legend {
  padding: 0;
  margin-bottom: 0.5rem;
  font-weight: 700;
}
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.seg label {
  position: relative;
  display: block;
}
.seg input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.seg label > span {
  display: block;
  padding: 0.5rem 0.9rem;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}
.seg input:checked + span {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
}
.seg input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.confirm {
  padding: 0.9rem;
  border: 1px solid var(--seal);
  border-radius: 0.5rem;
}
.confirm p {
  margin: 0 0 0.75rem;
}
.status {
  min-height: 1.5rem;
  margin: 0;
  color: var(--ink-soft);
}

/* ---------------------------------------------------------------- motion */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.reveal {
  animation: rise 0.16s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .reveal {
    animation: none;
  }
}

/* ---------------------------------------------------------------- Chinese course */

.hanzi-face {
  --hanzi-size: clamp(1.9rem, 7.2vw, 2.5rem);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.hanzi {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: var(--hanzi-size);
  font-weight: 500;
  line-height: 2.1;
  overflow-wrap: anywhere;
}
.hanzi ruby,
.tile-zh ruby,
.row-zh ruby {
  ruby-position: over;
  ruby-align: center;
  margin-inline-end: 0.12em;
}
.hanzi rt,
.tile-zh rt,
.row-zh rt {
  font-family: 'Atkinson Hyperlegible', system-ui, sans-serif;
  font-size: 0.4em;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
}
.hanzi-face .icon-btn {
  margin-top: calc((2.1 * var(--hanzi-size) - 2.75rem) / 2);
}
.native-face {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.45;
  font-weight: 500;
}
.today .native-face {
  margin-top: 0.25rem;
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--ink-soft);
}
.tile-zh {
  font-size: 1.4rem;
  line-height: 1.9;
}
.row-zh {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0;
  font: inherit;
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 2;
  text-align: start;
  color: var(--ink);
  background: none;
  border: 0;
  cursor: pointer;
}
.row .translation {
  margin: 0;
  color: var(--ink-soft);
}
