/* Python playground (see static/js/ide.js). Colours come from the theme variables in site.css. */
.ide { padding: 8px 0 32px; --ide-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; --ide-out-size: .9rem; }
.ide-head h1 { margin: 0 0 4px; }
.ide-lead { margin: 0 0 14px; color: var(--muted); max-width: 70ch; }
.ide-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ide kbd { font-family: var(--ide-mono); font-size: .8em; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); color: var(--ink); }

/* ---- toolbar ---- */
.ide-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 8px; }
.ide-group { display: flex; align-items: center; gap: 6px; }
.ide-group-end { margin-left: auto; }
.ide-btn { font: inherit; font-size: .86rem; font-weight: 600; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; transition: background-color .15s, border-color .15s, transform .1s; }
.ide-btn:hover:not([disabled]) { border-color: var(--accent); }
.ide-btn:active:not([disabled]) { transform: translateY(1px); }
.ide-btn[disabled] { opacity: .5; cursor: not-allowed; }
.ide-btn-small { padding: 3px 10px; font-size: .78rem; }
.ide-btn[aria-pressed="true"].is-on { background: var(--accent-soft); border-color: var(--accent); }
.ide-btn:focus-visible, .ide-tab:focus-visible, .ide-select:focus-visible, .ide-seg:focus-visible, .ide-item:focus-visible, .ide-splitter:focus-visible,
.ide-static:focus-visible, .ide-md:focus-visible, .ide-cell-text:focus-visible, .ide-stdin:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ide-run { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.ide-run:hover:not([disabled]) { background: var(--accent-strong); border-color: var(--accent-strong); }
.ide-select { font: inherit; font-size: .86rem; padding: 6px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink); max-width: 100%; min-width: 0; }

.ide-segment { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.ide-seg { font: inherit; font-size: .84rem; font-weight: 600; padding: 5px 14px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer; transition: background-color .15s, color .15s; }
.ide-seg[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.ide-seg:hover:not([aria-pressed="true"]) { color: var(--ink); }

.ide-menu { position: relative; }
.ide-menu-panel { position: absolute; z-index: 30; right: 0; top: calc(100% + 6px); width: min(320px, 86vw); max-height: 70vh; overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow-lg); animation: ide-pop .14s ease-out; }
.ide-menu-panel[hidden] { display: none; }
.ide-cell-menu { width: min(240px, 80vw); }
.ide-menu-title { margin: 8px 6px 2px; font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ide-menu-title:first-child { margin-top: 2px; }
.ide-item { display: block; width: 100%; text-align: left; font: inherit; font-size: .88rem; padding: 7px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); cursor: pointer; }
.ide-item:hover:not([disabled]) { background: var(--accent-soft); }
.ide-item[disabled] { opacity: .45; cursor: not-allowed; }
.ide-menu-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 4px; }
.ide-menu-row .ide-select { flex: 1 1 120px; }
@keyframes ide-pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.ide-hint { margin: 0 0 8px; color: var(--muted); font-size: .84rem; max-width: 90ch; }
.ide[data-layout="notebook"] .ide-nb-only { display: block; }
.ide[data-layout="editor"] .ide-nb-only { display: none; }

/* ---- file tabs ---- */
.ide-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0; padding: 0; min-height: 40px; }
.ide-tab { font: inherit; font-size: .86rem; padding: 7px 14px; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: var(--surface); color: var(--muted); cursor: pointer; font-family: var(--ide-mono); transition: background-color .15s, color .15s; }
.ide-tab.is-notebook { font-family: inherit; font-weight: 600; }
.ide-tab.is-active { background: var(--surface-2); color: var(--ink); border-color: var(--accent); }
.ide-name-input { font: inherit; font-size: .86rem; padding: 6px 10px; border: 1px solid var(--accent); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); width: 14rem; max-width: 100%; box-sizing: border-box; }

