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

:root {
  --bg: #e9e1d6;
  --surface: rgba(255, 252, 247, 0.62);
  --surface-strong: rgba(255, 251, 245, 0.86);
  --surface-soft: rgba(255, 252, 247, 0.74);
  --line: rgba(55, 40, 26, 0.2);
  --text: #1b1611;
  --muted: #36281e;
  --accent: #c25a21;
  --gold: #b8943e;
  --punk-cyan: #2fc9c2;
  --shadow: 0 24px 60px rgba(35, 25, 16, 0.16);
  --radius-lg: 24px;
  --radius-md: 16px;
  --font: Georgia, "Times New Roman", "Songti SC", serif;
  --font-mono: "SF Mono", "Fira Code", "Courier New", monospace;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--text);
  background:
    linear-gradient(rgba(245, 238, 229, 0.72), rgba(232, 223, 212, 0.76)),
    linear-gradient(180deg, #f4ede4 0%, #e6ddcf 100%);
  font-family: var(--font);
  line-height: 1.65;
  font-weight: 500;
}

body.night-mode {
  --bg: #13110f;
  --surface: rgba(26, 24, 21, 0.66);
  --surface-strong: rgba(32, 29, 25, 0.92);
  --surface-soft: rgba(30, 27, 24, 0.74);
  --line: rgba(230, 218, 198, 0.18);
  --text: #f1e9dc;
  --muted: #d0bfa9;
  --accent: #f08a45;
  --gold: #d6b65e;
  background:
    linear-gradient(rgba(18, 16, 14, 0.82), rgba(22, 20, 18, 0.86)),
    linear-gradient(180deg, #181512 0%, #0f0e0d 100%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.86' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  z-index: 2;
}

button,
textarea {
  font: inherit;
}

.page-border {
  position: fixed;
  inset: 8px;
  border: 1px solid var(--line);
  pointer-events: none;
  z-index: 4;
}

.page-border::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(55, 40, 26, 0.12);
}

.learn-page {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100dvh;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1.13fr) minmax(320px, .87fr);
  grid-template-rows: minmax(0, 1fr) clamp(122px, 17vh, 164px);
  gap: 10px;
}

.glass {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(140%);
}

.glass::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: calc(var(--radius-lg) - 6px);
  pointer-events: none;
  opacity: .48;
  z-index: 1;
}

.glass::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  right: -1px;
  bottom: -1px;
  border-right: 2px solid var(--gold);
  border-bottom: 2px solid var(--gold);
  opacity: .55;
  pointer-events: none;
  z-index: 2;
}

.panel-body {
  position: relative;
  z-index: 2;
  height: 100%;
  min-height: 0;
  padding: 12px;
}

.title-panel {
  height: 30px;
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid rgba(55, 40, 26, 0.07);
  border-radius: 12px;
  background: rgba(255, 252, 247, 0.26);
  backdrop-filter: blur(10px) saturate(112%);
}

.title-kicker {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 9px;
  font-weight: 700;
  white-space: nowrap;
}

.title-panel h1 {
  min-width: 0;
  margin: 0 0 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(15px, 1.12vw, 20px);
  line-height: 1;
  font-weight: 700;
}

.course-meta {
  margin-left: auto;
  max-width: 44%;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  white-space: nowrap;
}

.nav-panel {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
  width: calc((100% - 38px) * .435);
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid rgba(55, 40, 26, 0.07);
  border-radius: 14px;
  background: rgba(255, 252, 247, 0.15);
  backdrop-filter: blur(12px) saturate(116%);
}

.pill {
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(55, 40, 26, 0.17);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.78);
  color: var(--text);
  box-shadow: 0 10px 24px rgba(35, 25, 16, 0.08);
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.primary {
  border-color: rgba(194, 90, 33, .46);
  background: rgba(194, 90, 33, .14);
  color: #7b3111;
}

.original-panel {
  grid-column: 1;
  grid-row: 1;
}

.translation-panel {
  grid-column: 2;
  grid-row: 1;
}

.original-panel .panel-body {
  padding-top: 12px;
}

