/* Reset */
* {
  box-sizing: border-box;
}

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0; padding: 0; border: 0;
  font-size: 100%; font: inherit; vertical-align: baseline;
}
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section { display: block; }
body        { line-height: 1.5; }
ol, ul      { list-style: none; }
table       { border-collapse: collapse; border-spacing: 0; }

/* Layout & typography */
:root {
  --font-serif: 'Georgia', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: 'Menlo', 'Monaco', 'Consolas', 'Lucida Console', monospace;
  
  --primary-color: #4a337a;
  --primary-hover: #5d419a;
  --bg-color: #ffffff;
  --text-color: #252519;
  --text-muted: #6a6a6a;
  --code-bg: #f6f8fa;
  --border-color: #e1e4e8;
  --terminal-bg: #1e1e1e;
  --terminal-text: #d4d4d4;
  --row-hover-bg: #fffbdd;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #9d7dfa;
    --primary-hover: #b59dfb;
    --bg-color: #0d1117;
    --text-color: #c9d1d9;
    --text-muted: #8b949e;
    --code-bg: #161b22;
    --border-color: #30363d;
    --row-hover-bg: #2d2d1b;
  }
}

body {
  font-family: var(--font-serif);
  font-size: 17px;
  background-color: var(--bg-color);
  color: var(--text-color);
  -webkit-font-smoothing: antialiased;
}

h2 {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 32px;
  line-height: 1.2;
  margin-top: 60px;
  margin-bottom: 30px;
  letter-spacing: -0.02em;
}
h2 a { 
  text-decoration: none; 
  color: var(--text-color);
}
h2 a:hover {
  color: var(--primary-color);
}

h3 {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 20px;
  margin-top: 40px;
  margin-bottom: 10px;
  color: var(--text-muted);
}

/* Back-to-index link inside the content container */
.site-nav {
  font-family: var(--font-sans);
  font-size: 14px;
  margin-top: 6px;
  margin-bottom: 20px;
}

.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--primary-color);
  text-decoration: none;
}

div.example {
  width: 995px;
  max-width: calc(100% - 40px);
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 120px;
}

.example-grid, .playground-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 20px;
}

.row {
  display: grid;
  grid-template-columns: 420px 1fr;
  align-items: stretch;
  transition: background-color 0.1s ease;
}

.example-grid .row:hover .code {
  background-color: var(--row-hover-bg);
}

.docs {
  padding: 12px 20px 12px 0;
  vertical-align: top;
  min-width: 0;
}
.docs p {
  line-height: 1.6;
}
.docs p a {
  color: inherit;
}
.docs p a:hover {
  text-decoration: none;
  color: var(--primary-color);
}

.code {
  padding: 12px;
  background-color: var(--code-bg);
  border-radius: 4px;
  min-width: 0;
}
.code.empty { background: transparent; }

.code pre {
  white-space: pre-wrap;
  word-break: break-all;
}


.leading {
  min-width: 0;
}

.code-block {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 0;
  right: 0;
  font-family: var(--font-sans);
  font-size: 11px;
  padding: 2px 6px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.code-block:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  color: var(--primary-color);
  border-color: var(--primary-color);
}

@media (max-width: 800px) {
  .row {
    grid-template-columns: 1fr;
  }
  .docs {
    padding-right: 0;
    padding-bottom: 4px;
  }
  .example-grid, .playground-grid {
    gap: 20px;
  }
}

/* Home page grid */
div#intro {
  width: 995px;
  max-width: calc(100% - 40px);
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 120px;
}
div#intro p  { padding-top: 24px; }
div#intro ul { padding-top: 24px; }
div#intro li { margin-bottom: 8px; }

p.footer { 
  margin-top: 120px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  font-family: var(--font-sans);
  font-size: 14px; 
  color: var(--text-muted);
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover {
  text-decoration: underline;
  color: var(--primary-hover);
}

.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 40px;
  margin-top: 40px;
}

.group h3 {
  margin-top: 0;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
  margin-bottom: 15px;
}

.group li {
  margin-bottom: 6px;
  font-family: var(--font-sans);
}

pre, code {
  font-size: 14px;
  line-height: 1.5;
  font-family: var(--font-mono);
}

/* Playground Styling */
.playground-table {
  margin-top: 40px;
  border-top: 2px solid var(--border-color);
  padding-top: 20px;
}
.play-label {
  font-family: var(--font-sans);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.go-host-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: #00acd7;
  border-radius: 3px;
  padding: 2px 7px;
  display: inline-block;
  margin: 0;
  letter-spacing: 0.04em;
}

