/* medu-ext: WebGL graph + phone layout for the Medu web app (loaded after the app's own CSS). */

/* ---------------------------------------------------------------- graph */
.gwrap:has(> .mg) { padding: 0 !important; overflow: hidden; max-height: none; }
.mg {
  position: relative;
  height: clamp(380px, calc(100vh - var(--hdr-h, 56px) - 210px), 920px);
  height: clamp(380px, calc(100svh - var(--hdr-h, 56px) - 210px), 920px);
  background: radial-gradient(circle at 50% 40%, var(--panel) 0%, var(--sub) 100%);
  border-radius: inherit;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.mg-gl, .mg-labels { position: absolute; inset: 0; display: block; }
.mg-gl { cursor: grab; outline: none; }
.mg-labels { pointer-events: none; }
.mg.mg-kbd .mg-gl { box-shadow: inset 0 0 0 2px var(--acc); }
.mg-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.mg-top {
  position: absolute; top: 10px; left: 10px; right: 10px;
  display: flex; gap: 8px; align-items: flex-start; justify-content: space-between;
  pointer-events: none;
}
.mg-top > * { pointer-events: auto; }
.mg-search {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--r, 8px);
  padding: 0 10px; height: 36px; min-width: 0; flex: 0 1 260px;
  color: var(--muted); box-shadow: var(--shadow);
}
.mg-search:focus-within { border-color: var(--acc); }
.mg-search svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; }
.mg-search input { border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; font-size: 14px; min-width: 0; flex: 1; }
.mg-count { font-size: 12px; white-space: nowrap; }
.mg-tools { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.mg-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center;
  background: var(--panel); color: var(--ink); border: 1px solid var(--rule); border-radius: var(--r, 8px);
  cursor: pointer; box-shadow: var(--shadow); padding: 0;
}
.mg-btn:hover { border-color: var(--edge); }
.mg-btn[aria-pressed="true"], .mg-btn[aria-expanded="true"] { background: var(--acc-s); color: var(--acc); border-color: var(--acc); }
.mg-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.mg-panel {
  position: absolute; top: 54px; right: 10px; width: 300px; max-width: calc(100% - 20px);
  max-height: calc(100% - 64px); overflow: auto;
  background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; box-shadow: 0 8px 28px #0000002a;
  padding: 6px 12px 12px; font-size: 14px; z-index: 2;
}
.mg-panel[hidden] { display: none; }
.mg-panel-h { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 6px; }
.mg-panel-h .mg-btn { width: 30px; height: 30px; box-shadow: none; border-color: transparent; }
.mg-panel details { border-top: 1px solid var(--rule); padding: 6px 0; }
.mg-panel summary {
  cursor: pointer; font-family: var(--f-mono); font-size: 11px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 6px 0;
}
.mg-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; color: var(--ink); }
.mg-check input { accent-color: var(--acc); width: 16px; height: 16px; }
.mg-range { display: grid; grid-template-columns: 1fr 34px; gap: 2px 8px; }
.mg-range span { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.mg-range input { accent-color: var(--acc); width: 100%; }
.mg-range output { font-family: var(--f-mono); font-size: 12px; color: var(--muted); text-align: right; }
.mg-select { justify-content: space-between; }
.mg-select span { font-size: 13px; color: var(--muted); }
.mg-select select { font: inherit; font-size: 13px; color: var(--ink); background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 3px 6px; max-width: 60%; }
.mg-actions { gap: 8px; border-top: 1px solid var(--rule); padding-top: 10px; }
.mg-actions .btn { flex: 1; justify-content: center; }

.mg-hint {
  position: absolute; top: 54px; left: 50%; transform: translateX(-50%);
  background: var(--acc); color: var(--on-acc); border-radius: 99px; padding: 4px 12px; font-size: 13px; font-weight: 600;
  pointer-events: none; white-space: nowrap;
}
.mg-hint[hidden], .mg-hint:empty { display: none; }

.mg-card {
  position: absolute; left: 10px; bottom: 10px; max-width: min(380px, calc(100% - 20px));
  background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; box-shadow: 0 6px 20px #00000022;
  padding: 10px 12px; font-size: 14px; display: flex; flex-direction: column; gap: 4px;
}
.mg-card[hidden] { display: none; }
.mg-card-t { display: flex; align-items: center; gap: 8px; line-height: 1.3; }
.mg-card-t b { font-size: 15px; }
.mg-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.mg-card-m { color: var(--muted); font-size: 13px; }
.mg-card-tip { font-size: 12px; }
.mg-card-a { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.mg-card-a .btn { min-height: 32px; padding: 4px 12px; font-size: 14px; }
@media (min-width: 961px) { .mg-details { display: none; } }

.mg.mg-full {
  position: fixed !important; inset: 0; z-index: 100; height: auto !important; border-radius: 0;
}
.mg:fullscreen { height: 100vh; border-radius: 0; }

/* The side-panel toggle exists only on phones (see the phone rules below). */
.m-side-toggle { display: none; }

/* ---------------------------------------------------------------- phones */
@media (max-width: 640px) {
  /* Header: brand, course and tools on one row; the section tabs scroll sideways on a second row. */
  .hdr { padding: 0 12px; gap: 0 8px; min-height: 0; }
  .hdr .brand { padding: 10px 0; font-size: 18px; }
  .hdr .course { max-width: 42vw; min-height: 32px; padding: 0 6px; }
  .hdr .right { order: 2; gap: 6px; margin-left: auto; }
  .hdr .prog { display: none; }
  .hdr .iconbtn { width: 34px; height: 34px; min-height: 34px; padding: 0; }
  .hdr nav {
    order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain;
    margin: 0 -12px; padding: 0 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 20px), transparent 100%);
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 20px), transparent 100%);
  }
  .hdr nav::-webkit-scrollbar { display: none; }
  .hdr nav a { padding: 8px 10px 9px; white-space: nowrap; flex: none; }

  /* Search: an icon that opens into a full-width field over the header row. */
  .hdr .search { min-height: 34px; padding: 0 9px; cursor: text; }
  .hdr .search input { width: 0; padding: 0; transition: width .15s; }
  .hdr .search:focus-within {
    position: absolute; left: 12px; right: 12px; top: 8px; z-index: 5;
    background: var(--hdr-bg); border-color: var(--hdr-ink);
  }
  .hdr .search:focus-within input { width: 100%; }

  /* Left side panels collapse behind a toggle (added by medu-ext.js). */
  .side[data-m-side] { flex-basis: 100%; padding: 0; }
  .side[data-m-side]:not(.m-open) > :not(.m-side-toggle) { display: none !important; }
  .side[data-m-side]:not(.m-open) { padding: 0 !important; gap: 0 !important; min-height: 0 !important; }
  .m-side-toggle {
    display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px;
    padding: 12px 16px; background: transparent; border: 0; color: var(--ink);
    font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; text-align: left;
  }
  .m-side-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; transition: transform .15s; }
  .side.m-open .m-side-toggle svg { transform: rotate(180deg); }
  .side.m-open { max-height: 70vh; overflow: auto; }

  /* Content: use the width, keep tables and wide blocks scrolling inside themselves. */
  .main { padding: 14px 12px 56px; gap: 14px; }
  .ph h1, h1 { overflow-wrap: anywhere; }
  .tbl { font-size: 14px; }
  .tbl th, .tbl td { padding-left: 8px; padding-right: 8px; }
  pre, .mono { overflow-x: auto; max-width: 100%; }
  img, video, iframe, svg:not(.mg *) { max-width: 100%; }
  .card { min-width: 0; }

  /* Lesson cells: the action buttons wrap under the label instead of running off the edge. */
  .cell .tag { flex-wrap: wrap; row-gap: 6px; }
  .cell .tag .src { min-width: 0; overflow-wrap: anywhere; }
  .cell .tag .acts { flex-wrap: wrap; }
  .pathrow .stop { width: 84px; }
  .pathrow .stop > :last-child { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

  /* Data tables become one card per row; medu-ext.js copies each column name into data-label. */
  table.tbl[data-m-cards] { font-size: 15px; }
  table.tbl[data-m-cards] thead { display: none; }
  table.tbl[data-m-cards], table.tbl[data-m-cards] tbody { display: block; width: 100%; }
  table.tbl[data-m-cards] tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 12px 14px; border-top: 1px solid var(--rule); }
  table.tbl[data-m-cards] tbody tr:first-child { border-top: 0; }
  table.tbl[data-m-cards] td { display: block; border: 0; padding: 0; min-width: 0; }
  table.tbl[data-m-cards] td:first-child { flex: 1 1 100%; }
  table.tbl[data-m-cards] td:empty { display: none; }
  table.tbl[data-m-cards] td[data-label]:not(:first-child)::before {
    content: attr(data-label); display: block; font-family: var(--f-mono); font-size: 11px;
    letter-spacing: .06em; text-transform: uppercase; color: var(--muted); line-height: 1.4;
  }
  table.tbl[data-m-cards] td:last-child:not(:first-child) { margin-left: auto; }
  table.tbl[data-m-cards] td[colspan] { flex: 1 1 100%; }

  /* Graph page: the graph gets most of the screen, the topic panel follows. */
  .mg { height: 64vh; height: 64svh; min-height: 360px; }
  .mg-top { top: 8px; left: 8px; right: 8px; gap: 6px; }
  .mg-search { flex: 1 1 auto; padding: 0 8px; }
  .mg-count { display: none; }
  .mg-tools { flex: none; flex-wrap: nowrap; }
  .mg-panel { top: 56px; right: 8px; left: 8px; width: auto; max-height: calc(100% - 66px); }
  .mg-hint { top: 58px; }
  .mg-card { left: 8px; right: 8px; bottom: 8px; max-width: none; padding: 8px 10px; display: grid;
    grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; row-gap: 0; align-items: center; }
  .mg-card-t { grid-column: 1; }
  .mg-card-t b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
  .mg-card-m { grid-column: 1; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mg-card-a { grid-column: 2; grid-row: 1 / span 2; margin: 0; flex-wrap: nowrap; }
  .mg-card-a .btn { min-height: 34px; padding: 4px 10px; font-size: 13px; }
  .mg-card-tip { display: none; }
}

