/* Interlinear learning is intentionally isolated from the legacy layout CSS. */
.learn-selection-editor[open] {
  max-height: calc(100dvh - 24px) !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
}

.learn-selection-editor[open] .learn-highlight-form,
.learn-selection-editor[open] .learn-selection-meaning,
.learn-selection-editor[open] .learn-selection-word-meanings {
  min-height: 0;
  max-height: none !important;
  overflow: visible !important;
}

.learn-selection-meaning-row {
  display: grid !important;
  grid-template-columns: minmax(4.5rem, auto) minmax(12rem, 1fr) !important;
  align-items: center !important;
  gap: .65rem .85rem !important;
  padding-block: .75rem !important;
}

.learn-selection-meaning-row > input[type="text"] {
  min-width: 0;
  width: 100%;
}

.learn-selection-word-actions {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .55rem 1.2rem;
  padding: 0;
}

.learn-selection-editor .learn-selection-meaning-row > .learn-selection-word-actions {
  overflow: visible;
  white-space: normal;
  text-align: start;
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
}

.learn-selection-editor .learn-selection-deck-word {
  display: inline-flex !important;
  align-items: center;
  gap: .5rem;
  width: fit-content;
  min-width: 0;
  max-width: 100%;
  padding: .6rem .85rem;
  border: 1px solid var(--line);
  border-radius: .75rem;
  background: var(--card);
  color: var(--ink);
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
  font-size: .9rem;
  cursor: pointer;
  font-weight: 750;
  line-height: 1.25;
}

.learn-selection-editor .learn-selection-deck-word input[type="checkbox"],
.learn-selection-editor .learn-selection-deck-option input[type="checkbox"] {
  flex: 0 0 1.15rem;
  width: 1.15rem;
  height: 1.15rem;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: #257562;
}

.learn-selection-deck-word:has(input:checked) {
  border-color: var(--teal);
  background: var(--teal-pale);
}

.learn-selection-deck-destinations { min-width: 0; margin: 0; padding: 1rem; border: 1px solid var(--line); border-radius: 1rem; }
.learn-selection-deck-destinations legend { padding: 0 .4rem; font: 750 1rem/1.3 "Aptos", Arial, sans-serif; }
.learn-selection-deck-destinations > p { margin: 0 0 .75rem; color: var(--ink-soft); font: .9rem/1.4 "Aptos", Arial, sans-serif; }
.learn-selection-deck-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: .6rem; }
.learn-selection-editor .learn-selection-deck-option { display: flex; align-items: center; gap: .7rem; min-width: 0; padding: .85rem; border: 1px solid var(--line); border-radius: .8rem; background: var(--card); color: var(--ink); font: 700 .95rem/1.35 "Aptos", Arial, sans-serif; cursor: pointer; }
.learn-selection-deck-option span { overflow-wrap: anywhere; }
.learn-selection-deck-option:has(input:checked) { border-color: var(--teal); background: var(--teal-pale); }
.learn-selection-deck-create { display: flex; flex-wrap: wrap; align-items: end; gap: .6rem; margin-top: .85rem; }
.learn-selection-deck-create .field { flex: 1 1 12rem; min-width: 0; margin: 0; }
.learn-selection-deck-create .field { grid-template-columns: minmax(0, 1fr); }
.learn-selection-editor .learn-selection-deck-choice { display: block; }
.learn-selection-deck-create input { width: 100%; min-width: 0; }
.learn-selection-deck-create button { flex: 0 1 auto; white-space: normal; }

.learn-selection-deck-choice {
  position: relative;
  z-index: 1;
  margin-block: .7rem 1rem;
  padding-bottom: .35rem;
}

.show-interlinear-text {
  line-height: 1.18 !important;
  text-align: start !important;
}

.show-interlinear-text .source-token {
  position: relative;
  display: inline-grid !important;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto;
  justify-items: center;
  align-items: start;
  vertical-align: baseline;
  max-width: min(13rem, 46vw);
  margin-block: .1em .34em;
  margin-inline: .04em;
  white-space: normal !important;
}

.show-interlinear-text .source-token > .source-token-hebrew {
  grid-column: 1;
  grid-row: 1;
  line-height: 1.3;
}

