:root {
  color-scheme: dark;
  --page: #090b0f;
  --panel: #12161c;
  --panel-raised: #181d25;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f4f5f6;
  --muted: #9da4ad;
  --accent: #d3f478;
  --accent-dark: #9bbd45;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: radial-gradient(circle at 15% 0%, #202937 0%, transparent 27%), var(--page);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1660px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(18px, 3vw, 46px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 378px;
  gap: clamp(18px, 2.5vw, 38px);
  align-items: start;
}

.stage { min-width: 0; }

.stage-header, .panel-header { margin-bottom: 18px; }
.stage-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 760;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.65rem, 3.2vw, 2.75rem); line-height: 0.96; letter-spacing: -0.055em; }
h2 { margin-bottom: 9px; font-size: 1.55rem; letter-spacing: -0.045em; }
h3 { margin-bottom: 3px; font-size: 1rem; letter-spacing: -0.025em; }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}
.status-chip i { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }

.canvas-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: var(--preview-aspect, 4 / 3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #080a0c;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
}

.preview-canvas { display: block; width: 100%; height: 100%; }
#fallback-canvas { position: absolute; inset: 0; }
.preview-canvas[hidden] { display: none; }

.canvas-loading, .canvas-error {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: rgba(9, 11, 15, 0.84);
  color: var(--muted);
}
.canvas-loading[hidden], .canvas-error[hidden] { display: none; }
.canvas-loading::before { content: ""; width: 28px; height: 28px; margin: auto; border: 2px solid rgba(211, 244, 120, 0.2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.85s linear infinite; }
.canvas-error img { width: min(100%, 670px); max-height: 55%; border-radius: 10px; object-fit: contain; }
.canvas-error strong, .canvas-error span { display: block; width: 100%; max-width: 100%; overflow-wrap: anywhere; }
@keyframes spin { to { transform: rotate(1turn); } }

.stage-tools { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; padding-top: 14px; }
.outline-button, .solid-button, .preset-row button {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text);
  background: transparent;
  font-size: 0.76rem;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
.outline-button:hover, .preset-row button:hover { border-color: rgba(211, 244, 120, 0.48); background: rgba(211, 244, 120, 0.07); }
.solid-button { border-color: var(--accent); background: var(--accent); color: #18210a; font-weight: 760; }
.solid-button:hover { background: #e0fa95; transform: translateY(-1px); }
.solid-button:disabled { cursor: not-allowed; opacity: 0.55; }
.solid-button:disabled:hover { background: var(--accent); transform: none; }

.debug-control { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; color: var(--muted); font-size: 0.72rem; }
select { max-width: 158px; border: 1px solid var(--border); border-radius: 7px; padding: 7px; color: var(--text); background: var(--panel-raised); font-size: 0.72rem; }
.control-panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(30, 36, 46, 0.92), rgba(17, 21, 27, 0.96));
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.2);
}
.panel-header { padding: 24px 24px 0; }
.panel-header > p:last-child { margin-bottom: 0; color: var(--muted); font-size: 0.81rem; line-height: 1.55; }

.tabs { display: grid; grid-template-columns: repeat(2, 1fr); margin: 22px 16px 0; border-bottom: 1px solid var(--border); }
.tabs.has-secondary { grid-template-columns: repeat(3, 1fr); }
.tab { min-width: 0; border: 0; border-bottom: 2px solid transparent; padding: 11px 5px; color: var(--muted); background: transparent; font-size: 0.68rem; font-weight: 700; line-height: 1.1; }
.tab.is-active { border-color: var(--accent); color: var(--text); }

.control-section { padding: 23px 24px 25px; }
.section-intro { display: flex; gap: 11px; align-items: flex-start; margin-bottom: 21px; }
.section-intro p { margin-bottom: 0; color: var(--muted); font-size: 0.77rem; }
.section-number { color: var(--accent); font-size: 0.7rem; font-weight: 800; line-height: 1.6; }

.colour-field { display: grid; grid-template-columns: 1fr 45px auto; gap: 9px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: 10px; color: var(--muted); font-size: 0.76rem; }
input[type="color"] { width: 40px; height: 27px; padding: 0; border: 0; border-radius: 6px; background: none; overflow: hidden; }
.colour-field output { color: var(--text); font-size: 0.71rem; font-variant-numeric: tabular-nums; }

