:root {
  --void: #000000;
  --surface: #0a0a0a;
  --elevated: #121212;
  --border: #2e2e2e;
  --fg: #ecece6;
  --muted: #9a9a90;
  --subtle: #5a5a55;
  --primary: #c6ff00;
  --primary-fg: #0a0a0a;
  --danger: #ff5c5c;
  --ok: #6dffb0;
  --font-display: "Syne", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  background: var(--void);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--primary); }
.glyph-sheet {
  background-image:
    linear-gradient(rgba(46,46,46,0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(46,46,46,0.35) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
}
.skip {
  position: absolute; left: -9999px;
}
.skip:focus {
  left: 1rem; top: 1rem; z-index: 100;
  background: var(--primary); color: var(--primary-fg); padding: 0.5rem 0.75rem;
}

.top-nav {
  position: sticky; top: 0; z-index: 40;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.9);
  backdrop-filter: blur(8px);
}
.nav-inner {
  max-width: 72rem; margin: 0 auto;
  padding: 0 1.5rem; height: 4rem;
  display: flex; align-items: center; justify-content: space-between;
}
.brand {
  display: flex; align-items: center; gap: 0.6rem;
  font-family: var(--font-display); font-weight: 700; font-size: 1.1rem;
}
.mark {
  width: 1.5rem; height: 1.5rem;
  border: 2px solid var(--primary);
  box-shadow: 3px 3px 0 var(--primary);
  display: inline-block;
}
.top-nav nav { display: flex; align-items: center; gap: 0.15rem; }
.top-nav nav a {
  padding: 0.45rem 0.75rem; border-radius: 0.35rem;
  font-size: 0.9rem; color: var(--muted);
}
.top-nav nav a.active, .top-nav nav a:hover { color: var(--primary); }
.x-pill {
  margin-left: 0.5rem !important;
  border: 1px solid var(--border) !important;
  color: var(--muted) !important;
}
.x-pill:hover { border-color: var(--primary) !important; color: var(--primary) !important; }

.mobile-bar {
  display: flex; align-items: center; justify-content: space-between;
  height: 3.5rem; padding: 0 1rem;
  border-bottom: 1px solid var(--border);
}
.dock {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(6, 1fr);
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.95);
  padding-bottom: env(safe-area-inset-bottom);
}
.dock a {
  text-align: center; padding: 0.65rem 0.25rem;
  font-family: var(--font-mono); font-size: 0.65rem;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
.dock a.active { color: var(--primary); }

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: auto;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}
.foot {
  height: auto; padding: 1.25rem 1.5rem;
  font-size: 0.75rem; color: var(--subtle);
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  flex-wrap: wrap;
}
.foot a { margin-left: 1rem; color: var(--subtle); }
.foot a:hover { color: var(--primary); }

main#content {
  flex: 1 0 auto;
  width: 100%;
  padding-bottom: 5.5rem;
}
@media (min-width: 768px) {
  main#content { padding-bottom: 2rem; }
  .mobile-only { display: none !important; }
}
@media (max-width: 767px) {
  .desktop-only { display: none !important; }
}

.wrap { max-width: 72rem; margin: 0 auto; padding: 2rem 1rem; }
@media (min-width: 768px) { .wrap { padding: 2.5rem 1.5rem; } }

.mono { font-family: var(--font-mono); }
.display { font-family: var(--font-display); }
.muted { color: var(--muted); }
.subtle { color: var(--subtle); }
.primary { color: var(--primary); }
.uppercase { text-transform: uppercase; letter-spacing: 0.12em; }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }

h1.hero-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3rem, 10vw, 5.5rem);
  line-height: 0.92;
  letter-spacing: -0.03em;
  margin: 0.75rem 0 0;
}

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  border: 1px solid var(--border);
  background: transparent; color: var(--fg);
  padding: 0.55rem 1rem; font-size: 0.9rem;
  font-family: var(--font-body); cursor: pointer;
  border-radius: 0.25rem;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
  background: var(--primary); color: var(--primary-fg);
  border-color: var(--primary); font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.05); color: var(--primary-fg); }