/* touch: bigger hit areas for the graph buttons */
@media (pointer: coarse) {
  .mg-btn { width: 40px; height: 40px; }
  .mg-search { height: 40px; }
  .mg-btn[data-zoom] { display: none; }   /* pinch instead */
}

/* ---------------------------------------------------------------- lesson cells */

/* Code reads exactly as typed: no ligatures (JetBrains Mono would draw -> as an arrow and << as «). */
code, pre, kbd, samp, .mono, pre.code, .tag, .src, .lab, .kicker, .side-h {
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}

/* Editing notes about slide extraction are for the course author, not students. */
section.cell.m-editor-note { display: none !important; }

/* Cell header on one line: label, pill, source (truncated), actions. */
.cell .tag { white-space: nowrap; min-width: 0; }
.cell .tag .pill { flex: none; }
.cell .tag .src { flex: 1 1 40px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cell .tag .acts { flex: none; }

/* Long code blocks: taller before they scroll. */
.cell pre.code, .qprompt pre.code, .rich pre.code { max-height: min(78vh, 900px); }

/* Code in questions, model answers and hints (restyled by medu-ext.js). */
pre.m-code { margin: 4px 0 10px; font-size: 13.5px; white-space: pre; }

/* Inline code */
.cell code.m-nw, .qprompt code.m-nw, .rich code.m-nw { white-space: nowrap; }
.cell code.m-long, .qprompt code.m-long, .rich code.m-long { overflow-wrap: anywhere; word-break: normal; }

/* Tables in lesson text */
.m-tw {
  overflow-x: auto; max-width: 100%; margin: 6px 0 12px;
  border: 1px solid var(--rule); border-radius: var(--r, 8px); background: var(--panel);
}
.m-tw > table { border-collapse: collapse; width: 100%; margin: 0; font-size: .95em; line-height: 1.5; }
.m-tw th, .m-tw td { text-align: left; vertical-align: top; padding: 7px 12px; }
.m-tw thead th {
  background: var(--sub); color: var(--ink); font-weight: 650; font-family: var(--f-ui);
  border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.m-tw tbody tr + tr td, .m-tw tbody tr + tr th { border-top: 1px solid var(--rule); }
.m-tw tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--sub) 55%, transparent); }
.m-tw td:first-child { font-weight: 500; }
.m-tw + p { margin-top: 4px; }
@media (max-width: 640px) { .m-tw code { white-space: nowrap; overflow-wrap: normal; } }

