:root {
  --bg: #f4f8fb;
  --fg: #0e395e;
  --fg-muted: #5286a0;
  --accent: #098fb9;
  --accent-dark: #2564a4;
  --accent-green: #57c297;
  --surface: #ffffff;
  --border: #d4e2ed;
  --code-bg: #eaf1f5;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(14,57,94,0.06);
  --shadow-md: 0 4px 14px rgba(14,57,94,0.10);
  --font-display: 'Outfit', sans-serif;
  --font-body: 'Nunito', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --gradient: linear-gradient(135deg, #098fb9, #2564a4, #57c297);
}

html[data-theme="dark"] {
  --bg: #091a2a;
  --fg: #dfeaf4;
  --fg-muted: #7ba0bb;
  --accent: #3db8d9;
  --accent-dark: #5fc4de;
  --accent-green: #6dd8b0;
  --surface: #112240;
  --border: #1e3a5f;
  --code-bg: #0d2137;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.25);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.35);
  --gradient: linear-gradient(135deg, #3db8d9, #5fc4de, #6dd8b0);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 17px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.75;
  padding: 3rem 2rem 4rem;
  max-width: 820px;
  margin: 0 auto;
  -webkit-font-smoothing: antialiased;
}

/* ── Top gradient stripe ── */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--gradient);
  z-index: 10000;
}

/* ── Entrance animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
body > *:not(#nav-toggle):not(#page-nav) {
  animation: fadeUp 0.45s ease-out both;
}
body > *:not(#nav-toggle):not(#page-nav):nth-child(2) { animation-delay: 0.06s; }
body > *:not(#nav-toggle):not(#page-nav):nth-child(3) { animation-delay: 0.12s; }

/* ── Links ── */
a { color: var(--accent); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-dark); }

/* ── Theme toggle ── */
#theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1.2rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 10001;
  box-shadow: var(--shadow-sm);
}
#theme-toggle:hover {
  box-shadow: var(--shadow-md);
  transform: scale(1.1);
  border-color: var(--accent);
}
#theme-toggle svg {
  width: 20px;
  height: 20px;
  transition: transform 0.3s;
}
#theme-toggle:hover svg { transform: rotate(20deg); }
html[data-theme="dark"] #icon-sun,
html:not([data-theme="dark"]) #icon-moon { display: none; }

/* ── Nav toggle & side nav ── */
#nav-toggle {
  position: fixed;
  top: 1rem;
  left: 1.2rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all 0.3s;
  z-index: 10001;
  box-shadow: var(--shadow-sm);
}
#nav-toggle:hover {
  box-shadow: var(--shadow-md);
  transform: scale(1.1);
  border-color: var(--accent);
}

#page-nav {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  padding: 4.5rem 1rem 2rem;
  overflow-y: auto;
  z-index: 9997;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#page-nav.open {
  transform: translateX(0);
}
#page-nav a {
  display: block;
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s;
}
#page-nav a:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
}
#page-nav a.active {
  border-left-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-weight: 700;
}

/* ── Breadcrumbs ── */
.breadcrumbs {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg-muted);
}
.breadcrumbs a { color: var(--fg-muted); }
.breadcrumbs a:hover { color: var(--accent); }

