/* The homepage's exercise demo (demo.js), in the web app's Dark theme; code matches the blog's blocks (blog.css). */
/* The dragged line's ghost lives on <body>, so it gets the same variables. */
.try-demo, .td-ghost {
  --d-bg: #181818; --d-box: #1f1f1f; --d-elev: #262626; --d-edge: rgba(255, 255, 255, .08);
  --d-t1: #ededed; --d-t2: #b6b6b6; --d-amber: #e8b44a; --d-amber-dark: #3a2800;
  --d-good: #8fd16a; --d-bad: #ec7c6c; --d-mono: Menlo, Consolas, "Roboto Mono", "Droid Sans Mono", monospace; /* no "Courier New": Android maps it to a thin serif face */
  --d-code-bg: color-mix(in srgb, var(--d-bg) 78%, #000); --d-code-edge: color-mix(in srgb, var(--d-t1) 12%, transparent); --d-code-fg: #e6edf3;
}
.try-demo {
  display: flex; flex-direction: column; gap: 16px; height: clamp(520px, calc(100vh - 236px), 700px); padding: 26px 40px;
  background: var(--d-bg); color: var(--d-t1); text-align: left;
}
:where(.try-demo) button { font: inherit; color: inherit; cursor: pointer; }
:where(.try-demo) button:disabled { cursor: default; }
.try-demo code { font-family: var(--d-mono); font-size: 1em; font-weight: 700; color: var(--d-amber); }
.try-demo .hl { color: var(--d-code-fg); }

.td-tabs { display: flex; flex-wrap: wrap; gap: 10px; }
.td-tab { padding: 10px 18px; border-radius: 999px; border: 1.5px solid color-mix(in srgb, var(--d-t1) 22%, transparent); background: none; font-size: 15.5px; font-weight: 700; color: var(--d-t1); text-decoration: none; transition: border-color .12s ease; }
.td-tab:hover { border-color: color-mix(in srgb, var(--d-t1) 55%, transparent); }
.td-tab.on { background: var(--d-amber); border-color: var(--d-amber); color: var(--d-amber-dark); }
.td-tab.more { border-style: dashed; color: var(--d-t2); font-weight: 600; }

.td-concept { display: flex; flex-direction: column; gap: 2px; }
.td-concept span { font-size: 12.5px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--d-t2); }
/* The concept name in the site's pink-to-amber highlight, so it stands apart from the question text. */
.td-concept b { align-self: flex-start; font-size: 30px; font-weight: 800; line-height: 1.15; letter-spacing: -.02em; color: var(--d-amber); background: linear-gradient(90deg, #e0607a, var(--d-amber)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.td-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; scrollbar-width: thin; }
/* Every tab has the same height (the frame's), so switching never moves the page; a long exercise scrolls inside.
   The height leaves room for the section title above it, so Try it shows title and box on one screen. */
.td-q { margin: 0; font-size: 23px; line-height: 1.25; letter-spacing: -.015em; }
.td-prompt { margin: 0; font-size: 19px; line-height: 1.55; color: var(--d-t1); }
.td-sub { margin: 0; font-size: 16.5px; line-height: 1.5; color: var(--d-t2); }
.td-sub b { color: var(--d-t1); }
.td-hint { margin: 0; padding: 12px 6px; font-size: 16px; color: var(--d-t2); }
.td-why { margin: -6px 0 4px; padding: 14px 18px; border-radius: 12px; background: var(--d-box); font-size: 16.5px; line-height: 1.55; color: var(--d-t2); border-left: 3px solid var(--d-bad); }
.td-why.good { border-left-color: var(--d-good); }

/* Multiple choice */
.td-opts { display: flex; flex-direction: column; gap: 10px; }
.td-opt { display: flex; align-items: center; gap: 16px; width: 100%; padding: 14px 20px; border-radius: 15px; border: 1.5px solid var(--d-edge); background: var(--d-box); font-size: 19px; font-weight: 700; text-align: left; transition: border-color .12s ease, background-color .12s ease, transform .12s ease; }
.td-opt { touch-action: manipulation; user-select: none; }
.td-opt > span:last-child { flex: 1 1 auto; min-width: 0; }
.td-opt.good .td-num { background: var(--d-good); border-color: var(--d-good); color: #17330c; }
.td-opt.bad .td-num, .td-opt.on.bad .td-num { background: var(--d-bad); border-color: var(--d-bad); color: #fff; }
.td-opt:hover:not(:disabled) { border-color: rgba(255, 255, 255, .25); transform: translateY(-1px); }
.td-num { display: grid; place-items: center; flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, .25); font-size: 15px; }
.td-opt.on { border-color: var(--d-amber); background: color-mix(in srgb, var(--d-amber) 10%, var(--d-box)); }
.td-opt.on .td-num { background: var(--d-amber); border-color: var(--d-amber); color: var(--d-amber-dark); }
.td-opt.good { border-color: var(--d-good); background: color-mix(in srgb, var(--d-good) 14%, var(--d-box)); }
.td-opt.bad { border-color: var(--d-bad); background: color-mix(in srgb, var(--d-bad) 14%, var(--d-box)); }

/* Code blocks: the blog's look (background, edge, Menlo, 16px). */
.td-code { margin: 0; padding: 16px 22px; overflow-x: auto; border-radius: 14px; background: var(--d-code-bg); border: 1px solid var(--d-code-edge); font-family: var(--d-mono); font-size: 16px; line-height: 1.75; }
.td-line { display: block; white-space: pre; }
.td-blank { display: inline-block; min-width: 96px; margin: 0 3px; padding: 2px 10px; border-radius: 8px; border: 1.5px dashed rgba(255, 255, 255, .32); background: none; font-family: var(--d-mono); font-size: 15px; line-height: 1.5; color: var(--d-t1); vertical-align: middle; }
.td-blank.full { border-style: solid; border-color: var(--d-amber); color: var(--d-amber); }
.td-blank.good { border-color: var(--d-good); color: #a9cf96; }
.td-blank.bad { border-color: var(--d-bad); color: #e58a7c; }
.td-blank s { color: #e58a7c; }
.td-blank .td-ans { color: var(--d-good); }
.td-row.bad { border-color: var(--d-bad); background: color-mix(in srgb, var(--d-bad) 12%, var(--d-code-bg)); }
.td-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.td-chip { padding: 10px 16px; border-radius: 11px; border: 1.5px solid color-mix(in srgb, var(--d-t1) 30%, transparent); background: var(--d-box); font-family: var(--d-mono); font-size: 16px; font-weight: 400; color: var(--d-t1); transition: border-color .12s ease, transform .12s ease; }
.td-chip:hover:not(:disabled) { border-color: var(--d-amber); }
.td-chip:active:not(:disabled) { transform: scale(.96); }
.td-chip:disabled { opacity: .25; }

/* Order */
.td-order { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.td-placed, .td-bank { display: flex; flex-direction: column; gap: 6px; }
.td-placed { min-height: 100%; padding: 8px; border-radius: 14px; border: 1.5px dashed rgba(255, 255, 255, .18); }
.td-placed.good { border: 1.5px solid var(--d-good); }
.td-placed.bad { border: 1.5px solid var(--d-bad); }
.td-row { width: 100%; padding: 4px 14px; border-radius: 10px; border: 1px solid var(--d-edge); background: var(--d-box); text-align: left; transition: border-color .12s ease; }
.td-row:hover:not(:disabled) { border-color: rgba(255, 255, 255, .28); }
.td-row pre, .td-sline pre { margin: 0; overflow-x: auto; font-family: var(--d-mono); font-size: 16px; line-height: 1.55; white-space: pre; }
.td-placed .td-row { background: var(--d-code-bg); }
.td-order .td-row { cursor: grab; touch-action: none; user-select: none; }
/* The pre inside a row is its own scroll box, which would hand the touch back to the browser; nothing in a row may pan. */
.td-order .td-row * { touch-action: none; }
.td-row.td-lifted { opacity: .3; }
.td-ghost { position: fixed; z-index: 50; pointer-events: none; cursor: grabbing; border-color: var(--d-amber) !important; background: var(--d-elev) !important; box-shadow: 0 14px 34px rgba(0, 0, 0, .5); transform: rotate(-1deg); }
.td-drop { height: 3px; margin: 2px 0; border-radius: 3px; background: var(--d-amber); }

/* Spot the bug */
.td-spot { display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 14px; background: var(--d-code-bg); border: 1px solid var(--d-code-edge); }
.td-sline { display: flex; align-items: center; gap: 16px; width: 100%; padding: 4px 12px; border-radius: 10px; border: 1.5px solid transparent; background: none; text-align: left; }
.td-sline:hover:not(:disabled) { background: rgba(255, 255, 255, .05); }
.td-ln { flex-shrink: 0; width: 22px; text-align: right; font-family: var(--d-mono); font-size: 14px; color: color-mix(in srgb, var(--d-t1) 38%, transparent); }
.td-sline.on { border-color: var(--d-amber); background: color-mix(in srgb, var(--d-amber) 9%, transparent); }
.td-sline.good { border-color: var(--d-good); background: color-mix(in srgb, var(--d-good) 12%, transparent); }
.td-sline.miss { border: 1.5px dashed var(--d-good); background: none; }
.td-sline.bad { border-color: var(--d-bad); background: color-mix(in srgb, var(--d-bad) 12%, transparent); }
.td-sline.bad::after { content: "✕"; margin-left: auto; font-weight: 900; color: var(--d-bad); }
.td-spot .td-why { margin: 2px 0 8px 38px; }

/* Write the code: a see-through textarea over a colored copy of its text, both with the same font box. */
.td-ed { position: relative; flex: 1 0 220px; border-radius: 14px; border: 1.5px solid var(--d-code-edge); background: var(--d-code-bg); }
.td-ed:focus-within { border-color: var(--d-amber); }
.td-ed-hl, .td-editor { position: absolute; inset: 0; margin: 0; padding: 18px 22px; border: 0; overflow: auto; font-family: var(--d-mono); font-size: 16px; line-height: 1.7; tab-size: 4; white-space: pre; }
.td-ed-hl { pointer-events: none; scrollbar-width: none; }
.td-editor { width: 100%; height: 100%; resize: none; background: transparent; color: transparent; caret-color: var(--d-t1); outline: none; }
.td-editor::selection { background: rgba(232, 180, 74, .3); color: transparent; }

/* Run results */
.td-run:empty { display: none; }
.td-run { display: flex; flex-direction: column; gap: 8px; padding: 14px 18px; border-radius: 14px; background: var(--d-box); border: 1px solid var(--d-edge); }
.td-run .td-verdict { margin: 0; }
.td-run-status { margin: 0; font-size: 15.5px; color: var(--d-t2); }
.td-run-err { margin: 0; white-space: pre-wrap; font-family: var(--d-mono); font-size: 14px; color: #e58a7c; }
.td-checks { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; font-size: 15.5px; color: var(--d-t2); }
.td-checks li { display: grid; grid-template-columns: 16px minmax(0, 1fr); align-items: baseline; gap: 4px 10px; }
.td-checks li > span { font-weight: 800; }
.td-checks li.good > span { color: #a9cf96; }
.td-checks li.bad > span { color: #e58a7c; }
.td-checks code { grid-column: 2; font-weight: 500; color: var(--d-t1); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Checked footer: the web lesson's bar (green or red tint, title, text, Retry?, Continue). */
.td-actions.good, .td-actions.bad { margin: 0 -40px -26px; padding: 16px 40px 22px; border-radius: 0 0 18px 18px; }
.td-actions.good { background: color-mix(in srgb, #8fd16a 16%, #111111); border-top-color: #8fd16a; }
.td-actions.bad { background: color-mix(in srgb, #ec7c6c 16%, #111111); border-top-color: #ec7c6c; }
.td-fbk { flex: 1; min-width: 0; }
.td-fbk b { display: block; font-size: 19px; font-weight: 800; }
.td-actions.good .td-fbk b { color: #8fd16a; }
.td-actions.bad .td-fbk b { color: #ec7c6c; }
.td-fbk p { margin: 4px 0 0; max-height: 72px; overflow-y: auto; font-size: 15px; line-height: 1.5; color: var(--d-t1); }
.td-fbk code { font-size: .9em; }
.sbl { display: inline-flex; align-items: center; gap: 6px; margin-right: 16px; font-weight: 600; }
.sbl i { width: 11px; height: 11px; border-radius: 50%; }
.sbl i.f { background: #8fd16a; }
.sbl i.m { border: 2px dashed #8fd16a; }
.sbl em { font-style: normal; font-weight: 900; color: #ec7c6c; }
.td-retry { flex-shrink: 0; padding: 12px 18px; border-radius: 14px; border: 1.5px solid color-mix(in srgb, var(--d-t1) 35%, transparent); background: none; font-size: 15px; font-weight: 800; }
.td-retry:hover { background: color-mix(in srgb, var(--d-t1) 8%, transparent); }
.td-actions.good .td-btn { margin-left: 0; background: #8fd16a; color: #17330c !important; }
.td-actions.bad .td-btn { margin-left: 0; background: #ec7c6c; color: #fff !important; }

/* Footer */
.td-actions { display: flex; align-items: center; gap: 16px; padding-top: 16px; border-top: 1px solid var(--d-edge); }
.td-btn { display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; margin-left: auto; min-width: 160px; padding: 13px 26px; border-radius: 13px; border: 0; background: var(--d-amber); color: var(--d-amber-dark) !important; font-size: 17px; font-weight: 800; transition: filter .12s ease, transform .12s ease; }
.td-btn:hover:not(:disabled) { filter: brightness(1.07); transform: translateY(-1px); }
.td-btn:disabled { background: var(--d-elev); color: rgba(237, 237, 237, .35) !important; }
.td-btn.alt { margin-left: 0; min-width: 0; background: none; border: 1.5px solid rgba(237, 237, 237, .3); color: var(--d-t1) !important; }
.td-btn.alt:hover { border-color: rgba(237, 237, 237, .6); }
.td-verdict { margin-left: auto; font-weight: 800; font-size: 18px; }
.td-verdict + .td-btn { margin-left: 0; }
.td-btn.td-sol { margin-left: auto; }
.td-sol + .td-btn { margin-left: 0; }
.td-verdict.good { color: #a9cf96; }
.td-verdict.bad { color: #e58a7c; }

@media (max-width: 640px) {
  .try-demo { padding: 20px 16px; height: auto; min-height: 0; gap: 16px; }
  .td-body { overflow: visible; }
  .td-order { grid-template-columns: 1fr; }
  .td-q { font-size: 19px; }
  .td-concept b { font-size: 22px; }
  .td-prompt, .td-opt { font-size: 16.5px; }
  .td-opt { padding: 14px 16px; }
  .td-code, .td-row pre, .td-sline pre, .td-editor, .td-ed-hl, .td-chip { font-size: 14px; }
  .td-tab { padding: 8px 14px; font-size: 14px; }
  .td-tab.more { display: none; }
  .td-actions { gap: 8px; }
  .td-btn, .td-btn.alt { min-width: 0; padding: 12px 14px; font-size: 14.5px; }
  /* Long code lines wrap on phones instead of running off the box with a scrollbar under each line. */
  .td-row pre { overflow: visible; white-space: pre-wrap; overflow-wrap: anywhere; }
  .td-row { padding: 6px 12px; }
  /* Spot the bug keeps each line whole (wrapping loses the indentation); the block scrolls sideways as one. */
  .td-spot { overflow-x: auto; overscroll-behavior-x: contain; }
  .td-sline { width: max-content; min-width: 100%; gap: 10px; padding: 4px 8px; }
  .td-sline pre { overflow: visible; }
}

/* Scrolling to the end of anything inside the box stops there instead of carrying on to the page. */
/* Only the body stops the page; code blocks and the editor pass vertical scrolling on to the body. */
.td-body, .td-fbk p { overscroll-behavior: contain; }
.td-code, .td-row pre, .td-sline pre { overscroll-behavior-x: contain; }
/* Nothing in the body squeezes to fit: a long exercise scrolls inside the body instead. */
.td-body > * { flex-shrink: 0; }
.td-body { position: relative; } /* offsetTop of the solution is measured from the body */
