:root {
  --ink: #172525;
  --muted: #6c7b78;
  --paper: #fbfaf7;
  --panel: #ffffff;
  --line: #e5e8e2;
  --teal: #1f5c59;
  --teal-dark: #183b3b;
  --mint: #dceee7;
  --coral: #d87557;
  --gold: #d2a64a;
  --soft-shadow: 0 18px 50px rgba(24, 59, 59, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  color: var(--ink);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(31, 92, 89, 0.035) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--paper);
  font-family: Vazirmatn, "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1.9;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 30px 22px 24px;
  background: var(--teal-dark);
  color: #f8fbf7;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 25px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 9px;
  color: #fff8e7;
  font-size: 22px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--coral);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.4;
}

.sidebar .eyebrow {
  color: #9ad0bf;
}

.brand-lockup h1 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.3;
}

.book-meta {
  padding: 19px 0 23px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.book-meta p {
  margin: 0 0 4px;
  color: #eef5ee;
  font-family: Georgia, serif;
  font-size: 0.96rem;
  direction: ltr;
  text-align: right;
}

.book-meta span {
  color: #a9bebb;
  font-size: 0.78rem;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 20px 0 16px;
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
}

.search-icon {
  color: #a9cfc2;
  font-size: 1.25rem;
  line-height: 1;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: white;
  font-size: 0.84rem;
}

.search-box input::placeholder {
  color: #b4c8c3;
}

.chapter-nav {
  display: grid;
  gap: 3px;
  overflow-y: auto;
}

.part-label {
  margin: 16px 9px 6px;
  color: #7fa69b;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.09em;
}

.chapter-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 9px;
  border: 0;
  border-right: 2px solid transparent;
  background: transparent;
  color: #c2d2cd;
  text-align: right;
  transition: 160ms ease;
}

.chapter-link:hover,
.chapter-link.active {
  border-right-color: var(--gold);
  background: rgba(255, 255, 255, 0.08);
  color: white;
}

.chapter-number {
  min-width: 24px;
  color: #7fa69b;
  font-family: Georgia, serif;
  font-size: 0.9rem;
  direction: ltr;
}

.chapter-link.active .chapter-number {
  color: #f2ca67;
}

.chapter-name {
  flex: 1;
  font-size: 0.82rem;
  line-height: 1.55;
}

.chapter-state {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #67847c;
}

.chapter-state.done {
  background: #b7e0b2;
  box-shadow: 0 0 0 3px rgba(183, 224, 178, 0.12);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 24px;
  color: #a9bebb;
  font-size: 0.72rem;
}

.legend-dot,
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b7e0b2;
}

.workspace {
  min-width: 0;
}

.page-hidden {
  display: none !important;
}

.library-view {
  max-width: 1370px;
  margin: 0 auto;
  padding: clamp(52px, 8vw, 105px) clamp(24px, 4vw, 64px) 90px;
}

.library-heading h2 {
  margin: 0;
  color: var(--teal-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.6rem, 5vw, 4.8rem);
  font-weight: 500;
  line-height: 1.15;
}

.library-heading .hero-subtitle {
  margin-top: 16px;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 320px));
  gap: 22px;
  max-width: 1050px;
  margin-top: 58px;
}