/* ── Page heading ── */
h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.4rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-bottom: 1.5rem;
}
body > h1 {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Directory listing ── */
.listing {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.listing li {
  animation: fadeUp 0.4s ease-out both;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border-left: 4px solid transparent;
  transition: all 0.25s ease;
}
.listing li:nth-child(2)  { animation-delay: 0.04s; }
.listing li:nth-child(3)  { animation-delay: 0.08s; }
.listing li:nth-child(4)  { animation-delay: 0.12s; }
.listing li:nth-child(5)  { animation-delay: 0.16s; }
.listing li:nth-child(6)  { animation-delay: 0.20s; }
.listing li:nth-child(7)  { animation-delay: 0.24s; }
.listing li:nth-child(8)  { animation-delay: 0.28s; }
.listing li:nth-child(9)  { animation-delay: 0.32s; }
.listing li:nth-child(10) { animation-delay: 0.36s; }
.listing li:nth-child(n+11) { animation-delay: 0.4s; }

.listing li:hover {
  box-shadow: var(--shadow-md);
  transform: translateX(3px);
}
.listing li.folder  { border-left-color: var(--accent); }
.listing li.file    { border-left-color: var(--accent-green); }
.listing li.parent  { border-left-color: var(--fg-muted); }

.listing a {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  color: var(--fg);
  text-decoration: none;
}
.listing a::after {
  content: '\2192';
  margin-left: auto;
  opacity: 0;
  transform: translateX(-6px);
  transition: all 0.25s;
  color: var(--fg-muted);
  font-size: 0.9rem;
}
.listing a:hover::after {
  opacity: 1;
  transform: translateX(0);
}
.listing .icon {
  font-size: 1.15rem;
  width: 1.5rem;
  text-align: center;
  flex-shrink: 0;
}
.listing .name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
}

/* ── Markdown content ── */
.content { max-width: 720px; }

.content h1, .content h2, .content h3,
.content h4, .content h5, .content h6 {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
  line-height: 1.3;
  margin-top: 2.2rem;
  margin-bottom: 0.6rem;
}
.content h1 {
  font-weight: 800;
  font-size: 2.2rem;
  margin-top: 0;
  padding-bottom: 0.6rem;
  border-bottom: 3px solid transparent;
  border-image: var(--gradient) 1;
  -webkit-text-fill-color: unset;
  background: none;
}
.content h2 {
  font-weight: 700;
  font-size: 1.55rem;
  padding-left: 0.8rem;
  border-left: 4px solid var(--accent);
}
.content h3 {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--accent);
}
.content h4 {
  font-weight: 700;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
}

.content p  { margin: 1rem 0; }
.content ul, .content ol { margin: 1rem 0; padding-left: 1.4rem; }
.content li { margin: 0.35rem 0; }
.content li::marker { color: var(--accent-green); font-weight: 700; }
.content strong { font-weight: 800; }

.content blockquote {
  border-left: 4px solid transparent;
  border-image: var(--gradient) 1;
  padding: 0.8rem 1.2rem;
  margin: 1.2rem 0;
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  box-shadow: var(--shadow-sm);
}
.content blockquote p { margin: 0.4rem 0; }

.content aside {
  float: right;
  clear: right;
  width: 35%;
  margin: 0.3rem 0 1rem 1.5rem;
  padding: 1rem 1.2rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  box-shadow: var(--shadow-sm);
  font-size: 0.88rem;
  line-height: 1.6;
  position: relative;
}
.content aside::before {
  content: '\01f4a1';
  position: absolute;
  top: -0.7rem;
  left: 0.8rem;
  font-size: 1.1rem;
  background: var(--bg);
  padding: 0 0.3rem;
  border-radius: 50%;
}
.content aside p { margin: 0.3rem 0; }
.content aside p:first-child { margin-top: 0; }
.content aside p:last-child { margin-bottom: 0; }

@media (max-width: 640px) {
  .content aside {
    float: none;
    width: 100%;
    margin: 1rem 0;
  }
}

.content hr {
  border: none;
  height: 2px;
  background: var(--gradient);
  margin: 2rem 0;
  border-radius: 1px;
}

.content a {
  text-decoration: underline;
  text-decoration-color: var(--accent-green);
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
  transition: text-decoration-color 0.2s, color 0.2s;
}
.content a:hover { color: var(--accent-green); }

/* Inline code */
.content code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.84em;
  font-weight: 500;
  color: var(--accent-dark);
}

/* Code blocks */
.content pre {
  position: relative;
  background: var(--code-bg);
  padding: 1.3rem 1.4rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1.2rem 0;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.content pre code {
  background: none;
  padding: 0;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--fg);
}
.content pre code.hljs {
  background: transparent;
  padding: 0;
}

