/* ===========================================================================
   v051 — practice workspace: stop the question pane flickering
   ---------------------------------------------------------------------------
   Dragging the centre divider re-sizes the question column, which re-lays-out
   the question, which changes its height, which toggles the pane's scrollbar.
   A scrollbar takes width away from the content box, so the "base width" that
   the zoom stage is built from changes too — and the two states keep flipping.
   That feedback loop is what made the pane flicker non-stop at certain divider
   positions.

   Reserving the scrollbar gutter permanently removes the trigger: the content
   box keeps the same width whether or not the bar is showing. The script side
   is fixed as well (syncQuestionZoom only writes a value when it actually
   changes), so the loop cannot restart through the ResizeObserver either.
   =========================================================================== */

body.ial-v030 #workspace .questionPaper,
body.ial-v030 .questionPaper {
  scrollbar-gutter: stable;
}

/* ===========================================================================
   v051 — `vw` / `vh` do not follow a CSS zoom
   ---------------------------------------------------------------------------
   Viewport units are resolved against the *unzoomed* viewport, so a full-screen
   panel written as `width:100vw; height:100vh` still measures the whole window
   and then gets multiplied by the zoom: at 150% that is 1230 x 1770 inside an
   820 x 1180 window. The panel is `position:fixed` with `overflow:hidden`, so
   the excess was simply cut off — which is why the practice workspace, its
   mark-scheme pane and the header controls all looked "incomplete and unusable"
   as soon as the interface size went up.

   src/ui-scale.mjs publishes the current zoom as --ial-ui-zoom, so every rule
   that used a viewport unit can be divided by it and laid out against the space
   the user can actually see.
   =========================================================================== */
body.ial-v029 #workspace.panel.active {
  width: calc(100vw / var(--ial-ui-zoom, 1));
  height: calc(100vh / var(--ial-ui-zoom, 1));
}

body.workspace-mode #workspace {
  min-height: calc(100vh / var(--ial-ui-zoom, 1) - 14px);
}

body.ial-v030.workspace-mode .workspaceGrid {
  min-height: calc(100vh / var(--ial-ui-zoom, 1) - 68px);
}

/* The rail is sticky and as tall as the window; left unadjusted it ran past the
   bottom of an enlarged screen and hid the account card. */
body.ial-v030 .app {
  min-height: calc(100vh / var(--ial-ui-zoom, 1));
}

body.ial-v030 .sidebar {
  height: calc(100vh / var(--ial-ui-zoom, 1));
}

/* Paper workspace: same viewport-unit problem in both of its modes. */
body.ial-v030 .paperWorkspaceBody.continuousPaperBody {
  height: calc(100vh / var(--ial-ui-zoom, 1) - 50px) !important;
  max-height: calc(100vh / var(--ial-ui-zoom, 1) - 50px) !important;
}

/* Practice answer area caps so the writing surface stays reachable. */
html[data-ui-eff="narrow"] body.ial-v030 .questionStage,
html[data-ui-eff="mid"] body.ial-v030 .questionStage {
  max-height: calc(100vh / var(--ial-ui-zoom, 1) - 168px);
}

html[data-ui-eff="narrow"] body.ial-v030.workspace-mode .workingPanel,
html[data-ui-eff="mid"] body.ial-v030.workspace-mode .workingPanel {
  max-height: none;
}

/* The ink toolbar is intentionally one scrollable row on tablets, which is fine
   when the row fits. At a large interface size it does not, so wrapping puts
   every tool in reach instead of hiding the last cluster off the edge. */
html[data-ui-eff="narrow"] body.workspace-mode #workspace .inkToolbar,
html[data-ui-eff="mid"] body.workspace-mode #workspace .inkToolbar {
  flex-wrap: wrap !important;
  /* Wrapping is the goal, but keep the bar scrollable as a guaranteed fallback:
     a tool must never become unreachable just because a row refused to break. */
  overflow-x: auto !important;
  row-gap: 5px;
  max-width: 100% !important;
}

/* Wrapping the bar alone was not enough. A flex item defaults to a content-sized
   basis, so each group stayed 514px wide and merely poked out of its parent -
   flex-wrap only breaks *between* items, never inside one. Giving the group a
   100% basis constrains its width to the bar, which is what finally lets the
   buttons inside it wrap onto a second row. */
html[data-ui-eff="narrow"] body.workspace-mode #workspace .inkToolbar .toolGroup,
html[data-ui-eff="mid"] body.workspace-mode #workspace .inkToolbar .toolGroup {
  flex: 1 1 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  flex-wrap: wrap !important;
  border-right: 0 !important;
  padding-right: 0 !important;
}