.book-card {
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: var(--soft-shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.book-card:hover {
  transform: translateY(-3px);
  border-color: #a9c9bf;
  box-shadow: 0 22px 55px rgba(24, 59, 59, 0.13);
}

.book-cover {
  display: flex;
  align-items: stretch;
  justify-content: center;
  aspect-ratio: 1050 / 1379;
  width: min(100%, 220px);
  margin: 0 auto 21px;
  min-height: 0;
  overflow: hidden;
  border-radius: 4px;
  background: #f8f7f3;
}

.book-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.book-card-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.book-card h3 {
  margin: 0;
  color: var(--teal-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.book-card .english-title {
  margin: 7px 0 0;
  color: var(--muted);
  direction: ltr;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.87rem;
  text-align: right;
}

.book-card .book-authors {
  margin: 17px 0 0;
  color: #566966;
  font-size: 0.76rem;
}

.book-card .book-description {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.75;
}

.book-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 17px;
  color: var(--teal);
  font-size: 0.75rem;
  font-weight: 800;
}

.book-card-footer span:last-child {
  color: var(--coral);
  font-size: 1rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1370px;
  margin: 0 auto;
  padding: 19px clamp(24px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.77rem;
}

.breadcrumb strong {
  color: var(--ink);
}

.breadcrumb-separator {
  color: #b7bfbb;
  direction: ltr;
}

.icon-button,
.text-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  color: var(--teal);
  background: transparent;
  font-size: 0.79rem;
  font-weight: 800;
}

.icon-button span:first-child {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border: 1px solid #b8cfca;
  border-radius: 6px;
  font-size: 1rem;
}

.icon-button:hover,
.text-button:hover {
  color: var(--coral);
}

.chapter-hero,
.content-grid {
  max-width: 1370px;
  margin: 0 auto;
  padding-right: clamp(24px, 4vw, 64px);
  padding-left: clamp(24px, 4vw, 64px);
}

.chapter-hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  padding-top: clamp(43px, 7vw, 88px);
  padding-bottom: 43px;
}

.chapter-hero h2 {
  max-width: 730px;
  margin: 0;
  color: var(--teal-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 4vw, 4rem);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.2;
}

.hero-subtitle {
  max-width: 650px;
  margin: 19px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.progress-panel {
  width: 190px;
  padding-bottom: 6px;
}

.progress-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.7rem;
}

.progress-panel strong {
  display: block;
  margin-bottom: 12px;
  color: var(--teal-dark);
  font-family: Georgia, serif;
  font-size: 1.05rem;
  font-weight: 500;
  direction: ltr;
  text-align: right;
}

.progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 20px;
  background: #dfe6e0;
}

.progress-track span {
  display: block;
  width: 9%;
  height: 100%;
  border-radius: inherit;
  background: var(--coral);
  transition: width 240ms ease;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: clamp(34px, 5vw, 88px);
  align-items: start;
  padding-bottom: 80px;
}

.article {
  min-width: 0;
  max-width: 780px;
  padding-top: 7px;
  overflow-wrap: break-word;
}

.translation-guide {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 28px;
  padding: 11px 13px;
  border: 1px solid #d8e3de;
  border-radius: 6px;
  background: #f4f8f4;
  color: #59716b;
  font-size: 0.8rem;
}

.guide-mark {
  display: inline-grid;
  min-width: 27px;
  height: 22px;
  place-items: center;
  border-radius: 4px;
  background: var(--teal);
  color: white;
  direction: ltr;
  font: 0.67rem/1 "SFMono-Regular", Consolas, monospace;
}

.translation-block {
  margin: 0 0 24px;
}

.translation-trigger {
  position: relative;
  display: block;
  width: 100%;
  padding: 0 31px 0 5px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: right;
  transition: background 150ms ease, box-shadow 150ms ease;
}

.translation-trigger:hover,
.translation-block.is-open > .translation-trigger,
.list-translation-item.is-open > .translation-trigger {
  background: rgba(220, 238, 231, 0.35);
  box-shadow: inset -3px 0 0 var(--coral);
}

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

.translation-copy {
  margin: 0;
}

.translation-code .translation-copy {
  margin: 0;
}

.translation-quote .translation-copy {
  margin: 0;
  white-space: pre-line;
}

.translation-figure .translation-copy {
  margin: 0;
}

.translation-affordance {
  position: absolute;
  top: 8px;
  left: 7px;
  display: grid;
  width: 19px;
  height: 19px;
  place-items: center;
  border: 1px solid #b7ccc5;
  border-radius: 50%;
  color: var(--teal);
  font-size: 0.85rem;
  line-height: 1;
  transition: transform 150ms ease, background 150ms ease;
}

.translation-block.is-open .translation-affordance,
.list-translation-item.is-open .translation-affordance {
  transform: rotate(180deg);
  background: var(--mint);
}

.original-capsule {
  margin: 9px 5px 0 0;
  padding: 13px 15px 15px;
  border: 1px solid #d9e4df;
  border-right: 3px solid var(--teal);
  border-radius: 5px;
  background: #f3f7f5;
  animation: capsule-in 150ms ease-out;
}

.original-capsule-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: #658078;
  font-size: 0.7rem;
  font-weight: 800;
}

.original-language {
  direction: ltr;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
}

.original-copy {
  color: #3f504d;
  direction: ltr;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.94rem;
  line-height: 1.85;
  text-align: left;
  white-space: pre-line;
}

.original-code {
  margin: 0;
  padding: 0;
  overflow-x: auto;
  background: transparent;
  color: #30403e;
  font: 0.82rem/1.8 "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
}

.translation-list {
  margin: 0 0 27px;
  padding-right: 29px;
  color: #30403e;
}

.list-translation-item {
  margin-bottom: 11px;
  padding-right: 4px;
}

.list-translation-item .translation-trigger {
  padding-right: 8px;
}

.list-translation-item .translation-affordance {
  top: 1px;
}

.translation-table .translation-trigger {
  padding-right: 5px;
  overflow-x: auto;
}

.translation-table .translation-affordance {
  top: 10px;
}

@keyframes capsule-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.article > p,
.article > ul,
.article > ol,
.article > blockquote,
.article > table,
.article > .figure-note,
.article > .translation-note {
  margin-right: 0;
  margin-left: 0;
}

.article p {
  margin-top: 0;
  margin-bottom: 21px;
  color: #30403e;
  font-size: 1rem;
}

.article h3 {
  margin: 52px 0 17px;
  color: var(--teal-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.8rem;
  font-weight: 500;
  line-height: 1.35;
}

.article h4 {
  margin: 35px 0 13px;
  color: var(--teal);
  font-size: 1.15rem;
}

.article strong {
  color: var(--teal-dark);
}

.article em {
  color: #586965;
}

.article code,
.note-rail code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #edf1ec;
  color: #a34e38;
  direction: ltr;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.88em;
}

