:root {
  font-family: system-ui, sans-serif;
  color: #213b37;
  background: #f6f5ee;
  line-height: 1.5;
  font-size: 16px;
  --green: #1c594f;
  --line: #d4ded7;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
header {
  background: #fffef9;
  border-bottom: 1px solid var(--line);
  padding: 14px max(18px, calc((100vw - 1120px) / 2));
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 5;
}
#brand {
  font-weight: 800;
  text-decoration: none;
  color: var(--green);
  white-space: nowrap;
  font-size: 20px;
}
#brand span {
  font-weight: 450;
}
nav {
  display: flex;
  gap: 3px;
  margin-left: auto;
}
button,
.button {
  font: inherit;
  border: 1px solid #b5c9bf;
  border-radius: 9px;
  padding: 9px 14px;
  background: #fffef9;
  color: var(--green);
  cursor: pointer;
  min-height: 44px;
  text-decoration: none;
  display: inline-block;
}
button:hover,
.button:hover {
  background: #edf3ec;
}
button:disabled {
  opacity: 0.5;
  cursor: wait;
}
.primary {
  background: var(--green);
  color: white;
  border-color: var(--green);
}
.primary:hover {
  background: #123c36;
}
main {
  max-width: 1120px;
  margin: 32px auto;
  padding: 0 24px 100px;
}
h1 {
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.15;
  margin: 12px 0 16px;
}
h2 {
  font-size: 23px;
  margin: 12px 0;
}
h3 {
  margin: 6px 0 12px;
}
p {
  margin: 10px 0 18px;
}
.muted,
small {
  color: #53665e;
}
small {
  display: block;
  margin-top: 8px;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.lessonHeader {
  align-items: flex-start;
}
.lessonHeader details {
  margin: 0;
  max-width: 560px;
}
.between {
  justify-content: space-between;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}
.panel,
.card {
  background: #fffef9;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 22px;
  margin-bottom: 18px;
}
.card p.preview {
  max-height: 7.5em;
  overflow: auto;
  white-space: pre-line;
  color: #52695e;
}
label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin: 12px 0 5px;
}
input,
textarea,
select {
  font: inherit;
  padding: 10px;
  border: 1px solid #afc2b8;
  border-radius: 7px;
  background: white;
  color: #213b37;
  max-width: 100%;
  width: 100%;
}
input[type="file"] {
  font-size: 14px;
}
textarea {
  resize: vertical;
}
select,
input[type="number"] {
  width: auto;
}
details {
  margin: 16px 0;
}
summary {
  cursor: pointer;
  color: var(--green);
  padding: 8px 0;
}
#notice {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: min(560px, calc(100vw - 32px));
  max-height: 35vh;
  overflow: auto;
  border-radius: 10px;
  box-shadow: 0 5px 22px #14383022;
  z-index: 8;
  background: #e6efe3;
  color: #234437;
  border: 1px solid #acbfa9;
  padding: 12px 20px;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}
#notice[hidden] {
  display: none;
}
#notice.error {
  background: #fff0dc;
  color: #723b17;
  border-color: #d1a474;
}
dialog {
  border: 1px solid #b8cdc1;
  border-radius: 16px;
  box-shadow: 0 20px 70px #14383044;
  width: min(540px, calc(100% - 24px));
  padding: 24px;
  background: #fffef9;
}
dialog::backdrop {
  background: #142a2255;
}
blockquote {
  border-left: 3px solid #afc7b3;
  margin: 10px 0;
  padding: 8px 14px;
  color: #516459;
}
#readerLayout {
  display: grid;
  grid-template-columns: minmax(0, 740px) 270px;
  gap: 32px;
}
#reading {
  font-family: Georgia, serif;
  font-size: 22px;
  line-height: 1.9;
}
#reading p {
  padding: 10px 14px;
  margin: 0 0 15px;
  border-left: 3px solid transparent;
  border-radius: 4px;
  scroll-margin-top: 95px;
}
#reading p.current {
  border-left-color: #287968;
  background: #eef3e7;
}
.token {
  cursor: pointer;
  border-radius: 3px;
}
.token:hover {
  outline: 1px solid #4b78a0;
}
.token.new, .wordLegend .new {
  background: #d4e8fa;
  color: #173b58;
}
.token.saved, .wordLegend .saved {
  background: #fff1a8;
  color: #463b11;
}
.token.level2 { background: #fff4bd; }
.token.level3 { background: #fff7d4; }
.token.level4 { background: #fffbe9; }
.token.known, .token.ignored { background: transparent; color: inherit; }
.wordStates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; margin-top: 8px; }
.wordStates button { flex: 1; min-width: 0; padding: 6px 3px; }
.wordStates button[aria-pressed="true"] { background: #fff1a8; border: 2px solid #74651d; font-weight: 700; }
.wordStates button[data-status="known"][aria-pressed="true"] { background: #e4f1e7; border-color: #287047; }
.wordStates button[data-status="ignored"][aria-pressed="true"] { background: #ecefed; border-color: #58645c; }
#wordStateLabel { margin: 4px 0; }
.token.active {
  outline: 2px solid #376d9c;
  outline-offset: 2px;
}
.wordLegend {
  font-size: 13px;
}
.wordLegend span {
  padding: 3px 6px;
  border-radius: 3px;
}
#wordDialog {
  position: fixed;
  inset: auto;
  margin: 0;
  width: min(420px, calc(100vw - 24px));
  max-height: min(620px, calc(100dvh - 24px));
  overflow: auto;
  z-index: 7;
  padding: 16px;
  border-radius: 10px;
  background: white;
}
#wordDialog h2 {
  margin: 0;
  flex: 1;
}
#wordDialog blockquote {
  max-height: 4.5em;
  overflow: auto;
  font-size: 14px;
}
#wordDialog #meaning {
  font-size: 15px;
  max-height: 6em;
  overflow: auto;
  white-space: pre-wrap;
}
#wordDialog label {
  margin-top: 8px;
}
#wordDialog small {
  font-size: 12px;
}
#wordDialog #closeWord {
  border: none;
  padding: 4px 12px;
}