html[data-ui-eff="narrow"] body.workspace-mode #workspace .inkToolbar .inkPrimaryTools,
html[data-ui-eff="mid"] body.workspace-mode #workspace .inkToolbar .inkPrimaryTools {
  flex-wrap: wrap !important;
  min-width: 0 !important;
}

/* ===========================================================================
   v051 — Finish question moved into the header
   ---------------------------------------------------------------------------
   The submit action used to live at the bottom of the writing panel, under a
   sticky footer, so on a long question it scrolled out of reach and at a large
   interface size it left the screen entirely. It now sits in the workspace
   header next to Save, where it is always visible; the footer keeps only the
   explanatory note.
   =========================================================================== */
body.ial-v030 #workspace .taskSubmitStatus {
  font-size: 11.5px;
  font-weight: 700;
  color: #c9d6ea;
  white-space: nowrap;
  padding: 0 2px;
}

body.ial-v030 #workspace .taskSubmitStatus:not(:empty) {
  opacity: .95;
}

body.ial-v030 #workspace .taskFinishBtn {
  white-space: nowrap;
}

/* The footer note is now purely informational. */
body.ial-v030 #workspace .workspaceSubmit.inkSubmit {
  justify-content: flex-start;
}

/* ===========================================================================
   v051 — home card: exam series, module confirm, clickable figures
   =========================================================================== */

/* The exact-date picker was replaced by an exam-series selector; the old input
   stays in the DOM because the countdown reads it, but it must not be shown. */
body.ial-v030 .legacyDateControl {
  display: none !important;
}

body.ial-v030 .examSeriesControl {
  display: flex;
  justify-content: flex-end;
  margin: 4px 0 6px;
}

body.ial-v030 #examSeriesSelect {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: #12203a;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 8px;
  padding: 6px 9px;
  max-width: 100%;
  cursor: pointer;
}

body.ial-v030 .heroConfirmRow {
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

body.ial-v030 .heroConfirmBtn {
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .04em;
  padding: 6px 14px;
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  background: #dbb44a;
  color: #1a2438;
}

body.ial-v030 .heroConfirmBtn:disabled {
  background: rgba(255, 255, 255, .14);
  color: rgba(255, 255, 255, .5);
  cursor: default;
}

/* A chip whose state has not been confirmed yet gets a dashed outline, so it is
   visually obvious that the choice is still pending. */
body.ial-v030 .heroModuleChip.pending {
  border-style: dashed;
  border-color: #dbb44a;
}

body.ial-v030 .metric.metricLink {
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}

body.ial-v030 .metric.metricLink:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(20, 35, 55, .10);
}

body.ial-v030 .metric.metricLink:focus-visible {
  outline: 2px solid #4d7cff;
  outline-offset: 2px;
}

/* ===========================================================================
   v051 — sign-in entry on phones
   ---------------------------------------------------------------------------
   Below the sidebar breakpoint the sidebar is hidden, and it held the only
   account card / sign-in button, so a phone user could not sign in at all. The
   mobile header now carries the entry point.
   =========================================================================== */
