:root {
  --color-bg: #0a0a0f;
  --color-bg-elevated: #12121a;
  --color-bg-card: #16161f;
  --color-surface: #1a1a24;
  --color-text: #ffffff;
  --color-text-muted: #9ca3af;
  --color-text-subtle: #6b7280;
  --color-border: rgba(255, 255, 255, 0.08);
  --color-primary: #6366f1;
  --color-primary-light: #818cf8;
  --color-primary-dark: #4f46e5;
  --color-accent: #06b6d4;
  --color-accent-light: #22d3ee;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #f43f5e;
  --gradient-primary: linear-gradient(135deg, #6366f1 0%, #06b6d4 100%);
  --gradient-glow: radial-gradient(ellipse at 12% -10%, rgba(99, 102, 241, 0.18) 0%, transparent 55%);
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --ink: #1c1712;
  --ink-soft: #4a4036;
  --paper: #f3ead6;
  --rule: rgba(99, 102, 241, 0.16);
  --guide-cap: #6366f1;
  --guide-x: #06b6d4;
  --guide-base: #1c1712;
  --guide-desc: #a78bfa;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--gradient-glow), var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font: inherit;
}

a {
  color: var(--color-primary-light);
}

a:hover {
  color: var(--color-accent-light);
}

.gradient-text {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 22px;
  background: rgba(10, 10, 15, 0.86);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--color-border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 2px;
  color: var(--color-text);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  min-width: 0;
}

.logo:hover { color: var(--color-text); }

.logo-mark {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
}

.logo-text { white-space: nowrap; }

.step-nav {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
  overflow-x: auto;
}

.nav-btn {
  appearance: none;
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
}

.nav-btn[aria-current="page"],
.nav-btn:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(6, 182, 212, 0.35);
}

.topbar-cta {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--gradient-primary);
  color: #fff !important;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 68px);
}

.app-shell.on-home {
  grid-template-columns: 1fr;
}

.app-shell.on-home .sidebar {
  display: none;
}

.sidebar {
  background: var(--color-bg-elevated);
  border-right: 1px solid var(--color-border);
  padding: 22px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.side-label {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-primary-light);
}

.side-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-actions .hint { margin: 6px 0 0; }

#save-status { color: var(--color-accent-light); }

.main {
  padding: 28px 32px 56px;
  min-width: 0;
}

.panel { display: none; }
.panel.active { display: block; }

.panel h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0 0 22px;
  color: var(--color-text-muted);
  max-width: 70ch;
  line-height: 1.5;
}

.demo-banner {
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(6, 182, 212, 0.28);
  background: rgba(6, 182, 212, 0.08);
  color: var(--color-text-muted);
  font-size: 0.92rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

[hidden] { display: none !important; }

label, .label {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-accent);
  font-weight: 600;
}

input[type="text"],
input[type="number"],
input[type="range"],
select,
textarea {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(6, 182, 212, 0.45);
  outline-offset: 1px;
}

textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  line-height: 1.45;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  background: var(--gradient-primary);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  transition: transform var(--transition-fast), box-shadow var(--transition-base);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.28);
}

.btn.secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: none;
}

.btn.secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  box-shadow: none;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text);
  box-shadow: none;
}

.btn.danger {
  background: var(--color-danger);
  box-shadow: none;
}

.more-box {
  margin: 14px 0 0;
  padding: 10px 14px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-card);
}

.more-box summary {
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--color-primary-light);
  list-style: none;
}

.more-box summary::-webkit-details-marker { display: none; }

.more-box .row { margin-top: 12px; }

.paper-stage {
  margin-top: 18px;
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  padding: 18px;
}

.canvas-wrap {
  position: relative;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 31px,
      var(--rule) 31px,
      var(--rule) 32px
    ),
    var(--paper);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid #d7c9a8;
}

#capture-canvas,
#compose-canvas,
#stamp-canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: crosshair;
}

.guide-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -1px;
}

.glyph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 6px;
  margin-top: 14px;
}

.glyph-cell {
  aspect-ratio: 1;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.05rem;
  position: relative;
}

.glyph-cell.active { outline: 2px solid var(--color-accent); }
.glyph-cell.has-one { background: rgba(99, 102, 241, 0.28); }
.glyph-cell.has-many { background: rgba(16, 185, 129, 0.28); }

.glyph-cell .count {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-size: 0.65rem;
  opacity: 0.85;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.status {
  min-height: 1.3em;
  color: var(--color-accent-light);
  margin-top: 8px;
}

.missing {
  color: #fda4af;
  font-size: 0.95rem;
}

.bounds-bar {
  margin: 10px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
}

.bounds-bar[data-state="bad"] {
  border-color: rgba(244, 63, 94, 0.45);
  background: rgba(244, 63, 94, 0.1);
}

.bounds-status {
  margin: 0 0 10px;
  color: var(--color-accent-light);
  font-size: 0.95rem;
}

.bounds-bar[data-state="bad"] .bounds-status { color: #fda4af; }

.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 16px;
}

.card a { color: var(--color-accent-light); }

.card ol { color: var(--color-text-muted); }

.how-card {
  margin: 0 0 22px;
}

.how-card ol {
  margin: 8px 0 0;
  padding-left: 1.2rem;
  color: var(--color-text-muted);
}

.how-card li {
  margin-bottom: 8px;
}

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.dash-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.dash-wide { grid-column: 1 / -1; }

.dash-tag {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-primary-light);
}

.dash-card h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.dash-card > p {
  margin: 0 0 12px;
  color: var(--color-text-muted);
}

.dash-paper {
  margin-top: 0;
  padding: 10px;
  flex: 1;
}

.dash-paper canvas,
.dash-modes canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.dash-modes {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 16px;
}

.dash-modes figure {
  margin: 0;
  background: var(--paper);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid #d7c9a8;
}

.dash-modes figcaption {
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 6px 4px 10px;
  font-family: var(--font-display);
  font-weight: 600;
}

.dash-card .toolbar {
  margin-top: 4px;
  flex-wrap: wrap;
}

.variant-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.variant-thumb {
  width: 72px;
  height: 88px;
  background: var(--paper);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  color: var(--ink);
}

.stamp-caption {
  font-size: 0.65rem;
  line-height: 1.2;
  padding: 2px 4px 4px;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variant-thumb.selected { outline: 2px solid var(--color-accent); }

.hint {
  color: var(--color-text-subtle);
  font-size: 0.9rem;
  line-height: 1.45;
}

.site-footer {
  padding: 36px 24px 28px;
  background: var(--color-bg-elevated);
  border-top: 1px solid var(--color-border);
}

.site-footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 24px;
}

.site-footer p {
  margin: 0;
  color: var(--color-text-subtle);
  font-size: 0.88rem;
  max-width: 52ch;
}

.site-footer a { color: var(--color-primary-light); }

.panel h3 {
  font-family: var(--font-display);
  font-weight: 600;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
    padding: 16px;
  }
  .topbar {
    flex-wrap: wrap;
    padding: 8px 12px 10px;
  }
  .step-nav {
    order: 3;
    flex-basis: 100%;
    justify-content: flex-start;
  }
  .main { padding: 20px 16px 40px; }
  .topbar-cta { display: none; }
  .dash-grid { grid-template-columns: 1fr; }
  .dash-modes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .dash-modes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