.paragraphTools {
  font: 13px system-ui;
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.paragraphTools button {
  font-size: 13px;
  padding: 3px 8px;
  min-height: 34px;
}
aside {
  align-self: start;
  position: sticky;
  top: 100px;
}
audio {
  width: 100%;
  margin: 10px 0;
}
.audioDock {
  background: #fffef9;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin: 18px 0;
}
.badge {
  font-size: 13px;
  padding: 3px 8px;
  background: #e4eddd;
  border-radius: 20px;
}
.danger {
  color: #a13c24;
}
.reviewTerm {
  font-family: Georgia, serif;
  font-size: 38px;
}
.wrap {
  overflow-wrap: anywhere;
}
.answer {
  font-size: 22px;
  color: var(--green);
}
a {
  color: var(--green);
}
:focus-visible {
  outline: 3px solid #c79f3b;
  outline-offset: 3px;
}
#positionSelect {
  max-width: 100%;
}
.count {
  font-size: 14px;
  color: #61766d;
}
.stack > * {
  margin-bottom: 12px;
}
#reading::selection,
.token::selection {
  background: #bcd8ee;
}
@media (max-width: 750px) {
  header {
    padding: 10px 12px;
    gap: 4px;
    align-items: flex-start;
    flex-wrap: wrap;
  }
  #brand {
    font-size: 18px;
  }
  nav {
    gap: 3px;
  }
  nav button {
    padding: 6px 10px;
    font-size: 14px;
    min-height: 40px;
  }
  main {
    margin-top: 22px;
    padding: 0 14px 80px;
  }
  #readerLayout {
    display: block;
  }
  aside {
    position: static;
  }
  .panel,
  .card {
    padding: 17px;
  }
  #reading {
    font-size: 20px;
  }
  #reading p {
    padding-left: 9px;
  }
  dialog {
    padding: 20px;
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .audioDock {
    position: sticky;
    top: 65px;
    z-index: 3;
  }
  h1 {
    font-size: 29px;
  }
  .row > button {
    flex-shrink: 0;
  }
}

[hidden] {
  display: none !important;
}
@media (max-width: 750px) {
  .audioDock {
    position: static;
  }
  .paragraphTools {
    gap: 5px;
  }
}

.wordList {
  margin: 10px 0 0;
  padding-left: 20px;
  overflow-wrap: anywhere;
}
.wordList li {
  margin: 0 0 12px;
}
.wordList li div {
  white-space: pre-wrap;
}

#wordDialog details { margin: 8px 0 0; }
#wordDialog summary { font-size: 13px; }
#wordDialog #lookupStatus { margin: 4px 0 8px; }
#wordDialog #saveWord { margin-top: 8px; }
#wordDialog #onlineTranslate { margin-top: 10px; }

.readingHint { font-size: 14px; line-height: 1.4; margin: 8px 0; color: #516459; }
.optionalAudio { margin: 12px 0; }

/* Vocabulary keeps search and state selection stable while results change. */
.vocabularyFilters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.vocabularyFilters label:first-child { flex: 1 1 240px; }
.vocabularyFilters label { margin: 0; }
.vocabularyFilters select { display: block; min-height: 44px; }
.vocabularyWord h2 { margin: 0; overflow-wrap: anywhere; }
.vocabularyStatus { margin-left: auto; }
.vocabularyVersion p, .vocabularyVersion blockquote { white-space: pre-wrap; overflow-wrap: anywhere; }
.vocabularyVersion blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid #b9c9c2; }
.vocabularyWord small { overflow-wrap: anywhere; }
.vocabularyWord .row small { flex: 1 1 180px; }
#vocabularyWords { scroll-margin-top: 110px; }
.vocabularyPages[hidden] { display: none; }
@media(max-width:750px) {
  header nav { flex-wrap: wrap; }
  #vocabularyNav { min-height: 44px; }
  .vocabularyFilters { gap: 6px 10px; }
  .vocabularyFilters label:first-child { flex-basis: 100%; }
}