.btn-offset {
  background: var(--primary); color: var(--primary-fg);
  border: 2px solid var(--primary);
  box-shadow: 6px 6px 0 #5a7a00;
  font-weight: 600;
}
.btn-offset:hover { translate: 1px 1px; box-shadow: 5px 5px 0 #5a7a00; color: var(--primary-fg); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-ghost { border-color: transparent; color: var(--muted); }

.badge {
  display: inline-block;
  font-family: var(--font-mono); font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0.2rem 0.5rem; border: 1px solid var(--border);
  color: var(--muted);
}
.badge-live { border-color: var(--primary); color: var(--primary); }
.badge-ok { border-color: var(--ok); color: var(--ok); }
.badge-wait { border-color: #e6c200; color: #e6c200; }
.badge-no { border-color: var(--danger); color: var(--danger); }

.card {
  border: 1px solid var(--border);
  background: var(--void);
  padding: 1rem;
}
.card-offset {
  border: 2px solid var(--primary);
  box-shadow: 6px 6px 0 var(--primary);
  padding: 0.5rem;
}

input, textarea, select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.55rem 0.7rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  border-radius: 0.25rem;
}
input:focus, textarea:focus {
  outline: none; border-color: var(--primary);
}
label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.field { margin-bottom: 1rem; }

.grid-2 { display: grid; gap: 2rem; }
@media (min-width: 768px) {
  .grid-2 { grid-template-columns: 1fr 1fr; align-items: center; }
}
.stats {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1px; background: var(--border);
  border-bottom: 1px solid var(--border);
}
@media (min-width: 768px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stats > div {
  background: var(--void); text-align: center;
  padding: 2rem 1rem;
}
.stats .val {
  font-family: var(--font-display); font-weight: 700;
  font-size: 1.75rem;
}

.strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* mobile: 2 per row */
  gap: 0.75rem;
}
@media (min-width: 640px) { .strip { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 900px) { .strip { grid-template-columns: repeat(6, 1fr); } }
.strip .tile {
  border: 1px solid var(--border); padding: 0.35rem;
  background: var(--void);
}
.strip .tile canvas, .glyph-canvas { width: 100%; height: auto; display: block; }

.marquee {
  overflow: hidden; border-block: 1px solid var(--border);
  background: var(--surface); padding: 0.7rem 0;
}
.marquee-track {
  display: flex; gap: 2rem; width: max-content;
  font-family: var(--font-mono); font-size: 0.7rem;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  animation: marquee 40s linear infinite;
}
@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.faq details {
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 0;
}
.faq summary {
  cursor: pointer; font-weight: 600;
  list-style: none;
}
.faq summary::-webkit-details-marker { display: none; }
.faq p { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0 0; }

.flash {
  max-width: 72rem; margin: 1rem auto 0; padding: 0.75rem 1rem;
  border: 1px solid var(--border); font-size: 0.9rem;
}
.flash.ok { border-color: var(--ok); color: var(--ok); }
.flash.err { border-color: var(--danger); color: var(--danger); }

.admin-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1.5rem 0; }
.admin-tabs a, .admin-tabs button {
  font-size: 0.8rem;
}
.table-card {
  border: 1px solid var(--border); padding: 1rem; margin-bottom: 0.75rem;
}
.swatches { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.swatch {
  width: 1.75rem; height: 1.75rem; border: 1px solid var(--border);
  cursor: pointer; padding: 0;
}
.swatch.active { outline: 2px solid var(--primary); outline-offset: 2px; }

.studio-layout {
  display: grid; gap: 2rem;
}
@media (min-width: 900px) {
  .studio-layout { grid-template-columns: 1fr 20rem; }
}
.editor-frame {
  border: 2px solid var(--primary);
  box-shadow: 6px 6px 0 var(--primary);
  padding: 0.5rem;
}
#editor-canvas {
  width: 100%; max-width: 28rem; aspect-ratio: 1;
  display: block; touch-action: none; cursor: crosshair;
  image-rendering: pixelated;
}


/* Responsive canvases */
.glyph-canvas,
.tile canvas,
.card-offset canvas,
#preview-canvas {
  width: 100% !important;
  max-width: 100%;
  height: auto !important;
  aspect-ratio: 1 / 1;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
/* Editor canvas: avoid height:auto !important — collapses to 0 on mobile WebKit */
#editor-canvas {
  width: 100%;
  max-width: 28rem;
  aspect-ratio: 1 / 1;
  height: auto;
  display: block;
  touch-action: none;
  cursor: crosshair;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}
.card-offset { width: 100%; max-width: 22rem; }
.editor-frame {
  width: 100%;
  max-width: 28rem;
  min-height: 12rem;
}
@media (max-width: 767px) {
  .card-offset { max-width: min(100%, 20rem); margin-inline: auto; }
  .editor-frame {
    max-width: 100%;
    width: 100%;
    min-height: min(100vw - 2rem, 22rem);
  }
  #editor-canvas {
    width: 100% !important;
    max-width: 100%;
    /* Explicit min size so the box cannot collapse before aspect-ratio resolves */
    min-width: 12rem;
    min-height: min(100vw - 2rem, 22rem);
    aspect-ratio: 1 / 1;
    height: auto;
  }
}

/* Studio tools */
.tool-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.25rem;
}
.tool-btn.is-active {
  background: var(--primary) !important;
  color: #000 !important;
  border-color: var(--primary) !important;
}

/* Mobile: canvas first (DOM order), tools below — no sticky overlay */
@media (max-width: 767px) {
  .studio-layout {
    display: flex;
    flex-direction: column;
  }
  /* HTML already has editor before aside; do not reorder */
  .studio-aside {
    order: 2;
    position: static;
    max-height: none;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
  }
  .studio-layout > div:first-child {
    order: 1;
  }
  .studio-layout .editor-frame {
    width: 100%;
    max-width: 100%;
    flex-shrink: 0;
  }
  .dock a {
    font-size: 0.7rem;
    padding: 0.35rem 0.25rem;
  }
}
