/* The Study Room's tools: the Library, the Reader's contents, deck review,
 * the quiz runner, the page editor, Find material, the focus timer, the "What
 * to do now" strip and file import (site/study-room-tools.js, study-room-import.js).
 *
 * Every colour is one of system.css's tokens, so dark mode is whatever that
 * file says it is and the pages can never disagree. Classes are `st-`
 * prefixed so nothing here restyles the core by accident.
 *
 * Nothing here is green. Green is a gain (DESIGN_SYSTEM.md); a right answer,
 * a saved page and a finished step are none of them a gain in points, so a
 * right answer is an ink mark and a finished step is an ink check on muted.
 *
 * Targets are 44px under a coarse pointer and at least 32px under a fine one;
 * inputs are 16px so iOS never zooms; no text is smaller than 12px and
 * captions are 13px; hover exists only where a real hover does.
 */

/* --- shared ---------------------------------------------------------------- */
.st-reader-body{display:flex;flex-direction:column;gap:14px;min-width:0}
.st-empty{color:var(--text-2);font-size:14px;line-height:1.55;padding:12px 0}
.st-empty-inline{padding:4px 0 8px}
.st-meta{font-size:13px;color:var(--text-2);line-height:1.45;font-variant-numeric:tabular-nums}
.st-lead{font-size:15px;line-height:1.55}
.st-warning{font-size:13px;color:var(--text-2);line-height:1.5;padding-left:10px;border-left:2px solid var(--line)}
.st-notice{font-size:14px;line-height:1.55;padding:10px 14px;border:1px solid var(--line);background:var(--bg-subtle);border-radius:var(--r-md)}
.st-notice[hidden]{display:none}
.st-status{font-size:13px;color:var(--text-2);line-height:1.5;min-height:0}
.st-status:empty{display:none}
.st-status.is-error{color:var(--danger)}
.st-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.st-actions .button{min-height:max(36px,var(--target))}
.st-label{display:block;font-size:13px;font-weight:600;color:var(--text-2);margin:0 0 6px}
.st-input{width:100%;font-size:16px;line-height:1.45;border:1px solid var(--line);background:var(--bg);color:var(--text);border-radius:8px;min-height:44px;padding:10px 12px}
textarea.st-input{resize:vertical}
.st-subhead{font-size:13px;font-weight:600;color:var(--text-2);letter-spacing:.2px}
.st-teach{align-self:flex-start;margin-top:2px}
.st-download{display:none}
.st-reader-body details>summary{cursor:pointer;font-size:14px;font-weight:550;min-height:max(32px,var(--target));display:flex;align-items:center;gap:6px;list-style-position:inside}
.st-reader-body details>summary::-webkit-details-marker{color:var(--text-2)}
.tool[aria-busy=true] .tool-audience::before{content:"Working… ";font-weight:500}

