:root {
  color-scheme: light;
  --bg-linen: #f3ede3;
  --bg-panel: #fcf9f4;
  --bg-stage: #e5ddd0;
  --bg-well: #efe8dd;
  --border-soft: #d6cbbd;
  --border-control: #8a7b6d;
  --ink-espresso: #28211c;
  --ink-stone: #5f554d;
  --accent-taupe: #7a5641;
  --accent-taupe-hover: #634432;
  --accent-blush: #efe5dc;
  --sage-ink: #3c5440;
  --error-ink: #9c2b23;
  --error-bg: #fae9e7;
  --focus-ring: #5a3d2c;
}

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

body {
  margin: 0;
  min-block-size: 100dvb;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink-espresso);
  background: var(--bg-linen);
  accent-color: var(--accent-taupe);
  line-height: 1.5;
  text-align: start;
}

canvas,
img,
video {
  display: block;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  inline-size: 1px !important;
  block-size: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.studio-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 23rem;
  grid-template-areas:
    "topbar topbar"
    "stage  controls";
  grid-template-rows: auto minmax(0, 1fr);
  block-size: 100dvb;
  overflow: clip;
}

.hidden-video {
  position: fixed;
  inset-block-start: 0;
  inset-inline-start: 0;
  inline-size: 4px;
  block-size: 4px;
  opacity: 0.001;
  pointer-events: none;
}

.topbar {
  grid-area: topbar;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1.25rem;
  padding-block: 0.65rem;
  padding-inline: 1.35rem;
  background: var(--bg-panel);
  border-block-end: 1px solid var(--border-soft);
}

.brand-mark {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
}

.brand-home {
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-taupe);
  text-decoration: none;
}

.brand-home:hover,
.brand-home:focus-visible {
  text-decoration: underline;
  text-underline-offset: 0.22rem;
}

.brand-title {
  margin: 0;
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--ink-espresso);
}

.brand-scene {
  font-size: 0.88rem;
  color: var(--ink-stone);
}

.topbar-actions {
  margin-inline-start: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.stage-pane {
  grid-area: stage;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 1.4rem;
  background: var(--bg-stage);
  min-inline-size: 0;
}

.canvas-frame {
  position: relative;
  display: grid;
  place-items: center;
  max-inline-size: 100%;
  max-block-size: calc(100dvb - 9.5rem);
  border-radius: 0.85rem;
  overflow: clip;
  box-shadow: 0 20px 48px rgb(40 33 28 / 0.16);
  border: 1px solid var(--border-soft);
  background: var(--bg-panel);
}

.canvas-frame.is-dragover {
  outline: 3px dashed var(--accent-taupe);
  outline-offset: -4px;
}

#previewCanvas {
  max-inline-size: 100%;
  max-block-size: calc(100dvb - 9.75rem);
  inline-size: auto;
  block-size: auto;
  cursor: grab;
  touch-action: none;
}

#previewCanvas.is-over-art {
  cursor: move;
}

#previewCanvas.is-dragging {
  cursor: grabbing;
}

.stage-hint {
  margin: 0;
  font-size: 0.86rem;
  color: var(--ink-espresso);
  text-align: center;
}

.controls-pane {
  grid-area: controls;
  background: var(--bg-panel);
  border-inline-start: 1px solid var(--border-soft);
  padding: 0.78rem 1.05rem;
  display: flex;
  flex-direction: column;
  gap: 0.58rem;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  min-inline-size: 0;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 0.36rem;
  padding-block-end: 0.58rem;
  border-block-end: 1px solid var(--border-soft);
}

.panel-section:last-of-type {
  border-block-end: 0;
  padding-block-end: 0;
}

.section-heading {
  margin: 0;
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--ink-espresso);
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding-block: 1rem;
  padding-inline: 0.9rem;
  border: 2px dashed var(--border-control);
  border-radius: 0.7rem;
  background: var(--bg-well);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent-taupe);
  background: var(--accent-blush);
}

.dropzone:focus-within {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.dropzone-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone-title {
  font-weight: 600;
  font-size: 0.92rem;
}

.dropzone-sub {
  font-size: 0.8rem;
  color: var(--ink-stone);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--border-control);
  border-radius: 999px;
  padding-block: 0.48rem;
  padding-inline: 0.95rem;
  min-block-size: 2.25rem;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  background: var(--bg-panel);
  color: var(--ink-espresso);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: var(--bg-well);
}

.btn-quiet {
  border-color: transparent;
  background: var(--bg-well);
}

.btn-quiet:hover:not(:disabled) {
  background: var(--bg-stage);
}

.btn:focus-visible,
.brand-home:focus-visible,
.dialog-close:focus-visible,
.text-input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-taupe);
  border-color: var(--accent-taupe);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-taupe-hover);
  border-color: var(--accent-taupe-hover);
}

.btn-block {
  inline-size: 100%;
  padding-block: 0.62rem;
}

.aspect-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.aspect-option {
  position: relative;
}

.aspect-radio {
  position: absolute;
  opacity: 0;
  inline-size: 1px;
  block-size: 1px;
}