.swatches { display: flex; gap: 8px; padding: 13px 0 17px; }
.swatch { width: 25px; height: 25px; border: 2px solid rgba(255, 255, 255, 0.1); border-radius: 50%; background: var(--swatch); }
.swatch:hover { border-color: var(--accent); transform: scale(1.12); }
.silver { --swatch: #9da6ad; }.white { --swatch: #e9ecec; }.black { --swatch: #111418; }.red { --swatch: #bd1626; }.green { --swatch: #123e31; }.violet { --swatch: #4d246d; }

.slider-stack { display: grid; gap: 15px; }
.slider-row > span { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--muted); font-size: 0.75rem; }
.slider-row output { color: var(--text); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: ew-resize; }

.preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 24px; }
.preset-row > span { width: 100%; margin-bottom: 1px; color: var(--muted); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.preset-row button { padding: 7px 8px; font-size: 0.68rem; }
.control-note { margin: 19px 0 0; color: var(--muted); font-size: 0.72rem; line-height: 1.5; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 1fr; }
  .control-panel { max-width: 760px; }
}

@media (max-width: 700px) {
  body { overflow-x: hidden; }
  .app-shell {
    display: block;
    width: 100%;
    padding: 0 0 max(22px, env(safe-area-inset-bottom));
  }
  .stage {
    position: sticky;
    z-index: 10;
    top: 0;
    background: rgba(9, 11, 15, 0.96);
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(16px);
  }
  .stage-header {
    position: absolute;
    z-index: 4;
    top: 0;
    right: 0;
    left: 0;
    align-items: center;
    margin: 0;
    padding: max(10px, env(safe-area-inset-top)) 12px 30px;
    pointer-events: none;
    background: linear-gradient(to bottom, rgba(3, 5, 8, 0.82), transparent);
  }
  .stage-header .eyebrow { display: none; }
  .stage-header h1 {
    margin: 0;
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    background: rgba(9, 11, 15, 0.66);
    font-size: 0.9rem;
    line-height: 1;
    letter-spacing: -0.025em;
    backdrop-filter: blur(10px);
  }
  .status-chip {
    padding: 7px 9px;
    background: rgba(9, 11, 15, 0.66);
    font-size: 0.64rem;
    backdrop-filter: blur(10px);
  }
  .canvas-frame {
    display: grid;
    width: 100%;
    aspect-ratio: 1;
    place-items: center;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .preview-canvas {
    grid-area: 1 / 1;
    width: 100%;
    height: auto;
    max-height: 100%;
    object-fit: contain;
  }
  #fallback-canvas { position: static; inset: auto; }
  .stage-tools {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 9px 12px 11px;
    border-bottom: 1px solid var(--border);
    background: rgba(12, 15, 20, 0.97);
  }
  .stage-tools > button {
    width: 100%;
    min-height: 44px;
    padding: 8px 6px;
    touch-action: manipulation;
  }
  .debug-control { display: none; }
  .control-panel {
    position: static;
    max-width: none;
    padding: 15px 12px 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  .panel-header {
    margin: 0;
    padding: 2px 4px 13px;
  }
  .panel-header .eyebrow { margin-bottom: 3px; }
  .panel-header h2 { margin: 0; font-size: 1.25rem; }
  .panel-header > p:last-child { display: none; }
  .tabs { display: none; }
  .control-section {
    display: block !important;
    margin: 0 0 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: linear-gradient(145deg, rgba(30, 36, 46, 0.94), rgba(17, 21, 27, 0.98));
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.18);
  }
  #secondary-panel { display: none !important; }
  .control-panel.has-secondary #secondary-panel { display: block !important; }
  .section-intro { margin-bottom: 14px; }
  .section-intro p { font-size: 0.72rem; }
  .colour-field { min-height: 52px; }
  .swatches { flex-wrap: wrap; gap: 10px; padding: 14px 0 16px; }
  .swatch { width: 36px; height: 36px; touch-action: manipulation; }
  .slider-row input[type="range"] { min-height: 36px; touch-action: none; }
  .preset-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    margin-top: 17px;
  }
  .preset-row > span { grid-column: 1 / -1; }
  .preset-row button { min-height: 44px; padding: 7px 4px; touch-action: manipulation; }
  .control-note { margin-top: 12px; }
}

@media (max-width: 360px) {
  .stage-header { padding-inline: 8px; }
  .stage-header h1 { font-size: 0.78rem; }
  .status-chip { padding: 6px 7px; font-size: 0.58rem; }
  .stage-tools { gap: 6px; padding-inline: 8px; }
  .stage-tools > button { font-size: 0.68rem; }
  .control-panel { padding-inline: 8px; }
  .control-section { padding: 14px; }
  .preset-row { gap: 5px; }
  .preset-row button { font-size: 0.62rem; }
}
