:root {
  --desk: #eef0f3;
  --paper: #ffffff;
  --ink: #1e5adc;
  --ink-dark: #1647b3;
  --graphite: #1f2430;
  --muted: #5f6673;
  --rule: #d6dae1;
  --radius-control: 6px;
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--graphite);
  background: var(--desk);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "toolbar toolbar"
    "panel   stage";
  height: 100vh;
  height: 100dvh;
}

/* Toolbar ---------------------------------------------------------- */

.toolbar {
  grid-area: toolbar;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 24px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--rule);
}

.title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.export-group {
  display: flex;
}

.export-group .btn {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.export-group .select {
  border-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* Controls --------------------------------------------------------- */

.btn,
.select {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--graphite);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  padding: 7px 14px;
  cursor: pointer;
}

.select {
  padding-right: 10px;
}

.btn:hover:not(:disabled),
.select:hover:not(:disabled) {
  border-color: #b9bfc9;
}

.btn:disabled,
.select:disabled {
  cursor: default;
  opacity: 0.55;
}

.btn-primary {
  width: 100%;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

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

:focus-visible,
.color-btn:has(input:focus-visible) {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.color-btn {
  position: relative;
  display: inline-block;
  background: var(--ink);
  border-color: transparent;
  color: #fff;
}

.color-btn input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--ink);
}

/* Side panel ------------------------------------------------------- */

.panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  overflow-y: auto;
}

.field-label {
  display: block;
  margin-bottom: -10px;
  font-weight: 600;
  font-size: 14px;
}

textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  font: inherit;
  font-size: 15px;
  color: var(--graphite);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  padding: 10px 12px;
}

.slider label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  font-weight: 600;
}

.slider output {
  font-weight: 400;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.slider input[type="range"] {
  width: 100%;
  margin: 8px 0 0;
  accent-color: var(--ink);
}

.panel-foot {
  margin-top: auto;
}

.hint {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* Stage ------------------------------------------------------------ */

.stage {
  grid-area: stage;
  position: relative;
  margin: 0 20px 20px 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
}

#stage-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.status {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 12px;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
}

.stage.dark .status { color: #a9afba; }

.status.error { color: #b3261e; }
.stage.dark .status.error { color: #ff8a80; }

.export-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(340px, calc(100% - 32px));
  padding: 20px 22px;
  background: var(--paper);
  color: var(--graphite);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(31, 36, 48, 0.16);
  text-align: center;
}

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

.export-title {
  margin: 0 0 14px;
  font-weight: 600;
}

.bar {
  height: 6px;
  background: var(--desk);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  width: 0;
  height: 100%;
  background: var(--ink);
  transition: width 0.15s linear;
}

.export-note {
  margin: 8px 0 14px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Phones and narrow windows: paper on top, controls below --------- */

@media (max-width: 760px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 46vh auto;
    grid-template-areas:
      "toolbar"
      "stage"
      "panel";
    height: auto;
    min-height: 100vh;
  }

  .toolbar { padding: 10px 14px; }
  .stage { margin: 12px 14px 0; }
  .panel { padding: 16px 14px 24px; overflow: visible; }
  textarea { min-height: 100px; }
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}

/* Server version: the preview is a video ------------------------------ */

#preview {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 32px);
  max-height: calc(100% - 64px);
  object-fit: contain;
  background: transparent;
}

#preview[hidden] { display: none; }

.empty-note {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  margin: 0;
  padding: 0 24px;
  text-align: center;
  color: var(--muted);
}

.stage.dark .empty-note { color: #a9afba; }

.examples {
  max-width: 180px;
}

#preview { cursor: pointer; }

/* Stop / Pause / Resume while playing, Replay when finished */
.player-controls {
  position: absolute;
  right: 14px;
  bottom: 10px;
  display: flex;
  gap: 8px;
}

.player-btn {
  padding: 5px 12px;
  font-size: 13px;
}

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