/* Tabs (groups of note boxes) */
.m-tablist {
  display: flex; gap: 2px; flex-wrap: wrap; margin: 8px 0 0;
  border-bottom: 1px solid var(--rule);
}
.m-tab {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
  background: transparent; border: 1px solid transparent; border-bottom: 0;
  border-radius: var(--r, 8px) var(--r, 8px) 0 0; padding: 7px 14px; cursor: pointer; margin-bottom: -1px;
}
.m-tab:hover { color: var(--ink); }
.m-tab[aria-selected="true"] { color: var(--acc); background: var(--panel); border-color: var(--rule); }
.m-tab code { font-size: .9em; }
.m-tabpanel { margin-top: 0 !important; border-top-left-radius: 0 !important; }
.m-tabpanel > .lab { display: none; }
.m-reveal { margin: 8px 0 4px; align-self: flex-start; }

/* Matching and ordering questions */
.m-hidden { display: none !important; }
.m-native { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 4px; font-family: var(--f-ui); font-size: 15px; }
.m-native-h { margin: 0; color: var(--muted); font-size: 14px; }
.m-match .m-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(130px, 34%) 22px; gap: 4px 10px; align-items: center;
  padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--r, 8px); background: var(--panel);
}
.m-match select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--panel);
  border: 1px solid var(--edge); border-radius: 6px; padding: 6px 8px; min-height: 36px; width: 100%;
}
.m-match .m-want { grid-column: 1 / -1; font-size: 13px; color: var(--good); font-weight: 600; }
.m-mark { font-weight: 700; text-align: center; }
.m-ok .m-mark { color: var(--good); }
.m-bad .m-mark { color: var(--bad); }
.m-match .m-row.m-ok, .m-oitem.m-ok { border-color: var(--good); background: var(--good-s); }
.m-match .m-row.m-bad, .m-oitem.m-bad { border-color: var(--bad); background: var(--ex-s); }
.m-olist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; counter-reset: mo; }
.m-oitem {
  display: grid; grid-template-columns: 18px 26px minmax(0, 1fr) auto 34px 34px; gap: 6px; align-items: center;
  padding: 6px 8px; border: 1px solid var(--rule); border-radius: var(--r, 8px); background: var(--panel);
  counter-increment: mo;
}
.m-oitem::before { content: counter(mo) "."; grid-column: 2; grid-row: 1; color: var(--muted); font-family: var(--f-mono); font-size: 13px; text-align: right; }
.m-oitem .m-grip { grid-column: 1; grid-row: 1; color: var(--muted); cursor: grab; letter-spacing: -3px; user-select: none; }
.m-oitem .m-item { grid-column: 3; }
.m-oitem .m-mark { grid-column: 4; font-size: 12px; white-space: nowrap; }
.m-codeitems .m-item { font-family: var(--f-mono); font-size: 13.5px; white-space: pre-wrap; }
.m-oitem.m-drag { opacity: .5; }
.m-mv {
  font: inherit; width: 34px; height: 32px; border: 1px solid var(--rule); border-radius: 6px;
  background: var(--panel); color: var(--ink); cursor: pointer;
}
.m-mv:disabled { opacity: .35; cursor: default; }
.m-done .m-grip { visibility: hidden; }
.m-item > p { margin: 0; }
.m-native-sum { margin: 2px 0 0; font-weight: 600; }
.m-native-sum:empty { display: none; }
.m-native-sum.m-ok { color: var(--good); }
.m-native-sum.m-part { color: var(--hl-ink); }
.m-native-sum.m-bad { color: var(--bad); }
.ctrl button.m-suggest { outline: 2px solid var(--acc); outline-offset: 2px; }