.article pre {
  max-width: 100%;
  direction: ltr;
  margin: 19px 0 25px;
  padding: 18px 20px;
  overflow-x: auto;
  border-right: 3px solid var(--coral);
  border-radius: 4px;
  background: #1c2d2c;
  color: #e7f2e9;
  font: 0.86rem/1.85 "SFMono-Regular", Consolas, monospace;
  text-align: left;
  white-space: pre-wrap;
}

.article blockquote {
  margin: 25px 0;
  padding: 17px 22px;
  border-right: 3px solid var(--gold);
  background: #fff8e8;
  color: #5d5137;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.02rem;
}

.article ol {
  margin-top: 12px;
  margin-bottom: 26px;
  padding-right: 26px;
  color: #30403e;
}

.article li {
  margin-bottom: 8px;
  padding-right: 5px;
}

.figure-note,
.translation-note {
  margin: 25px 0 27px;
  padding: 14px 16px;
  border: 1px solid #d8e3de;
  border-radius: 6px;
  background: #f4f8f4;
  color: #59716b;
  font-size: 0.88rem;
}

.figure-note strong,
.translation-note strong {
  display: block;
  margin-bottom: 3px;
  color: var(--teal);
  font-size: 0.76rem;
}

.article table {
  display: table;
  max-width: 100%;
  overflow-x: auto;
  width: 100%;
  margin: 27px 0 32px;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.article th,
.article td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: right;
}

.article th {
  color: var(--teal-dark);
  background: #edf5f0;
  font-weight: 800;
}

.article td:first-child,
.article th:first-child {
  direction: ltr;
  text-align: left;
}

.chapter-placeholder {
  padding: 30px 0;
}

.chapter-placeholder .placeholder-mark {
  display: grid;
  width: 54px;
  height: 54px;
  margin-bottom: 18px;
  place-items: center;
  border-radius: 10px;
  background: var(--mint);
  color: var(--teal-dark);
  font-size: 1.45rem;
  font-weight: 800;
}

.chapter-placeholder h3 {
  margin-top: 0;
}

.chapter-placeholder p {
  max-width: 610px;
}

.context-rail {
  position: sticky;
  top: 22px;
  padding-top: 9px;
}

.rail-section {
  padding: 18px 0 22px;
  border-bottom: 1px solid var(--line);
}

.rail-section:first-child {
  padding-top: 0;
}

.rail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-list {
  display: grid;
  gap: 7px;
  margin: 15px 0 0;
  padding: 0;
  list-style: none;
}

.section-list li {
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.55;
}

.section-list li::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 8px;
  border: 1px solid var(--coral);
  border-radius: 50%;
  content: "";
}

.source-rail p,
.note-rail p {
  margin: 10px 0 15px;
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.8;
}

.text-button {
  padding: 0;
}

.empty-state {
  padding: 35px 0;
  color: var(--muted);
  font-size: 0.95rem;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 238px minmax(0, 1fr);
  }

  .content-grid {
    grid-template-columns: minmax(0, 1fr) 205px;
    gap: 32px;
  }
}

@media (max-width: 780px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: relative;
    min-height: auto;
    padding: 18px 18px 14px;
  }

  .brand-lockup {
    padding-bottom: 15px;
  }

  .book-meta {
    display: none;
  }

  .search-box {
    margin: 14px 0 7px;
  }

  .chapter-nav {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .part-label {
    display: none;
  }

  .chapter-link {
    min-width: max-content;
    padding: 8px 9px;
    border-right: 0;
    border-bottom: 2px solid transparent;
  }

  .chapter-link:hover,
  .chapter-link.active {
    border-bottom-color: var(--gold);
  }

  .chapter-state {
    display: none;
  }

  .sidebar-footer {
    display: none;
  }

  .topbar {
    gap: 12px;
    padding: 15px 18px;
  }

  .topbar-actions {
    flex: 0 0 auto;
  }

  .library-view {
    padding: 45px 18px 60px;
  }

  .book-grid {
    grid-template-columns: minmax(0, 1fr);
    margin-top: 40px;
  }

  .book-card {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    padding: 16px;
  }

  .book-cover {
    width: min(100%, 215px);
    margin-bottom: 19px;
  }

  .breadcrumb span:first-child,
  .breadcrumb-separator {
    display: none;
  }

  .chapter-hero {
    display: block;
    padding: 40px 18px 30px;
  }

  .chapter-hero h2 {
    font-size: 2.2rem;
  }

  .hero-subtitle {
    font-size: 0.94rem;
  }

  .progress-panel {
    width: 100%;
    margin-top: 28px;
  }

  .content-grid {
    display: block;
    padding: 0 18px 60px;
  }

  .article {
    max-width: none;
  }

  .article p {
    font-size: 0.96rem;
  }

  .article h3 {
    font-size: 1.6rem;
  }

  .article h4 {
    font-size: 1.08rem;
  }

  .article pre {
    padding: 14px 15px;
    font-size: 0.76rem;
    line-height: 1.75;
  }

  .article blockquote {
    padding: 14px 16px;
    font-size: 0.96rem;
  }

  .article table {
    display: block;
    font-size: 0.78rem;
  }

  .article th,
  .article td {
    min-width: 120px;
  }

  .context-rail {
    position: static;
    margin-top: 50px;
  }
}