.show-interlinear-text .source-token > .source-token-interlinear {
  grid-column: 1;
  grid-row: 2;
}

.review-text-view .show-interlinear-text .source-token > .learn-vocabulary-marker {
  position: absolute;
  inset: auto .1em 100% auto;
  margin: 0;
  transform: none;
}

.source-token-hebrew {
  direction: rtl;
  unicode-bidi: isolate;
  max-width: 100%;
}

.source-token-interlinear {
  direction: ltr;
  unicode-bidi: isolate;
  max-width: 100%;
  min-height: 1.15em;
  padding: .1em .25em 0;
  color: #38534f;
  font-family: "Aptos", "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(.68rem, .55em, .92rem);
  font-weight: 620;
  line-height: 1.12;
  text-align: center;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
}

.source-token-interlinear.is-empty {
  min-width: 1.4em;
  border-bottom: 1px solid color-mix(in srgb, #6b817d 32%, transparent);
}

.learn-source-summary-controls .learn-interlinear-toggle[aria-pressed="true"] {
  border-color: #9b6a1d;
  background: #fff5d7;
  color: #4f3510;
}

.learn-print-segmented.learn-print-font-sizes {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 7rem), 1fr));
}

@media (max-width: 600px) {
  .learn-selection-word-actions { grid-column: 1 / -1; }
}

