:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --background: #181818;
  --panel: #202020;
  --panel-raised: #282828;
  --viewport: #0e0e0e;
  --border: #383838;
  --border-strong: #505050;
  --muted: #999;
  --text: #e4e4e4;
  --cyan: #4dd0e1;
  --danger: #ff8c82;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--background);
}

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  flex-direction: column;
  color: var(--text);
}

button,
input {
  font: inherit;
}

button,
input,
pre,
a {
  outline: none;
}

button:focus-visible,
input:focus-visible,
pre:focus-visible,
a:focus-visible {
  box-shadow: 0 0 0 2px rgba(77, 208, 225, 0.58);
}

a {
  color: var(--cyan);
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.55rem 0.75rem;
  color: #071113;
  background: var(--cyan);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-toolbar {
  display: flex;
  min-height: 2.75rem;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.55rem;
  background: #1b1b1b;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  gap: 0.55rem;
  align-items: center;
  color: var(--text);
  font-size: 0.93rem;
  font-weight: 650;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 1.75rem;
  height: 1.75rem;
  place-items: center;
  color: #071113;
  background: var(--cyan);
  border-radius: 0.16rem;
  font: 800 0.72rem/1 ui-monospace, monospace;
}

.brand-home {
  color: var(--cyan);
}

.toolbar-actions,
.actions,
.preview-title {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.toolbar-separator {
  width: 1px;
  height: 1.4rem;
  margin: 0 0.2rem;
  background: var(--border);
}

.local-badge {
  color: #9ab0b3;
  font-size: 0.7rem;
}

.button,
.text-button {
  min-height: 1.95rem;
  padding: 0.35rem 0.65rem;
  color: var(--text);
  cursor: pointer;
  background: #303030;
  border: 1px solid #4a4a4a;
  border-radius: 0.15rem;
  font-size: 0.74rem;
}

.button:hover:not(:disabled),
.text-button:hover:not(:disabled) {
  background: #3b3b3b;
  border-color: #626262;
}

.button:active:not(:disabled),
.text-button:active:not(:disabled) {
  background: #252525;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.text-button {
  min-height: auto;
  padding: 0.2rem 0.35rem;
  color: #b8c8ca;
  background: transparent;
  border-color: transparent;
}

.editor-shell {
  min-height: 0;
  flex: 1;
  padding: 1px;
  overflow: hidden;
  background: var(--border);
}

.workspace-grid {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-areas:
    "source settings"
    "preview settings";
  grid-template-columns: minmax(0, 1fr) minmax(285px, 340px);
  grid-template-rows: minmax(230px, 42%) minmax(260px, 1fr);
  gap: 1px;
  background: var(--border);
}

.panel {
  min-width: 0;
  min-height: 0;
  padding: 0.65rem;
  overflow: hidden;
  background: var(--panel);
}

.source-panel {
  display: flex;
  grid-area: source;
  flex-direction: column;
}

.settings-panel {
  grid-area: settings;
  overflow-y: auto;
  scrollbar-color: #555 #1c1c1c;
}

.output-panel {
  display: flex;
  grid-area: preview;
  flex-direction: column;
}

.panel-heading {
  display: flex;
  min-height: 2rem;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin: -0.1rem 0 0.5rem;
}

.panel h1,
.panel h2 {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 560;
}

.metadata {
  color: var(--muted);
  font: 0.68rem/1.35 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.source-stage {
  position: relative;
  display: grid;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  place-items: center;
  background:
    linear-gradient(45deg, #131313 25%, transparent 25%),
    linear-gradient(-45deg, #131313 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #131313 75%),
    linear-gradient(-45deg, transparent 75%, #131313 75%),
    var(--viewport);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  border: 1px solid #303030;
}

.source-stage.is-dragging {
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px var(--cyan);
}

.drop-zone {
  display: grid;
  width: min(28rem, calc(100% - 2rem));
  max-width: 100%;
  min-height: 8rem;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.9rem;
  align-items: center;
  padding: 1rem;
  color: var(--text);
  cursor: pointer;
  background: rgba(27, 27, 27, 0.93);
  border: 1px dashed #59676a;
  border-radius: 0.2rem;
  text-align: left;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  background: #242b2c;
  border-color: var(--cyan);
}

.drop-zone strong,
.drop-zone span {
  display: block;
}

.drop-zone strong {
  margin-bottom: 0.3rem;
  font-size: 0.86rem;
}

.drop-zone .drop-copy > span {
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.45;
}

.drop-icon {
  display: grid !important;
  width: 2rem;
  height: 2rem;
  place-items: center;
  color: var(--cyan);
  border: 1px solid #43757a;
  border-radius: 50%;
  font: 300 1.3rem/1 ui-monospace, monospace;
}

.source-preview {
  position: absolute;
  inset: 0;
  display: grid;
  margin: 0;
  place-items: center;
}

.source-preview[hidden],
.drop-zone[hidden] {
  display: none;
}

.source-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.source-preview figcaption {
  position: absolute;
  right: 0.45rem;
  bottom: 0.4rem;
  max-width: calc(100% - 0.9rem);
  padding: 0.22rem 0.4rem;
  overflow: hidden;
  color: #c9d1d2;
  background: rgba(10, 10, 10, 0.78);
  font: 0.66rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls {
  display: grid;
  gap: 0.8rem;
  margin: 0;
  padding: 0.75rem 0 0.9rem;
  border: 0;
  border-top: 1px solid var(--border);
}

.controls legend {
  padding: 0 0.4rem 0 0;
  color: #c9c9c9;
  font-size: 0.74rem;
  font-weight: 600;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.field-header {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  color: #d0d0d0;
  font-size: 0.72rem;
}

.field-header > span:last-child {
  color: var(--muted);
  font-size: 0.65rem;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  color: var(--text);
  background: #101010;
  border: 1px solid #484848;
  border-radius: 0.12rem;
}

input[type="text"] {
  padding: 0.45rem 0.5rem;
  font: 0.78rem/1.25 ui-monospace, SFMono-Regular, Consolas, monospace;
}

input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--cyan);
}

.field small,
.matte-field small {
  color: var(--muted);
  font-size: 0.63rem;
}

.number-label {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.64rem;
}

.number-label input {
  width: 4rem;
  padding: 0.28rem 0.35rem;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  height: 0.85rem;
  margin: 0;
  accent-color: var(--cyan);
  cursor: pointer;
}

.tone-controls {
  gap: 0.48rem;
}

.slider-field {
  display: grid;
  grid-template-columns: 5.4rem minmax(5rem, 1fr) 2.65rem;
  gap: 0.45rem;
  align-items: center;
  color: #c8c8c8;
  font-size: 0.67rem;
}

.slider-field output {
  color: #aebabc;
  font: 0.64rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-align: right;
}

.red-control input {
  accent-color: #e66b62;
}

.green-control input {
  accent-color: #70c98b;
}

.blue-control input {
  accent-color: #68a5ed;
}

.matte-field {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.25rem;
  color: #c8c8c8;
  font-size: 0.67rem;
}

.matte-field span,
.matte-field small {
  display: block;
}

input[type="color"] {
  width: 2.2rem;
  height: 1.55rem;
  padding: 0.1rem;
  cursor: pointer;
  background: #111;
  border: 1px solid #555;
  border-radius: 0.12rem;
}

.field-error {
  min-height: 1rem;
  margin: 0;
  color: var(--danger);
  font-size: 0.67rem;
}

.output-heading {
  flex: 0 0 auto;
}

.preview-shell {
  position: relative;
  display: grid;
  min-height: 0;
  flex: 1;
  overflow: auto;
  background: #080808;
  border: 1px solid #303030;
  scrollbar-color: #555 #151515;
}

.preview-shell pre {
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0.7rem;
  color: #f0f0f0;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: var(--preview-font-size, 11px);
  font-variant-ligatures: none;
  line-height: 0.94;
  tab-size: 1;
  white-space: pre;
  transition: opacity 100ms ease;
}

.preview-shell pre.is-stale {
  opacity: 0.42;
}

.empty-preview {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  color: #6f6f6f;
  text-align: center;
  pointer-events: none;
}

.empty-preview span {
  color: #7bbbc3;
  font: 0.9rem/1 ui-monospace, monospace;
  letter-spacing: 0.14em;
}

.empty-preview p {
  margin: 0.65rem 0 0;
  font-size: 0.7rem;
}

.preview-shell:not([data-empty="true"]) .empty-preview {
  display: none;
}

.status {
  min-height: 1rem;
  margin: 0.45rem 0 -0.1rem;
  color: var(--muted);
  font-size: 0.67rem;
}

.status[data-kind="success"] {
  color: #88d3a1;
}

.status[data-kind="error"] {
  color: var(--danger);
}

.app-statusbar {
  display: flex;
  min-height: 1.7rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.6rem;
  color: #8b8b8b;
  background: #191919;
  border-top: 1px solid var(--border);
  font-size: 0.65rem;
}

.app-statusbar a {
  color: #a8b8ba;
}

.statusbar-links {
  display: inline-flex;
  gap: 0.85rem;
  align-items: center;
}

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

@media (max-width: 900px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .editor-shell {
    overflow: visible;
  }

  .workspace-grid {
    height: auto;
    grid-template-areas:
      "source"
      "settings"
      "preview";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(300px, 48vh) auto minmax(360px, 55vh);
  }

  .settings-panel {
    overflow: visible;
  }
}

@media (max-width: 560px) {
  .app-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-actions {
    width: 100%;
  }

  .local-badge {
    margin-left: auto;
  }

  .panel {
    padding: 0.5rem;
  }

  .panel-heading.output-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    width: 100%;
  }

  .actions .button {
    flex: 1;
  }

  .slider-field {
    grid-template-columns: 4.8rem minmax(4rem, 1fr) 2.55rem;
  }

  .app-statusbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
