:root {
  --ink: #152238;
  --muted: #66758f;
  --line: #dbe5f2;
  --panel: #ffffff;
  --wash: #f4f8fd;
  --blue: #2f80ed;
  --blue-soft: #e8f2ff;
  --word: #dff3ff;
  --word-ink: #145c80;
  --phrase: #e3f8e9;
  --phrase-ink: #1b6b3b;
  --idiom: #fff1c7;
  --idiom-ink: #806012;
  --pattern: #f0e7ff;
  --pattern-ink: #5a3ca0;
  --shadow: 0 18px 48px rgba(21, 34, 56, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #ffffff 0%, #f5f9fe 100%);
  color: var(--ink);
  font-family: Inter, system-ui, sans-serif;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus,
input:focus {
  outline: none;
}

button:focus-visible,
input:focus-visible {
  box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.2);
  outline: 1px solid rgba(47, 128, 237, 0.45);
  outline-offset: 2px;
}

.app-shell {
  height: 100vh;
  margin: 0 auto;
  padding: 24px 24px 44px;
  width: min(1500px, 100%);
}

.kicker {
  color: var(--blue);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.11em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h2,
h3,
p {
  margin-top: 0;
}

.date-strip {
  background: #edf4fc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
  padding: 4px;
}

.archive-control {
  display: grid;
  gap: 10px;
  margin-bottom: 24px;
}

.archive-button {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(21, 34, 56, 0.05);
  display: grid;
  gap: 3px;
  min-height: 58px;
  padding: 12px 14px;
  text-align: left;
  width: 100%;
}

.archive-button span {
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.archive-button strong {
  color: var(--ink);
  font-size: 0.95rem;
}

.archive-browser {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(21, 34, 56, 0.08);
  padding: 12px;
}

.archive-browser__head {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 34px 1fr 34px;
  margin-bottom: 10px;
  text-align: center;
}

.archive-browser__head strong {
  color: var(--ink);
  font-size: 0.95rem;
}

.archive-nav {
  background: #edf4fc;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #40516d;
  font-size: 1.1rem;
  font-weight: 900;
  min-height: 34px;
}

.archive-list {
  display: grid;
  gap: 6px;
}

.archive-edition {
  align-items: center;
  background: #f7fbff;
  border: 1px solid #dbe5f2;
  border-radius: 6px;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  min-height: 40px;
  padding: 0 10px;
  text-align: left;
}

.archive-edition span {
  font-weight: 900;
}

.archive-edition strong {
  color: var(--muted);
  font-size: 0.8rem;
}

.date-chip,
.level-button,
.target-tab,
.tool-button {
  border: 0;
  border-radius: 6px;
  color: #4c5d78;
  font-weight: 800;
}

.date-chip {
  background: transparent;
  display: grid;
  gap: 2px;
  min-height: 48px;
  padding: 7px 8px;
  text-align: left;
}

.date-chip span {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.date-chip strong {
  color: inherit;
  font-size: 0.86rem;
}

.date-chip.is-active,
.level-button.is-active,
.target-tab.is-active {
  background: var(--panel);
  box-shadow: 0 6px 16px rgba(21, 34, 56, 0.08);
  color: var(--blue);
}

.level-control {
  align-items: center;
  background: #edf4fc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 4px;
  min-height: 48px;
  padding: 4px;
}

.level-control span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  padding: 0 10px;
  text-transform: uppercase;
}

.level-button {
  background: transparent;
  min-height: 38px;
  min-width: 52px;
}

.search-box {
  display: grid;
  margin: 16px 0 18px;
}

.search-box span {
  height: 0;
  opacity: 0;
  overflow: hidden;
}

.search-box input {
  background: var(--panel);
  border: 1px solid #cad7e7;
  border-radius: 8px;
  color: var(--ink);
  height: 48px;
  padding: 0 14px;
  width: 100%;
}

.reader-grid {
  align-items: start;
  display: grid;
  gap: clamp(28px, 4vw, 48px);
  grid-template-columns: 370px minmax(0, 1fr);
  height: 100%;
  overflow: hidden;
}

.mobile-library-backdrop,
.mobile-library-button {
  display: none;
}

.edition-panel {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 44px rgba(21, 34, 56, 0.07);
  display: flex;
  flex-direction: column;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 12px;
  position: relative;
}

.edition-panel__head {
  align-items: start;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0;
}

.edition-panel h2 {
  font-size: 1.2rem;
  margin-bottom: 0;
}

#storyCount {
  background: var(--blue-soft);
  border-radius: 999px;
  color: #1f65bd;
  font-weight: 900;
  padding: 6px 10px;
}

.legend {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend.compact {
  border-top: 1px solid var(--line);
  margin: 0 0 10px;
  padding-top: 14px;
}

.legend-item {
  align-items: center;
  color: #51627d;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 800;
  gap: 6px;
}

.swatch {
  border-radius: 4px;
  display: inline-block;
  height: 12px;
  width: 18px;
}

.swatch.word {
  background: var(--word);
}

.swatch.phrase {
  background: var(--phrase);
}

.swatch.idiom {
  background: var(--idiom);
}

.swatch.pattern {
  background: var(--pattern);
}

.story-list {
  background: #f7fbff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  display: grid;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  scrollbar-color: #b7c7da transparent;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.story-card,
.article-card,
.learning-panel,
.target-focus,
.target-pill {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(21, 34, 56, 0.06);
}

.story-card {
  display: grid;
  gap: 9px;
  padding: 15px;
  text-align: left;
  width: 100%;
}

.story-card.is-active {
  border-color: rgba(47, 128, 237, 0.7);
  box-shadow: 0 14px 36px rgba(47, 128, 237, 0.15);
}

.story-meta,
.article-meta {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.74rem;
  font-weight: 900;
  gap: 8px;
  text-transform: uppercase;
}

.story-card h3 {
  color: #101a2d;
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1.18;
  margin: 0;
}

.story-card p {
  color: #4d5d76;
  font-size: 0.94rem;
  line-height: 1.48;
  margin: 0;
}

.mini-stats {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.pill {
  background: var(--blue-soft);
  border-radius: 999px;
  color: #1f65bd;
  padding: 4px 8px;
}

.article-card {
  --article-pad: clamp(22px, 4vw, 54px);
  max-height: 100%;
  min-height: 760px;
  outline: none;
  overflow-y: auto;
  padding: 0;
  position: relative;
  scrollbar-gutter: stable;
}

.article-card::before {
  background: #ffffff;
  content: "";
  display: block;
  height: var(--article-pad);
  margin-bottom: calc(-1 * var(--article-pad));
  pointer-events: none;
  position: sticky;
  top: 0;
  z-index: 40;
}

.article-card:focus,
.article-card:focus-visible {
  outline: none;
}

.article-header {
  border-bottom: 1px solid var(--line);
  margin: var(--article-pad) var(--article-pad) 28px;
  padding-bottom: 22px;
}

.article-card.focus-mode .learning-panel {
  border-color: transparent;
  box-shadow: none;
  margin-bottom: 18px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding-bottom: 0;
  padding-top: 0;
  transform: translateY(-10px);
}

.article-card.focus-mode .learning-panel::before {
  display: none;
}

.article-card h2 {
  color: #101a2d;
  font-size: clamp(2.15rem, 3.9vw, 4.35rem);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.02;
  margin: 18px 0;
}

.article-summary {
  color: #33445d;
  font-size: 1.18rem;
  line-height: 1.68;
  margin-bottom: 18px;
  max-width: 900px;
}

.learning-panel {
  background: #fcfcfc;
  border-color: #cddff3;
  border-radius: 14px;
  box-shadow: 0 16px 42px rgba(21, 34, 56, 0.11);
  isolation: isolate;
  margin: 0 var(--article-pad) clamp(28px, 6vh, 64px);
  max-height: 760px;
  overflow: visible;
  padding: 18px;
  position: sticky;
  top: var(--article-pad);
  transform: translateY(0);
  transition:
    max-height 280ms ease,
    opacity 220ms ease,
    padding 280ms ease,
    transform 280ms ease;
  z-index: 45;
}

.learning-panel::before {
  background: #ffffff;
  border-radius: 18px;
  content: "";
  inset: -10px -12px -12px;
  pointer-events: none;
  position: absolute;
  z-index: -1;
}

.learning-panel__head {
  align-items: start;
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(220px, 0.72fr) minmax(520px, 1.28fr);
  margin-bottom: 14px;
}

.learning-panel h3 {
  color: #101a2d;
  font-size: 1.15rem;
  font-weight: 900;
  margin-bottom: 0;
}

.learning-controls {
  display: grid;
  gap: 10px;
}

.learning-panel__body {
  max-height: 520px;
  opacity: 1;
  overflow: hidden;
  transform: translateY(0);
}

.target-tabs {
  background: #eaf2fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(5, 1fr);
  padding: 4px;
}

.target-tab {
  background: transparent;
  min-height: 38px;
}

.target-focus {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 18px;
}

.target-focus__top {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.target-focus h4 {
  color: #101a2d;
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1.1;
  margin: 0;
}

.target-kind {
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 900;
  padding: 5px 8px;
  text-transform: uppercase;
}

.target-kind.word,
.highlight.word {
  background: var(--word);
  color: var(--word-ink);
}

.target-kind.phrase,
.highlight.phrase {
  background: var(--phrase);
  color: var(--phrase-ink);
}

.target-kind.idiom,
.highlight.idiom {
  background: var(--idiom);
  color: var(--idiom-ink);
}

.target-kind.pattern,
.highlight.pattern {
  background: var(--pattern);
  color: var(--pattern-ink);
}

.target-focus p {
  color: #43536c;
  line-height: 1.58;
  margin: 0;
}

.example {
  background: #f0f5fb;
  border: 1px solid #dfe9f5;
  border-radius: 8px;
  color: #4f607a;
  font-style: italic;
  line-height: 1.62;
  padding: 12px;
}

.target-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.target-pill {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  line-height: 1.25;
  min-height: 40px;
  padding: 8px 11px;
}

.target-pill.is-active {
  border-color: rgba(47, 128, 237, 0.7);
}

.article-tools {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0;
  padding: 0;
}

.tool-button {
  background: #eaf2fb;
  min-height: 40px;
  padding: 0 13px;
}

.tool-button.is-active {
  background: var(--blue);
  color: #ffffff;
}

.article-tools a {
  color: var(--blue);
  font-weight: 900;
  text-decoration: none;
}

.article-body {
  color: #273852;
  display: grid;
  font-size: 1.12rem;
  gap: 22px;
  line-height: 1.9;
  margin: 0 var(--article-pad) var(--article-pad);
  max-width: 920px;
  position: relative;
  z-index: 1;
}

.article-body p {
  margin: 0;
}

.article-body.no-highlights .highlight {
  background: transparent;
  color: inherit;
  font-weight: inherit;
  padding: 0;
}

.highlight {
  border: 0;
  border-radius: 5px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  display: inline;
  font-weight: 850;
  line-height: 1.55;
  margin: 0 1px;
  padding: 1px 3px;
  vertical-align: baseline;
}

.highlight.is-selected {
  box-shadow: inset 0 0 0 2px rgba(21, 34, 56, 0.18);
}

.empty {
  color: var(--muted);
  padding: 16px;
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
  }

  .reader-grid,
  .learning-panel__head {
    grid-template-columns: 1fr;
  }

  .reader-grid {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .article-card {
    max-height: none;
    min-height: 0;
    order: 1;
    overflow: visible;
  }

  .edition-panel {
    max-height: none;
    order: 2;
    overflow: visible;
  }

  .date-strip {
    width: 100%;
  }

  .learning-panel {
    max-height: none;
    position: static;
  }

  .article-card::before {
    display: none;
  }

  .learning-panel__body {
    max-height: none;
  }
}

@media (max-width: 820px) {
  body.mobile-library-open {
    overflow: hidden;
  }

  .app-shell {
    padding: 10px;
  }

  .reader-grid {
    display: block;
  }

  .article-card {
    background: transparent;
    border-color: transparent;
    border-radius: 12px;
    box-shadow: none;
    width: 100%;
  }

  .article-header {
    margin-bottom: 18px;
    padding-bottom: 18px;
  }

  .article-card h2 {
    font-size: clamp(2.15rem, 10vw, 3.25rem);
    line-height: 1.04;
    margin: 14px 0;
  }

  .article-summary {
    font-size: 1rem;
    line-height: 1.55;
    margin-bottom: 14px;
  }

  .article-body {
    font-size: 1rem;
    gap: 18px;
    line-height: 1.78;
    max-width: none;
  }

  .article-tools {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mobile-library-button {
    display: flex;
  }

  .tool-button,
  .article-tools a {
    align-items: center;
    display: flex;
    font-size: 0.92rem;
    justify-content: center;
    min-height: 38px;
    padding: 0 10px;
    text-align: center;
  }

  .article-tools a {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
  }

  .mobile-library-backdrop {
    background: rgba(21, 34, 56, 0.28);
    border: 0;
    border-radius: 0;
    bottom: 0;
    display: block;
    left: 0;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    right: 0;
    top: 0;
    transition: opacity 180ms ease;
    z-index: 90;
  }

  .mobile-library-backdrop[hidden] {
    display: none;
  }

  .mobile-library-backdrop:not([hidden]) {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .edition-panel {
    border-radius: 18px 18px 14px 14px;
    bottom: 10px;
    box-shadow: 0 24px 70px rgba(21, 34, 56, 0.25);
    left: 10px;
    max-height: min(82dvh, 760px);
    overflow: hidden;
    position: fixed;
    right: 10px;
    top: auto;
    transform: translateY(calc(100% + 24px));
    transition: transform 240ms ease;
    z-index: 100;
  }

  .edition-panel.is-mobile-open {
    transform: translateY(0);
  }

  .archive-control {
    margin-bottom: 14px;
  }

  .search-box {
    margin: 12px 0;
  }

  .legend.compact {
    padding-top: 10px;
  }

  .story-list {
    max-height: min(42dvh, 420px);
  }

  .learning-panel {
    margin-left: 0;
    margin-right: 0;
    max-height: min(40dvh, 390px);
    overflow: hidden;
    padding: 14px;
    position: sticky;
    top: 8px;
    z-index: 45;
  }

  .learning-panel::before {
    inset: -8px;
  }

  .learning-panel__head {
    gap: 12px;
    margin-bottom: 12px;
  }

  .learning-panel h3 {
    font-size: 1rem;
  }

  .learning-panel__body {
    max-height: min(28dvh, 260px);
    overflow-y: auto;
    padding-right: 1px;
    scrollbar-width: none;
  }

  .learning-panel__body::-webkit-scrollbar {
    display: none;
  }

  .learning-controls {
    gap: 8px;
  }

  .level-control,
  .target-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .level-control::-webkit-scrollbar,
  .target-tabs::-webkit-scrollbar,
  .target-rail::-webkit-scrollbar {
    display: none;
  }

  .level-control span {
    flex: 0 0 auto;
    padding: 0 6px;
  }

  .level-button,
  .target-tab {
    flex: 1 0 auto;
    min-height: 36px;
    min-width: 56px;
    padding: 0 12px;
  }

  .target-focus {
    gap: 9px;
    margin-bottom: 10px;
    padding: 14px;
  }

  .target-focus h4 {
    font-size: 1.35rem;
  }

  .target-focus p,
  .example {
    font-size: 0.95rem;
  }

  .target-rail {
    display: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 8px;
  }

  .date-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .level-control {
    align-items: center;
  }

  .level-control span {
    align-self: center;
    padding: 0 4px;
  }

  .article-card {
    --article-pad: 16px;
  }

  .article-card h2 {
    font-size: clamp(2rem, 9.8vw, 3rem);
  }

  .learning-panel {
    padding: 14px;
  }

  .target-focus {
    padding: 14px;
  }
}
