@import "./reference-css/question-widget.css";

:root {
  --ok: #0f7a2a;
  --fail: #9a1f1f;
  --run: #8a5a00;
  --border: rgb(224, 224, 224);
  --muted: #666;
  --bg: #ffffff;
  --headline: #242060;
}

* {
  box-sizing: border-box;
}

/* HTML hidden attribute: v3 styles load after reference-css, so this overrides display rules without !important. */
[hidden] {
  display: none;
}

body,
p,
input,
textarea,
button {
  font-family: "Futura Light", "Trebuchet MS", Arial, sans-serif;
  font-size: 15px;
  color: rgb(64, 64, 64);
}

body {
  margin: 0;
  padding: 0 0 240px;
  background: var(--bg);
}

h1,
h2,
h3 {
  margin: 0;
}

.page-header {
  display: none;
}

.questionWidget {
  margin: 50px auto 0;
  max-width: 700px;
}

/* v3 stacked progression: match reference platform spacing between consecutive cards. */
.questionWidget-shell + .questionWidget-shell .questionWidget {
  margin-top: 55px;
}

.questionWidget-continueWrap {
  width: 698px;
  max-width: 100%;
  margin: 34px auto 0;
  padding-left: 15px;
}

.questionWidget-trackComplete {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ok);
}

/* Override fixed 700px shell slots from reference CSS so content never exceeds the card width. */
div.questionWidget-body {
  width: 100%;
  max-width: 100%;
}

/* Reference widget uses bold feedback text; v4 uses normal weight for status + error lines. */
div.questionWidget-feedback {
  width: 100%;
  max-width: 100%;
  font-weight: 400;
}

.questionWidget-text {
  font-size: 15px;
  line-height: 1.55;
  margin: 0 0 0.75rem;
  color: rgb(45, 45, 45);
}

/* Prompt: markdown (marked + MathJax), same prose feel as explanation/slides. */
.questionWidget-promptBody p {
  margin: 0 0 0.5rem;
}

.questionWidget-promptBody p:last-child {
  margin-bottom: 0;
}

.questionWidget-promptBody ul,
.questionWidget-promptBody ol {
  margin: 0.35rem 0 0.65rem;
  padding-left: 1.25rem;
}

.questionWidget-promptBody li {
  margin: 0.12rem 0;
}