.translation-panel .panel-body {
  padding-top: 12px;
}

.reader {
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.reader-text {
  min-height: 0;
  overflow: auto;
  padding: clamp(16px, 1.8vw, 24px);
  border: 1px solid rgba(55, 40, 26, 0.13);
  border-radius: var(--radius-md);
  background: rgba(255, 252, 247, 0.9);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45);
  font-size: clamp(17px, 1.25vw, 21px);
  line-height: 1.9;
}

.reader-text p {
  margin: 0 0 1em;
}

.reader-text p:last-child {
  margin-bottom: 0;
}

.reader-placeholder {
  height: 100%;
  min-height: 240px;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
}

.reader-placeholder strong {
  color: var(--text);
  font-family: var(--font);
  font-size: clamp(20px, 2vw, 30px);
  line-height: 1.25;
}

.translation-reader {
  padding: 10px;
  background: rgba(250, 246, 238, 0.94);
  scroll-behavior: smooth;
}

.translation-page {
  min-height: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(18px, 2vw, 30px);
  border: 1px solid rgba(55, 40, 26, 0.16);
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 18px 38px rgba(35, 25, 16, 0.12);
}

.translation-page-meta {
  margin: 0 0 18px;
  color: rgba(54, 40, 30, 0.58);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

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

.translation-block {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  scroll-margin: 35vh;
}

.translation-block:hover,
.translation-block:focus-visible {
  border-color: rgba(47, 201, 194, 0.28);
  background: rgba(47, 201, 194, 0.06);
  outline: none;
}

.translation-block.is-active {
  border-color: rgba(47, 201, 194, 0.46);
  background: rgba(47, 201, 194, 0.13);
  box-shadow: inset 3px 0 0 rgba(47, 201, 194, 0.82);
}

.translation-block-index {
  color: rgba(194, 90, 33, 0.76);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.9;
}

.translation-block p {
  margin: 0;
  white-space: pre-wrap;
  font-size: clamp(16px, 1.08vw, 19px);
  line-height: 1.82;
}

.translation-empty {
  height: 100%;
  min-height: 240px;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
}

.translation-empty strong {
  color: var(--text);
  font-family: var(--font);
  font-size: clamp(20px, 2vw, 30px);
  line-height: 1.25;
}

.translation-error {
  border-left: 3px solid rgba(194, 90, 33, 0.76);
  padding: 10px 12px;
  color: #7b3111;
  background: rgba(194, 90, 33, 0.08);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
}

.translation-skeleton {
  height: 18px;
  margin: 0 0 15px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(232, 220, 204, .45), rgba(255, 252, 247, .88), rgba(232, 220, 204, .45));
  background-size: 220% 100%;
  animation: pdf-loading 1.2s ease-in-out infinite;
}

.translation-skeleton.short {
  width: 68%;
}

.pdf-host {
  height: 100%;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  background: rgba(239, 233, 224, 0.96);
  scrollbar-gutter: stable both-edges;
}

.pdf-official-host {
  overflow: hidden;
  background: rgba(239, 233, 224, 0.96);
}

.pdf-official-frame {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  background: #f4efe7;
}

.pdf-viewer {
  min-height: 100%;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 18px;
  padding: 18px;
}

.pdf-page {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-height: 280px;
  overflow: hidden;
  border: 1px solid rgba(55, 40, 26, 0.18);
  border-radius: 8px;
  background: #fffdfa;
  box-shadow: 0 18px 38px rgba(35, 25, 16, 0.16);
  touch-action: pan-y;
}

.pdf-page.is-rendering {
  background:
    linear-gradient(90deg, rgba(255,255,255,.6), rgba(240,232,220,.9), rgba(255,255,255,.6)),
    #fffdfa;
  background-size: 220% 100%;
  animation: pdf-loading 1.2s ease-in-out infinite;
}

.pdf-page canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.pdf-page-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(54, 40, 30, 0.48);
  font-family: var(--font-mono);
  font-size: 12px;
}