@media (max-width: 640px) {
  .m-match .m-row { grid-template-columns: minmax(0, 1fr) 22px; }
  .m-match select { grid-column: 1; }
  .m-match .m-mark { grid-column: 2; grid-row: 1 / span 2; }
  .m-oitem { grid-template-columns: 22px minmax(0, 1fr) 34px 34px; row-gap: 2px; }
  .m-oitem .m-grip { display: none; }
  .m-oitem::before { grid-column: 1; }
  .m-oitem .m-item { grid-column: 2; grid-row: 1; }
  .m-oitem .m-mv { grid-row: 1; }
  .m-oitem .m-mark { grid-column: 2; grid-row: 2; text-align: left; }
  .m-oitem .m-mark:empty { display: none; }
  .m-codeitems .m-item { white-space: pre; overflow-x: auto; font-size: 12.5px; }
  .m-tablist { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .m-tablist::-webkit-scrollbar { display: none; }
  .m-tab { white-space: nowrap; flex: none; padding: 7px 12px; }
  .cell .tag .acts button { padding: 0 7px; }
  .cell pre.code.num .ln:before { width: 1.6em; margin-right: .55em; }
  .cell pre.code, .qprompt pre.code { font-size: 12.5px; padding: 10px; }
}
.question:has(.m-codeitems) .fbk .rich li { font-family: var(--f-mono); font-size: 13.5px; white-space: pre-wrap; }

/* ---------------------------------------------------------------- small fixes across pages */
b + .pill, strong + .pill, a + .pill { margin-left: 6px; }
.pill { white-space: nowrap; display: inline-block; vertical-align: 1px; }
.tbl th { white-space: nowrap; }

@media (max-width: 640px) {
  /* Tables without a header row stay tables; keep the first column (a time, a number) narrow. */
  table.tbl:not([data-m-cards]) td:first-child { width: 1%; white-space: nowrap; padding-right: 10px; }
  table.tbl:not([data-m-cards]) td { padding-left: 10px; padding-right: 10px; }
  /* Flashcard ratings: one compact row of four instead of four tall rows. */
  .g4:has(> button.btn.lg) { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 6px !important; }
  .g4:has(> button.btn.lg) > button.btn.lg { min-height: 54px !important; padding: 4px 2px; font-size: 14px; }
}
