/* Trainer view — Practicum-style split: Task | Code + Result, action bar, Topics drawer.
   Scoped to .pr-trainer. Builds on css/base.css tokens. */

.pr-trainer {
  --pr-top: 0px;
  position: relative;
  display: flex; flex-direction: column;
  height: calc(100vh - var(--pr-top) - 40px); min-height: 560px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.pr-trainer [hidden] { display: none !important; }

/* ---- header ---- */
.pr-head { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-bottom: 1px solid var(--line); flex: none; }
.pr-crumb { flex: 1; font-size: 14px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-crumb b { color: var(--text); }
.pr-provlink { color: var(--accent); text-decoration: none; }
.pr-provlink:hover { text-decoration: underline; }
.pr-hint-kbd { font-size: 12.5px; color: var(--text-3); }

/* ---- buttons ---- */
.pr-trainer .pr-btn { font: inherit; font-size: 14px; font-weight: 600; border-radius: 12px;
  padding: 9px 16px; border: 1px solid transparent; line-height: 1.2; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s; }
.pr-trainer .pr-btn:disabled { opacity: .45; cursor: default; }
.pr-trainer .pr-primary { background: var(--brand); color: var(--on-brand); min-width: 140px; }
.pr-trainer .pr-primary:hover:not(:disabled) { background: var(--brand-hover); }
.pr-trainer .pr-primary[data-mode="next"] { background: var(--inv-bg); color: var(--inv-fg); }
.pr-trainer .pr-primary[data-mode="next"]:hover { background: var(--inv-hover); }
.pr-trainer .pr-secondary { background: var(--subtle); }
.pr-trainer .pr-secondary:hover { background: var(--line); }
.pr-trainer .pr-ghost { color: var(--text-2); }
.pr-trainer .pr-ghost:hover { background: var(--subtle); color: var(--text); }
.pr-trainer .pr-sm { padding: 5px 10px; font-size: 13px; }
/* close "x" drawn in CSS */
.pr-trainer .pr-x { position: relative; width: 28px; height: 28px; border-radius: 6px; }
.pr-trainer .pr-x:hover { background: var(--subtle); }
.pr-trainer .pr-x::before, .pr-trainer .pr-x::after { content: ""; position: absolute; left: 7px; top: 13px;
  width: 14px; height: 1.5px; background: var(--text-2); }
.pr-trainer .pr-x::before { transform: rotate(45deg); }
.pr-trainer .pr-x::after { transform: rotate(-45deg); }

/* ---- body: task | editor + result ---- */
.pr-empty { flex: 1; display: grid; place-items: center; }
.pr-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
.pr-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pr-pane.pr-task { border-right: 1px solid var(--line); }
.pr-right { display: grid; grid-template-rows: minmax(0, 3fr) minmax(0, 2fr); min-height: 0; }
.pr-pane.pr-code { border-bottom: 1px solid var(--line); }
.pr-pane-head { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--line); flex: none; min-height: 42px; }
.pr-pane-title { font-size: 13px; font-weight: 600; color: var(--text-3); }
.pr-file { font: 12px var(--mono); color: var(--text-3); margin-left: auto; }
.pr-env { font-size: 11px; color: var(--text-3); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; cursor: help; }

/* task */
.pr-task-body { padding: 18px 22px 24px; overflow: auto; flex: 1; }
.pr-task h2 { font-size: 21px; line-height: 1.3; margin: 0 0 8px; }
.pr-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; font-size: 13px; color: var(--text-3); margin-bottom: 16px; }
.pr-min { color: var(--text-3); }
.pr-badge { background: var(--subtle); color: var(--text-2); border-radius: 6px; padding: 2px 8px; font-size: 12.5px; }
.pr-badge.ok { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.pr-badge.gaveup { background: var(--accent-soft); color: var(--accent); }
.pr-prompt { font-size: 15px; line-height: 1.65; }
.pr-taskerr { margin-top: 16px; padding-left: 12px; border-left: 2px solid var(--err);
  color: var(--err); font-size: 13.5px; word-break: break-word; }

/* inline md */
.pr-trainer code { font-family: var(--mono); font-size: .9em; background: var(--subtle); padding: 1px 5px; border-radius: 4px; }
.pr-trainer .tr-pre { background: var(--subtle); border-radius: var(--radius-sm); padding: 10px 12px;
  font: 13px/1.55 var(--mono); overflow-x: auto; margin: 10px 0; white-space: pre; }

/* editor with gutter — dark IDE surface in both themes */
.pr-ed { flex: 1; min-height: 0; display: flex; background: #16181d; }
.pr-gutter { margin: 0; padding: 14px 10px 14px 12px; min-width: 46px; text-align: right;
  border-right: 1px solid rgba(255,255,255,.09); color: #636a76; font: 14px/1.6 var(--mono);
  overflow: hidden; user-select: none; white-space: pre; background: #16181d; }
.pr-trainer .tr-edit { position: relative; flex: 1; min-width: 0; min-height: 0; }
.pr-trainer .tr-hl { position: absolute; inset: 0; margin: 0; border: none; padding: 14px 16px;
  font: 14px/1.6 var(--mono); tab-size: 4; white-space: pre; overflow: hidden;
  color: #d6dae2; pointer-events: none; }
.pr-trainer .tr-hl code { background: none; padding: 0; border-radius: 0; font-size: inherit; }
.pr-trainer .tr-hl .tk-k { color: #7ee787; font-weight: 600; }
.pr-trainer .tr-hl .tk-s { color: #ffa198; }
.pr-trainer .tr-hl .tk-c { color: #8b949e; font-style: italic; }
.pr-trainer .tr-hl .tk-n { color: #79c0ff; }
.pr-trainer .tr-hl .tk-d { color: #d2a8ff; }
.pr-trainer .tr-hl .tk-t { color: #7ee787; }
.pr-trainer .tr-hl .tk-a { color: #79c0ff; }
.pr-trainer .tr-editor { position: relative; z-index: 1; width: 100%; height: 100%; min-height: 0; border: none; border-radius: 0;
  background: transparent; color: transparent; font: 14px/1.6 var(--mono); padding: 14px 16px;
  resize: none; tab-size: 4; white-space: pre; overflow: auto; outline: none; caret-color: #9fb2ff; }
.pr-trainer .tr-editor::selection { background: rgba(159,178,255,.30); }
.pr-code:focus-within .pr-pane-head { border-bottom-color: var(--line-strong); }

/* result / theory */
.pr-result, .pr-theory { flex: 1; overflow: auto; padding: 14px 18px; font-size: 14px; }
.pr-theory { line-height: 1.65; }
.pr-trainer .tr-muted { color: var(--text-3); font-size: 13.5px; margin: 0 0 8px; }
.pr-trainer .tr-pass { color: var(--ok); font-weight: 600; }
.pr-trainer .tr-fail { color: var(--err); font-weight: 600; word-break: break-word; white-space: pre-wrap; }
.pr-trainer .tr-diff { color: var(--text-2); font-size: 13px; margin: 8px 0 0; }
.pr-trainer .tr-case { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; margin-top: 12px; }
.pr-trainer .tr-arg { margin-top: 6px; }
.pr-trainer .tr-lbl { color: var(--text-3); font-size: 12px; font-weight: 600; }
.pr-trainer .tr-cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.pr-trainer .tr-case .tr-pre { white-space: pre-wrap; word-break: break-all; margin: 4px 0; background: var(--bg); }
.pr-success { border-left: 2px solid var(--ok); padding-left: 14px; }
.pr-success-t { font-size: 16px; font-weight: 700; color: var(--ok); }
.pr-success-s { font-size: 13.5px; margin-top: 4px; color: var(--text-2); }
.pr-loading::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: pr-spin .8s linear infinite; vertical-align: -1px; }
@keyframes pr-spin { to { transform: rotate(360deg); } }

/* ---- action bar ---- */
.pr-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); flex: none; }
.pr-flex { flex: 1; }
.pr-status { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---- Topics drawer ---- */
.pr-drawer-back { position: absolute; inset: 0; background: rgba(17, 17, 19, .3); z-index: 20; }
.pr-drawer { position: absolute; top: 0; bottom: 0; left: 0; width: min(360px, 92%);
  background: var(--bg); border-right: 1px solid var(--line); z-index: 21;
  display: flex; flex-direction: column; transform: translateX(-105%); transition: transform .2s ease; visibility: hidden; }
.pr-drawer.open { transform: none; visibility: visible; }
.pr-drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.pr-nav { flex: 1; overflow: auto; padding: 6px 8px 16px; }
.pr-trainer .tr-mod { display: flex; align-items: center; gap: 8px; padding: 9px 8px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px; outline: none; }
.pr-trainer .tr-mod:hover { background: var(--subtle); }
.pr-trainer .tr-mod:focus-visible { background: var(--subtle); outline: 2px solid var(--accent); outline-offset: -2px; }
.pr-trainer .tr-mod.cur .tr-mname { font-weight: 700; }
.pr-caret { width: 6px; height: 6px; flex: none; border-right: 1.5px solid var(--text-3); border-bottom: 1.5px solid var(--text-3);
  transform: rotate(-45deg); transition: transform .15s; margin: 0 2px; }
.pr-navmod.open .pr-caret { transform: rotate(45deg); }
.pr-trainer .tr-mid { font-weight: 600; color: var(--accent); min-width: 32px; }
.pr-trainer .tr-mname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-trainer .tr-mcnt { color: var(--text-3); font-size: 12px; }
.pr-trainer .tr-mcnt.full { color: var(--ok); font-weight: 600; }
.pr-navex { display: none; padding: 2px 0 6px 18px; }
.pr-navmod.open .pr-navex { display: block; }
.pr-trainer .tr-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13.5px; outline: none; }
.pr-trainer .tr-item:hover { background: var(--subtle); }
.pr-trainer .tr-item:focus-visible { background: var(--subtle); outline: 2px solid var(--accent); outline-offset: -2px; }
.pr-trainer .tr-item.cur { font-weight: 600; background: var(--subtle); }
.pr-trainer .tr-item.ok { color: var(--text-3); }
.pr-trainer .tr-name { flex: 1; }
.pr-trainer .tr-meta { color: var(--text-3); font-size: 11.5px; white-space: nowrap; }
.pr-trainer .tr-empty { color: var(--text-3); padding: 12px; }
.pr-sdot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; border: 1.5px solid var(--line-strong); }
.pr-sdot.done { background: var(--brand); border-color: var(--brand); }
.pr-sdot.tried { border-color: var(--text-3); background: var(--text-3); }

/* ---- hint modal ---- */
.pr-modal { position: absolute; inset: 0; background: rgba(17, 17, 19, .35); z-index: 30; display: grid; place-items: center; padding: 16px; }
.pr-modal-card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(560px, 100%); max-height: 80%; display: flex; flex-direction: column; }
.pr-modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.pr-hintbody { padding: 16px 18px 20px; overflow: auto; font-size: 14.5px; line-height: 1.65; }

/* ---- responsive ---- */
@media (max-width: 900px) {
  .pr-trainer { height: auto; min-height: 0; overflow: visible; }
  .pr-body { display: flex; flex-direction: column; }
  .pr-pane.pr-task { border-right: 0; border-bottom: 1px solid var(--line); }
  .pr-right { display: flex; flex-direction: column; }
  /* cap long prompts so the editor isn't buried below the fold */
  .pr-task-body { max-height: 46vh; overflow: auto; }
  .pr-ed { min-height: 300px; }
  .pr-result, .pr-theory { min-height: 160px; overflow: visible; }
  .pr-bar { position: sticky; bottom: 0; z-index: 15; background: var(--bg); flex-wrap: wrap; }
  .pr-status { order: 10; flex-basis: 100%; }
  .pr-hint-kbd { display: none; }
  .pr-drawer, .pr-drawer-back, .pr-modal { position: fixed; }
  .pr-drawer { top: 0; }
  .pr-trainer .tr-cmp { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .pr-trainer .pr-btn { padding: 9px 12px; font-size: 13px; }
  .pr-trainer .pr-primary { min-width: 0; flex: 1; }
}

/* short/zoomed viewports: drop the height floor so the Check bar stays reachable */
@media (max-height: 640px) {
  .pr-trainer { min-height: 0; }
}

/* iOS zooms an editor under 16px on focus — bump for touch */
@media (pointer: coarse) {
  .pr-trainer .tr-editor { font-size: 16px; }
  .pg-editor { font-size: 16px; }
  /* gutter line-numbers must match the editor's 16px or they drift */
  .pr-gutter { font-size: 16px; }
  /* touch targets */
  .pr-trainer .pr-btn { min-height: 44px; }
  .pg-kbdhint { display: none; }
}
.tr-stuck { margin-top: 10px; padding: 8px 12px; border-left: 3px solid var(--warn); background: var(--accent-soft, rgba(0,0,0,.03)); font-size: 13.5px; border-radius: 4px; }
.tr-stuck .pr-provlink { color: var(--text); }
