/*
 * A sentence's breakdown (iʿrāb), from "Explain this sentence": the
 * structure, a row per word (role, case badge, the word, the reason), the
 * states around it (preparing the page, analysing, messages), the sentence
 * highlighted in the text, the sentence menu and the phone sheet.
 * Markup: sentence_breakdowns/_breakdown, sentence_breakdown.js,
 * sentence_tools_controller.js.
 */

/* ── The breakdown ────────────────────────────────────────────────── */
.bd { display: flex; flex-direction: column; gap: 12px; }
.bd__structure { display: flex; gap: 10px; align-items: baseline; border-top: 1px solid var(--line); padding-top: 12px; font-size: 14px; line-height: 1.45; font-weight: 600; }
.bd__label { flex-shrink: 0; font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.bd__structure .ar { font-size: 1.2em; }
.bd__flag { display: flex; gap: 10px; align-items: flex-start; background: var(--paper); border-radius: 12px; padding: 10px 12px; font-size: 13px; line-height: 1.45; color: var(--ink-line); }
.bd__flag-i { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--gold-deep); color: var(--gold-deep); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }

.bd__rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.bd__row { background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 5px; }
.bd__row.is-selected { background: var(--field); border-color: var(--ink); }
.bd__row-top { display: flex; align-items: center; gap: 10px; }
.bd__role { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; background: none; border: none; padding: 0; text-align: left; color: var(--ink); cursor: pointer; }
.bd__role:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; border-radius: 6px; }
.bd__role-en { font-size: 14px; font-weight: 700; }
.bd__role-ar { font-size: 16px; line-height: 1.6; color: var(--text-body); }
.bd__badge { border-radius: var(--radius-sm); padding: 2px 8px; font-size: 11px; font-weight: 700; white-space: nowrap; background: var(--sand); color: var(--ink-line); }
.bd__badge--nominative, .bd__badge--indicative { background: var(--green-soft); color: var(--green); }
.bd__badge--accusative, .bd__badge--subjunctive { background: var(--mark); color: var(--gold-deep); }
.bd__badge--genitive, .bd__badge--jussive { background: var(--clay-soft); color: var(--clay); }
/* Turkish's other cases */
.bd__badge--dative, .bd__badge--locative, .bd__badge--ablative, .bd__badge--instrumental { background: var(--sand); color: var(--text-body); }
.bd__ar { min-width: 64px; text-align: right; font-size: 24px; line-height: 1.8; color: var(--ink); text-decoration: none; }
.bd__ar:hover { color: var(--clay); text-decoration: none; }
.bd__reason { font-size: 13px; line-height: 1.55; color: var(--ink-line); }
.bd__reason .ar { font-size: 17px; }
/* Long sentences (and flashcards): only the selected row's reason */
.bd.is-collapsed .bd__row:not(.is-selected) .bd__reason { display: none; }

.bd__foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; }
.bd__report { font-size: 13px; color: var(--text-body); text-decoration: underline; }
.bd__reported { font-size: 13px; color: var(--green); font-weight: 600; }
.bd__actions { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }

/* Compact, on a flashcard's back: one line a row */
.bd--compact { gap: 8px; }
.bd--compact .bd__structure { border-top: none; padding-top: 0; font-size: 13px; }
.bd--compact .bd__structure .bd__label { display: none; }
.bd--compact .bd__flag { font-size: 12px; padding: 8px 10px; }
.bd--compact .bd__rows { gap: 0; }
.bd--compact .bd__row { background: none; border: none; border-top: 1px solid var(--line-soft); border-radius: 0; padding: 5px 0; gap: 2px; }
.bd--compact .bd__row.is-selected { background: none; }
.bd--compact .bd__role { flex-direction: row; }
.bd--compact .bd__role-en { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bd--compact .bd__role-ar { display: none; }
.bd--compact .bd__ar { font-size: 20px; min-width: 56px; }
.bd--compact .bd__reason { font-size: 12px; padding-bottom: 4px; }
.bd--compact .bd__foot { border-top: none; padding-top: 0; }
.bd--compact .bd__report { font-size: 12px; }

/* ── States ───────────────────────────────────────────────────────── */
.bd-state { display: flex; flex-direction: column; gap: 10px; }
.bd-state--preparing, .bd-state--message { background: var(--paper); border-radius: 16px; padding: 16px; }
.bd-state__status { margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 15px; font-weight: 600; }
.bd-state__time { font-weight: 400; color: var(--text-muted); font-size: 13px; }
.bd-state__title { font-size: 15px; line-height: 1.4; }
.bd-state__body { margin: 0; font-size: 14px; line-height: 1.5; color: var(--ink-line); }
.bd-state__hint, .bd-state__foot { margin: 0; font-size: 13px; line-height: 1.45; color: var(--text-muted); }
.bd-state__foot { margin-top: 10px; }
.bd-state__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bd-spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--ink); flex-shrink: 0; animation: bd-spin .8s linear infinite; }
@keyframes bd-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .bd-spin { animation: none; } }
.bd-skeleton { display: flex; flex-direction: column; gap: 8px; }
.bd-skeleton__row { border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.bd-skeleton__lines { width: 60%; height: 10px; border-radius: 5px; background: var(--line-soft); box-shadow: 0 16px 0 var(--line-soft); margin-bottom: 16px; }
.bd-skeleton__badge { width: 54px; height: 22px; border-radius: var(--radius-sm); background: var(--line-soft); }
.bd-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.bd-steps__step { display: flex; gap: 10px; align-items: center; color: var(--text-muted); }
.bd-steps__step.is-current { color: var(--ink); }
.bd-steps__dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line-strong); flex-shrink: 0; }
.bd-steps__time { margin-left: auto; color: var(--text-muted); }