.pdf-page-badge {
  position: absolute;
  right: 10px;
  bottom: 9px;
  z-index: 4;
  padding: 3px 8px;
  border: 1px solid rgba(55, 40, 26, 0.14);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.82);
  color: rgba(54, 40, 30, 0.64);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}

.annotation-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  cursor: crosshair;
}

.annotation {
  position: absolute;
  pointer-events: none;
}

.annotation.highlight {
  border-radius: 3px;
  background: rgba(255, 221, 64, 0.42);
  mix-blend-mode: multiply;
}

.annotation.underline {
  border-bottom: 4px solid rgba(37, 176, 171, 0.82);
}

.annotation.mark {
  border: 2px solid rgba(194, 90, 33, 0.76);
  border-radius: 6px;
  background: rgba(194, 90, 33, 0.08);
}

.annotation.draft {
  outline: 1px dashed rgba(27, 22, 17, 0.45);
}

body.night-mode .pdf-host {
  background: #1d1a17;
}

body.night-mode .pdf-page {
  border-color: rgba(230, 218, 198, 0.18);
  background: #f3eee4;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.32);
}

body.night-mode .pdf-page-badge {
  background: rgba(34, 30, 26, 0.72);
  color: rgba(241, 233, 220, 0.72);
}

body.night-mode .translation-reader {
  background: #1d1a17;
}

body.night-mode .translation-page {
  border-color: rgba(230, 218, 198, 0.18);
  background: #211e1a;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.3);
}

body.night-mode .translation-page-meta,
body.night-mode .translation-block-index {
  color: rgba(240, 186, 129, 0.76);
}

body.night-mode .translation-block:hover,
body.night-mode .translation-block:focus-visible {
  background: rgba(47, 201, 194, 0.1);
}

body.night-mode .translation-block.is-active {
  background: rgba(47, 201, 194, 0.16);
}

body.night-mode .translation-error {
  color: #ffd6bd;
  background: rgba(194, 90, 33, 0.14);
}

@keyframes pdf-loading {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

.actions-panel {
  grid-column: 1 / 3;
  grid-row: 1;
  align-self: end;
  justify-self: center;
  width: min(920px, calc(100vw - 56px));
  height: 76px;
  padding: 8px 10px;
  z-index: 8;
  border-radius: 22px;
  background: rgba(255, 252, 247, 0.72);
  backdrop-filter: blur(20px) saturate(140%);
}

.actions-grid {
  position: relative;
  z-index: 2;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(2, 1fr);
  gap: 7px;
}

.action {
  min-width: 0;
  border: 1px solid rgba(55, 40, 26, 0.16);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.78);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(11px, .9vw, 13px);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(35, 25, 16, 0.08);
}

.action.accent {
  border-color: rgba(47, 201, 194, .46);
  background: rgba(47, 201, 194, .13);
}

.action.is-active {
  border-color: rgba(194, 90, 33, .54);
  background: rgba(194, 90, 33, .18);
  color: #7b3111;
}

body.night-mode .action.is-active {
  color: #ffd6bd;
}

.action:disabled {
  cursor: not-allowed;
  opacity: .52;
}

.page-jump {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 5px;
}

.page-jump input,
.page-jump button {
  min-width: 0;
  border: 1px solid rgba(55, 40, 26, 0.16);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.78);
  color: var(--text);
  box-shadow: 0 8px 18px rgba(35, 25, 16, 0.08);
  font-family: var(--font-mono);
  font-size: clamp(11px, .84vw, 12px);
  font-weight: 700;
}

.page-jump input {
  width: 100%;
  padding: 0 8px;
  text-align: center;
  outline: none;
}

.page-jump button {
  padding: 0;
  cursor: pointer;
}

.page-jump input:focus {
  border-color: rgba(47, 201, 194, .56);
  background: rgba(47, 201, 194, .1);
}

.notes-panel {
  grid-column: 1;
  grid-row: 2;
}

.notes-layout {
  height: 100%;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
}

.note-tools {
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 10px;
  border-right: 1px solid rgba(55, 40, 26, 0.12);
}