/* Code language badge */
.code-lang {
  position: absolute;
  top: 0; right: 0;
  background: var(--gradient);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  padding: 0.15rem 0.7rem 0.2rem;
  border-radius: 0 var(--radius) 0 var(--radius);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Tables */
.content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.2rem 0;
  font-size: 0.92rem;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.content th {
  background: var(--gradient);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 0.9rem;
  text-align: left;
}
.content td {
  padding: 0.55rem 0.9rem;
  border-top: 1px solid var(--border);
}
.content tr:last-child td { border-bottom: none; }
.content tbody tr:hover td {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.content img {
  max-width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

/* ── Mermaid ── */
.mermaid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.2rem 0;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.mermaid svg { max-width: 100%; height: auto; }

/* ── Misc ── */
::selection { background: color-mix(in srgb, var(--accent-green) 30%, transparent); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-muted); }

/* ── Python run button ── */
.run-btn {
  position: absolute;
  bottom: 0.5rem; right: 0.5rem;
  background: var(--gradient);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.35rem 1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  letter-spacing: 0.04em;
  box-shadow: 0 2px 6px rgba(9,143,185,0.3);
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
}
.run-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(9,143,185,0.45);
  filter: brightness(1.1);
}

/* ── Code drawer ── */
#drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 10010;
}
#drawer-overlay.open { display: block; }

#code-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 520px;
  max-width: 90vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0,0,0,0.18);
  z-index: 10011;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.3s ease, visibility 0.3s;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
#code-drawer.open { transform: translateX(0); visibility: visible; }

.drawer-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--border);
  background: var(--code-bg);
}
.drawer-header h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.drawer-close {
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}
.drawer-close:hover {
  background: var(--border);
  color: var(--fg);
}

#drawer-editor {
  font-size: 0.82rem;
  line-height: 1.7;
  border-bottom: 1px solid var(--border);
  min-height: 80px;
  height: 40vh;
  flex-shrink: 0;
}

.drawer-play-btn {
  display: block;
  margin: 0.8rem 1.2rem;
  padding: 0.55rem 1.5rem;
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}
.drawer-play-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(9,143,185,0.35);
}

#drawer-turtle {
  display: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 1.2rem;
  height: 150px;
  flex-shrink: 0;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
#drawer-turtle > svg {
  transform-origin: top left;
  transform: scale(0.3);
}
#drawer-turtle.visible { display: block; }

/* ── Turtle fullscreen modal ── */
#turtle-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10020;
  background: rgba(0,0,0,0.7);
  cursor: pointer;
  justify-content: center;
  align-items: center;
}
#turtle-modal.open {
  display: flex;
}
#turtle-modal-inner {
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
  max-width: 95vw;
  max-height: 95vh;
  overflow: auto;
}
#turtle-modal-close {
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  background: none;
  border: none;
  font-size: 1.6rem;
  color: #666;
  cursor: pointer;
  z-index: 1;
  line-height: 1;
}
#turtle-modal-close:hover { color: #000; }
#turtle-modal-inner svg {
  display: block;
  max-width: 90vw;
  max-height: 85vh;
}

#drawer-console {
  flex: 1;
  margin: 0.8rem 1.2rem 1.2rem;
  padding: 0.8rem 1rem;
  background: #0d1117;
  color: #c9d1d9;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  border-radius: var(--radius);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 640px) {
  html { font-size: 16px; }
  body { padding: 2rem 1.2rem 3rem; }
  h1, .content h1 { font-size: 1.8rem !important; }
  .content h2 { font-size: 1.3rem; }
  #theme-toggle { top: 0.7rem; right: 0.7rem; width: 36px; height: 36px; }
  #theme-toggle svg { width: 17px; height: 17px; }
  #nav-toggle { top: 0.7rem; left: 0.7rem; width: 36px; height: 36px; font-size: 1rem; }
  #page-nav { width: 100vw; }
  #code-drawer { width: 100vw; max-width: 100vw; }
  #drawer-editor { height: 30vh; min-height: 60px; }
  #drawer-console { margin: 0.5rem 0.8rem 0.8rem; }
  .drawer-play-btn { margin: 0.5rem 0.8rem; }
  body.drawer-open { overflow: hidden; position: fixed; width: 100%; }
}