/* ── Save sentence ────────────────────────────────────────────────── */
.sentence-save { display: inline-flex; flex-direction: column; gap: 6px; max-width: 100%; }
.sentence-save__button {
  background: none; border: 1.5px solid var(--ink); border-radius: var(--radius-pill); padding: 0 16px; min-height: 38px;
  font-size: 13px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.sentence-save__button:hover { background: var(--sand-hover); }
.sentence-save__button.is-busy { background: var(--sand); border-color: var(--sand); cursor: progress; }
.sentence-save__button.is-saved { background: var(--green-soft); border-color: var(--green-soft); color: var(--green); }
.sentence-save__button.is-full { background: var(--sand); border-color: var(--sand); color: var(--text-body); cursor: not-allowed; }
.sentence-save__status { font-size: 13px; line-height: 1.45; color: var(--ink-line); }
.sentence-save__status:empty { display: none; }
.sentence-save__status a { font-weight: 700; }
.sentence-save__count { display: block; margin-top: 2px; font-size: 12px; color: var(--text-muted); }

/* ── The library reader ───────────────────────────────────────────── */
/* The sentence being explained: a soft gold wash and a dotted clay underline;
   the selected word, an ink box. Both read the same with any amount of vowels. */
.st-highlight, .st-highlight-word {
  background: var(--mark); border-bottom: 2px dotted var(--clay); border-radius: 6px; padding: 4px 0;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.reader__sentence.is-explaining .reader__ar { background: var(--mark); border-bottom: 2px dotted var(--clay); border-radius: 6px; }
.reader__w.is-bd-selected { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 6px; background: var(--field); }

/* The Sentence tab: a dot when its breakdown is ready while another tab is open */
.reader__tab.has-dot::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 5px; vertical-align: 2px; border-radius: 50%; background: var(--clay); }
.st-panel { display: flex; flex-direction: column; gap: 14px; }
.st-panel[hidden] { display: none; }
.st-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.st-head__pos { font-size: 13px; color: var(--text-muted); }
.st-head__pos strong { color: var(--ink); }
.st-head__nav { display: flex; gap: 6px; }
.st-head__step { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line-strong); background: none; color: var(--ink); }
.st-head__step:hover { border-color: var(--ink); }
.st-sentence { margin: 0; font-size: 27px; line-height: 2.2; text-align: right; }
.st-sentence__w { background: none; border: none; margin: 0; padding: 0 3px; font: inherit; color: inherit; border-radius: 6px; cursor: pointer; }
.st-sentence__w:hover { background: var(--sand-hover); }
.st-sentence__w.is-selected { outline: 2px solid var(--ink); background: var(--field); }
.st-body { display: flex; flex-direction: column; gap: 12px; }

