:root {
  color-scheme: dark;
  --bg: #080a09;
  --panel: #101411;
  --panel-2: #151a16;
  --line: #29352d;
  --text: #f2f5f3;
  --muted: #99a49d;
  --accent: #73df9a;
  --accent-soft: #b8f7cc;
  --radius: 18px;
  --dock-height: 32dvh;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(circle at 16% 0%, rgba(72, 155, 100, .09), transparent 30rem),
    var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }

.app {
  width: min(1260px, calc(100% - 22px));
  margin: 0 auto;
  padding: 18px 0 calc(28px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 4vw, 2.15rem);
  font-weight: 800;
  letter-spacing: .12em;
  font-variant: all-small-caps;
}

.top-actions, .output-actions {
  display: flex;
  gap: 8px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(15, 20, 17, .96);
  box-shadow: 0 20px 55px rgba(0, 0, 0, .22);
}

.source-panel { padding: 14px 18px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  align-items: start;
  gap: 14px;
  margin-top: 14px;
}

.controls {
  min-width: 0;
  padding: 6px 16px 16px;
}

details {
  padding: 3px 0 11px;
  border-bottom: 1px solid var(--line);
}

details:last-child { border-bottom: 0; }

summary {
  padding: 13px 0 9px;
  color: var(--accent-soft);
  font-size: .9rem;
  font-weight: 800;
  letter-spacing: .13em;
  font-variant: all-small-caps;
  cursor: pointer;
  user-select: none;
}

.field, .range-field {
  display: grid;
  gap: 7px;
  margin: 11px 0;
}

.field > span,
.range-field > span,
.mini-label {
  color: var(--muted);
  font-size: .84rem;
  font-weight: 650;
  letter-spacing: .035em;
}

.range-field > span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

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

textarea,
select,
input[type="number"],
input[type="text"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  background: var(--panel-2);
  color: var(--text);
}

textarea {
  resize: vertical;
  padding: 12px 13px;
  line-height: 1.45;
}

select,
input[type="number"],
input[type="text"] { padding: 0 12px; }

textarea:focus,
select:focus,
input[type="number"]:focus,
input[type="text"]:focus {
  border-color: color-mix(in srgb, var(--accent) 65%, var(--line));
  box-shadow: 0 0 0 3px rgba(115, 223, 154, .08);
}

input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(115, 223, 154, .52), rgba(115, 223, 154, .06)),
    var(--panel-2);
}

input[type="range"]::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -7px;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 9px;
  background: var(--accent);
}

input[type="range"]::-moz-range-track {
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
}

input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 9px;
  background: var(--accent);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: var(--muted);
  font-size: .86rem;
  cursor: pointer;
}

.check-row input {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

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

.button {
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 800;
  letter-spacing: .08em;
  font-variant: all-small-caps;
  cursor: pointer;
}

.button:active { transform: scale(.98); }

.button.primary {
  border-color: rgba(115, 223, 154, .52);
  background: var(--accent);
  color: #071008;
}

.button.compact { padding-inline: 13px; }

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.3rem;
}

.note {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.42;
}

.output-panel {
  min-width: 0;
  padding: 14px;
}

.output-panel.fixed {
  position: sticky;
  top: 10px;
  max-height: calc(100dvh - 20px);
  overflow: auto;
}

.output-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-title {
  color: var(--accent-soft);
  font-size: .9rem;
  font-weight: 800;
  letter-spacing: .14em;
  font-variant: all-small-caps;
}

.stats {
  max-width: 52ch;
  margin-top: 3px;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.35;
}

.preview {
  min-height: 250px;
  max-height: 48dvh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    #090c0a;
  background-size: 22px 22px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: center;
  font-size: 38px;
  line-height: 2;
  letter-spacing: .02em;
}

.density-wrap { margin: 12px 0; }

.density-graph {
  display: flex;
  align-items: end;
  gap: 2px;
  height: 48px;
  margin-top: 6px;
  padding: 5px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #090c0a;
}

.density-bar {
  flex: 1 1 0;
  min-width: 2px;
  max-width: 12px;
  border-radius: 3px 3px 1px 1px;
  background: var(--accent);
  opacity: .72;
}

.raw-field { margin-bottom: 0; }
#rawOutput { min-height: 150px; }

.preset-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 9px 0;
}

