/* ==========================================================================
   iLoveMaze UI — Standalone Framework-Free Design Package
   Print-Studio / Editorial Architectural Instrument Styling
   ========================================================================== */

:root {
  /* Force light rendering regardless of the device's OS/browser dark-mode
     setting. Without this, some mobile browsers auto-invert pages that
     don't declare a color-scheme, which produced the "black frame around
     the white plate" artifact — most of the paper-toned page got force-
     darkened while the maze's own explicit colors resisted the inversion,
     leaving a mismatched dark bezel around it in light/non-inverted mode. */
  color-scheme: light;

  /* Editorial Print Colors — original iLoveMaze palette (restored) */
  --paper: #F5F0E7;
  --paper-deep: #EBE3D0;
  --paper-light: #FAF6EB;
  --panel: #FFFDF8;
  --panel-warm: #FAF6EF;
  --panel-accent: #E9E1CF;
  --ink: #111111;
  --ink-rich: #1C1A15;
  --ink-soft: #4D4841;
  --ink-mute: #8E877C;
  --ink-faint: #BFB7A6;
  --rule: rgba(17, 17, 17, 0.15);
  --rule-subtle: rgba(17, 17, 17, 0.08);
  --rule-strong: rgba(17, 17, 17, 0.35);

  /* Accents */
  --teal: #168C86;
  --teal-hover: #0D5D58;
  --teal-deep: #0D5D58;
  --orange: #F06A24;
  --orange-hover: #B93C0F;
  --orange-deep: #B93C0F;
  --amber: #C99028;
  --sol-color: #168C86;

  /* Warm shadow base (avoids a flat, cold black) */
  --shadow-tint: 80, 60, 40;
  --shadow-xs: 0 1px 2px rgba(var(--shadow-tint), 0.06);
  --shadow-sm: 0 1px 3px rgba(var(--shadow-tint), 0.08), 0 1px 2px rgba(var(--shadow-tint), 0.04);
  --shadow-md: 0 4px 14px -3px rgba(var(--shadow-tint), 0.14), 0 2px 4px -2px rgba(var(--shadow-tint), 0.08);
  --shadow-plate: 0 16px 40px -20px rgba(var(--shadow-tint), 0.35);
  --shadow-glow-orange: 0 8px 20px -6px rgba(240, 106, 36, 0.35);

  /* Typography Stacks (High-grade system & web font fallbacks) */
  --font-mono: 'IBM Plex Mono', 'SF Mono', Monaco, Consolas, 'Liberation Mono', Menlo, monospace;
  --font-sans: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;

  /* Sizing & Transitions */
  --radius-xs: 3px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-pill: 9999px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-fast: 150ms ease;
  --transition-normal: 220ms ease;
}

/* ==========================================================================
   Base & Resets
   ========================================================================== */

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

html {
  color-scheme: light;
  background-color: #F5F0E7;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-feature-settings: 'ss01', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100%;
  overflow-x: hidden;
  position: relative;
}

::selection {
  background: var(--amber);
  color: var(--ink);
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 100%;
  line-height: 1.15;
  color: inherit;
  border: none;
  background: none;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

/* Technical typography utility */
.font-mono-tech {
  font-family: var(--font-mono);
}

/* ==========================================================================
   Page Shell Layout
   ========================================================================== */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  width: 100%;
  background-color: var(--paper);
  position: relative;
  z-index: 1;
}

/* ==========================================================================
   1. Header
   ========================================================================== */

.site-header {
  flex: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0)), var(--paper);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: saturate(120%);
  position: relative;
  z-index: 20;
}

.header-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

@media (min-width: 640px) {
  .header-container {
    padding: 0 1.5rem;
    height: 4rem;
  }
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: var(--ink);
  user-select: none;
  min-height: 44px;
  transition: opacity var(--transition-fast);
}

.brand-link:hover {
  opacity: 0.85;
}

.brand-icon {
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.brand-link:hover .brand-icon {
  transform: rotate(12deg);
}

.brand-name {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.04em;
  line-height: 1;
  text-transform: uppercase;
}

.heart-glyph {
  color: var(--teal);
  padding: 0 1px;
  display: inline-block;
  transform: translateY(-1px);
  transition: transform 0.4s var(--ease-spring);
}

.brand-link:hover .heart-glyph {
  transform: translateY(-1px) scale(1.15) rotate(-8deg);
}

.brand-badge {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding-left: 0.875rem;
  border-left: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  color: var(--ink-mute);
  letter-spacing: 0.08em;
  line-height: 1;
}

@media (min-width: 1024px) {
  .brand-badge {
    display: flex;
  }
}

.pulse-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--teal);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

