@import url("brand.css");

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.6 var(--font-body);
  overflow-x: hidden;
}
#root { display: flex; flex-direction: column; flex: 1; }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--backdrop);
  animation: var(--drift);
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  background: var(--scanlines);
}
@keyframes grid-drift {
  to { background-position: 0 0, 0 0, 0 48px, 48px 0, 0 0; }
}

main { flex: 1; }
a { color: var(--primary); }
a:hover { color: var(--secondary); }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; width: 100%; }
.mono { font-family: var(--font-ui); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.boot { padding-top: 80px; color: var(--primary); }
.boot p::before, .filters output::before { content: var(--prompt); }

h1, h2, h3 { font-family: var(--font-display); letter-spacing: calc(var(--tracking) * 0.04em); }
h1 { margin: 0 0 10px; font-size: clamp(30px, 7vw, 52px); line-height: 1.1; text-transform: var(--caps); }
h2 { margin: 0; font-size: clamp(18px, 3vw, 22px); text-transform: var(--caps); }

.glitch { position: relative; display: inline-block; }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}
.glitch::before { color: var(--secondary); }
.glitch::after { color: var(--primary); }
.glitch:hover::before, a:hover .glitch::before { opacity: 0.8; animation: glitch-a 0.4s steps(2) infinite; }
.glitch:hover::after, a:hover .glitch::after { opacity: 0.8; animation: glitch-b 0.4s steps(2) infinite; }
/* The Flask nav always renders a glitch, so the other themes switch it off here. */
:root:not([data-theme="cyberpunk"]) .glitch::before,
:root:not([data-theme="cyberpunk"]) .glitch::after { content: none; }
@keyframes glitch-a {
  0% { transform: translate(-2px, 1px); clip-path: inset(10% 0 60% 0); }
  50% { transform: translate(2px, -1px); clip-path: inset(55% 0 15% 0); }
  100% { transform: translate(-1px, 0); clip-path: inset(30% 0 40% 0); }
}
@keyframes glitch-b {
  0% { transform: translate(2px, -1px); clip-path: inset(65% 0 5% 0); }
  50% { transform: translate(-2px, 1px); clip-path: inset(5% 0 70% 0); }
  100% { transform: translate(1px, 0); clip-path: inset(40% 0 30% 0); }
}

.site-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--secondary) 25%, transparent);
}
.site-nav .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding-top: 12px; padding-bottom: 12px; }
.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: calc(var(--tracking) * 0.12em);
  text-transform: var(--caps);
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
  text-shadow: 0 0 12px color-mix(in srgb, var(--glow-color) 50%, transparent);
}
.site-nav ul { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.site-nav ul a {
  display: block;
  padding: 6px 12px;
  border: 1px solid transparent;
  color: var(--muted);
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 14px;
  text-transform: var(--caps);
  letter-spacing: calc(var(--tracking) * 0.06em);
}
.site-nav ul a:hover { color: var(--primary); border-color: var(--border); }
.site-nav ul a[aria-current="page"] { color: var(--primary); border-color: var(--primary); box-shadow: var(--glow); }
.site-nav .theme-picker { margin-left: 8px; }
.menu-toggle {
  display: none;
  font: 600 13px var(--font-ui);
  text-transform: var(--caps);
  letter-spacing: calc(var(--tracking) * 0.1em);
  padding: 6px 12px;
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  cursor: pointer;
}
@media (max-width: 640px) {
  .menu-toggle { display: block; }
  .site-nav ul { display: none; width: 100%; flex-direction: column; padding-bottom: 8px; }
  .site-nav.open ul { display: flex; }
  .site-nav .theme-picker { margin: 6px 12px 0; }
}

.hero { padding: 40px 0 28px; }
.hero-home { padding: clamp(48px, 10vw, 96px) 0 48px; }
.kicker { margin: 0 0 12px; font: 500 13px var(--font-ui); color: var(--secondary); text-transform: var(--caps); letter-spacing: calc(var(--tracking) * 0.2em); }
.hero h1 { text-shadow: 0 0 24px color-mix(in srgb, var(--glow-color) 35%, transparent); }
.tag { margin: 0; color: var(--muted); font-size: clamp(16px, 2.4vw, 19px); max-width: 680px; }
.hero-home .tag { font-family: var(--font-ui); font-size: clamp(15px, 2.2vw, 18px); color: var(--text); min-height: 3.2em; }
.cursor {
  display: inline-block;
  width: 0.6em;
  height: 1.1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--primary);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

section { margin-bottom: 56px; }
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 18px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.section-head h2::before { content: var(--prompt); color: var(--secondary); }
.section-head a { font: 600 14px var(--font-ui); text-decoration: none; text-transform: var(--caps); }
.section-head a:hover { text-decoration: underline; }

/* Four tiles across, then 2x2, then one column on phones, so four never break into 3+1.
   Project cards (.two-up) stay two across until phones. */
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.grid.two-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .grid, .grid.two-up { grid-template-columns: minmax(0, 1fr); }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, var(--panel-hover), var(--panel) 60%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  animation: var(--card-in);
  animation-delay: calc(var(--i, 0) * 70ms);
}
.card::before, .card::after {
  content: var(--corner);
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
}
.card::before { top: -1px; left: -1px; border-top: 2px solid var(--primary); border-left: 2px solid var(--primary); }
.card::after { bottom: -1px; right: -1px; border-bottom: 2px solid var(--secondary); border-right: 2px solid var(--secondary); }
.grid .card:hover, a.card:hover { transform: translateY(-4px); border-color: var(--primary); box-shadow: var(--glow); }
@keyframes card-in {
  from { opacity: 0; transform: translateY(12px); }
}
@keyframes ink-in {
  from { opacity: 0; filter: blur(4px); }
}
.card h3 { margin: 0 0 8px; font-size: 16px; text-transform: var(--caps); }
.card p { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
.two-up .card h3 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Always three lines tall, so every project card is the same height. */
.desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  line-height: 1.6;
  height: 4.8em;
}
a.card { color: inherit; text-decoration: none; }
.tile .count { margin-top: auto; font: 600 13px var(--font-ui); color: var(--highlight); text-transform: var(--caps); }

