:root {
  --ink: #3b342f;
  --muted: #786f66;
  --paper: #fffdf8;
  --panel: #f4efe6;
  --line: #e0d7c8;
  --red: #a84b43;
  --blue: #406f8d;
  --green: #5e8565;
  --gold: #bd8446;
  --shadow: 0 18px 52px rgba(55, 45, 34, 0.11);
  --serif: Georgia, "Times New Roman", serif;
  --sans: Avenir Next, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(64,111,141,0.055) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(0deg, rgba(168,75,67,0.035) 1px, transparent 1px) 0 0 / 28px 28px,
    #ebe4d8;
  color: var(--ink);
  font-family: var(--sans);
}

button, input { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.library {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px 18px;
  background: rgba(251, 250, 246, 0.92);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-family: var(--serif);
  font-size: 31px;
  line-height: 1;
}

h2 {
  max-width: 780px;
  font-size: 25px;
  line-height: 1.15;
}

.status-dot {
  width: 12px;
  height: 12px;
  margin-top: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(40,113,76,0.12);
}

.search-toggle {
  border: 1px solid rgba(64,111,141,0.25);
  border-radius: 8px;
  background: rgba(64,111,141,0.08);
  color: var(--blue);
  cursor: pointer;
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 850;
  text-align: left;
}

.search-toggle.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.search-box {
  display: none;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

body.search-open .search-box {
  display: grid;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 13px 14px;
  outline: none;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
}

.search-box input:focus {
  border-color: rgba(44,101,168,0.55);
  box-shadow: 0 0 0 4px rgba(44,101,168,0.11);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.view-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.mode-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 9px 10px;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.filter-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.filter-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.doc-list {
  display: grid;
  gap: 9px;
  overflow: auto;
  padding-right: 4px;
}

.doc-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.72);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.doc-item:hover { transform: translateX(3px); }

.doc-item.active {
  background: #fff;
  border-color: rgba(214,22,22,0.45);
  box-shadow: 0 8px 26px rgba(35,31,24,0.08);
}

.doc-name {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 850;
}

.doc-meta {
  color: var(--muted);
  font-size: 12px;
}

.reader {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.reader-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 96px;
  padding: 22px 28px;
  background: rgba(251,250,246,0.72);
  border-bottom: 1px solid var(--line);
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn, .peek-btn, .back-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  height: 38px;
}

.icon-btn {
  width: 38px;
  font-size: 30px;
  line-height: 1;
}

.peek-btn {
  padding: 0 14px;
  font-weight: 850;
}

.back-btn {
  padding: 0 13px;
  color: var(--blue);
  font-weight: 850;
}

.back-btn:hover {
  border-color: rgba(64,111,141,0.35);
  background: rgba(64,111,141,0.08);
}

.peek-btn:active,
body.page-peek .peek-btn {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.page-chip {
  min-width: 78px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.62);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.page-stage {
  min-height: 0;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 24px;
  padding: 24px 28px;
  overflow: hidden;
}

.page-rail {
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow: auto;
  padding-right: 4px;
}

.page-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.64);
  color: var(--muted);
  padding: 9px 6px;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.page-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.page-card {
  overflow: auto;
  max-width: 1120px;
  margin: 0 auto;
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 30px 34px 46px;
  scroll-behavior: smooth;
}

.document-scroll {
  display: grid;
  gap: 30px;
}

.document-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 5px 0 18px;
  border-bottom: 1px solid var(--line);
}

.document-intro h3 {
  margin: 0;
  color: var(--red);
  font-size: 28px;
  line-height: 1.1;
}

.reader-page {
  scroll-margin-top: 18px;
}

.text-page {
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(224,215,200,0.75);
}

.calendar-board {
  display: none;
  overflow: auto;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

body.calendar-mode .calendar-board {
  display: block;
}

body.calendar-mode .back-btn,
body.calendar-mode .peek-btn,
body.calendar-mode .page-step {
  display: none;
}

body.calendar-mode .page-card,
body.calendar-mode .page-rail {
  display: none;
}

body.calendar-mode .page-stage {
  display: block;
  overflow: auto;
}

body.calendar-mode .calendar-board {
  grid-column: 1 / -1;
}

.calendar-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
  padding: 18px 2px 14px;
  border-bottom: 1px solid var(--line);
}

.calendar-head h3 {
  margin: 0;
  color: var(--red);
  font-size: 28px;
}

.calendar-note {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(190px, 1fr));
  gap: 12px;
  padding-bottom: 42px;
}