/* The Word panel's "This word's sentence" */
.st-group { background: var(--paper); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.st-group[hidden] { display: none; }
.st-group__label { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.st-group__buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.st-group__buttons .sentence-save { display: contents; }
.st-group__buttons .sentence-save__button { min-height: 44px; font-size: 14px; }
.st-group__buttons .sentence-save__status { grid-column: 1 / -1; }
.st-group__explain {
  display: flex; align-items: center; justify-content: center; gap: 8px; background: var(--ink); color: var(--paper); border: none;
  border-radius: var(--radius-pill); min-height: 44px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.st-group__explain:hover { background: var(--ink-raised); }
.st-group__explain:focus-visible, .sentence-save__button:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
.st-group__mark, .st-menu__icon.ar { font-size: 17px; color: var(--peach); }
.st-group__counts { font-size: 12px; color: var(--text-muted); }
.st-group__counts:empty { display: none; }

/* The sentence menu (right-click, long-press, Shift+F10) */
.st-menu {
  position: absolute; z-index: 30; width: 300px; background: var(--field); border: 1px solid var(--line-strong); border-radius: 14px;
  box-shadow: 0 18px 34px -16px rgba(28, 35, 33, .5); padding: 6px; display: flex; flex-direction: column;
}
.st-menu[hidden] { display: none; }
.st-menu__label { padding: 8px 12px 6px; font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.st-menu__item {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: none; border-radius: 9px; background: none;
  font-size: 15px; color: var(--ink); text-align: left; cursor: pointer;
}
.st-menu__item:hover, .st-menu__item:focus { background: var(--paper); }
.st-menu__item:focus-visible { outline: 3px solid var(--green); outline-offset: -3px; }
.st-menu__icon { width: 18px; text-align: center; }
.st-menu__icon:not(.ar) { color: var(--text-muted); }
.st-menu__key { margin-left: auto; font-size: 12px; color: var(--text-muted); }
.st-menu__help { border-top: 1px solid var(--line-soft); margin-top: 4px; padding: 8px 12px 4px; font-size: 12px; line-height: 1.4; color: var(--text-muted); }
.st-menu__status { padding: 0 12px 6px; font-size: 13px; font-weight: 600; color: var(--green); }
.st-menu__status:empty { display: none; }

/* The phone sheet: three heights, the highlighted sentence in view above it at peek and half */
.st-sheet { display: none; }
@media (max-width: 700px) {
  .st-menu { width: auto; left: 16px !important; right: 16px; background: var(--ink); color: var(--paper); border: none; border-radius: 16px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .st-menu__label, .st-menu__help, .st-menu__key { display: none; }
  .st-menu__item { min-height: 52px; flex-direction: column; justify-content: center; gap: 1px; font-size: 13px; font-weight: 600; color: var(--paper); text-align: center; }
  .st-menu__item:first-of-type { background: var(--ink-raised); }
  .st-menu__item:hover, .st-menu__item:focus { background: var(--ink-raised); }
  .st-menu__icon:not(.ar) { color: var(--paper); }
  .st-menu__status { grid-column: 1 / -1; color: var(--green-bright); padding: 6px 12px; }

  .st-sheet:not([hidden]) {
    display: flex; flex-direction: column; position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; height: 50vh;
    background: var(--card); border-top: 1px solid var(--line-strong); border-radius: 22px 22px 0 0;
    box-shadow: 0 -16px 34px -18px rgba(28, 35, 33, .45); transition: height .2s ease;
  }
  .st-sheet[data-height="peek"] { height: 42vh; }
  .st-sheet[data-height="half"] { height: 58vh; }
  .st-sheet[data-height="full"] { height: 85vh; }
  .st-sheet__grip { display: flex; justify-content: center; padding-top: 6px; }
  .st-sheet__handle { width: 64px; height: 24px; border: none; background: none; display: flex; align-items: center; justify-content: center; }
  .st-sheet__handle span { width: 40px; height: 4px; border-radius: 4px; background: var(--line-dashed); }
  .st-sheet__head { display: flex; justify-content: space-between; align-items: center; padding: 0 8px 6px 16px; }
  .st-sheet__buttons { display: flex; gap: 2px; }
  .st-sheet__button { width: 44px; height: 44px; border: none; background: none; font-size: 18px; color: var(--ink); }
  .st-sheet__body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; }
  .st-sheet__body .bd__row { padding: 8px 10px; }
  .st-sheet__body .bd__ar { font-size: 21px; }
  .st-sheet__body .bd.is-collapsed .bd__row:not(.is-selected) .bd__reason,
  .st-sheet__body .bd .bd__row:not(.is-selected) .bd__reason { display: none; }
  /* The text scrolls clear of the sheet */
  body:has(.st-sheet:not([hidden])) .reader__page { padding-bottom: 50vh; }
}