/* ==========================================================================
   2. Maze Type Selector (4-segment Equal Grid)
   ========================================================================== */

.type-selector-bar {
  width: 100%;
  background-color: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: 0.625rem 0.75rem;
  flex: none;
  user-select: none;
}

@media (min-width: 640px) {
  .type-selector-bar {
    padding: 0.75rem 1.5rem;
  }
}

.type-selector-nav {
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 0.25rem;
  background-color: var(--panel-accent);
  border: 1px solid rgba(17, 17, 17, 0.2);
  border-radius: var(--radius-pill);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

.type-tab {
  width: 100%;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.type-tab svg {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
  transition: transform 0.3s var(--ease-spring);
}

.type-tab:hover {
  color: var(--ink);
  background-color: rgba(17, 17, 17, 0.06);
}

.type-tab:hover svg {
  transform: scale(1.1);
}

.type-tab.active {
  background-color: var(--ink);
  color: var(--paper);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.type-tab.active svg {
  color: var(--amber);
}

/* ==========================================================================
   3. Main Workspace Composition
   ========================================================================== */

.workspace-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

@media (min-width: 1024px) {
  .workspace-main {
    display: grid;
    grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
    align-items: start;
  }
}

/* ==========================================================================
   Stage Preview Section (Hero Focus)
   ========================================================================== */

.stage-viewport {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0.75rem 1rem 1.25rem;
  background-color: var(--paper);
  border-bottom: 1px solid var(--rule);
  user-select: none;
  order: 1;
}

@media (min-width: 1024px) {
  .stage-viewport {
    order: 2;
    min-width: 0;
    border-bottom: none;
    justify-content: flex-start;
    padding: 1.5rem 2rem 2rem;
  }
}

/* Status Readout Strip */
.status-readout-strip {
  width: 100%;
  max-width: 580px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.375rem 0.875rem;
  background-color: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  margin-bottom: 0.625rem;
}

.status-metric {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-seed {
  display: none;
  align-items: center;
  gap: 0.375rem;
  color: var(--ink-mute);
  text-transform: uppercase;
  font-size: 0.625rem;
}

@media (min-width: 480px) {
  .status-seed {
    display: flex;
  }
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.status-badge.ready {
  color: var(--teal);
}

.status-badge.generating {
  color: var(--orange);
}

.status-badge.error {
  color: #DC2626;
}

.status-badge.empty {
  color: var(--amber);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: currentColor;
}

/* Preview Toolbar */
.preview-toolbar {
  width: 100%;
  max-width: 580px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
}

.plate-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink);
  letter-spacing: 0.05em;
}

.plate-square-icon {
  width: 8px;
  height: 8px;
  border: 1px solid var(--ink);
  background-color: #ffffff;
}

.plate-dim {
  display: none;
  font-size: 0.625rem;
  color: var(--ink-mute);
  font-weight: 400;
}

@media (min-width: 640px) {
  .plate-dim {
    display: inline;
  }
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background-color: rgba(255, 255, 255, 0.75);
  padding: 0.25rem 0.375rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--rule);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.tool-btn {
  height: 1.75rem;
  min-height: 28px;
  padding: 0 0.625rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--ink-soft);
  transition: all var(--transition-fast);
}

.tool-btn:hover {
  color: var(--ink);
  background-color: rgba(17, 17, 17, 0.05);
}

.tool-btn.active {
  background-color: var(--teal);
  color: #ffffff;
}

/* Bug fix: disabled tool/export buttons had no visual treatment at all,
   so a button that silently ignored clicks (e.g. Solution before a maze
   exists) looked identical to a live one. */
.tool-btn:disabled,
.tool-icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.tool-icon-btn {
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  color: var(--ink-soft);
  transition: all var(--transition-fast);
}

.tool-icon-btn:hover {
  color: var(--ink);
  background-color: rgba(17, 17, 17, 0.05);
}

.tool-icon-btn.active {
  background-color: var(--ink);
  color: var(--paper);
}

.tool-divider {
  width: 1px;
  height: 0.875rem;
  background-color: var(--rule);
  margin: 0 0.125rem;
}

.zoom-label {
  width: 2.25rem;
  text-align: center;
  font-size: 0.625rem;
  color: var(--ink-mute);
  user-select: none;
}

/* ==========================================================================
   CRITICAL MAZE PREVIEW FRAME:
   - Width-driven
   - Strictly aspect-ratio: 1 / 1
   - Never depends on viewport height (no vh, dvh, svh, lvh)
   - Scrolling never affects size
   ========================================================================== */

.maze-stage-frame {
  position: relative;
  width: 100%;
  max-width: 580px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Architectural Registration Crop Marks */
.crop-mark {
  position: absolute;
  width: 14px;
  height: 14px;
  color: var(--rule-strong);
  pointer-events: none;
  z-index: 5;
}

.crop-mark::before,
.crop-mark::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.crop-mark::before {
  width: 1px;
  height: 100%;
}

.crop-mark::after {
  height: 1px;
  width: 100%;
}

.crop-mark.tl { top: -5px; left: -5px; }
.crop-mark.tl::before { top: 0; left: 0; }
.crop-mark.tl::after { top: 0; left: 0; }

.crop-mark.tr { top: -5px; right: -5px; }
.crop-mark.tr::before { top: 0; right: 0; }
.crop-mark.tr::after { top: 0; right: 0; }

.crop-mark.bl { bottom: -5px; left: -5px; }
.crop-mark.bl::before { bottom: 0; left: 0; }
.crop-mark.bl::after { bottom: 0; left: 0; }

.crop-mark.br { bottom: -5px; right: -5px; }
.crop-mark.br::before { bottom: 0; right: 0; }
.crop-mark.br::after { bottom: 0; right: 0; }

/* Physical Paper Canvas Frame
   No border and no heavy/blurred drop-shadow here by design: either one
   reads as a dark bezel or "smoke" halo around the preview square. The
   plate is always the same flat, uniform panel fill — iLoveMaze is
   light-mode only, so there is no inverted/dark plate state at all. */
.plate-frame {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 1.25rem;
  background-color: var(--panel);
  border: none;
  box-shadow: none;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (min-width: 640px) {
  .plate-frame {
    padding: 1.75rem;
  }
}

.maze-artwork-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  transition: transform var(--transition-fast);
}

.maze-svg-display {
  width: 100%;
  height: 100%;
  display: block;
}

/* Note: solution visibility is controlled by re-rendering the maze via
   renderMaze({ showSolution }) at the platform layer (see
   app/ui/mazePreview.js's showSVG()) — the SVG that lands in
   #maze-svg-host already does or doesn't contain the solution path.
   There is no CSS-level toggle for it. */

/* Overlay States */
.stage-overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  z-index: 10;
}

.stage-overlay.active {
  display: flex;
}

/* Generating State */
.loading-overlay {
  background-color: rgba(245, 240, 231, 0.92);
}

.spinner-disc {
  position: relative;
  width: 4rem;
  height: 4rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.disc-dashed {
  position: absolute;
  inset: 0;
  border: 2px dashed var(--ink);
  border-radius: 50%;
  animation: spin 6s linear infinite;
}

.disc-pulse {
  position: absolute;
  inset: 0.5rem;
  border: 1px solid var(--orange);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

.spinner-icon {
  width: 1.75rem;
  height: 1.75rem;
  animation: spin 1s linear infinite;
}

.overlay-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.overlay-subtitle {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--ink-soft);
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.progress-track {
  width: 11rem;
  height: 4px;
  background-color: rgba(17, 17, 17, 0.15);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-bar {
  width: 100%;
  height: 100%;
  background-color: var(--orange);
  animation: pulse 1.2s ease-in-out infinite;
}

/* Error State */
.error-overlay {
  background-color: rgba(255, 255, 255, 0.95);
  border: 2px dashed rgba(220, 38, 38, 0.5);
}

.error-badge {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background-color: #FEF2F2;
  border: 1px solid #FCA5A5;
  color: #DC2626;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.error-overlay .overlay-title {
  color: #B91C1C;
}

.overlay-msg {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--ink-soft);
  max-width: 22rem;
  margin-bottom: 1rem;
  line-height: 1.4;
}

.overlay-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.action-pill-btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-height: 38px;
  transition: all var(--transition-fast);
}

.action-pill-btn.primary {
  background-color: var(--ink);
  color: #ffffff;
}

.action-pill-btn.primary:hover {
  background-color: var(--orange);
}

.action-pill-btn.secondary {
  border: 1px solid var(--rule);
  color: var(--ink);
}

.action-pill-btn.secondary:hover {
  background-color: rgba(17, 17, 17, 0.06);
}

/* Empty State */
.empty-overlay {
  border: 1px dashed var(--rule-strong);
}

.empty-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: 1px dashed var(--rule-strong);
  color: var(--ink-mute);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
}

/* Technical Plate Footer */
.plate-footer {
  width: 100%;
  max-width: 580px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.5rem 0.25rem 0;
}

/* ==========================================================================
   4. Control Panel (Parameter Deck)
   ========================================================================== */

.control-deck {
  width: 100%;
  background-color: var(--paper);
  display: flex;
  flex-direction: column;
  flex: none;
  order: 2;
}

@media (min-width: 1024px) {
  .control-deck {
    order: 1;
    width: auto;
    max-width: none;
    min-width: 0;
    border-right: 1px solid var(--rule);
  }
}

.deck-header {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--rule);
  background-color: var(--panel-warm);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.deck-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.deck-title::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 0 3px rgba(240, 106, 36, 0.14);
  flex-shrink: 0;
}

.deck-subtitle {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Scrollable Controls Body */
.deck-body {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
}

/* ==========================================================================
   Unified Collapsible Settings System (Core & Advanced)
   - Visually consistent
   - Collapsed by default
   - Same border, radius, height, typography, icon alignment, chevron
   ========================================================================== */

.accordion-group {
  position: relative;
  border: 1px solid rgba(17, 17, 17, 0.2);
  border-radius: var(--radius-md);
  background-color: rgba(255, 255, 255, 0.4);
  overflow: hidden;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.accordion-group::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--orange);
  transform: scaleY(0);
  transform-origin: top;
  transition: transform var(--transition-normal);
}

.accordion-group:has(.accordion-trigger[aria-expanded="true"])::before {
  transform: scaleY(1);
}

.accordion-group:has(.accordion-trigger[aria-expanded="true"]) {
  box-shadow: var(--shadow-sm);
}

.accordion-group.advanced::before {
  background: var(--teal);
}

.accordion-group:hover {
  border-color: rgba(17, 17, 17, 0.35);
}

.accordion-group.advanced {
  border-color: rgba(17, 17, 17, 0.15);
  background-color: rgba(17, 17, 17, 0.02);
}

.accordion-group.advanced:hover {
  border-color: rgba(17, 17, 17, 0.25);
}

.accordion-trigger {
  width: 100%;
  padding: 0.75rem 0.875rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  user-select: none;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.accordion-trigger:hover {
  background-color: rgba(17, 17, 17, 0.04);
}

.accordion-trigger:active {
  background-color: rgba(17, 17, 17, 0.07);
}

.accordion-label-wrap {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.accordion-icon {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
  color: var(--orange);
  transition: transform 0.5s var(--ease-spring);
}

.accordion-group.advanced .accordion-icon {
  color: var(--teal);
}

.accordion-trigger:hover .accordion-icon {
  transform: rotate(30deg) scale(1.08);
}

.accordion-trigger[aria-expanded="true"] .accordion-icon {
  transform: rotate(0) scale(1.1);
}

.accordion-title {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.accordion-group.advanced .accordion-title {
  font-weight: 600;
  color: var(--ink-soft);
}

.accordion-chevron {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  color: var(--ink-mute);
  transition: transform 0.2s ease, color 0.2s ease;
}

.accordion-trigger[aria-expanded="true"] .accordion-chevron {
  transform: rotate(180deg);
  color: var(--ink);
}

.accordion-content {
  display: none;
  padding: 1rem;
  border-top: 1px solid rgba(17, 17, 17, 0.1);
  background-color: rgba(255, 255, 255, 0.6);
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 0.2s ease-out;
}

.accordion-trigger[aria-expanded="true"] + .accordion-content {
  display: flex;
}

.accordion-group.advanced .accordion-content {
  background-color: rgba(255, 255, 255, 0.5);
  gap: 0.875rem;
}

/* ==========================================================================
   Form Fields, Sliders, and Pickers
   ========================================================================== */

.field-block {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field-block[hidden] {
  display: none;
}

.field-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.field-label {
  font-family: var(--font-mono);
  font-size: 0.65625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.field-value-wrap {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.field-number-input {
  width: 3.5rem;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 1px solid rgba(17, 17, 17, 0.3);
  padding: 0 0.125rem;
}

.field-number-input:hover {
  border-bottom-color: var(--ink);
}

.field-number-input:focus {
  border-bottom-color: var(--orange);
}

.field-unit {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--ink-mute);
}

.field-subtext-wrap {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  color: var(--ink-mute);
}

/* Custom Fader Slider */
.fader-slider {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.fader-slider::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(
    to right,
    var(--ink) 0%,
    var(--ink) var(--val-p, 50%),
    var(--rule-strong) var(--val-p, 50%),
    var(--rule-strong) 100%
  );
}

.fader-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -7px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  transition: transform 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
}

.fader-slider:hover::-webkit-slider-thumb {
  background: var(--orange);
  border-color: var(--orange);
  transform: scale(1.15);
}

.fader-slider:active::-webkit-slider-thumb {
  background: var(--orange);
  border-color: var(--orange);
}

.fader-slider:focus-visible {
  outline: none;
}

.fader-slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(240, 106, 36, 0.28);
}

.fader-slider::-moz-range-track {
  height: 2px;
  border-radius: 1px;
  background: var(--rule-strong);
}

.fader-slider::-moz-range-progress {
  height: 2px;
  background: var(--ink);
}

.fader-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  transition: transform 0.12s ease, background-color 0.12s ease;
}

.fader-slider:hover::-moz-range-thumb {
  background: var(--orange);
  border-color: var(--orange);
  transform: scale(1.15);
}

/* Two-column strokes grid */
.strokes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(17, 17, 17, 0.1);
}

/* Seed Coordinate Field */
.seed-row {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(17, 17, 17, 0.1);
}

.seed-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.seed-text-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--ink);
  background-color: #ffffff;
  border: 1px solid rgba(17, 17, 17, 0.2);
  border-radius: var(--radius-sm);
  padding: 0.375rem 0.75rem;
  height: 2.25rem;
}

