@layer base, layout, components, responsive;

@layer base {
  :root { color-scheme: dark; --bg: #101319; --surface: #161b23; --raised: #1d242e; --border: #303947; --muted: #a1adbd; --text: #e3e9f1; --accent: #8ce0c3; --amber: #f0c679; --red: #ffaaa4; --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font: 14px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
  * { box-sizing: border-box; }
  body { margin: 0; background: var(--bg); color: var(--text); }
  [hidden] { display: none !important; }
  button, select, textarea, input { font: inherit; }
  button, .file-button, select { min-height: 38px; border: 1px solid var(--border); border-radius: 5px; background: var(--raised); color: var(--text); }
  button { padding: 6px 13px; cursor: pointer; }
  button:hover:not(:disabled), .file-button:hover, select:hover { background: #2b3541; border-color: #607187; }
  button:disabled { opacity: .42; cursor: not-allowed; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
  a { color: var(--accent); text-underline-offset: 3px; }
  h1, h2, h3, p, pre, ol, ul { margin: 0; }
  h1 { display: inline; font-size: 15px; font-weight: 500; letter-spacing: -.2px; }
  h2 { font-size: 15px; font-weight: 600; }
  h3 { font-size: 12px; font-weight: 600; }
  code, pre, .mono { font-family: var(--mono); }
  pre { white-space: pre-wrap; overflow-wrap: anywhere; }
  .muted { color: var(--muted); }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
  .skip-link { position: absolute; top: -70px; left: 12px; z-index: 10; padding: 10px; background: var(--surface); }
  .skip-link:focus { top: 10px; }
}

@layer layout {
  .site-header { min-height: 76px; padding: 18px max(24px, calc((100vw - 1440px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border); }
  .brand { display: flex; align-items: center; gap: 14px; }
  .brand-mark { display: grid; place-items: center; width: 36px; height: 36px; background: #20372f; color: var(--accent); font: bold 20px var(--mono); border: 1px solid #395e50; border-radius: 7px; }
  .wordmark { font-size: 21px; font-weight: 750; letter-spacing: -1px; }
  .brand-divider { margin: 0 14px; color: #657083; }
  .header-meta { display: flex; align-items: center; gap: 14px; font: 11px var(--mono); color: var(--muted); }
  main { max-width: 1440px; margin: auto; padding: 30px 24px 18px; }
  .intro { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
  .intro h2 { font-size: clamp(23px, 3vw, 31px); font-weight: 550; letter-spacing: -.9px; margin: 4px 0; }
  .intro p:not(.eyebrow) { color: var(--muted); font-size: 13px; }
  .eyebrow { font: 10px/1.5 var(--mono); color: var(--accent); letter-spacing: 1.6px; }
  .quiet-link { color: var(--muted); font-size: 12px; white-space: nowrap; }
  .debugger { border: 1px solid var(--border); border-radius: 9px; background: var(--surface); overflow: hidden; box-shadow: 0 20px 80px #0002; }
  .toolbar { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--border); background: #1b212b; }
  .transport { display: flex; gap: 7px; }
  .execution-meta { display: flex; align-items: center; gap: 20px; }
  .workspace { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
  .source-panel { min-width: 0; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
  .machine-panels { min-width: 0; display: flex; flex-direction: column; }
  .stack-panel { border-bottom: 1px solid var(--border); }
  .objects-panel { flex: 1; }
  .panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 16px 19px 12px; gap: 10px; }
  .panel-heading > div { display: flex; align-items: center; gap: 10px; }
  .effects-panel { border-top: 1px solid var(--border); }
  .effects-content { display: grid; grid-template-columns: 1.1fr 1fr; gap: 30px; padding: 5px 20px 23px; }
  .site-footer { display: flex; justify-content: space-between; gap: 12px; max-width: 1440px; padding: 0 24px 24px; margin: auto; color: var(--muted); font-size: 11px; }
}

@layer components {
  .primary { background: var(--accent); color: #102a21; border-color: var(--accent); font-weight: 650; }
  button.primary:hover:not(:disabled) { background: #b6f3de; color: #102a21; border-color: #b6f3de; }
  .transport button span:first-child { margin-right: 5px; font-size: 16px; }
  .small-button { min-height: 32px; padding: 3px 10px; font-size: 11px; }
  .model-note { margin: -9px 0 22px; padding: 9px 13px; border: 1px solid var(--border); border-radius: 5px; font-size: 11px; color: var(--muted); }
  .model-note summary { cursor: pointer; color: var(--amber); }
  .model-note summary span { margin-left: 8px; color: var(--muted); }
  .model-note p { margin-top: 8px; max-width: 110ch; }
  .return-value { color: var(--accent); font-family: var(--mono); }
  .tag, .status-chip { display: inline-flex; align-items: center; padding: 3px 8px; border: 1px solid var(--border); border-radius: 4px; font: 10px/1.6 var(--mono); color: var(--muted); }
  .status-chip { color: var(--accent); background: #20372f; border-color: #395e50; }
  .status-chip[data-status="undefined_behavior"], .status-chip[data-status="error"] { color: var(--red); background: #3c2627; border-color: #76413e; }
  .status-chip[data-status="finished"] { color: var(--muted); background: var(--raised); border-color: var(--border); }
  .status-chip[data-status="limit"] { color: var(--amber); background: #382f20; border-color: #695735; }
  .step-counter { color: var(--muted); font: 10px var(--mono); letter-spacing: 1px; white-space: nowrap; }
  .step-counter strong { display: inline-block; color: var(--text); margin-left: 7px; min-width: 3ch; font-size: 15px; letter-spacing: 0; }
  .panel-index { color: #a5b0c0; font: 10px var(--mono); }
  .count { color: var(--muted); font: 10px var(--mono); white-space: nowrap; }
  .program-tools { display: flex; gap: 8px; padding: 0 18px 15px; }
  .program-tools select { min-width: 0; flex: 1; font-size: 12px; padding: 6px 8px; }
  .file-button { position: relative; padding: 6px 11px; font-size: 12px; cursor: pointer; display: flex; align-items: center; }
  .file-button input { position: absolute; width: 100%; height: 100%; inset: 0; opacity: 0; cursor: pointer; }
  .file-button:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
  .source-tabs { display: flex; align-items: center; padding: 0 18px; gap: 16px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: #141920; }
  .source-tabs button { padding: 10px 0; min-height: 43px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); background: transparent; font-size: 11px; }
  .source-tabs button[aria-pressed="true"] { border-bottom-color: var(--accent); color: var(--accent); }
  .source-tabs > span { margin-left: auto; font-size: 10px; text-align: right; }
  .code-view { flex: 1; background: #12171e; min-height: 390px; max-height: 620px; overflow: auto; padding: 16px 0; font: 12px/1.9 var(--mono); tab-size: 4; }
  .code-line { display: flex; width: max-content; min-width: 100%; min-height: 24px; line-height: 24px; white-space: pre; border-left: 3px solid transparent; }
  .line-number { flex: 0 0 48px; border: 0; border-radius: 0; background: transparent; padding: 0 14px 0 7px; min-height: 24px; font: 11px/24px var(--mono); color: #8794a6; text-align: right; }
  .line-number:hover:not(:disabled) { background: #27392f; color: var(--accent); border: 0; }
  .line-code { padding-right: 22px; }
  .code-line.is-current { background: #23372f; border-left-color: var(--accent); }
  .code-line.is-current .line-number { color: var(--accent); }
  .code-line.is-target .line-number { color: var(--amber); background: #413725; box-shadow: inset 2px 0 var(--amber); }
  mark { background: #8ce0c32b; color: inherit; border-bottom: 1px solid var(--accent); }
  .syntax-keyword { color: #c7b7fa; }
  .syntax-number { color: #f0c679; }
  .syntax-comment { color: #8a99a6; }
  .syntax-string { color: #8ce0c3; }
  .source-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); font-size: 10px; color: var(--muted); }
  .source-footer button { white-space: nowrap; }
  .editor-view { background: #12171e; flex: 1; display: flex; flex-direction: column; min-height: 390px; }
  #source-editor { width: 100%; min-height: 340px; flex: 1; resize: vertical; padding: 16px 18px; color: var(--text); background: transparent; border: 0; border-radius: 0; font: 12px/1.9 var(--mono); tab-size: 4; }
  #source-editor:focus-visible { outline-offset: -3px; }
  .editor-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }
  .editor-footer button { font-size: 11px; }
  .call-stack { list-style: none; padding: 0 18px 14px; }
  .stack-frame { display: flex; align-items: center; gap: 10px; padding: 9px 10px; margin-bottom: 4px; border: 1px solid var(--border); border-radius: 4px; background: #1b222c; }
  .stack-frame.is-active { border-color: #436958; background: #1e2c28; }
  .frame-depth { font: 10px var(--mono); color: var(--muted); }
  .frame-name { font: 12px var(--mono); }
  .frame-meta { margin-left: auto; font: 10px var(--mono); color: var(--muted); }
  .object-legend { display: flex; flex-wrap: wrap; gap: 15px; margin: -2px 18px 12px; color: var(--muted); font-size: 9px; }
  .legend-dot { display: inline-block; width: 5px; height: 5px; margin-right: 4px; border-radius: 50%; vertical-align: 1px; }
  .live-dot { background: var(--accent); }
  .ended-dot { background: #a1adbd; }
  .objects { padding: 0 18px 18px; max-height: 470px; overflow-y: auto; scroll-padding: 10px; }
  .object-card { border: 1px solid var(--border); border-radius: 5px; margin-bottom: 8px; padding: 11px 12px; scroll-margin: 10px; }
  .object-card:target { border-color: var(--accent); }
  .object-card.is-ended { background: #141920; border-style: dashed; }
  .object-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .object-title h3 { font: 12px var(--mono); }
  .object-id { color: var(--muted); font: 10px var(--mono); }
  .object-type { margin-left: auto; color: #c7b7fa; font: 10px var(--mono); }
  .object-details { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 13px; color: var(--muted); font-size: 9px; }
  .object-lifetime { color: var(--accent); }
  .is-ended .object-lifetime { color: var(--muted); }
  .object-value { margin-top: 8px; font: 12px/1.6 var(--mono); overflow-wrap: anywhere; display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
  .indeterminate { color: var(--amber); background: #382f20; padding: 2px 6px; border: 1px solid #695735; border-radius: 3px; font-size: 10px; }
  .pointer-link { color: var(--accent); background: #20372f; padding: 2px 6px; border-radius: 3px; font-size: 10px; }
  .array-item { display: inline-flex; flex-direction: column; align-items: center; min-width: 34px; padding: 2px 7px; background: #202732; border: 1px solid var(--border); border-radius: 3px; }
  .array-index { color: var(--muted); font-size: 9px; }
  .empty-state { color: var(--muted); font-size: 12px; line-height: 1.8; padding: 12px 0 20px; }
  .current-event > p:not(.eyebrow) { margin-top: 5px; font-size: 12px; }
  .pending-effects { border-left: 1px solid var(--border); padding-left: 23px; }
  .pending-effects h3 { margin-bottom: 7px; }
  .pending-effects h3 .count { margin-left: 7px; }
  #effects-list { list-style: none; font: 11px/1.8 var(--mono); padding: 0; }
  #effects-list li + li { margin-top: 5px; }
  .effect-target { color: var(--accent); }
  .notice { display: flex; align-items: flex-start; gap: 15px; background: #29251d; border: 1px solid #74613e; border-radius: 7px; padding: 18px 20px; margin-bottom: 20px; color: #ede3ce; font-size: 12px; }
  .notice-icon { display: grid; place-items: center; width: 22px; height: 22px; flex-shrink: 0; color: var(--amber); border: 1px solid #9c8050; border-radius: 50%; font: 12px var(--mono); }
  .notice h2 { color: var(--amber); font-size: 13px; margin-bottom: 5px; }
  .notice p { margin: 5px 0; }
  .notice pre { margin: 8px 0; padding: 10px 13px; border-radius: 4px; background: #191a18; font-size: 11px; }
  .notice button { margin-top: 8px; }
  .diagnostic { border: 1px solid #8d514a; border-radius: 7px; background: #302022; padding: 20px 23px; margin-top: 18px; }
  .diagnostic-label { color: var(--red); font: 10px var(--mono); letter-spacing: 1.5px; margin-bottom: 6px; }
  .diagnostic h2 { color: #ffcfca; margin-bottom: 5px; }
  .diagnostic p { font-size: 12px; }
  .diagnostic pre { margin-top: 10px; font-size: 11px; }
  .citation { color: #ffc3b7; margin-top: 12px; font-family: var(--mono); }
}

@layer responsive {
  @media (min-width: 1700px) { .code-view { min-height: 480px; } }
  @media (max-width: 900px) { .header-meta .engine-indicator { max-width: 160px; text-align: right; line-height: 1.6; } .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .toolbar { flex-wrap: wrap; } .source-tabs { gap: 12px; } .source-tabs > span { max-width: 110px; } .program-tools { flex-wrap: wrap; } .program-tools select { min-width: 120px; } .source-footer { flex-wrap: wrap; } }
  @media (max-width: 700px) { .site-header { padding: 16px; min-height: 68px; } .brand { gap: 9px; } .brand-divider { margin: 0 7px; } h1 { font-size: 12px; } .wordmark { font-size: 19px; } .header-meta { gap: 7px; } .header-meta .engine-indicator { display: none; } main { padding: 24px 12px 15px; } .intro { align-items: flex-start; gap: 14px; margin-bottom: 20px; } .intro .quiet-link { font-size: 10px; margin-top: 7px; } .intro p:not(.eyebrow) { font-size: 11px; max-width: 245px; } .intro h2 { font-size: 23px; } .toolbar { padding: 12px; gap: 12px; } .transport { flex: 1; gap: 5px; } .transport button { padding: 6px 10px; font-size: 12px; flex: 1; } .transport button span:first-child { margin-right: 2px; } .execution-meta { width: 100%; justify-content: space-between; gap: 12px; } .workspace { grid-template-columns: 1fr; } .source-panel { border-right: 0; border-bottom: 1px solid var(--border); } .code-view { min-height: 290px; max-height: 440px; } .effects-content { grid-template-columns: 1fr; gap: 18px; } .pending-effects { border-left: 0; border-top: 1px solid var(--border); padding: 15px 0 0; } .objects { max-height: none; } .site-footer { padding: 0 16px 20px; font-size: 10px; flex-wrap: wrap; } .notice { padding: 15px; gap: 10px; } .panel-heading { padding: 14px 16px 12px; } }
  @media (prefers-reduced-motion: no-preference) { button, a, .file-button { transition: background-color .12s, border-color .12s; } }
  @media (forced-colors: active) { .code-line.is-current { outline: 2px solid Highlight; outline-offset: -2px; } .code-line.is-target .line-number { outline: 1px dashed Highlight; } .legend-dot { border: 1px solid CanvasText; } }
}