.thumb {
  display: grid;
  place-items: center;
  margin: -20px -20px 16px;
  aspect-ratio: 16 / 9;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--secondary) 18%, transparent), color-mix(in srgb, var(--primary) 12%, transparent)),
    var(--panel);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.thumb img { max-width: 100%; height: 100%; object-fit: contain; display: block; }
.tags { display: flex; gap: 6px; margin: auto 0 16px; padding: 0; list-style: none; overflow: hidden; }
.tags li {
  flex: none;
  font: 500 11px var(--font-ui);
  padding: 2px 8px;
  border: 1px solid color-mix(in srgb, var(--secondary) 45%, transparent);
  color: var(--secondary);
  text-transform: var(--caps);
}
.links { display: flex; gap: 8px 16px; font: 600 13px var(--font-ui); text-transform: var(--caps); white-space: nowrap; }
.links a { text-decoration: none; }
.links a:hover { text-decoration: underline; }
.soon { color: var(--muted); font: italic 14px var(--font-ui); }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-bottom: 40px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
}
.filters label { display: flex; align-items: center; gap: 8px; font: 600 13px var(--font-ui); color: var(--muted); text-transform: var(--caps); }
.filters output { margin-left: auto; color: var(--highlight); font-size: 13px; }

.cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.btn { display: inline-block; text-decoration: none; }
.callout { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; animation: none; }
.callout h2 { margin-bottom: 6px; }
.callout p { margin: 0; }
.callout .cta { margin-top: 0; }

.prose { max-width: 700px; }
.prose h2 { margin: 36px 0 10px; }
.prose p { margin: 0 0 16px; }
.prose ul { margin: 0 0 16px; padding-left: 22px; }
.prose li::marker { color: var(--secondary); }
.readme { overflow-wrap: anywhere; }
.readme code { font-size: 0.9em; }
code, pre { font-family: var(--font-mono); }
.readme pre { margin: 0 0 16px; padding: 12px 16px; overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-left: 2px solid var(--primary); }

.site-footer { padding: 28px 0 36px; color: var(--muted); font: 13px var(--font-ui); border-top: 1px solid var(--border); }
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--primary); }