.aspect-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-block: 0.45rem;
  padding-inline: 0.35rem;
  border: 1px solid var(--border-control);
  border-radius: 0.65rem;
  background: var(--bg-panel);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.aspect-label small {
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--ink-stone);
}

.aspect-label.is-locked::after {
  content: "Code locked";
  margin-block-start: 0.15rem;
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--accent-taupe);
}

.aspect-radio:checked + .aspect-label {
  background: var(--accent-blush);
  border-color: var(--accent-taupe);
  color: var(--accent-taupe-hover);
}

.aspect-radio:focus-visible + .aspect-label {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.slider-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

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

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.84rem;
}

.slider-val {
  color: var(--ink-stone);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  inline-size: 100%;
  margin: 0;
  cursor: pointer;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.export-progress {
  inline-size: 100%;
  block-size: 10px;
  appearance: none;
  border: 0 solid;
  border-radius: 1e5px;
  background: var(--bg-well);
  overflow: clip;
  box-shadow: inset 0 1px 2px rgb(40 33 28 / 0.12);
}

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

.export-progress::-webkit-progress-bar {
  background: transparent;
}

.export-progress::-webkit-progress-value {
  background: var(--accent-taupe);
  border-radius: 1e5px;
  transition: inline-size 0.15s ease;
}

.export-progress::-moz-progress-bar {
  background: var(--accent-taupe);
  border-radius: 1e5px;
}

.status-line {
  margin: 0;
  min-block-size: 1.25em;
  font-size: 0.82rem;
  color: var(--ink-stone);
}

/* Unlock modal styling */
.unlock-dialog {
  inline-size: min(100% - 2rem, 28rem);
  border: 1px solid var(--border-control);
  border-radius: 1rem;
  background: var(--bg-panel);
  color: var(--ink-espresso);
  padding: 1.45rem;
  box-shadow: 0 24px 60px rgb(40 33 28 / 0.25);
}

.unlock-dialog::backdrop {
  background: rgb(40 33 28 / 0.45);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-block-end: 0.6rem;
}

.dialog-title {
  margin: 0;
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  font-size: 1.28rem;
}

.dialog-close {
  appearance: none;
  border: 1px solid var(--border-soft);
  background: var(--bg-well);
  color: var(--ink-espresso);
  border-radius: 999px;
  min-inline-size: 2.1rem;
  min-block-size: 2.1rem;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

.dialog-intro {
  margin: 0 0 0.9rem;
  font-size: 0.92rem;
  color: var(--ink-stone);
  text-wrap: pretty;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-block-end: 0.7rem;
}

.field-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.field-hint {
  font-size: 0.82rem;
  color: var(--ink-stone);
}

.text-input {
  inline-size: 100%;
  min-block-size: 2.55rem;
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--border-control);
  border-radius: 0.55rem;
  background: #ffffff;
  color: var(--ink-espresso);
  text-transform: uppercase;
}

.error-msg {
  display: none;
  color: var(--error-ink);
  font-size: 0.84rem;
  font-weight: 500;
}

.error-msg [role="img"] {
  display: inline-grid;
  place-items: center;
  inline-size: 1.1rem;
  block-size: 1.1rem;
  border-radius: 999px;
  background: var(--error-ink);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  margin-inline-end: 0.25rem;
}

:is(.text-input:user-invalid, .text-input.user-invalid-fallback) {
  border-color: var(--error-ink);
  background: var(--error-bg);
}

:is(.text-input:user-invalid, .text-input.user-invalid-fallback) + .error-msg {
  display: block;
}

.text-input:user-valid {
  border-color: var(--sage-ink);
}

.dialog-status {
  margin: 0 0 0.8rem;
  min-block-size: 1.25em;
  font-size: 0.86rem;
  color: var(--ink-stone);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.6rem;
}

@supports not (accent-color: #7a5641) {
  input[type="range"] {
    appearance: none;
    background: transparent;
  }

  input[type="range"]::-webkit-slider-runnable-track {
    block-size: 6px;
    background: var(--border-soft);
    border-radius: 999px;
  }

  input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    inline-size: 16px;
    block-size: 16px;
    border-radius: 50%;
    background: var(--accent-taupe);
    margin-block-start: -5px;
  }

  input[type="range"]::-moz-range-track {
    block-size: 6px;
    background: var(--border-soft);
    border-radius: 999px;
  }

  input[type="range"]::-moz-range-thumb {
    inline-size: 16px;
    block-size: 16px;
    border: 0;
    border-radius: 50%;
    background: var(--accent-taupe);
  }
}

@media (max-width: 920px) {
  .studio-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "stage"
      "controls";
    grid-template-rows: auto auto 1fr;
    block-size: auto;
    min-block-size: 100dvb;
    overflow: visible;
  }

  .controls-pane {
    border-inline-start: 0;
    border-block-start: 1px solid var(--border-soft);
  }

  #previewCanvas,
  .canvas-frame {
    max-block-size: 56dvb;
  }
}

@media (forced-colors: active) {
  .btn,
  .aspect-label,
  .dropzone,
  .unlock-dialog,
  .text-input {
    border: 1px solid CanvasText;
  }

  .btn-primary {
    background: Highlight;
    color: HighlightText;
  }
}