/* File tabs (multi-file examples) */
.file-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: -1px;
  padding: 0 4px;
  position: relative;
  z-index: 1;
}
.file-tab {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 12px;
  border: 1px solid var(--border-color);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  background: var(--code-bg);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.file-tab.active {
  background: var(--bg-color);
  color: var(--text-color);
  border-bottom: 1px solid var(--bg-color);
}
.file-tab:hover:not(.active) {
  background: color-mix(in srgb, var(--code-bg) 70%, var(--bg-color));
}

/* Static code view — filename badge above a code block */
.filename-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 3px 3px 0 0;
  padding: 3px 10px;
  display: inline-block;
  margin-bottom: -4px;
}

.editor-wrap {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  min-width: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background-color: var(--code-bg);
  border-bottom: 1px solid var(--border-color);
}

button.run-btn, button.reset-btn {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 13px;
  padding: 4px 12px;
  cursor: pointer;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-color);
  color: var(--text-color);
  transition: all 0.2s ease;
}

button.run-btn:not(:disabled) {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}
button.run-btn:not(:disabled):hover {
  background: var(--primary-hover);
}

button.reset-btn:hover {
  background: var(--code-bg);
}

#wasm-status {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-muted);
}

#example-picker {
  margin-left: auto;
  font-family: var(--font-sans);
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-color);
  color: var(--text-color);
  cursor: pointer;
  max-width: 260px;
}

#output {
  background-color: var(--terminal-bg);
  color: var(--terminal-text);
  padding: 16px;
  border-radius: 6px;
  margin-top: 8px;
  min-height: 40px;
  white-space: pre-wrap;
  word-break: break-all;
}
#output.error { color: #f87171; }
#output.expected-output {
  color: color-mix(in srgb, var(--terminal-text) 55%, transparent);
}
#output.expected-output::before {
  content: "$ expected output";
  display: block;
  font-family: var(--font-sans);
  font-size: 11px;
  color: color-mix(in srgb, var(--terminal-text) 40%, transparent);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--terminal-text) 15%, transparent);
}

/* Navigation */
.nav-links {
  display: flex;
  justify-content: space-between;
  margin-top: 60px;
  font-family: var(--font-sans);
}
.nav-links a {
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 15px;
}
.nav-links a:hover {
  background-color: var(--code-bg);
  text-decoration: none;
}

/* Standalone playground page */
.standalone-playground {
  width: 1200px;
  max-width: calc(100% - 40px);
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 120px;
}

.standalone-playground h2 {
  margin-bottom: 12px;
}

.playground-intro {
  font-family: var(--font-sans);
  color: var(--text-muted);
  margin-bottom: 20px;
}

.standalone-playground .playground-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.standalone-playground .playground-body .editor-wrap {
  min-width: 0;
}

.standalone-playground .playground-body #output {
  min-height: 120px;
}

@media (min-width: 860px) {
  .standalone-playground .playground-body {
    flex-direction: row;
    align-items: flex-start;
    gap: 20px;
  }
  .standalone-playground .playground-body .editor-wrap {
    flex: 3;
  }
  .standalone-playground .playground-body #output {
    flex: 2;
    min-height: 200px;
    margin-top: 0;
    position: sticky;
    top: 20px;
  }
}

/* CodeMirror overrides */
.CodeMirror {
  height: auto;
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 0px 0px 1em 0;
  background-color: var(--bg-color) !important;
}
.CodeMirror-gutters {
  background-color: var(--bg-color) !important;
  border-right: 1px solid var(--border-color);
}

/* Syntax Highlighting */
.cm-keyword, .token.keyword { color: #d73a49; }
.cm-string, .token.string { color: #032f62; }
.cm-number, .token.number { color: #005cc5; }
.cm-comment, .token.comment { color: #6a737d; font-style: italic; }
.cm-builtin, .token.builtin { color: #6f42c1; }

@media (prefers-color-scheme: dark) {
  .cm-keyword, .token.keyword { color: #ff7b72; }
  .cm-string, .token.string { color: #a5d6ff; }
  .cm-number, .token.number { color: #79c0ff; }
  .cm-comment, .token.comment { color: #8b949e; }
  .cm-builtin, .token.builtin { color: #d2a8ff; }
}