.seed-text-input:focus {
  border-color: var(--ink);
}

.shuffle-seed-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0 0.875rem;
  height: 2.25rem;
  background-color: #ffffff;
  color: var(--ink);
  border: 1px solid rgba(17, 17, 17, 0.2);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.65625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all var(--transition-fast);
}

.shuffle-seed-btn:hover {
  background-color: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
}

.shuffle-seed-btn svg {
  color: var(--orange);
  transition: color var(--transition-fast);
}

.shuffle-seed-btn:hover svg {
  color: var(--amber);
}

/* Advanced Settings Internal Controls */
.button-matrix {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.59375rem;
  text-transform: uppercase;
}

.button-matrix[hidden] {
  display: none;
}

.matrix-btn {
  padding: 0.375rem;
  text-align: center;
  border: 1px solid rgba(17, 17, 17, 0.15);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: var(--ink-soft);
  transition: all var(--transition-fast);
}

.matrix-btn:hover {
  border-color: var(--orange);
  color: var(--ink);
}

.matrix-btn.active {
  background-color: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
}

/* ==========================================================================
   5. Bottom Actions Deck (ONE Primary Generate & ONE Export Area)
   ========================================================================== */

.deck-actions {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--rule);
  background-color: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ONE Primary Generate Button */
.primary-generate-btn {
  width: 100%;
  height: 3rem;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  background-color: var(--ink);
  color: var(--paper);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.primary-generate-btn::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent);
  transition: left 700ms var(--ease-out);
}