.learn-gold-action {
  min-height: 3.4rem !important;
  min-width: 10.5rem;
  padding: .8rem 1.35rem !important;
  border-color: #b37b22 !important;
  background: linear-gradient(145deg, #f8dc85, #d7a63a) !important;
  color: #38250a !important;
  box-shadow: 0 .45rem 1.1rem rgba(132, 87, 17, .2) !important;
  font-size: 1rem !important;
  font-weight: 850 !important;
}

.learn-gold-action:hover:not(:disabled),
.learn-gold-action:focus-visible {
  background: linear-gradient(145deg, #ffe9a6, #e0ad3d) !important;
  transform: translateY(-1px);
}

.learn-progress-action {
  border-color: #24715f !important;
  background: linear-gradient(145deg, #2f8b72, #1c6757) !important;
  color: #fffdf5 !important;
  box-shadow: 0 .35rem .9rem rgba(24, 92, 75, .18) !important;
  font-weight: 850 !important;
}

.learn-progress-action:hover:not(:disabled),
.learn-progress-action:focus-visible {
  background: linear-gradient(145deg, #3a9b80, #1f705e) !important;
}

.learn-print-dialog {
  width: min(44rem, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  padding: 0;
  border: 1px solid #d5c7ad;
  border-radius: 1.35rem;
  background: #fffdf8;
  color: #173b36;
  box-shadow: 0 1.4rem 4rem rgba(18, 49, 44, .28);
  overflow: hidden;
}

.learn-print-dialog::backdrop {
  background: rgba(9, 34, 30, .58);
  backdrop-filter: blur(5px);
}

.learn-print-preflight {
  display: grid;
  gap: 1rem;
  max-height: calc(100dvh - 1.5rem);
  padding: clamp(1rem, 3vw, 1.65rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.learn-print-preflight-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.learn-print-preflight-header h2 {
  margin: .12rem 0 0;
  font-family: var(--font-display, Georgia, serif);
  font-size: clamp(2rem, 6vw, 3.2rem);
  line-height: 1;
}

.learn-print-close {
  display: grid;
  place-items: center;
  width: 2.7rem;
  height: 2.7rem;
  flex: 0 0 auto;
  border: 1px solid #d9cfbc;
  border-radius: 50%;
  background: #f6f0e5;
  color: #173b36;
  font-size: 1.65rem;
  line-height: 1;
}

.learn-print-choice-group {
  min-width: 0;
  margin: 0;
  padding: 1rem;
  border: 1px solid #ddd1bd;
  border-radius: 1rem;
  background: #fffcf7;
}

.learn-print-choice-group legend {
  padding: 0 .35rem;
  font-size: 1rem;
  font-weight: 850;
}

.learn-print-segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .7rem;
}

.learn-print-segmented label,
.learn-print-source-include,
.learn-print-script-choice {
  cursor: pointer;
}

.learn-print-segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.learn-print-segmented span {
  display: grid;
  min-height: 3.3rem;
  place-items: center;
  padding: .65rem;
  border: 2px solid #d8cfbf;
  border-radius: .85rem;
  background: #fff;
  font-weight: 850;
  text-align: center;
}

.learn-print-segmented input:checked + span {
  border-color: #276f61;
  background: #e8f4ef;
  box-shadow: 0 0 0 3px rgba(39, 111, 97, .12);
}

.learn-print-segmented input:focus-visible + span {
  outline: 3px solid #d6a538;
  outline-offset: 2px;
}

.learn-print-switches {
  display: grid;
  gap: .65rem;
}

.learn-print-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.2rem;
  padding: .75rem 1rem;
  border: 1px solid #ddd1bd;
  border-radius: .9rem;
  background: #fff;
  cursor: pointer;
}

.learn-print-switch > span {
  display: grid;
  gap: .1rem;
}

.learn-print-switch small {
  color: #66736f;
  line-height: 1.25;
}

.learn-print-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.learn-print-switch b {
  position: relative;
  width: 3.1rem;
  height: 1.75rem;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #b8c1be;
  transition: background .16s ease;
}

.learn-print-switch b::after {
  content: "";
  position: absolute;
  top: .2rem;
  left: .2rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
  transition: transform .16s ease;
}

.learn-print-switch input:checked + b {
  background: #24715f;
}

.learn-print-switch input:checked + b::after {
  transform: translateX(1.35rem);
}

.learn-print-switch input:focus-visible + b {
  outline: 3px solid #d6a538;
  outline-offset: 2px;
}

.learn-print-base-source {
  margin: 0 0 .7rem;
  color: #5a6965;
  font-weight: 700;
}

.learn-print-source-options {
  display: grid;
  gap: .65rem;
}

.learn-print-source-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .7rem;
  padding: .75rem;
  border: 1px solid #ded4c3;
  border-radius: .85rem;
  background: #f8f4eb;
  opacity: .68;
}

.learn-print-source-option.is-selected {
  border-color: #7ca99e;
  background: #eef7f3;
  opacity: 1;
}

.learn-print-source-include,
.learn-print-script-choice {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  min-width: 0;
  font-weight: 800;
}

.learn-print-source-include span {
  overflow-wrap: anywhere;
}

.learn-print-script-choice {
  padding: .4rem .55rem;
  border: 1px solid #c8d7d2;
  border-radius: .65rem;
  background: #fff;
  white-space: nowrap;
}

.learn-print-script-choice:has(input:disabled) {
  opacity: .45;
  cursor: default;
}

.learn-print-no-mefarshim {
  margin: .3rem 0 0;
  color: #66736f;
}

.learn-print-preflight-actions {
  position: sticky;
  bottom: calc(-1 * clamp(1rem, 3vw, 1.65rem));
  display: flex;
  justify-content: flex-end;
  gap: .7rem;
  margin: .1rem calc(-1 * clamp(1rem, 3vw, 1.65rem)) calc(-1 * clamp(1rem, 3vw, 1.65rem));
  padding: .9rem clamp(1rem, 3vw, 1.65rem);
  border-top: 1px solid #ddd1bd;
  background: rgba(255, 253, 248, .96);
  backdrop-filter: blur(8px);
}

@media (max-width: 720px) {
  .learn-selection-meaning-row {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .learn-selection-word-actions {
    grid-column: 1;
    padding-inline-start: 0;
    align-items: flex-start;
    flex-direction: column;
  }

  .show-interlinear-text .source-token {
    max-width: 42vw;
  }

  .learn-print-source-option {
    grid-template-columns: minmax(0, 1fr);
  }

  .learn-print-script-choice {
    justify-content: center;
  }
}

body[data-theme="dark"] .source-token-interlinear,
[data-theme="dark"] .source-token-interlinear {
  color: #d8d0b7;
}

body[data-theme="dark"] .learn-source-summary-controls .learn-interlinear-toggle[aria-pressed="true"],
[data-theme="dark"] .learn-source-summary-controls .learn-interlinear-toggle[aria-pressed="true"] {
  background: #3f351f;
  color: #f7e3a9;
}