.day-card {
  min-height: 260px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251,250,246,0.92);
  box-shadow: 0 10px 30px rgba(55,45,34,0.07);
  overflow: hidden;
}

.day-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: #6f7863;
  color: #fff;
}

.day-top span {
  font-size: 13px;
  font-weight: 850;
}

.day-top strong {
  font-size: 12px;
  color: #f7f1e4;
}

.topic-list {
  flex: 1;
  margin: 0;
  padding: 13px 16px 8px 28px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.topic-list li {
  margin-bottom: 7px;
}

.material-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 12px;
}

.material-pill {
  border: 1px solid rgba(44,101,168,0.22);
  border-radius: 999px;
  background: rgba(44,101,168,0.08);
  color: var(--blue);
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 850;
  cursor: pointer;
}

.material-pill:hover {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.calendar-missing {
  border-radius: 999px;
  background: rgba(214,22,22,0.08);
  color: var(--red);
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 850;
}

.slide-peek {
  display: grid;
  place-items: center;
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(55,45,34,0.12);
}

.slide-img {
  grid-area: 1 / 1;
  width: 100%;
  height: auto;
  background: #fff;
  transition: opacity 0.12s ease;
}

.slide-en {
  opacity: 0;
}

body.page-peek .slide-en {
  opacity: 1;
}

body.page-peek .slide-de {
  opacity: 0;
}

body.page-peek .slide-peek,
body.page-peek .slide-peek * {
  cursor: none;
}

.line-study {
  margin-top: 14px;
  border: 1px solid rgba(64,111,141,0.18);
  border-radius: 8px;
  background: rgba(64,111,141,0.045);
  padding: 12px;
}

.line-study-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.line-study-head span {
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.line-study-head small {
  font-size: 12px;
  font-weight: 750;
}

.line-study .segment-list {
  margin-top: 8px;
}

.line-study .segment {
  margin: 4px 0;
  padding: 5px 7px;
}

.line-study .segment-text {
  font-size: 15px;
  line-height: 1.35;
  font-weight: 620;
}

.text-fallback {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.text-fallback summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
}

.segment-list {
  margin-top: 10px;
}

.page-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.page-title-row h3 {
  margin: 0;
  color: var(--red);
  font-size: 22px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.segment {
  position: relative;
  min-height: 28px;
  margin: 5px 0;
  border-radius: 6px;
  padding: 5px 8px;
  cursor: help;
}

.segment:hover,
.segment.hover-peek {
  background: rgba(64,111,141,0.1);
  box-shadow: inset 3px 0 0 rgba(64,111,141,0.48);
}

.segment-text {
  display: block;
  white-space: pre-wrap;
  font-size: 16px;
  line-height: 1.38;
  font-weight: 560;
}

.segment-en {
  display: none;
  color: var(--blue);
}

.segment:hover .segment-de,
.segment.hover-peek .segment-de,
.segment.peek .segment-de,
body.page-peek .text-page .segment-de {
  display: none;
}

.segment:hover .segment-en,
.segment.hover-peek .segment-en,
.segment.peek .segment-en,
body.page-peek .text-page .segment-en {
  display: block;
}

.segment-empty {
  color: var(--muted);
  font-size: 15px;
  font-style: italic;
}

.loading, .empty {
  padding: 30px;
  color: var(--muted);
}

mark {
  background: rgba(214,22,22,0.16);
  color: inherit;
  border-radius: 3px;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .library {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .reader {
    min-height: 58vh;
  }

  .reader-top {
    align-items: stretch;
    flex-direction: column;
    padding: 18px;
  }

  .reader-actions {
    flex-wrap: wrap;
  }

  .page-stage {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .calendar-head {
    align-items: start;
    flex-direction: column;
  }

  .calendar-grid {
    grid-template-columns: 1fr;
  }

  .page-rail {
    flex-direction: row;
    padding-bottom: 4px;
  }

  .page-btn {
    min-width: 46px;
  }

  .page-card {
    padding: 24px 18px 36px;
  }

  .document-intro {
    align-items: start;
    flex-direction: column;
  }

  .document-intro h3 {
    font-size: 24px;
  }

  .segment-text {
    font-size: 17px;
  }
}