.form { display: grid; gap: 14px; max-width: 380px; margin-bottom: 24px; }
.form p { margin: 0; }
.form label { display: grid; gap: 4px; font: 600 13px var(--font-ui); text-transform: var(--caps); color: var(--muted); }
.form input, .form select, .filters select {
  font: 15px var(--font-ui);
  padding: 8px 12px;
  border: 1px solid var(--control-border);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  max-width: 100%;
}
.form input:focus, .form select:focus, .filters select:focus { outline: var(--focus-outline); outline-offset: 2px; border-color: var(--primary); box-shadow: var(--glow); }
.form button, .btn {
  justify-self: start;
  font: 700 14px var(--font-ui);
  text-transform: var(--caps);
  letter-spacing: calc(var(--tracking) * 0.08em);
  padding: 10px 20px;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--on-accent);
  cursor: pointer;
  clip-path: var(--clip);
  transition: filter 0.15s;
}
.form button:hover, .btn:hover { filter: brightness(1.15); color: var(--on-accent); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
.error { color: var(--danger); }

:is([data-theme="light"], [data-theme="dark"]) :is(.grid .card, a.card):hover { transform: none; }

[data-theme="terminal"] .site-nav ul a:hover,
[data-theme="terminal"] .site-nav ul a[aria-current="page"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
  box-shadow: none;
  text-shadow: none;
}
[data-theme="terminal"] .grid .card:hover h3 { background: var(--text); color: var(--bg); text-shadow: none; }
[data-theme="terminal"] .hero-home h1 .cursor { display: none; }
[data-theme="terminal"] .hero-home .tag { min-height: 8.5em; }
.boot-line { display: block; color: var(--muted); }

.backdrop-canvas { position: fixed; inset: 0; z-index: -1; display: block; width: 100%; height: 100%; pointer-events: none; opacity: 0.35; }

.d20 { margin-top: 24px; }
.d20-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.d20 .btn { display: inline-flex; align-items: center; gap: 12px; padding: 6px 18px 6px 8px; }
.d20 .btn:disabled { cursor: progress; }
.d20-die { flex: none; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linejoin: round; }
.d20-die path { stroke-width: 1.2; opacity: 0.6; }
.d20-die text { fill: currentColor; stroke: none; font: 700 24px var(--font-display); }
.d20.tumbling .d20-die { animation: d20-tumble 0.9s ease-out; }
.d20.crit .d20-die { color: var(--secondary); animation: d20-shimmer 1.4s ease-in-out 2; }
.d20.fumble .d20-die { opacity: 0.45; filter: blur(0.6px); }
.d20-result { margin: 0; color: var(--muted); font-style: italic; }
.roll-table { width: 100%; max-width: 440px; margin-top: 16px; border-collapse: collapse; font-size: 15px; }
.roll-table th, .roll-table td { padding: 6px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.roll-table th { font: 600 13px var(--font-ui); color: var(--muted); }
.roll-table td:first-child { width: 4.5em; color: var(--secondary); font-variant-numeric: tabular-nums; }
.roll-table tr.rolled td { background: color-mix(in srgb, var(--secondary) 14%, transparent); }
@keyframes d20-tumble {
  30% { transform: rotate(200deg) translateY(-6px) scale(1.15); }
  60% { transform: rotate(430deg) translateY(2px) scale(0.95); }
  to { transform: rotate(720deg); }
}
@keyframes d20-shimmer {
  50% { filter: drop-shadow(0 0 8px var(--secondary)); }
}

.crosshair { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.crosshair::before, .crosshair::after { content: ""; position: absolute; background: color-mix(in srgb, var(--highlight) 45%, transparent); }
.crosshair::before { top: 0; bottom: 0; left: var(--mx, -10px); width: 1px; }
.crosshair::after { left: 0; right: 0; top: var(--my, -10px); height: 1px; }
.crosshair-readout {
  position: absolute;
  right: 16px;
  bottom: 16px;
  padding: 2px 8px;
  border: 1px solid var(--highlight);
  background: var(--bg);
  color: var(--highlight);
  font: 500 12px var(--font-mono);
  letter-spacing: 0.1em;
}
.crosshair-readout:empty { display: none; }
@media (hover: none) {
  .crosshair { display: none; }
}

.dims { position: absolute; inset: 0; pointer-events: none; }
.dim {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--highlight);
  font: 500 10px var(--font-mono);
  letter-spacing: 0.08em;
  transition: transform 0.3s ease-out;
}
.dim > span { padding: 0 4px; background: var(--bg); }
.dim::before, .dim::after { content: ""; position: absolute; border: 4px solid transparent; }
.dim-width {
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  height: 12px;
  background: linear-gradient(currentColor, currentColor) 0 50% / 100% 1px no-repeat;
  transform: scaleX(0);
}
.dim-width::before { top: 2px; left: -4px; border-right-color: currentColor; }
.dim-width::after { top: 2px; right: -4px; border-left-color: currentColor; }
.dim-height {
  top: 0;
  bottom: 0;
  left: calc(100% + 6px);
  width: 12px;
  writing-mode: vertical-rl;
  background: linear-gradient(currentColor, currentColor) 50% 0 / 1px 100% no-repeat;
  transform: scaleY(0);
}
.dim-height::before { left: 2px; top: -4px; border-bottom-color: currentColor; }
.dim-height::after { left: 2px; bottom: -4px; border-top-color: currentColor; }
.card:is(:hover, :focus-visible, :focus-within) .dim { transform: none; }

.title-block {
  display: grid;
  grid-template-columns: repeat(4, auto);
  flex-basis: 100%;
  margin: 0 0 12px;
  border: 1px solid var(--border);
}
.title-block div { padding: 6px 10px; border-left: 1px solid var(--border); }
.title-block div:first-child { border-left: 0; }
.title-block dt { font-size: 10px; text-transform: var(--caps); letter-spacing: 0.12em; }
.title-block dd { margin: 0; color: var(--text); }
@media (max-width: 520px) {
  .title-block { grid-template-columns: repeat(2, auto); }
  .title-block div:nth-child(3) { border-left: 0; }
  .title-block div:nth-child(n + 3) { border-top: 1px solid var(--border); }
}

.taskbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-basis: 100%;
  margin: 0 0 12px;
  padding: 4px;
  background: var(--panel);
  box-shadow: var(--bevel);
}
.taskbar .btn { padding: 4px 12px; }
.taskbar .task, .taskbar .tray { padding: 4px 10px; box-shadow: var(--bevel-in); color: var(--text); }
.taskbar .task { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.taskbar .tray { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
