[x-cloak] { display: none !important; }

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

html {
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Fira Code', 'Cascadia Code', 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, 'Courier New', monospace;
  font-size: var(--text-base);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition:
    background-color var(--duration) var(--ease),
    color var(--duration) var(--ease);
}

::selection {
  background: var(--selection-bg);
  color: var(--selection-fg);
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--accent-on);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  left: 0;
  outline: 2px solid var(--ink-strong);
  outline-offset: 0;
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-family: inherit;
  color: var(--ink-strong);
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
  text-wrap: balance;
}

h1 { font-size: var(--text-2xl); letter-spacing: 0.005em; }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }

p {
  margin: 0;
  color: var(--ink);
  text-wrap: pretty;
}

small { font-size: var(--text-sm); color: var(--ink-muted); }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 50%, transparent);
  text-underline-offset: 0.18em;
  transition:
    color var(--duration-fast) var(--ease),
    text-decoration-color var(--duration-fast) var(--ease);
}

a:hover {
  color: var(--accent-2);
  text-decoration-color: var(--accent-2);
}

img, svg { display: block; max-width: 100%; height: auto; }

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: var(--space-lg) 0;
}

/* Lists */
ul, ol {
  margin: 0;
  padding-left: 1.5rem;
}

ul { list-style: none; }
ul > li { position: relative; }
ul > li::before {
  content: "▸";
  color: var(--accent-deep);
  position: absolute;
  left: -1.25rem;
  top: 0;
  font-weight: 700;
}

.list-plain {
  list-style: none;
  padding-left: 0;
}
.list-plain > li::before { content: none; }
.list-plain > li { padding-left: 0; }

ol > li { color: var(--ink); }

li { margin: 0.125rem 0; }

code, kbd, samp, pre {
  font-family: inherit;
}

/* Buttons */
button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  background: var(--bg-3);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4375rem 0.875rem;
  line-height: 1.2;
  transition-property: background-color, border-color, color, transform;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
}

button:hover {
  background: var(--bg-3);
  border-color: var(--line-strong);
  color: var(--ink-strong);
}

button:active { transform: scale(0.96); }

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0.4375rem 0.875rem;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.2;
  color: var(--accent-on);
  background: var(--accent-deep);
  border: 1px solid var(--accent-deep);
  border-radius: var(--radius);
  text-decoration: none;
  cursor: pointer;
  transition-property: background-color, border-color, color, transform;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  min-height: 36px;
  white-space: nowrap;
}

.btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-on);
  text-decoration: none;
}

.btn:active { transform: scale(0.96); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn-ghost:hover {
  background: var(--bg-2);
  color: var(--ink-strong);
  border-color: var(--line-strong);
}

/* Tag / pill */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.1875rem 0.5rem;
  font-size: var(--text-xs);
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  transition-property: background-color, border-color, color;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease);
  min-height: 24px;
}

.tag:hover {
  color: var(--ink-strong);
  background: var(--bg-3);
  border-color: var(--accent);
  text-decoration: none;
}

.tag.is-active,
.tag[aria-current="page"] {
  background: var(--accent-deep);
  color: var(--accent-on);
  border-color: var(--accent-deep);
}

.tag.is-active::before {
  content: "✓ ";
  font-weight: 700;
}

/* Form elements */
input, textarea, select {
  font-family: inherit;
  font-size: var(--text-sm);
  background: var(--bg-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  transition: border-color var(--duration-fast) var(--ease);
  min-height: 36px;
}

input:hover, textarea:hover, select:hover {
  border-color: var(--line-strong);
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

::placeholder { color: var(--ink-faint); opacity: 1; }

/* Layout */
.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

.container-narrow { max-width: var(--container-narrow); }

/* Panel */
.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  position: relative;
  transition: border-color var(--duration-fast) var(--ease);
}

.panel:has(.panel-link:hover),
.panel:has(.panel-link:focus-visible) {
  border-color: var(--accent);
}

.panel-link {
  color: var(--ink-strong);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease);
}

.panel-link::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
}

.panel-link:hover,
.panel-link:focus-visible {
  color: var(--accent);
  text-decoration: none;
}

.panel .tag {
  position: relative;
  z-index: 1;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: var(--bg-3);
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-strong);
  letter-spacing: 0.02em;
  border-radius: var(--radius) var(--radius) 0 0;
  margin: 0;
}

.panel-title-index {
  color: var(--ink-faint);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.panel-body {
  padding: var(--space-md);
}

.panel-body > :first-child { margin-top: 0; }
.panel-body > :last-child { margin-bottom: 0; }

/* Empty state */
.empty {
  padding: var(--space-xl);
  text-align: center;
  color: var(--ink-muted);
  font-style: italic;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* Scrollbars */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: var(--radius);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); }

/* Screen reader only */
.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;
}

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

button:focus-visible,
.btn:focus-visible,
.tag:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes fade-in-up {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .stagger-children > * {
    animation: fade-in-up 0.4s var(--ease) both;
  }
  .stagger-children > *:nth-child(2) { animation-delay: 80ms; }
  .stagger-children > *:nth-child(3) { animation-delay: 160ms; }
  .stagger-children > *:nth-child(4) { animation-delay: 240ms; }
  .stagger-children > *:nth-child(n+5) { animation-delay: 320ms; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Print */
@media print {
  body { background: white; color: black; }
  .site-header, .site-footer, .skip-link, #kbd-help { display: none !important; }
  a { color: black; text-decoration: underline; }
  a[href^="http"]::after {
    content: " <" attr(href) ">";
    font-size: 90%;
    color: #666;
  }
}

@media (min-width: 1280px) {
  body { font-size: 1.0625rem; }
}

@media (max-width: 640px) {
  :root {
    --gutter: 1rem;
    --space-2xl: 2.5rem;
  }
  body { font-size: 0.9375rem; }
  h1 { font-size: var(--text-xl); }
  h2 { font-size: var(--text-lg); }
}