.primary-generate-btn:hover {
  background-color: var(--orange);
  box-shadow: var(--shadow-glow-orange);
}

.primary-generate-btn:hover::after {
  left: 120%;
}

.primary-generate-btn:active {
  transform: translateY(0);
}

.primary-generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Bug fix: the icon was --orange by default, which turned invisible against
   the same orange the button background switches to on hover. Match UI1:
   amber at rest, explicit white on hover so it stays visible either way. */
.primary-generate-btn svg {
  color: var(--amber);
  transition: transform 0.4s var(--ease-spring);
}

.primary-generate-btn:hover svg {
  color: #ffffff;
  transform: rotate(-15deg) scale(1.15);
}

.primary-generate-btn.loading svg {
  animation: spin 1s linear infinite;
  color: currentColor;
  transform: none;
}

/* ONE Export Artwork Area */
.export-artwork-area {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding-top: 0.25rem;
}

.export-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0 0.25rem;
}

.export-feedback {
  color: var(--teal);
  font-weight: 700;
  display: none;
  align-items: center;
  gap: 0.25rem;
}

.export-feedback.active {
  display: flex;
}

.export-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.export-btn {
  height: 2.75rem;
  min-height: 44px;
  padding: 0 0.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--ink);
  background-color: #ffffff;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  transition: all var(--transition-fast);
}