/* ---- Editor layout: code | divider | result ---- */
.ide-view[hidden] { display: none; }
.ide-main { --ide-split: 60%; display: grid; grid-template-columns: minmax(0, var(--ide-split)) 12px minmax(0, 1fr); align-items: stretch; }
.ide-main.no-side { grid-template-columns: minmax(0, 1fr); }
.ide-main.no-side .ide-splitter, .ide-main.no-side .ide-side { display: none; }
.ide-editor-wrap { min-width: 0; }
.ide-editor { position: relative; height: clamp(360px, 62vh, 760px); border: 1px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.ide-fallback { display: block; box-sizing: border-box; width: 100%; height: 100%; margin: 0; padding: 12px 14px; border: 0; background: var(--surface-2); color: var(--ink); font-family: var(--ide-mono); line-height: 1.5; tab-size: 4; resize: none; overflow: auto; }

.ide-splitter { position: relative; cursor: col-resize; touch-action: none; }
.ide-splitter::before { content: ""; position: absolute; top: 12px; bottom: 12px; left: 50%; width: 4px; margin-left: -2px; border-radius: 4px; background: var(--line); transition: background-color .15s; }
.ide-splitter:hover::before, .ide-splitter.is-dragging::before, .ide-splitter:focus-visible::before { background: var(--accent); }

.ide-skeleton { position: absolute; inset: 0; padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; pointer-events: none; }
.ide-skeleton span { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--line) 25%, var(--surface) 50%, var(--line) 75%); background-size: 300% 100%; animation: ide-shimmer 1.4s linear infinite; }
.ide-skeleton span:nth-child(1) { width: 52%; } .ide-skeleton span:nth-child(2) { width: 38%; } .ide-skeleton span:nth-child(3) { width: 66%; }
.ide-skeleton span:nth-child(4) { width: 30%; } .ide-skeleton span:nth-child(5) { width: 48%; }
@keyframes ide-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.ide-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ide-label { font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ide-stdin-box { display: flex; flex-direction: column; gap: 6px; }
.ide-stdin { box-sizing: border-box; width: 100%; height: 88px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-family: var(--ide-mono); font-size: 15px; resize: vertical; }
.ide-out-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ide-out { flex: 1 1 auto; min-height: 200px; max-height: 62vh; margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-family: var(--ide-mono); font-size: var(--ide-out-size); white-space: pre-wrap; overflow-wrap: anywhere; overflow: auto; }
.ide-empty { color: var(--muted); font-family: inherit; font-style: italic; }
.ide-stderr { color: #b3261e; }
.ide-result { margin-top: 6px; padding: 4px 8px; border-left: 3px solid var(--accent); background: var(--accent-soft); color: var(--ink); white-space: pre-wrap; }
.ide-figure { display: block; max-width: 100%; height: auto; margin: 8px 0; border-radius: 8px; background: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ide-stderr { color: #ffb4ab; } }
:root[data-theme="dark"] .ide-stderr { color: #ffb4ab; }

/* ---- Notebook layout ---- */
.ide-nb-input { margin: 0 0 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.ide-nb-input summary { cursor: pointer; font-weight: 600; font-size: .86rem; color: var(--ink); }
.ide-nb-input .ide-stdin-box { margin-top: 8px; }
.ide-nb-input .ide-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.ide-nb-input .ide-stdin { height: 64px; }
.ide-cells { display: flex; flex-direction: column; gap: 14px; }
.ide-cell { border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.ide-cell.is-active { border-left-color: var(--accent); box-shadow: var(--shadow); }
.ide-cell.is-running { border-left-color: var(--tint-3); }
.ide-cell.is-waiting { border-left-style: dashed; }
.ide-cell.has-error { border-left-color: #b3261e; }
.ide-cell.is-moved { animation: ide-moved .35s ease-out; }
@keyframes ide-moved { from { background: var(--accent-soft); } to { background: var(--surface); } }
.ide-cell-bar { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 10px; border-bottom: 1px solid var(--line); font-size: .78rem; color: var(--muted); }
.ide-cell-count { min-width: 3.2ch; font-family: var(--ide-mono); color: var(--accent-strong); }
.ide-cell-kind { font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.ide-spacer { flex: 1 1 auto; }
.ide-cell-editor { min-height: 44px; overflow: hidden; background: var(--surface-2); border-radius: 0; }
.ide-cell-editor.is-static { overflow: auto; }
.ide-static { margin: 0; padding: 8px 12px; font-family: var(--ide-mono); line-height: 1.5; color: var(--ink); tab-size: 4; cursor: text; min-height: 28px; }
.ide-cell-text { display: block; box-sizing: border-box; width: 100%; padding: 8px 12px; border: 0; background: var(--surface-2); color: var(--ink); font-family: var(--ide-mono); line-height: 1.5; resize: none; tab-size: 4; overflow: hidden; }
.ide-cell-md { padding: 8px 14px; }
.ide-md { color: var(--text); line-height: 1.6; cursor: text; }
.ide-md h2, .ide-md h3, .ide-md h4 { margin: .2em 0 .4em; color: var(--ink); }
.ide-md p, .ide-md ul, .ide-md ol, .ide-md blockquote { margin: .4em 0; }
.ide-md pre { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); overflow: auto; font-family: var(--ide-mono); }
.ide-md code { font-family: var(--ide-mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.ide-md blockquote { padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.ide-cell-md-edit { background: var(--surface-2); border-radius: 8px; font-family: var(--ide-mono); min-height: 64px; }
.ide-cell-out { padding: 10px 14px; border-top: 1px dashed var(--line); background: var(--surface); font-family: var(--ide-mono); font-size: var(--ide-out-size); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 60vh; overflow: auto; }
.ide-cell-out[hidden] { display: none; }
.ide-cells-add { display: flex; gap: 8px; margin: 12px 0 0; }

/* ---- status, toasts, dialog, help ---- */
.ide-statusbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin: 12px 0 0; padding: 7px 12px; border-radius: var(--radius-sm); background: var(--accent); color: var(--on-accent); font-size: .82rem; }
.ide-toasts { position: fixed; z-index: 60; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(560px, calc(100vw - 32px)); pointer-events: none; }
.ide-toast { padding: 10px 16px; border-radius: 12px; background: var(--brand); color: var(--on-brand); font-size: .88rem; box-shadow: var(--shadow-lg); animation: ide-pop .2s ease-out; }
.ide-toast.is-error { background: #b3261e; color: #fff; }
.ide-toast.is-leaving { opacity: 0; transition: opacity .25s; }
.ide-dialog { max-width: min(520px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); padding: 20px 22px; }
.ide-dialog::backdrop { background: rgba(10, 20, 30, .5); }
.ide-dialog h2 { margin: 0 0 10px; font-size: 1.1rem; }
.ide-keys { border-collapse: collapse; width: 100%; margin: 0 0 14px; font-size: .88rem; }
.ide-keys th, .ide-keys td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ide-keys th { white-space: nowrap; font-weight: 600; }
.ide-help { margin: 16px 0 0; color: var(--muted); font-size: .9rem; max-width: 80ch; }
.ide-help summary { cursor: pointer; font-weight: 600; color: var(--ink); }

/* ---- phones and narrow windows: everything stacks, no sideways scrolling, at most two toolbar rows ---- */
@media (max-width: 900px) {
  .ide-main, .ide-main.no-side { grid-template-columns: minmax(0, 1fr); }
  .ide-splitter { display: none; }
  .ide-editor { height: clamp(300px, 52vh, 520px); border-radius: var(--radius-sm); }
  .ide-side { margin-top: 12px; }
  .ide-out { max-height: 50vh; }
}
@media (max-width: 560px) {
  .ide-toolbar { gap: 6px 8px; }
  .ide-btn { padding: 6px 11px; font-size: .82rem; }
  .ide-seg { padding: 5px 11px; font-size: .8rem; }
  .ide-group-end { margin-left: 0; }
  .ide-menu-panel { position: fixed; left: 16px; right: 16px; top: auto; bottom: 16px; width: auto; max-height: 75vh; }
  .ide-cell-menu { position: absolute; left: auto; right: 0; bottom: auto; top: calc(100% + 6px); width: min(240px, 80vw); }
  .ide-hint { font-size: .8rem; }
}
@media (prefers-reduced-motion: reduce) {
  .ide *, .ide-toast, .ide-menu-panel { transition: none !important; animation: none !important; }
}