body.ial-v030 .mobileHeaderRight {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

body.ial-v030 .mobileHeaderSub {
  font-size: 10px;
  color: #9fb1c9;
  white-space: nowrap;
}

body.ial-v030 .mobileAcctBtn {
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 800;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}

body.ial-v030 .mobileAcctBtn.signedIn {
  background: #dbb44a;
  border-color: #dbb44a;
  color: #1a2438;
}

@media (max-width: 430px) {
  body.ial-v030 .mobileHeaderSub {
    display: none;
  }
}

/* ===========================================================================
   v051 — review rows act as links back into Practice
   =========================================================================== */
body.ial-v030 .v027ReviewQuestionRow.reviewRowClickable {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background .12s ease;
}

body.ial-v030 .v027ReviewQuestionRow.reviewRowClickable:hover {
  background: #f2f6ff;
}

body.ial-v030 .v027ReviewQuestionRow.reviewRowClickable:focus-visible {
  outline: 2px solid #4d7cff;
  outline-offset: -2px;
}

body.ial-v030 .reviewRowText {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

body.ial-v030 .reviewRowText b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.ial-v030 .reviewRowText span {
  font-size: 11.5px;
  color: var(--c-muted);
}

body.ial-v030 .reviewRowState {
  font-style: normal;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .03em;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  background: #eef1f6;
  color: #5a6a86;
}

body.ial-v030 .reviewRowState.wrong { background: #ffe8e8; color: #b4232a; }
body.ial-v030 .reviewRowState.correct { background: #e3f6ea; color: #176341; }
body.ial-v030 .reviewRowState.partial { background: #fff3d9; color: #8a5a00; }
body.ial-v030 .reviewRowState.unsure { background: #eef0ff; color: #3748a5; }

body.ial-v030 .reviewRowGo {
  font-size: 11.5px;
  font-weight: 800;
  color: #315efb;
  white-space: nowrap;
}

/* ===========================================================================
   v051 — attached photos of handwritten working
   =========================================================================== */
body.ial-v030 .questionPhotos {
  margin: 10px 12px 0;
  padding: 10px 12px;
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 12px;
}

body.ial-v030 .questionPhotos[hidden] {
  display: none;
}

body.ial-v030 .photoStripHead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

body.ial-v030 .photoStripHead b {
  font-size: 12px;
}

body.ial-v030 .photoStripHead span {
  font-size: 11px;
  color: var(--c-muted);
}

body.ial-v030 .photoStrip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

body.ial-v030 .photoThumb {
  margin: 0;
  width: 104px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

body.ial-v030 .photoThumb img {
  display: block;
  width: 100%;
  height: 76px;
  object-fit: cover;
  cursor: zoom-in;
}

body.ial-v030 .photoThumb figcaption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 6px;
  font-size: 10.5px;
  color: var(--c-muted);
}

body.ial-v030 .photoThumb figcaption button {
  border: 0;
  background: transparent;
  color: #b4232a;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

/* The overlay is full-screen and therefore hits the same `vw`/`vh` zoom trap as
   the workspace panel, so its box is divided by the zoom too. */
body.ial-v030 .photoViewer {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  display: none;
  place-items: center;
  width: calc(100vw / var(--ial-ui-zoom, 1));
  height: calc(100vh / var(--ial-ui-zoom, 1));
  background: rgba(8, 20, 39, .86);
  padding: 20px;
  box-sizing: border-box;
}

body.ial-v030 .photoViewer.show {
  display: grid;
}

body.ial-v030 .photoViewer img {
  max-width: 92vw;
  max-height: 86vh;
  border-radius: 10px;
  background: #fff;
}

body.ial-v030 .photoViewerClose {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

/* ===========================================================================
   v051 — interface language switch
   =========================================================================== */
body.ial-v030 .langToggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #eef1f6;
  padding: 4px;
  border-radius: 10px;
}

body.ial-v030 .langBtn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  color: #5a6a86;
}

body.ial-v030 .langBtn.active {
  background: #fff;
  color: #16213a;
  box-shadow: 0 1px 4px rgba(20, 35, 55, .12);
}

/* Slightly wider line height reads better with Chinese characters. */
body.ial-v030.lang-zh {
  line-height: 1.55;
}

/* The tablet layout makes Hand and Pen two half-width buttons (flex 1 1 45%).
   That reads well at tablet width, but once the interface is enlarged the row
   has less usable space than that rule assumes, so each button grew to ~379px
   and the toolbar ran off the edge. Let them size to their content instead -
   the order (Hand, Pen first) and the touch height are both preserved. */
/* Blanket rule rather than naming ids: the half-width treatment reaches several
   buttons through different selectors, and missing one is exactly how the last
   cluster kept spilling past the edge. */
html[data-ui-eff="narrow"] body.ial-v030.workspace-mode #workspace .inkToolbar .inkTool,
html[data-ui-eff="mid"] body.ial-v030.workspace-mode #workspace .inkToolbar .inkTool,
html[data-ui-eff="narrow"] body.ial-v030 #handTool,
html[data-ui-eff="narrow"] body.ial-v030 #penTool,
html[data-ui-eff="narrow"] body.ial-v030 #paperHandBtn,
html[data-ui-eff="narrow"] body.ial-v030 #paperPenBtn,
html[data-ui-eff="narrow"] body.ial-v030 .onPaperToolbar .btn,
html[data-ui-eff="mid"] body.ial-v030 #handTool,
html[data-ui-eff="mid"] body.ial-v030 #penTool,
html[data-ui-eff="mid"] body.ial-v030 #paperHandBtn,
html[data-ui-eff="mid"] body.ial-v030 #paperPenBtn,
html[data-ui-eff="mid"] body.ial-v030 .onPaperToolbar .btn {
  flex: 0 1 auto !important;
  min-height: 40px;
  max-width: 100% !important;
  min-width: 0 !important;
}
