/* Canvas-first studio. Theme overrides are scoped so the landing page stays independent. */
body.studio-page {
  --bg: #edf0eb;
  --panel-bg: #f9faf7;
  --panel-alt: #f2f4ef;
  --text: #253b34;
  --text-muted: #697a72;
  --border: #d9e1d8;
  --input-bg: #fff;
  --preview-bg: #f3f5f0;
  --accent: #27624f;
  --accent-hover: #1b4a3a;
  --header-bg: #203d33;
  background: var(--bg);
}
body.studio-page.dark {
  --bg: #171e1b;
  --panel-bg: #202a25;
  --panel-alt: #1b241f;
  --text: #edf1e9;
  --text-muted: #a6b4a8;
  --border: #3a483e;
  --input-bg: #18221c;
  --preview-bg: #28362c;
  --accent: #387d62;
  --accent-hover: #449976;
  --header-bg: #18251f;
}
.studio-page [hidden] {
  display: none !important;
}
.studio-page button,
.studio-page select,
.studio-page input {
  font: inherit;
}
.studio-page button:focus-visible,
.studio-page select:focus-visible,
.studio-page input:focus-visible,
.studio-page textarea:focus-visible {
  outline: 3px solid #c18c45;
  outline-offset: 3px;
}
.studio-page button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.studio-page header {
  padding: 14px 28px;
  min-height: 64px;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}
