:root {
  --bg: #0a0c14;
  --bg-raised: #12151f;
  --panel: rgba(22, 26, 38, 0.82);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e8ecf5;
  --text-dim: #949cb0;
  --accent: #7cf5c4;
  --accent-ink: #06251b;
  --danger: #ff7a7a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1100px 600px at 12% -8%, rgba(124, 245, 196, 0.09), transparent 60%),
    radial-gradient(900px 520px at 105% 5%, rgba(122, 160, 255, 0.09), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ------------------------------ top bar ------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 20, 0.7);
  backdrop-filter: blur(14px);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--accent);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand svg {
  width: 26px;
  height: 26px;
}

.brand-name {
  color: var(--text);
  font-size: 16px;
}

.title-input {
  flex: 1;
  min-width: 0;
  max-width: 420px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 7px 10px;
  font-size: 15px;
  font-weight: 500;
}

.title-input:hover {
  border-color: var(--border);
}

.title-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-state {
  color: var(--text-dim);
  font-size: 12.5px;
  min-width: 74px;
  text-align: right;
}

/* ------------------------------ layout ------------------------------ */

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 306px;
  gap: 14px;
  padding: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
  box-shadow: var(--shadow);
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.panel h2 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  font-weight: 650;
}

.panel-section + .panel-section {
  padding-top: 15px;
  border-top: 1px solid var(--border);
}

.stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.canvas-frame {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  place-items: center;
  position: relative;
  /* The canvas is sized in JS from this box; it must not size the box. */
  overflow: hidden;
}

#board {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  touch-action: none;
  cursor: crosshair;
  display: block;
}

.empty-hint {
  position: absolute;
  inset: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  color: var(--text-dim);
  text-align: center;
  transition: opacity 0.25s;
}

.empty-hint strong {
  color: var(--text);
  font-size: 17px;
}

.empty-hint[hidden] {
  display: none;
}

/* ------------------------------ transport ------------------------------ */

.transport {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.scrub {
  flex: 1;
  min-width: 60px;
}

.time {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
}

/* ------------------------------ controls ------------------------------ */

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.field-label output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.inline {
  display: flex;
  gap: 10px;
  align-items: center;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
}

select,
input[type="password"],
input[type="text"] {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  font-size: 13.5px;
}

select:focus,
input:focus {
  outline: 2px solid rgba(124, 245, 196, 0.4);
  outline-offset: 1px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  box-shadow: 0 0 0 3px rgba(124, 245, 196, 0.18);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}

input[type="color"] {
  width: 100%;
  height: 34px;
  padding: 2px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.mini {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
}

.mini input[type="color"] {
  width: 44px;
  height: 26px;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
}

.hint code {
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 11.5px;
}

/* ------------------------------ buttons ------------------------------ */

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    transform 0.06s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}

.btn.primary:hover:not(:disabled) {
  background: #96ffd6;
  border-color: transparent;
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 6px 11px;
  font-size: 12.5px;
}

.btn.danger {
  color: var(--danger);
  border-color: rgba(255, 122, 122, 0.35);
}

.btn.wide {
  flex: 1;
}

.btn.icon {
  padding: 7px;
  width: 34px;
  height: 34px;
}

.btn.icon svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.btn.play {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  flex: 0 0 auto;
}

.btn.play:hover:not(:disabled) {
  background: #96ffd6;
}

.btn.play svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

/* The `hidden` IDL property does not reflect to the attribute on SVG
   elements, so the icon swap is driven by a class on the button. */
.btn.play .icon-pause,
.btn.play.is-playing .icon-play {
  display: none;
}

.btn.play.is-playing .icon-pause {
  display: block;
}

.tool-row {
  display: flex;
  gap: 7px;
}

.tool-row.wrap {
  flex-wrap: wrap;
}

.tool {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 5px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.tool svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.tool:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.tool.is-active {
  color: var(--accent);
  border-color: rgba(124, 245, 196, 0.45);
  background: rgba(124, 245, 196, 0.12);
}

.swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.swatch {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s;
}

.swatch:hover {
  transform: scale(1.14);
}

.swatch.is-active {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5);
}

/* ------------------------------ export ------------------------------ */

.progress {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: var(--text-dim);
}

.progress-bar {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.progress-bar > div {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.14s linear;
}

.result {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
}

.result video {
  width: 100%;
  border-radius: 8px;
  background: #000;
  display: block;
}

.result-actions {
  display: flex;
  gap: 7px;
}

/* ------------------------------ dialogs ------------------------------ */

.dialog {
  width: min(920px, 92vw);
  max-height: 84vh;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  padding: 0;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.dialog.narrow {
  width: min(430px, 92vw);
}

.dialog::backdrop {
  background: rgba(4, 6, 12, 0.72);
  backdrop-filter: blur(3px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}

.dialog-head h2 {
  margin: 0;
  font-size: 15px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}

.dialog-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gallery-body {
  padding: 18px;
  overflow-y: auto;
  max-height: 68vh;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 13px;
  color: var(--text-dim);
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s;
}

.card:hover {
  border-color: var(--accent);
}

.card-thumb {
  aspect-ratio: 16 / 10;
  background: #0b0e17 center/cover no-repeat;
  border: none;
  padding: 0;
  cursor: pointer;
  display: block;
  width: 100%;
}

.card-body {
  padding: 9px 11px 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.card-title {
  color: var(--text);
  font-size: 13.5px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  font-size: 11.5px;
  color: var(--text-dim);
}

.card-actions {
  display: flex;
  gap: 6px;
  margin-top: 7px;
}

/* ------------------------------ toast ------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 24px);
  background: #1b2030;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 11px 17px;
  border-radius: 11px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.22s,
    transform 0.22s;
  z-index: 50;
  max-width: min(520px, 90vw);
  font-size: 13.5px;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-error {
  border-color: rgba(255, 122, 122, 0.55);
}

/* ------------------------------ view mode ------------------------------ */

body.view-mode .tools,
body.view-mode .settings,
body.view-mode .title-input,
/* A share link is someone else's drawing: saving would overwrite it. */
body.view-mode #saveBtn,
body.view-mode .save-state {
  display: none;
}

body.view-mode .workspace {
  grid-template-columns: minmax(0, 1fr);
}

/* ------------------------------ responsive ------------------------------ */

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "tools" "settings";
  }

  .stage {
    grid-area: stage;
  }

  .tools {
    grid-area: tools;
  }

  .settings {
    grid-area: settings;
  }

  .panel {
    overflow: visible;
  }
}

@media (max-width: 620px) {
  .topbar {
    flex-wrap: wrap;
  }

  .title-input {
    order: 3;
    max-width: none;
    flex-basis: 100%;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }
}
