:root {
  color-scheme: dark;
  --bg: #08090b;
  --panel: #111418;
  --panel-2: #191e24;
  --text: #f4f0e8;
  --muted: #a9a39a;
  --line: #2f353d;
  --accent: #61e0ff;
  --hot: #ff4f9a;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 79, 154, 0.16), transparent 25%),
    radial-gradient(circle at 72% 22%, rgba(97, 224, 255, 0.14), transparent 26%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.stage {
  display: grid;
  place-items: center;
  min-width: 0;
  overflow: hidden;
}

.canvas-shell {
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

#mosaic {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  transform-origin: top left;
  background: #050607;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.45);
}

.panel {
  align-self: start;
  display: grid;
  gap: 10px;
  padding: 14px;
  background: color-mix(in srgb, var(--panel), transparent 4%);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.project-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.project-links a {
  display: inline-grid;
  min-height: 32px;
  place-items: center;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  text-decoration: none;
}

.project-links a:hover {
  border-color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 108px;
  gap: 12px;
  align-items: start;
}

.brand p {
  margin: 6px 0 0;
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.language-control {
  align-self: start;
}

.control-group {
  display: grid;
  gap: 7px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.section-title {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.section-help {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
}

.section-help a {
  color: var(--accent);
  text-decoration: none;
}

.section-help a:hover {
  text-decoration: underline;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hint {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  margin-left: 4px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  vertical-align: 1px;
}

output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.value-field {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.numeric-input {
  width: 46px;
  min-height: 0;
  height: 24px;
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  -moz-appearance: textfield;
}

.numeric-input::-webkit-outer-spin-button,
.numeric-input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.numeric-input:hover,
.numeric-input:focus {
  border-color: var(--accent);
  outline: none;
}

.value-unit {
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

select,
button,
.upload {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

select {
  padding: 7px 9px;
}

input[type="color"] {
  width: 38px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  cursor: pointer;
}

.channel-controls {
  display: grid;
  gap: 6px;
}

.channel-row {
  grid-template-columns: minmax(72px, 0.7fr) 42px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.channel-row select {
  min-height: 32px;
}

button,
.upload {
  display: inline-grid;
  place-items: center;
  padding: 8px 10px;
  cursor: pointer;
}

button:hover,
.upload:hover,
select:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.upload {
  background:
    linear-gradient(135deg, rgba(255, 79, 154, 0.18), rgba(97, 224, 255, 0.16)),
    var(--panel-2);
  color: var(--text);
  text-align: center;
}

.upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#downloadPng,
#downloadVideo,
#downloadEmbed {
  grid-column: span 2;
}

.video-dialog {
  width: min(360px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.video-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.dialog-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-button {
  width: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.dialog-actions {
  justify-content: flex-end;
}

.dialog-actions button {
  width: auto;
  min-width: 150px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .stage {
    min-height: min(58vh, 520px);
  }

  .panel {
    align-self: auto;
    gap: 12px;
  }
}

@media (max-width: 460px) {
  .app-shell {
    gap: 10px;
    padding: 10px;
  }

  .stage {
    min-height: 260px;
  }

  .panel {
    padding: 12px;
  }

  .brand {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .language-control {
    width: 100%;
  }

  .control-group,
  .project-links {
    gap: 9px;
    padding-top: 12px;
  }

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

  #downloadPng,
  #downloadVideo,
  #downloadEmbed {
    grid-column: auto;
  }
}