.questionWidget-promptBody a {
  color: rgb(9, 107, 183);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.questionWidget-promptBody a:hover {
  color: rgb(7, 86, 148);
}

/* Inline code in prompts: same 15px monospace as signatures/editor. If it looks optically small vs sans body, try 16px here only. */
.questionWidget-promptBody code {
  font-family: "Courier New", monospace;
  font-size: 15px;
  line-height: 1.55;
  color: rgb(45, 45, 45);
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.questionWidget-apiBlock {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  margin: 0 0 0.7rem;
}

.questionWidget-apiLabel {
  margin: 0;
  color: rgb(45, 45, 45);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.55;
}

.questionWidget-slideBody {
  margin-top: 0.6rem;
  font-size: 15px;
  line-height: 1.5;
}

.questionWidget-slideSection + .questionWidget-slideSection {
  margin-top: 0.9rem;
}

.questionWidget-slideFigure {
  margin: 1rem 0 0;
}

.questionWidget-slideImage {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
}

.questionWidget-slideCaption {
  margin-top: 0.4rem;
  font-size: 13px;
  color: var(--muted);
}

.questionWidget-codeSignatureRow {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  line-height: 1.3;
}

.questionWidget-codeSignatureRow > .questionWidget-codeSignatureValue {
  margin-left: 0;
}

.questionWidget-codeSignatureValue {
  font-family: "Courier New", monospace;
  background: transparent;
  display: inline;
  padding: 0;
  border-radius: 0;
  font-size: 15px;
  line-height: 1.55;
  color: rgb(45, 45, 45);
}

.questionWidget-apiSignature {
  color: inherit;
}

.questionWidget-libraryFunctionsBlock {
  margin-bottom: 0;
}

.questionWidget-libraryFunctionsList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
}

.questionWidget-libraryFunctionsList .questionWidget-codeSignatureValue {
  display: block;
}

.questionWidget-codeEditor {
  margin-top: 0.7rem;
  display: inline-block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0;
  background: white;
}

.questionWidget-runControls {
  margin-top: 0.7rem;
}

.questionWidget-runControls .questionWidget-feedback {
  margin-top: 0.7rem;
}

div.questionWidget-buttonBar.questionWidget-submitBar {
  margin-top: 14px;
}

.questionCard.is-active .questionWidget-codeEditor:focus-within {
  border-color: rgb(9, 107, 183);
  box-shadow: 0 0 0 1px rgba(9, 107, 183, 0.18);
}

/* Code editor: match v2 styling (CodeMirror + fallback). */
.questionWidget-codeEditor .CodeMirror {
  width: 100%;
  min-height: 220px;
  height: 220px;
  border: none;
  font-family: "Courier New", monospace;
  font-size: 15px;
  border-radius: 0;
  resize: vertical;
  overflow: hidden;
}

/* CM5 scrolls here; hide track to reduce visual noise (wheel/touch/keys still scroll). */
.questionWidget-codeEditor .CodeMirror-scroll {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.questionWidget-codeEditor .CodeMirror-scroll::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.questionWidget-codeEditor .CodeMirror-lines {
  padding: 0.8rem 0;
}

.editor-fallback {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: none;
  outline: none;
  padding: 0.8rem;
  font-family: "Courier New", monospace;
  font-size: 15px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.editor-fallback::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.questionWidget-debugInput {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 0;
  font-family: "Courier New", monospace;
  font-size: 15px;
  background: #ffffff;
  padding: 0.6rem;
  outline: none;
}

.questionWidget-debugInput:focus {
  border-color: rgb(9, 107, 183);
  box-shadow: 0 0 0 1px rgba(9, 107, 183, 0.18);
}

/* Reference widget uses 40px body top margin; feedback uses 25px below controls.
   Match the 25px rhythm for space between status ("Ready") and test UI. */
div.questionWidget-body.questionWidget-codeTestBlock {
  margin-top: 25px;
  margin-bottom: 0;
  width: 100%;
  line-height: normal;
  /* Title ("TEST CASES" / "CUSTOM TEST CASE") → column header row; shared in both blocks. */
  --code-test-title-to-header-gap: 0.5rem;
}

.questionWidget-codeVisibleResults,
.questionWidget-codeDebugRows {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* Match margin above TEST CASES block (codeTestBlock margin-top: 25px). */
.questionWidget-codeDebugRows {
  margin-top: 25px;
}

.questionWidget-visibleTestsBlock {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.questionWidget-visibleGrid {
  border-top: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.questionWidget-visibleGridHeader,
.questionWidget-visibleGridRow {
  display: grid;
  grid-template-columns: 70px minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 0.6rem;
  align-items: start;
}

/* One light rule under column titles; row separation uses gap above, not stripes. */
.questionWidget-visibleGridHeader {
  padding: 0 0 0.5rem;
  border-bottom: 1px solid rgba(30, 25, 78, 0.14);
}

.questionWidget-visibleGridHeadCell {
  margin: 0;
  color: rgb(88, 86, 102);
  font-size: 13px;
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.questionWidget-visibleGridRow {
  padding: 0.1rem 0 0;
  border-bottom: none;
}

.questionWidget-visibleGridCell {
  min-width: 0;
}

.questionWidget-visibleGridCell .questionWidget-valueText {
  line-height: 1.3;
}

.questionWidget-visibleGridCellTest {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.08rem;
}

.questionWidget-codeGridError {
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
  color: var(--fail);
  white-space: pre-wrap;
  word-break: break-word;
}

.questionWidget-codeEmptyValue {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
  color: var(--muted);
}

button.questionWidget-codePracticeButton {
  display: inline-block;
  text-align: center;
  width: 100px;
  min-width: 100px;
  max-width: 100px;
  padding-top: 10px;
  padding-bottom: 10px;
  border-radius: 17px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  margin-right: 7px;
  background: white;
  color: rgb(9, 107, 183);
  border: 1px rgb(224, 224, 224) solid;
  font-weight: 500;
}

button.questionWidget-codePracticeButton:hover {
  background: #f2f8ff;
}

button.questionWidget-submitButton {
  border: none;
}

.questionWidget-codeStatusText {
  margin: 0;
  text-align: left;
  font-weight: 400;
  font-style: italic;
}

.questionWidget-codeStatusText.idle {
  color: rgb(45, 45, 45);
}

.questionWidget-codeStatusText.pass {
  color: var(--ok);
}

.questionWidget-codeStatusText.fail,
.questionWidget-codeStatusText.error {
  color: var(--fail);
}

.questionWidget-codeStatusText.running {
  color: var(--run);
}

.questionWidget-codeErrorText {
  margin: 0.3rem 0 0;
  max-width: 420px;
  text-align: left;
  color: var(--fail);
  font-family: "Courier New", monospace;
  font-weight: 400;
  white-space: pre-wrap;
}

.questionWidget-value {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.questionWidget-valueText {
  margin: 0;
  font-family: "Courier New", monospace;
  font-size: 15px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.questionWidget-codeTestCard {
  border: none;
  border-radius: 0;
  padding: 0.5rem 0;
  background: #ffffff;
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  column-gap: 0.6rem;
  align-items: start;
}

.questionWidget-codeTestMeta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  justify-content: flex-start;
  gap: 0.1rem;
  min-width: 0;
}

.questionWidget-codeTestTitle {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
  width: 100%;
  text-align: left;
}

/* Match explanation header size; softer than bold + full ink to reduce visual noise. */
.questionWidget-codeTestTitle.questionWidget-visibleTestsHeading {
  margin: 0 0 var(--code-test-title-to-header-gap);
  font-size: 15px;
  font-weight: 600;
  color: rgb(52, 48, 88);
  letter-spacing: 0.02em;
  line-height: 1.25;
  text-align: left;
}

.questionWidget-codeDebugRows .questionWidget-codeTestTitle {
  font-size: 15px;
  font-weight: 600;
  color: rgb(52, 48, 88);
  letter-spacing: 0.02em;
}

.questionWidget-codeTestContent {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.questionWidget-codeDebugRows .questionWidget-codeTestCard {
  grid-template-columns: 1fr;
  row-gap: var(--code-test-title-to-header-gap);
}

.questionWidget-codeDebugRows .questionWidget-codeTestMeta {
  display: block;
}

.questionWidget-codeDebugRows .questionWidget-codeTestContent {
  display: flex;
  flex-direction: column;
  gap: 0;
  align-items: stretch;
}

/* Align with visible test grid: single light rule under column titles. */
.questionWidget-codeDebugRows .questionWidget-debugContentHeader {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 0.6rem;
  align-items: start;
  padding: 0 0 0.5rem;
  border-bottom: 1px solid rgba(30, 25, 78, 0.14);
}

.questionWidget-codeDebugRows .questionWidget-debugContentBody {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 0.6rem;
  align-items: start;
  padding-top: 0.35rem;
}

/* Extra air between the Input column and Return Value (wider than column-gap alone). */
.questionWidget-codeDebugRows .questionWidget-debugContentHeader > :first-child,
.questionWidget-codeDebugRows .questionWidget-debugContentBody > :first-child {
  padding-right: 0.55rem;
}

.questionWidget-codeDebugRows .questionWidget-debugHeadCell {
  min-width: 0;
}

.questionWidget-codeDebugRows label.questionWidget-debugHeadCell {
  cursor: pointer;
}

.questionWidget-codeDebugRows .questionWidget-debugResultSlot {
  min-height: 1.35rem;
}

.questionWidget-codeStateBadge {
  font-family: "Futura Light", "Trebuchet MS", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 400;
  letter-spacing: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  text-transform: none;
}

.questionWidget-field {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  column-gap: 0.6rem;
  align-items: start;
}

.questionWidget-fieldLabel {
  margin: 0;
  padding-top: 0;
  line-height: 1.25;
  font-family: "Futura Light", "Trebuchet MS", Arial, sans-serif;
  font-size: 14px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: rgb(45, 45, 45);
}

.questionWidget-codeMutedText {
  color: var(--muted);
  margin: 0;
}

.questionWidget-codeMetaLine {
  margin: 0.2rem 0 0;
  font-size: 11px;
  line-height: 1.2;
  color: var(--muted);
}

.questionWidget-noReturnText {
  margin: 0;
  font-size: 13px;
  line-height: 1.25;
  color: rgb(88, 88, 88);
}

/* Reserve space for value + meta so Run Tests/Submit buttons don't shift when debug output appears. */
.questionWidget-debugResultSlot {
  min-height: 1.2rem;
}

.questionWidget-codeDebugOutputPre {
  margin: 0;
  max-height: 200px;
  overflow: auto;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #404040;
  font-family: "Courier New", monospace;
  font-size: 15px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Explanation section: markdown-rendered content (marked + MathJax; prose and LaTeX only). */
.questionWidget-explanationSection {
  margin-top: 1rem;
}

.questionWidget-explanationBody {
  margin-top: 0.5rem;
  font-size: 15px;
  line-height: 1.5;
}

.questionWidget-explanationBody code {
  font-family: "Courier New", monospace;
  font-size: 15px;
}

/* Reference implementation code block. */
.questionWidget-referenceCode {
  margin: 1.25rem 0 0;
  padding: 0.8rem 0;
  max-height: 300px;
  overflow: auto;
  font-family: "Courier New", monospace;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre;
}

@media (max-width: 640px) {
  body {
    margin: 0.9rem;
    padding: 0;
  }

  .questionWidget {
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  .questionWidget-codeTestCard {
    grid-template-columns: 1fr;
    row-gap: 0.4rem;
  }

  .questionWidget-codeTestMeta {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .questionWidget-codeDebugRows .questionWidget-debugContentHeader,
  .questionWidget-codeDebugRows .questionWidget-debugContentBody {
    grid-template-columns: 1fr;
    row-gap: 0.32rem;
  }

  .questionWidget-visibleGridHeader {
    display: none;
  }

  .questionWidget-visibleGridRow {
    grid-template-columns: 1fr;
    row-gap: 0.32rem;
    padding: 0.48rem 0;
  }

  .questionWidget-visibleGridCell:not(.questionWidget-visibleGridCellTest) {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr);
    column-gap: 0.45rem;
    align-items: start;
  }

  .questionWidget-visibleGridCell:not(.questionWidget-visibleGridCellTest)::before {
    content: attr(data-label);
    font-size: 12px;
    line-height: 1.2;
    color: rgb(45, 45, 45);
    font-weight: 400;
  }

  .questionWidget-visibleGridCellTest {
    padding-bottom: 0.25rem;
    border-bottom: 1px solid rgba(30, 25, 78, 0.1);
    margin-bottom: 0.05rem;
  }

  .questionWidget-continueWrap {
    width: 100%;
    padding-left: 0;
  }
}