.preset-row.triple { grid-template-columns: 1fr auto auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 500;
  transform: translate(-50%, 12px);
  padding: 10px 14px;
  border: 1px solid rgba(115, 223, 154, .35);
  border-radius: 12px;
  background: #162219;
  opacity: 0;
  pointer-events: none;
  transition: .16s ease;
}

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

@media (max-width: 800px) {
  .app {
    width: min(100% - 14px, 760px);
    padding-top: 10px;
  }

  .topbar {
    display: grid;
    align-items: stretch;
  }

  .top-actions .button { flex: 1; }

  .workspace { display: block; }

  .controls {
    margin-top: 14px;
    padding-bottom: calc(var(--dock-height) + 28px + env(safe-area-inset-bottom));
  }

  .output-panel {
    margin-top: 14px;
  }

  .output-panel.fixed {
    position: fixed;
    left: 7px;
    right: 7px;
    bottom: calc(7px + env(safe-area-inset-bottom));
    top: auto;
    z-index: 100;
    width: auto;
    height: var(--dock-height);
    max-height: var(--dock-height);
    margin: 0;
    overflow: hidden;
    box-shadow: 0 18px 55px rgba(0, 0, 0, .72);
    backdrop-filter: blur(12px);
  }

  .output-panel.fixed[data-edge="top"] {
    top: calc(7px + env(safe-area-inset-top));
    bottom: auto;
  }

  .output-panel.fixed .output-head {
    margin-bottom: 8px;
  }

  .output-panel.fixed .output-meta {
    min-width: 0;
  }

  .output-panel.fixed .stats {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .output-panel.fixed .preview {
    min-height: 0;
    height: calc(var(--dock-height) - 83px);
    max-height: none;
    padding: 14px 10px;
  }

  .output-panel.fixed .density-wrap,
  .output-panel.fixed .raw-field {
    display: none;
  }

  .output-panel.fixed.show-density .density-wrap {
    display: block;
    margin: 8px 0 0;
  }

  .output-panel.fixed.show-density .density-graph {
    height: 34px;
  }

  .output-panel.fixed.show-density .preview {
    height: calc(var(--dock-height) - 136px);
  }

  .output-panel.fixed.compact {
    height: 104px;
    max-height: 104px;
  }

  .output-panel.fixed.compact .output-meta .stats,
  .output-panel.fixed.compact .density-wrap {
    display: none;
  }

  .output-panel.fixed.compact .preview {
    height: 43px;
    padding: 2px 8px;
    font-size: min(24px, var(--preview-font-size, 38px)) !important;
    line-height: 1.45 !important;
    overflow: hidden;
  }

  .output-panel:not(.fixed) {
    position: static;
    height: auto;
    max-height: none;
  }

  body:has(.output-panel:not(.fixed)) .controls {
    padding-bottom: 16px;
  }

  .raw-field { display: none; }
}

@media (max-width: 470px) {
  h1 { font-size: 1.45rem; }
  .output-actions .button { min-height: 40px; padding-inline: 11px; }
  .output-actions .icon-button { width: 40px; padding: 0; }
  .section-title { font-size: .82rem; }
}


/* v4 preview zoom controls */
.preview-wrap {
  position: relative;
  min-width: 0;
}

.preview-zoom {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(9, 12, 10, .88);
  backdrop-filter: blur(9px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .28);
}

.zoom-button,
.zoom-value {
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.zoom-button {
  width: 34px;
  font-size: 1.25rem;
  line-height: 1;
}

.zoom-value {
  min-width: 52px;
  padding: 0 6px;
  color: var(--muted);
  font-size: .72rem;
  font-variant-numeric: tabular-nums;
}

.zoom-button:active,
.zoom-value:active {
  background: rgba(115, 223, 154, .13);
}

@media (max-width: 800px) {
  .preview-zoom {
    top: 6px;
    right: 6px;
  }

  .zoom-button,
  .zoom-value {
    height: 29px;
  }

  .zoom-button {
    width: 31px;
  }

  .zoom-value {
    min-width: 46px;
    font-size: .68rem;
  }

  .output-panel.fixed.compact .preview-zoom {
    top: 2px;
    right: 4px;
  }

  .output-panel.fixed.compact .zoom-button,
  .output-panel.fixed.compact .zoom-value {
    height: 25px;
  }

  .output-panel.fixed.compact .zoom-button {
    width: 27px;
  }

  .output-panel.fixed.compact .zoom-value {
    min-width: 42px;
  }
}