/* --- rendered markdown ----------------------------------------------------- */
.st-md{font-size:15px;line-height:1.65;overflow-wrap:anywhere;min-width:0}
.st-md>*+*{margin-top:10px}
.st-md .st-h{color:var(--text);letter-spacing:-.2px;line-height:1.3;margin-top:18px}
.st-md .st-h:first-child{margin-top:0}
.st-md h3.st-h{font-size:18px;font-weight:620}
.st-md h4.st-h{font-size:16px;font-weight:600}
.st-md h5.st-h,.st-md h6.st-h{font-size:15px;font-weight:600}
.st-md .st-p{margin:0}
.st-md .st-list{padding-left:22px;margin:0}
.st-md .st-list .st-list{margin-top:4px}
.st-md .st-li+.st-li{margin-top:4px}
.st-md .st-task{list-style:none;margin-left:-22px}
.st-task-label{display:flex;align-items:flex-start;gap:10px;font-size:inherit;font-weight:inherit;margin:0;cursor:pointer;min-height:max(28px,var(--target))}
.st-check{width:20px;height:20px;min-height:0;margin:3px 0 0;flex-shrink:0;accent-color:var(--text);padding:0}
.st-check:disabled{cursor:default}
.st-check:disabled+.st-task-text{cursor:default}
.st-check:checked+.st-task-text{color:var(--text-2);text-decoration:line-through;text-decoration-color:var(--text-2)}
.st-md .st-quote{margin:0;padding:2px 0 2px 14px;border-left:3px solid var(--line);color:var(--text-2)}
.st-md .st-callout{padding:10px 14px;border:1px solid var(--line);border-radius:var(--r-md);background:var(--bg-subtle)}
.st-callout-label{display:block;font-size:13px;letter-spacing:.2px;margin-bottom:2px}
.st-callout>.st-p:first-of-type{display:inline}
.st-md .st-pre{margin:0;padding:12px 14px;background:var(--bg-muted);border-radius:8px;overflow-x:auto;font-family:var(--mono);font-size:13px;line-height:1.55;white-space:pre}
.st-md .st-pre code{font:inherit;background:none;padding:0}
.st-code{font-family:var(--mono);font-size:.9em;background:var(--bg-muted);border-radius:4px;padding:1px 5px}
.st-link{text-decoration:underline;text-underline-offset:3px;text-decoration-color:var(--text-2)}
.st-hr{border:0;border-top:1px solid var(--line);margin:16px 0}
.st-cite{display:inline-flex;align-items:center;justify-content:center;vertical-align:baseline;font-family:var(--mono);font-size:12px;font-weight:600;
  line-height:1;color:var(--text);background:var(--bg-muted);border:1px solid var(--line);border-radius:999px;padding:3px 7px;margin:0 2px;min-height:22px}

/* --- the Library ----------------------------------------------------------- */
.st-lib-group{display:flex;flex-direction:column;gap:6px;padding:8px 0 12px}
.st-lib-group+.st-lib-group{border-top:1px solid var(--line)}
.st-lib-heading{font-size:13px;font-weight:600;color:var(--text-2);letter-spacing:.2px;padding:4px 0}
.st-lib-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}
.st-lib-item{display:flex;flex-direction:column;gap:6px;min-width:0}
.st-row{display:flex;flex-direction:column;align-items:flex-start;gap:4px;width:100%;text-align:left;border:0;border-radius:8px;
  background:transparent;padding:10px;min-height:max(44px,var(--target));min-width:0}
