:root {
  color-scheme: light;
  --bg: #fdfdfd;
  --surface: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --accent: #2563eb;
  --border: rgba(12, 12, 12, 0.08);
  --code-bg: #f4f4f4;
  font-family: "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-family: inherit;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html {
  scroll-behavior: smooth;
}

a {
  color: inherit;
  text-decoration: none;
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  background: var(--bg);
  max-width: 100vw;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  padding: 2.5rem 1.75rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.brand h1 {
  font-size: 1.75rem;
  margin: 0;
  letter-spacing: 0.02em;
}

.brand__link {
  display: inline-block;
  color: inherit;
}

.brand p {
  margin: 0.5rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.kofi-widget {
  margin: 0 0 2.5rem 0;
}

.toc {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.toc__section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toc__section-title {
  display: inline-block;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.toc__links {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toc__links a {
  font-size: 0.95rem;
  color: var(--text);
  padding-left: 0.25rem;
  border-left: 2px solid transparent;
  transition: color 150ms ease, border-color 150ms ease, padding-left 150ms ease;
}

.toc__links a:hover,
.toc__links a:focus-visible {
  color: var(--accent);
  border-left-color: var(--accent);
  padding-left: 0.5rem;
}

.toc__links a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.copyright {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

.content {
  padding: 3rem clamp(2rem, 4vw, 4rem) 5rem;
  display: flex;
  flex-direction: column;
  gap: 4rem;
  min-width: 0;
}

.topic {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.topic header h2 {
  margin: 0;
  font-size: 2rem;
}

.topic header p {
  margin: 0;
  color: var(--muted);
  max-width: 60ch;
}

.subtopic {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
  box-shadow: 0 20px 30px -25px rgba(15, 15, 15, 0.25);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.subtopic h3 {
  margin: 0;
  font-size: 1.3rem;
}

.subtopic .description {
  margin: 0;
  color: var(--muted);
}

.description .term-definition {
  position: relative;
  cursor: help;
  color: var(--accent);
  border-bottom: 1px dashed rgba(37, 99, 235, 0.5);
  font-weight: 600;
  outline: none;
}

.description .term-definition::after {
  content: attr(data-definition);
  position: absolute;
  z-index: 20;
  bottom: calc(100% + 0.35rem);
  left: 50%;
  transform: translate(-50%, 6px);
  padding: 0.5rem 0.75rem;
  width: clamp(200px, 65vw, 320px);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 35px -25px rgba(15, 15, 15, 0.6);
  font-weight: 500;
  font-size: 0.85rem;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}

.description .term-definition:hover::after,
.description .term-definition:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.code-block {
  position: relative;
}

.code-block.is-editing .code-output {
  margin-top: 1rem;
}

.code-block__actions {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.code-editor {
  width: 100%;
  min-height: 220px;
  margin: 0;
  margin-top: 0.75rem;
  padding: 1.25rem 1.5rem;
  font-family: "JetBrains Mono", "Fira Code", "Menlo", "Monaco", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  resize: vertical;
  outline: none;
}

.code-editor:focus-visible {
  border-color: rgba(37, 99, 235, 0.4);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

pre {
  margin: 0;
  padding: 1.25rem 1.5rem;
  background: var(--code-bg);
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.9rem;
}

code {
  font-family: "JetBrains Mono", "Fira Code", "Menlo", "Monaco", "Courier New", monospace;
}

.code-action-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(28, 28, 28, 0.08);
  color: inherit;
  cursor: pointer;
  transition: all 150ms ease;
}

.code-action-button:hover,
.code-action-button:focus-visible {
  border-color: rgba(37, 99, 235, 0.3);
  background: rgba(37, 99, 235, 0.12);
  color: var(--accent);
}

.copy-button.is-copied {
  background: rgba(22, 163, 74, 0.15);
  border-color: rgba(22, 163, 74, 0.3);
  color: #15803d;
}

.copy-button.has-error {
  background: rgba(220, 38, 38, 0.15);
  border-color: rgba(220, 38, 38, 0.3);
  color: #b91c1c;
}

.code-action-button:disabled {
  cursor: default;
  opacity: 0.8;
}

.run-button {
  font-weight: 700;
}

.code-output {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(28, 28, 28, 0.04);
  border: 1px solid rgba(28, 28, 28, 0.08);
  border-radius: 8px;
  font-family: "JetBrains Mono", "Fira Code", "Menlo", "Monaco", "Courier New", monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  min-height: 2.25rem;
}

.code-output.has-error {
  border-color: rgba(220, 38, 38, 0.3);
  background: rgba(220, 38, 38, 0.08);
  color: #991b1b;
}

.no-script-warning {
  margin: 2rem auto;
  max-width: 60ch;
  padding: 1rem 1.5rem;
  background: rgba(255, 208, 0, 0.1);
  border: 1px solid rgba(255, 208, 0, 0.3);
  border-radius: 10px;
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    position: relative;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .content {
    height: auto;
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 2rem 1.5rem 3rem;
  }

  .subtopic {
    padding: 1.25rem;
  }
}