.tool {
  height: 36px;
  border: 1px solid rgba(55, 40, 26, 0.14);
  border-radius: 12px;
  background: rgba(255, 252, 247, 0.78);
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(35, 25, 16, 0.08);
}

.tool.is-busy {
  opacity: .58;
  cursor: wait;
}

.note-editor {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 30px minmax(0, 1fr);
  gap: 8px;
}

.note-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(120px, 220px) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.note-row input {
  width: 100%;
  min-width: 0;
  height: 30px;
  border: 1px solid rgba(55, 40, 26, 0.14);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.86);
  color: var(--text);
  padding: 0 12px;
  outline: none;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

.note-row input:focus {
  border-color: rgba(47, 201, 194, .56);
  background: rgba(47, 201, 194, .1);
}

#noteStatus {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
}

.note-area {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  border: 1px solid rgba(55, 40, 26, 0.14);
  border-radius: var(--radius-md);
  background: rgba(255, 252, 247, 0.9);
  color: var(--text);
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.75;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45);
}

body.night-mode .note-row input,
body.night-mode .note-area,
body.night-mode .tool {
  border-color: rgba(230, 218, 198, 0.18);
  background: rgba(34, 30, 26, 0.86);
  color: var(--text);
}

.status-panel {
  grid-column: 2;
  grid-row: 2;
}

.status-panel .panel-body {
  display: grid;
  grid-template-rows: 30px minmax(0, 1fr);
  gap: 8px;
  padding-bottom: 48px;
}

.status-grid {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.metric {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 8px 9px;
  border: 1px solid rgba(55, 40, 26, 0.12);
  border-radius: 12px;
  background: rgba(255, 252, 247, 0.82);
  box-shadow: 0 10px 24px rgba(35, 25, 16, 0.08);
}

.metric strong {
  color: var(--accent);
  font-size: clamp(14px, 1.05vw, 20px);
  line-height: 1.1;
  font-weight: 700;
}

.metric span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.corner-nav {
  position: absolute;
  right: 16px;
  bottom: 12px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
}

.corner-link {
  height: 30px;
  min-width: 72px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(55, 40, 26, 0.16);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.78);
  color: var(--text);
  box-shadow: 0 10px 24px rgba(35, 25, 16, 0.1);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

.corner-link.primary {
  border-color: rgba(194, 90, 33, .42);
  background: rgba(194, 90, 33, .14);
  color: #7b3111;
}

.corner-link:hover {
  border-color: rgba(47, 201, 194, .56);
  background: rgba(47, 201, 194, .14);
  color: #0e7772;
}

.cyan-mark {
  color: #0e7772;
}

@media (max-width: 900px) {
  html,
  body {
    overflow: auto;
  }

  .page-border {
    display: none;
  }

  .learn-page {
    height: auto;
    min-height: 100dvh;
    padding: 10px;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .glass {
    grid-column: 1 !important;
    grid-row: auto !important;
    min-height: 130px;
  }

  .title-panel,
  .nav-panel {
    position: static;
    width: auto;
    height: auto;
    min-height: 76px;
  }

  .title-panel {
    flex-wrap: wrap;
    align-content: center;
    gap: 6px 12px;
  }

  .title-panel h1 {
    margin-left: 0;
    width: 100%;
  }

  .course-meta {
    margin-left: 0;
    padding-left: 0;
  }

  .nav-panel {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .reader-text {
    max-height: 42dvh;
  }

  .pdf-host {
    min-height: 58dvh;
    max-height: none;
  }

  .pdf-viewer {
    padding: 12px;
    gap: 14px;
  }

  .original-panel .panel-body,
  .translation-panel .panel-body {
    padding-top: 12px;
  }

  .actions-panel {
    min-height: 132px;
  }

  .actions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .notes-panel,
  .status-panel {
    min-height: 260px;
  }

  .notes-layout {
    grid-template-columns: 1fr;
  }

  .note-tools {
    display: flex;
    border-right: 0;
    border-bottom: 1px solid rgba(55, 40, 26, 0.12);
    padding: 0 0 10px;
  }

  .note-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .status-grid {
    grid-template-columns: 1fr;
  }
}