.export-btn:hover {
  background-color: var(--ink);
  color: #ffffff;
}

.export-btn[hidden] {
  display: none;
}

/* Bug fix: no disabled treatment existed, so the SVG/PNG export buttons
   looked fully live before a maze had ever been generated. */
.export-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.export-btn:disabled:hover {
  background-color: #ffffff;
  color: var(--ink);
}

.engine-status-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  color: var(--ink-mute);
  text-transform: uppercase;
  padding: 0.25rem 0.25rem 0;
  border-top: 1px solid rgba(17, 17, 17, 0.1);
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ==========================================================================
   Responsive Viewport Specific Adjustments
   ========================================================================== */


/* Small-screen layout: wrap the preview toolbar before it can collide. */
@media (max-width: 420px) {
  .preview-toolbar {
    flex-wrap: wrap;
    row-gap: 0.5rem;
  }

  .plate-meta {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar-controls {
    width: 100%;
    justify-content: center;
  }

  .plate-footer {
    gap: 0.75rem;
  }

  .plate-footer span:last-child {
    text-align: right;
  }
}

/* Very small screens: 320px - 360px */
@media (max-width: 360px) {
  .type-tab {
    font-size: 0.575rem;
    gap: 0.25rem;
    padding: 0 0.0625rem;
  }
  .type-tab svg {
    width: 0.75rem;
    height: 0.75rem;
  }
  .toolbar-controls {
    padding: 0.125rem 0.25rem;
  }
}


/* Final responsive safety rails */
html, body {
  width: 100%;
  max-width: 100%;
}

body {
  overflow-x: clip;
}

.workspace-main,
.stage-viewport,
.control-deck,
.deck-body,
.maze-stage-frame,
.plate-frame {
  min-width: 0;
}

.maze-stage-frame {
  flex: 0 0 auto;
  align-self: center;
}

.plate-frame {
  aspect-ratio: 1 / 1;
}

@media (max-width: 420px) {
  .header-container {
    padding-inline: 0.75rem;
  }

  .brand-wrapper {
    gap: 0;
  }

  .deck-header {
    padding-inline: 1rem;
  }

  .deck-body,
  .deck-actions {
    padding-inline: 1rem;
  }

  .strokes-grid {
    gap: 0.625rem;
  }

  .seed-input-group {
    gap: 0.375rem;
  }

  .shuffle-seed-btn {
    padding-inline: 0.75rem;
  }
}

@media (max-width: 340px) {
  .type-selector-bar {
    padding-inline: 0.5rem;
  }

  .type-selector-nav {
    padding: 0.1875rem;
  }

  .type-tab {
    letter-spacing: 0.02em;
  }

  .accordion-trigger {
    padding-inline: 0.75rem;
  }

  .accordion-title {
    font-size: 0.625rem;
  }
}

@media (min-width: 1024px) {
  .stage-viewport {
    width: 100%;
  }

  .maze-stage-frame,
  .status-readout-strip,
  .preview-toolbar,
  .plate-footer {
    max-width: min(680px, 100%);
  }
}

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

/* ==========================================================================
   Phase 19 additions — generic settings field types the mock design
   didn't need (boolean toggles, file upload) and the export note text,
   styled to match the existing field-block/matrix-btn/seed language.
   ========================================================================== */

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--ink);
  cursor: pointer;
}

.file-input-row {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.file-input-row[hidden] {
  display: none;
}

.file-input {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink);
  background-color: #ffffff;
  border: 1px solid rgba(17, 17, 17, 0.2);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.625rem;
}

.file-input-hint {
  font-size: 0.59375rem;
  line-height: 1.4;
}

.export-controls__note {
  font-family: var(--font-mono);
  font-size: 0.59375rem;
  color: var(--ink-mute);
  text-align: center;
}