.st-row:disabled{opacity:.55}
.st-row-title{font-size:14px;font-weight:550;line-height:1.35;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.st-row-meta{font-size:13px;color:var(--text-2);line-height:1.35;font-variant-numeric:tabular-nums;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.st-file-place:empty{display:none}
.st-file-place{padding:2px 2px 4px}
.st-file-link{display:inline-flex;align-items:center;min-height:max(32px,var(--target));font-size:14px;font-weight:550;text-decoration:underline;text-underline-offset:3px}

/* --- the "What to do now" strip ---------------------------------------------- */
.st-now-list{list-style:none;margin:0;padding:0;display:flex;flex-wrap:wrap;gap:6px 8px}
.st-now-item{min-width:0;max-width:100%}
.st-now{display:inline-flex;align-items:center;flex-wrap:wrap;max-width:100%;text-align:left;border:0;border-radius:8px;background:transparent;
  padding:5px 12px;min-height:max(32px,var(--target));font-size:14px;line-height:1.3;font-variant-numeric:tabular-nums}
.st-now-fact{color:var(--text)}
.st-now-dot{color:var(--text-2);white-space:pre}
.st-now-action{font-weight:600;text-decoration:underline;text-decoration-color:var(--accent);text-decoration-thickness:2px;text-underline-offset:3px}

/* --- deck review ------------------------------------------------------------- */
.st-deck{display:flex;flex-direction:column;gap:14px}
.st-deck:focus{outline:none}
.st-deck-stage{display:flex;flex-direction:column;gap:12px}
.st-deck-footer{display:flex;flex-direction:column;gap:10px}
.st-progress{font-size:13px;color:var(--text-2);font-variant-numeric:tabular-nums}
.st-card{border:1px solid var(--line);border-radius:var(--r-lg);background:var(--bg);padding:22px 22px 24px;min-height:180px;display:flex;flex-direction:column;gap:8px;cursor:default;box-shadow:var(--shadow-md);transform-origin:50% 0}
.st-card-side{font-family:var(--mono);font-size:12px;letter-spacing:1px;text-transform:uppercase;color:var(--text-2)}
.st-card-front{font-size:20px;font-weight:600;line-height:1.4;letter-spacing:-.2px;overflow-wrap:anywhere;white-space:pre-wrap}
.st-card-back-wrap{border-top:1px dashed var(--line);margin-top:10px;padding-top:12px;display:flex;flex-direction:column;gap:6px}
.st-card-back{font-size:16px;line-height:1.55;overflow-wrap:anywhere}
.st-flip{align-self:stretch}
.st-rate{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:6px}
.st-rate-button{display:flex;flex-direction:column;align-items:center;gap:1px;padding:6px 4px;min-height:max(52px,var(--target))}
.st-rate-label{font-size:14px;font-weight:600}
.st-rate-when{font-size:12px;color:var(--text-2);font-variant-numeric:tabular-nums}
.st-rate-key{display:none;font-size:12px}
.st-done{font-size:16px;font-weight:560}
.st-rejected{border:1px solid var(--line);border-radius:10px;padding:6px 12px;background:var(--bg-subtle)}
.st-rejected-list{margin:6px 0 4px;padding-left:18px;font-size:13px;color:var(--text-2);overflow-wrap:anywhere}
.st-card-edit{display:flex;flex-direction:column;gap:6px}
.st-card-edit label{font-size:13px;font-weight:600;color:var(--text-2);margin:6px 0 0}

/* --- the quiz ---------------------------------------------------------------- */
.st-quiz{display:flex;flex-direction:column;gap:14px}
.st-quiz:focus{outline:none}
.st-q-prompt{font-size:17px;font-weight:550;line-height:1.5}
.st-options{display:flex;flex-direction:column;gap:8px}
.st-option{display:grid;grid-template-columns:28px minmax(0,1fr) auto;gap:10px;align-items:center;width:100%;text-align:left;
  border:1px solid var(--line);border-radius:var(--r-md);background:var(--bg);padding:10px 12px;transition:border-color var(--dur-fade) var(--ease-out),background-color var(--dur-fade) var(--ease-out),box-shadow var(--dur-fade) var(--ease-out),transform var(--dur-press) var(--ease-out);min-height:max(44px,var(--target));font-size:15px;line-height:1.4}
.st-option-letter{display:grid;place-items:center;width:26px;height:26px;border-radius:50%;border:1px solid var(--line);font-family:var(--mono);font-size:13px;font-weight:600}
.st-option-text{overflow-wrap:anywhere}
.st-option.is-chosen{border-color:var(--text);box-shadow:inset 0 0 0 1px var(--text)}
.st-option.is-chosen .st-option-letter{background:var(--text);color:var(--bg);border-color:var(--text)}
.st-option.is-answer{border-style:solid;border-color:var(--text);background:var(--bg-muted)}
.st-option-mark{font-size:12px;font-weight:600;color:var(--text);white-space:nowrap}
.st-option[aria-disabled=true]{cursor:default;opacity:1;color:var(--text-2)}
.st-option.is-answer[aria-disabled=true],.st-option.is-chosen[aria-disabled=true]{color:var(--text)}
.st-yours{font-size:15px;line-height:1.5;overflow-wrap:anywhere;white-space:pre-wrap}
.st-verdict{display:flex;flex-direction:column;gap:8px;padding:12px 14px;border:1px solid var(--line);border-radius:10px;background:var(--bg-subtle)}
.st-verdict-line{font-size:15px;font-weight:560;line-height:1.45;display:flex;gap:8px;align-items:baseline}
.st-mark{font-weight:700;color:var(--text)}
.st-explanation{font-size:14px}
.st-score{font-size:22px;font-weight:600;letter-spacing:-.4px;font-variant-numeric:tabular-nums}
.st-score:focus{outline:none}
.st-misses{padding-left:18px;font-size:14px;line-height:1.5;display:flex;flex-direction:column;gap:4px}
.st-answers{border-top:1px solid var(--line);padding-top:8px}

/* --- the page editor ----------------------------------------------------------- */
.st-editor{display:flex;flex-direction:column;gap:10px}
.st-title-input{font-size:18px;font-weight:600}
.st-share{display:flex;align-items:center;flex-wrap:wrap;gap:8px 10px}
.st-share-label{font-size:13px;font-weight:600;color:var(--text-2)}
.st-editor-bar{display:flex;align-items:center;flex-wrap:wrap;gap:8px}
.st-save-state{display:flex;align-items:center;gap:8px;margin-left:auto;min-width:0}
.st-save-state .st-status{font-variant-numeric:tabular-nums}
.st-editor-body{position:relative;min-width:0}
.st-page-text{min-height:min(52vh,420px);font-family:var(--mono);font-size:16px;line-height:1.6;tab-size:2}
.st-page-read{min-height:120px;padding:4px 2px}
.st-help{font-size:13px}
.st-slash{position:absolute;left:8px;top:8px;z-index:6;list-style:none;margin:0;padding:6px;width:min(260px,calc(100% - 16px));max-height:180px;overflow-y:auto;
  background:var(--bg);border:1px solid var(--line);border-radius:10px;box-shadow:var(--shadow-lg)}
.st-slash-item{padding:8px 10px;border-radius:6px;font-size:15px;cursor:pointer;min-height:max(36px,var(--target));display:flex;align-items:center}
.st-slash-item[aria-selected=true]{background:var(--bg-muted)}
.st-danger{color:var(--danger)}
.st-conflict{display:flex;flex-direction:column;gap:8px;padding:12px 14px;border:1px solid var(--danger);border-radius:var(--r-md);background:var(--danger-soft);animation:lx-pop var(--dur-enter) var(--ease-out) both}
.st-conflict-title{font-size:15px;font-weight:600;line-height:1.4}
.st-confirm-host:empty{display:none}

/* --- Find material --------------------------------------------------------------- */
.st-materials{display:flex;flex-direction:column;gap:12px}
.st-materials-form{display:flex;flex-direction:column;gap:10px;align-items:stretch}
.st-materials-form .segmented{align-self:flex-start}
.st-materials-form>.button{align-self:flex-start}
.st-results{display:flex;flex-direction:column;gap:10px}
.st-material-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px}
.st-material{display:flex;flex-direction:column;gap:4px;border:1px solid var(--line);border-radius:var(--r-lg);background:var(--bg);padding:12px 14px}
.st-material-title{font-size:15px;font-weight:600;line-height:1.4;overflow-wrap:anywhere}
.st-material-facts,.st-material-authors{font-size:13px;color:var(--text-2);line-height:1.45;overflow-wrap:anywhere}
.st-excerpt{font-size:14px;line-height:1.55;overflow-wrap:anywhere}
.st-material .st-actions{margin-top:6px}
.st-open{text-decoration:none}

/* --- the focus timer ------------------------------------------------------------ */
.st-timer{display:flex;flex-direction:column;gap:14px;align-items:flex-start}
.st-phase{font-size:14px;font-weight:600;color:var(--text-2)}
.st-clock{font-family:var(--mono);font-size:44px;font-weight:500;letter-spacing:-1px;line-height:1;font-variant-numeric:tabular-nums}
.st-timer-settings{display:flex;flex-wrap:wrap;align-items:flex-end;gap:10px;padding-top:10px;border-top:1px solid var(--line);width:100%}
.st-field{display:flex;flex-direction:column;gap:4px}
.st-field label{font-size:13px;font-weight:600;color:var(--text-2);margin:0}
.st-minutes{width:110px;font-variant-numeric:tabular-nums}

/* --- the page picker --------------------------------------------------------------- */
.st-picker{display:flex;flex-direction:column;gap:10px}

/* --- pointers ------------------------------------------------------------------------ */
@media (pointer:coarse){
  .st-row,.st-now,.st-option,.st-slash-item,.st-file-link,.st-actions .button{min-height:44px}
  .st-task-label{min-height:44px;align-items:center}
  .st-check{margin-top:0;width:22px;height:22px}
  /* A citation chip keeps its size in the text and gains a 44px hit area. */
  .st-cite{min-width:44px;min-height:44px;margin:-11px 0;border-color:transparent;background:none;position:relative}
  .st-cite::before{content:"";position:absolute;inset:11px 6px;border:1px solid var(--line);border-radius:999px;background:var(--bg-muted);z-index:-1}
  .st-cite{z-index:0;isolation:isolate}
  .st-rate-button{min-height:56px}
}
@media (hover:hover) and (pointer:fine){
  .st-rate-key{display:inline-block;margin-top:2px}
  .st-row:hover:not(:disabled),.st-now:hover,.st-option:not([aria-disabled=true]):hover{background:var(--bg-muted)}
  .st-cite:hover{border-color:var(--text)}
  .st-slash-item:hover{background:var(--bg-muted)}
  .st-link:hover,.st-file-link:hover{color:var(--accent-ink)}
}
.st-row:focus-visible,.st-now:focus-visible,.st-option:focus-visible,.st-cite:focus-visible{outline:2px solid var(--accent);outline-offset:2px}

@media (min-width:700px){
  .st-clock{font-size:48px}
}

/* --- importing a file ----------------------------------------------------------- */
.st-import{display:flex;flex-direction:column;gap:14px}
.st-import-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px}
.st-import-row{display:flex;flex-direction:column;gap:8px;padding:14px 16px;border:1px solid var(--line);border-radius:var(--r-lg);background:var(--bg)}
.st-import-head{display:flex;align-items:center;gap:10px;min-width:0}
.st-import-head .ui-icon{color:var(--text-2)}
.st-import-name{flex:1;min-width:0;font-size:14px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.st-import-row .st-meta.is-error{color:var(--danger)}
.st-import-row .st-meter>span{transition:transform var(--dur-enter) var(--ease-out)}
.st-import-made{display:flex;flex-direction:column;gap:6px;align-items:stretch}
.st-import-made .button{justify-content:flex-start;border-radius:var(--r-md)}
.st-import-button .ui-icon{width:16px;height:16px;flex-basis:16px}
.st-page-practice .st-actions{gap:6px}

/* --- motion ------------------------------------------------------------------- */
/* Progress is a hairline that grows from where it was (--from) to where it is
   (--p), so moving on reads as moving on. Set through the CSSOM. */
.st-meter{height:3px;border-radius:var(--r-pill);background:var(--bg-muted);overflow:hidden}
.st-meter>span{display:block;height:100%;background:var(--text);transform-origin:0 50%;transform:scaleX(var(--p,0))}
/* The focus timer is a dial: the remaining time is the ring. */
@property --dial{syntax:'<number>';inherits:true;initial-value:1}
.st-dial{--dial:1;position:relative;width:min(240px,100%);aspect-ratio:1;border-radius:50%;display:grid;place-items:center;align-self:center;
  background:conic-gradient(var(--text) calc(var(--dial) * 1turn),var(--bg-muted) 0);transition:--dial .5s linear}
.st-dial::before{content:"";position:absolute;inset:8px;border-radius:50%;background:var(--bg)}
.st-dial>*{position:relative;text-align:center}
.st-dial-face{display:flex;flex-direction:column;align-items:center;gap:6px}
.st-timer{align-items:stretch}
.st-timer .st-actions{justify-content:center}
.st-timer.is-break .st-dial{background:conic-gradient(var(--accent) calc(var(--dial) * 1turn),var(--bg-muted) 0)}
@keyframes st-meter{from{transform:scaleX(var(--from,0))}to{transform:scaleX(var(--p,0))}}
@keyframes st-card-in{from{opacity:0;transform:translateX(18px) scale(.985)}to{opacity:1;transform:none}}
@keyframes st-card-turn{0%{transform:perspective(1000px) rotateX(0)}45%{transform:perspective(1000px) rotateX(-7deg) scale(.99)}100%{transform:perspective(1000px) rotateX(0)}}
@keyframes st-unfold{from{opacity:0;transform:translateY(-6px);clip-path:inset(0 0 100% 0)}to{opacity:1;transform:none;clip-path:inset(0 0 0 0)}}
@keyframes st-pick{0%{transform:scale(1)}40%{transform:scale(.985)}100%{transform:scale(1)}}
@keyframes st-score{from{opacity:0;transform:translateY(8px) scale(.96)}to{opacity:1;transform:none}}
@media (prefers-reduced-motion:no-preference){
  .st-meter>span{animation:st-meter var(--dur-settle) var(--ease-out) both}
  .st-card{animation:st-card-in var(--dur-settle) var(--ease-out) both}
  .st-card.is-flipped{animation:st-card-turn var(--dur-settle) var(--ease-settle) both}
  .st-card.is-flipped .st-card-back-wrap{animation:st-unfold var(--dur-settle) var(--ease-out) both}
  .st-rate-button{animation:lx-rise var(--dur-enter) var(--ease-out) both}
  .st-rate-button:nth-child(2){animation-delay:40ms}
  .st-rate-button:nth-child(3){animation-delay:80ms}
  .st-rate-button:nth-child(4){animation-delay:120ms}
  /* The quiz redraws on every pick; only a NEW question or a new verdict moves. */
  .st-quiz.is-fresh:not(.is-checked) .st-q-prompt,.st-quiz.is-fresh:not(.is-checked) .st-options{animation:st-card-in var(--dur-settle) var(--ease-out) both}
  .st-quiz.is-fresh:not(.is-checked) .st-options{animation-delay:60ms}
  .st-quiz.is-picked .st-option.is-chosen{animation:st-pick var(--dur-enter) var(--ease-settle)}
  .st-quiz.is-fresh.is-checked .st-verdict{animation:lx-rise var(--dur-enter) var(--ease-out) both}
  .st-quiz.is-fresh.is-checked .st-option.is-chosen:not(.is-answer){animation:lx-shake 260ms var(--ease-in-out) 2}
  .st-score{animation:st-score var(--dur-settle) var(--ease-settle) both}
  .st-material{animation:lx-rise var(--dur-enter) var(--ease-out) both}
  .st-material-list>li:nth-child(2) .st-material{animation-delay:40ms}
  .st-material-list>li:nth-child(3) .st-material{animation-delay:80ms}
  .st-material-list>li:nth-child(n+4) .st-material{animation-delay:120ms}
  .st-import-row{animation:lx-rise var(--dur-enter) var(--ease-out) both}
}
@media (prefers-reduced-motion:reduce){
  .st-reader-body *,.st-now,.st-row{transition:none!important;animation:none!important}
  .st-dial{transition:none}
}

/* Print what is being read, not the controls around it. */
@media print{
  .st-actions,.st-editor-bar,.st-share,.st-help,.st-page-text,.st-slash,.st-conflict,.st-confirm-host,.st-deck-footer,
  .st-rate,.st-materials-form,.st-timer-settings,.st-label,.st-title-input,.st-status,.st-notice{display:none!important}
  .st-page-read{display:block!important}
  .st-md{color:#000;font-size:12pt}
  .st-md .st-callout,.st-md .st-pre,.st-code,.st-cite{background:#fff!important;color:#000!important;border-color:#999!important}
  .st-link::after{content:" (" attr(href) ")";font-size:.85em}
  .st-card,.st-material,.st-verdict{break-inside:avoid;border-color:#999}
}

.st-page-practice{display:flex;flex-direction:column;gap:8px;padding:16px 0;border-top:1px solid var(--line)}
.st-page-practice .st-label{margin:0}

/* Secondary note actions stay on demand; summaries keep keyboard disclosure. */
.st-action-menu{max-width:100%}.st-action-menu>summary{cursor:pointer;min-height:44px;display:list-item;padding:12px 8px;color:var(--text-2);font-weight:550}.st-action-menu>summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:6px}.st-action-menu[open]>.st-actions{padding:8px 0;gap:8px}
