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

:root {
  color-scheme: light dark;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --tag-bg: #eef2ff;
  --tag-text: #3730a3;
  --code-bg: #0f172a;
  --code-text: #e5e7eb;
  --success: #16a34a;
  --warning: #d97706;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  --radius-card: 18px;
  --radius-button: 999px;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --max-width: 1180px;

  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1020;
  --surface: #111827;
  --surface-2: #1f2937;
  --text: #f9fafb;
  --muted: #9ca3af;
  --border: #263244;
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --tag-bg: #1e293b;
  --tag-text: #bfdbfe;
  --code-bg: #020617;
  --code-text: #e5e7eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    color-scheme: dark;
    --bg: #0b1020;
    --surface: #111827;
    --surface-2: #1f2937;
    --text: #f9fafb;
    --muted: #9ca3af;
    --border: #263244;
    --primary: #60a5fa;
    --primary-hover: #93c5fd;
    --tag-bg: #1e293b;
    --tag-text: #bfdbfe;
    --code-bg: #020617;
    --code-text: #e5e7eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --shadow: none;
  }
}

body {
  min-height: 100vh;
  line-height: 1.6;
}

.site-header {
  padding: 40px 24px;
  text-align: center;
}

.hero {
  max-width: var(--max-width);
  margin: 0 auto;
}

.eyebrow {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 8px;
}

.hero h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.hero__desc {
  font-size: 1rem;
  color: var(--muted);
  max-width: 520px;
  margin: 0 auto;
}

.app-shell {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  align-items: flex-end;
}

.toolbar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8125rem;
  color: var(--muted);
  flex: 1;
  min-width: 140px;
}

.search-box {
  flex: 3;
  min-width: 200px;
}

.toolbar input,
.toolbar select {
  font-size: 0.875rem;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.toolbar input:focus,
.toolbar select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

html[data-theme="dark"] .toolbar input:focus,
html[data-theme="dark"] .toolbar select:focus {
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .toolbar input:focus,
  html[data-theme="system"] .toolbar select:focus {
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
  }
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 28px;
}

.tag-filter {
  font-size: 0.8125rem;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-button);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all 0.15s ease;
}

.tag-filter:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tag-filter.is-active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.script-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  padding-bottom: 60px;
}

@media (min-width: 768px) {
  .script-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 1200px) {
  .script-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.script-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 24px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  outline: none;
}

.script-card:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

html[data-theme="dark"] .script-card:focus-visible {
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.35);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .script-card:focus-visible {
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.35);
  }
}

.script-card:hover {
  transform: translateY(-2px);
}

html[data-theme="light"] .script-card:hover {
  box-shadow: 0 24px 50px rgba(15, 23, 42, 0.12);
}

@media (prefers-color-scheme: light) {
  html[data-theme="system"] .script-card:hover {
    box-shadow: 0 24px 50px rgba(15, 23, 42, 0.12);
  }
}

.script-card__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.script-card__language {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 4px;
}

.script-card h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.script-card__summary {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.5;
}

.icon-button {
  flex-shrink: 0;
  font-size: 0.8125rem;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-button:hover {
  background: var(--border);
}

.fav-button {
  flex-shrink: 0;
  font-size: 1.125rem;
  line-height: 1;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--warning);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.fav-button:hover {
  background: var(--border);
  transform: scale(1.15);
}

.favorites-toggle {
  display: flex !important;
  align-items: flex-end !important;
  flex: 0 0 auto !important;
  min-width: auto !important;
}

.script-card__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.dep-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-button);
  white-space: nowrap;
}

.dep-badge--stdlib {
  background: #dcfce7;
  color: #166534;
}

.dep-badge--external {
  background: #fef3c7;
  color: #92400e;
}

html[data-theme="dark"] .dep-badge--stdlib {
  background: #052e16;
  color: #86efac;
}

html[data-theme="dark"] .dep-badge--external {
  background: #451a03;
  color: #fcd34d;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .dep-badge--stdlib {
    background: #052e16;
    color: #86efac;
  }

  html[data-theme="system"] .dep-badge--external {
    background: #451a03;
    color: #fcd34d;
  }
}

.script-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.tag {
  font-size: 0.75rem;
  padding: 3px 10px;
  border: none;
  border-radius: var(--radius-button);
  background: var(--tag-bg);
  color: var(--tag-text);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: opacity 0.15s ease;
}

.tag:hover {
  opacity: 0.8;
}

.script-card__body {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 4px;
}

.description-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 20px;
}

.detail-section h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.detail-section ul {
  padding-left: 20px;
  font-size: 0.875rem;
  color: var(--muted);
}

.detail-section li {
  margin-bottom: 4px;
}

.detail-section li code {
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

table th,
table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

table th {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

table td {
  color: var(--muted);
}

table td code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
}

.file-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 12px;
}

.file-section__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}

.file-section__header h3 {
  font-size: 0.875rem;
  font-weight: 600;
}

.button {
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 8px 16px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.button--soft {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.button--soft:hover {
  background: var(--border);
}

.code-slot {
  margin-top: 12px;
}

.loading {
  font-size: 0.8125rem;
  color: var(--muted);
  font-style: italic;
}

.error {
  font-size: 0.8125rem;
  color: var(--warning);
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--warning);
}

.code-panel {
  position: relative;
  background: var(--code-bg);
  border-radius: 12px;
  overflow: hidden;
}

.code-panel pre {
  margin: 0;
  padding: 20px;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.6;
}

.code-panel code {
  font-family: var(--font-mono);
  color: var(--code-text);
  white-space: pre;
}

.code-actions {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.code-lang-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--code-text);
  opacity: 0.5;
  margin-right: 4px;
}

.code-panel:hover .code-actions,
.code-actions:focus-within {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.hl-keyword {
  color: #c084fc;
  font-weight: 600;
}

.hl-string {
  color: #6ee7b7;
}

.hl-comment {
  color: #6b7280;
  font-style: italic;
}

.hl-number {
  color: #fbbf24;
}

.hl-builtin {
  color: #67e8f9;
}

.hl-decorator {
  color: #f9a8d4;
}

.mini-button {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.15);
  color: var(--code-text);
  cursor: pointer;
  font-family: var(--font-sans);
  text-decoration: none;
  line-height: 1.6;
  transition: background 0.15s ease;
}

.mini-button:hover {
  background: rgba(255, 255, 255, 0.25);
}

.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--muted);
}

.empty-state h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9375rem;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 20px 0 48px;
  flex-wrap: wrap;
}

.pagination__info {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-right: 12px;
}

.page-button {
  font-size: 0.8125rem;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-button:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.page-button.is-active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.page-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.site-footer {
  text-align: center;
  padding: 32px 24px;
  font-size: 0.8125rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.noscript-banner {
  background: var(--warning);
  color: #ffffff;
  text-align: center;
  padding: 14px 24px;
  font-size: 0.875rem;
  font-weight: 500;
}

.script-card--error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 24px;
}

.script-card--error h2 {
  color: var(--warning);
  margin-bottom: 8px;
}

.script-card--error p {
  color: var(--muted);
}