.studio-page header h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  font-size: 20px;
  letter-spacing: -0.7px;
}
.brand-mark {
  color: #d4e7b6;
  font-size: 30px;
  line-height: 1;
}
.brand-tag {
  color: #b4c6b8;
  font-size: 9px;
  letter-spacing: 2px;
  margin: 4px 0 0 8px;
  font-weight: 500;
}
.studio-page .header-right {
  gap: 14px;
}
.studio-page .theme-toggle {
  min-height: 32px;
  font-size: 13px;
  border-color: #52695b;
}
.studio-page .gpu-stats {
  display: none;
}
.studio-page main.studio {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
  gap: 0;
  overflow: visible;
  flex: 1;
}
.studio-page .workspace {
  padding: 24px 32px 20px;
  background: var(--bg);
  border: 0;
  overflow: visible;
  min-width: 0;
}
.workspace-heading {
  margin-bottom: 20px;
}
.eyebrow {
  display: block;
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 1.8px;
  font-weight: 650;
  margin-bottom: 6px;
}
.studio-page h2 {
  font-size: 23px;
  font-weight: 550;
  letter-spacing: -0.6px;
  line-height: 1.25;
}
.workspace-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 auto 16px;
  max-width: 1000px;
  flex-wrap: wrap;
}
.view-switch {
  display: flex;
  padding: 4px;
  gap: 3px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.view-switch button {
  padding: 8px 18px;
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
}
.view-switch button.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 4px #0001;
}
#viewHint {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}
#backendSettings {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.backend-label {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}
#backendSelect {
  max-width: 170px;
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 7px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: 12px;
}
.studio-page .studio-stage {
  width: min(100%, calc(100vh - 330px));
  min-width: 280px;
  max-width: 1000px;
  margin: 0 auto 14px;
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 35px #17251c0a;
  overflow: hidden;
}
.studio-page #sketchCanvas {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 0;
  background: #fff;
  touch-action: none;
}
.studio-page #canvasOverlayImg {
  display: none !important;
}
.studio-page #drawerBtn {
  display: none;
}
.studio-page #outputPreview {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: white;
  min-height: 0;
}
.studio-page #outputPreview > img:not(.overlay-img) {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.studio-stage[data-view="result"] #outputPreview,
.studio-stage[data-view="compare"] #outputPreview,
.studio-stage[data-view="blend"] #outputPreview {
  display: flex !important;
}
.studio-stage[data-view="result"] #sketchCanvas {
  visibility: hidden;
}
.studio-stage[data-view="compare"] #outputPreview {
  clip-path: inset(0 0 0 var(--compare-position, 50%));
  pointer-events: none;
}
.compare-divider {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--compare-position, 50%);
  width: 2px;
  background: #377b62;
  pointer-events: none;
  box-shadow: 0 0 0 1px #fff8;
}
.studio-stage[data-view="compare"] .compare-divider {
  display: block;
}
#compareControls {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto 12px;
  color: var(--text-muted);
  font-size: 12px;
}
#compareControls input {
  flex: 1;
}
.studio-page .canvas-toolbar {
  justify-content: center;
  max-width: 100%;
  margin: 0 auto 8px;
  gap: 6px;
  flex-wrap: wrap;
}
.studio-page .canvas-toolbar .range-row {
  flex: 0 1 120px;
  min-width: 90px;
}
.studio-page .canvas-toolbar-row {
  display: flex;
  gap: 5px;
}
.studio-page .toolbar-overflow {
  display: flex;
  gap: 5px;
  align-items: center;
}
.studio-page #toolbarMoreBtn {
  display: none;
}
.studio-page .tool-btn {
  min-height: 33px;
  padding: 7px 11px;
  font-size: 12px;
  border-radius: 7px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  color: var(--text);
}
.studio-page .tool-btn.active {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}
.studio-page .tool-btn-icon {
  width: auto;
  display: inline-flex;
  gap: 5px;
  align-items: center;
}
.studio-page .tool-btn:hover {
  border-color: var(--text-muted);
}
.studio-page #canvasImgInfo,
.studio-page #outputImgInfo {
  text-align: center;
  max-width: none;
  font-size: 10px;
  margin: 8px 0;
}
.studio-page #queueStatus,
.studio-page #outputStatus {
  text-align: center;
  font-size: 12px;
}
.studio-page #sketchTips {
  max-width: 660px;
  margin: auto;
}
.result-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}
.result-note {
  font-size: 11px;
  color: var(--text-muted);
}
.studio-sidebar {
  border-left: 1px solid var(--border);
  background: var(--panel-bg);
  padding: 25px 22px;
  min-height: 100%;
}
.sidebar-heading {
  margin-bottom: 22px;
}
.studio-sidebar h2 {
  font-size: 21px;
}
.studio-sidebar .form-group {
  margin-bottom: 15px;
}
.studio-sidebar .form-group label {
  font-size: 12px;
  margin-bottom: 8px;
  font-weight: 600;
}
.studio-sidebar textarea {
  min-height: 118px;
  padding: 12px;
  line-height: 1.55;
  font-size: 13px;
  border-radius: 9px;
}
.prompt-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin: -5px 0 22px;
}
.keep-sketch {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
}
.studio-page input[type="range"],
.studio-page input[type="checkbox"] {
  accent-color: var(--accent);
}
.range-captions {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 5px;
}
.generation-actions {
  margin: 20px 0 14px;
}
.studio-page #renderBtn {
  width: 100%;
  padding: 13px 16px;
  border-radius: 9px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  box-shadow: 0 3px 8px #17392712;
}
.live-control {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  font-size: 12px;
  cursor: pointer;
}
.live-control span {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: auto;
}
#renderStatus {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-muted);
  min-height: 32px;
  margin-top: 10px;
}
#advancedControls {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
#advancedControls .checkbox-row {
  display: flex;
  font-size: 12px;
}
.library-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.library-heading h3 {
  font-size: 15px;
  font-weight: 600;
}
.library-heading span,
.preset-library p {
  font-size: 11px;
  color: var(--text-muted);
}
.preset-library {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 20px;
}
.preset-library p {
  margin: 5px 0 14px;
}
.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 12px;
}
.category-tabs button {
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 7px;
  font-size: 11px;
  cursor: pointer;
}
.category-tabs button.active {
  background: var(--preview-bg);
  color: var(--text);
  border-color: var(--border);
}
.studio-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  max-height: 312px;
  overflow-y: auto;
  padding: 3px;
  margin: -3px;
}
.studio-preset {
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: left;
  color: var(--text);
  background: var(--input-bg);
  cursor: pointer;
}
.studio-preset:hover,
.studio-preset[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.studio-preset img {
  display: block;
  width: 100%;
  height: 84px;
  object-fit: contain;
  background: #fefefe;
  padding: 4px;
}
.studio-preset span {
  display: block;
  padding: 8px;
  font-size: 11px;
  font-weight: 550;
}
.studio-page .history-strip {
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  padding: 16px 28px;
}
.studio-page .history-scroll {
  min-height: 65px;
}
.studio-page .variations-strip {
  max-width: 800px;
  margin: 16px auto;
}
.studio-page .progress-bar-container {
  max-width: 600px;
  margin: 12px auto;
}
.studio-page .settings-menu {
  z-index: 100;
}
.studio-page .onboarding-tip {
  background: #203d33;
  color: white;
}
@media (min-width: 1600px) {
  .studio-page main.studio {
    grid-template-columns: minmax(0, 1fr) 370px;
  }
  .studio-page .workspace {
    padding: 28px 48px;
  }
}
@media (max-width: 1100px) {
  #viewHint {
    display: none;
  }
  .studio-page .workspace {
    padding: 20px;
  }
  .studio-page .studio-stage {
    width: 100%;
    min-width: 0;
  }
  .studio-page main.studio {
    grid-template-columns: minmax(0, 1fr) 310px;
  }
  .studio-sidebar {
    padding: 22px 18px;
  }
  .view-switch button {
    padding: 8px 12px;
  }
  .backend-label {
    display: none;
  }
}
@media (max-width: 760px) {
  /* Keep the existing button (including its loading/disabled state) in reach. */
  body.studio-page {
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
  .studio-page .generate-dock {
    position: fixed;
    inset: auto 0 0;
    z-index: 50;
    padding: 12px max(14px, env(safe-area-inset-right, 0px))
      calc(12px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px));
    background: var(--panel-bg);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px #00000012;
  }
  .studio-page .generate-dock #renderBtn {
    min-height: 48px;
    max-width: 560px;
    margin: 0 auto;
  }
  .studio-page main.studio {
    display: flex;
    flex-direction: column;
  }
  .studio-page .workspace {
    width: 100%;
    padding: 18px 14px;
  }
  .studio-sidebar {
    width: 100%;
    padding: 22px 18px;
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  .studio-page header {
    padding: 12px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .studio-page .header-right {
    gap: 9px;
    flex-wrap: wrap;
  }
  .studio-page header h1 {
    font-size: 18px;
  }
  .brand-tag {
    display: none;
  }
  .studio-page .health-indicator {
    font-size: 11px;
  }
  .studio-page h2 {
    font-size: 21px;
  }
  .workspace-heading {
    margin-bottom: 16px;
  }
  .workspace-bar {
    gap: 8px;
  }
  .view-switch button {
    padding: 7px 10px;
    font-size: 12px;
  }
  #backendSelect {
    max-width: 140px;
    font-size: 11px;
    padding: 7px 4px;
  }
  .studio-page .studio-stage {
    width: 100%;
    max-width: 560px;
  }
  .result-note {
    display: none;
  }
  .studio-presets {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: 340px;
  }
  .studio-page .history-strip {
    padding: 16px;
  }
  .studio-page .toolbar-overflow {
    display: flex;
  }
}
@media (prefers-reduced-motion: reduce) {
  .studio-page * {
    animation: none !important;
    transition: none !important;
  }
}
.studio-stage[data-view="compare"] #sketchCanvas {
  pointer-events: none;
}
.studio-page .canvas-toolbar-row {
  flex-basis: auto;
}
.studio-sidebar .assist-btn {
  font-size: 11px;
  padding: 5px 7px;
}
.studio-page .studio-stage {
  width: min(100%, max(460px, calc(100vh - 300px)));
}
@media (max-width: 760px) {
  .studio-page .studio-stage {
    width: 100%;
  }
}
.studio-page .canvas-toolbar .range-row input {
  min-width: 0;
  width: 100%;
}

/* Blend preserves drawing input beneath the live result layer. */
.studio-stage[data-view="blend"] #outputPreview {
  opacity: var(--blend-opacity, 0.8);
  pointer-events: none;
}
#blendControls {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto 12px;
  font-size: 12px;
  color: var(--text-muted);
}
#blendControls input {
  flex: 1;
  min-width: 0;
}
#blendValue {
  min-width: 35px;
  text-align: right;
}

@media (max-width: 760px) {
  /* Put the two primary controls before the canvas in the initial phone view. */
  .studio-sidebar {
    display: contents;
  }
  .prompt-panel {
    order: 0;
    width: 100%;
    padding: 16px 18px 8px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border);
  }
  .studio-page .workspace {
    order: 1;
  }
  .sidebar-secondary {
    order: 2;
    width: 100%;
    padding: 16px 18px;
    background: var(--panel-bg);
  }
  .prompt-panel .sidebar-heading {
    margin-bottom: 10px;
  }
  .prompt-panel .sidebar-heading .eyebrow {
    display: none;
  }
  .prompt-panel textarea {
    min-height: 76px;
    height: 76px;
  }
  .prompt-panel .form-group {
    margin-bottom: 10px;
  }
  .prompt-panel .prompt-actions {
    margin: 0 0 14px;
  }
  .studio-page .workspace-heading {
    display: none;
  }
}
