:root {
  --bg: #0b0d0b;
  --bg-soft: #111411;
  --panel: #151814;
  --panel-strong: #181c17;
  --line: #333932;
  --line-soft: #242923;
  --text: #e8ebe2;
  --muted: #9ca294;
  --dim: #6f7669;
  --green: #88d75f;
  --green-strong: #69bd47;
  --amber: #f0b743;
  --amber-soft: #6a5423;
  --danger: #d97962;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.38);
  --font-mono: "SFMono-Regular", "Cascadia Code", "Liberation Mono", Menlo, Consolas, monospace;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: var(--font-mono);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 32%),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.scanline {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0.035) 0,
      rgba(255, 255, 255, 0.035) 1px,
      transparent 1px,
      transparent 5px
    );
  mix-blend-mode: soft-light;
  opacity: 0.2;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border: 1px solid var(--line-soft);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.app-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 16, 14, 0.9);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--text);
  text-decoration: none;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.brand-mark span {
  display: block;
  background: var(--green);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.28);
}

.brand-mark span:nth-child(5),
.brand-mark span:nth-child(6),
.brand-mark span:nth-child(8) {
  background: transparent;
  border: 2px solid var(--green);
}

.header-actions,
.export-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.button,
.export-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 18px;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.button svg,
.export-button svg,
.status-bar svg,
.upload-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button:hover,
.export-button:hover,
.segment:hover,
.media-tab:hover,
.format-tab:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.button-amber {
  color: var(--amber);
  border-color: var(--amber);
  background: rgba(240, 183, 67, 0.05);
}

.button-green {
  color: var(--green);
  border-color: var(--green-strong);
  background: rgba(136, 215, 95, 0.05);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, 38vw) minmax(0, 1fr);
}

.control-panel {
  min-width: 0;
  border-right: 1px solid var(--line);
  background: rgba(17, 20, 17, 0.76);
  overflow: auto;
}

.panel-section {
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
}

.panel-section h2,
.preview-label-row,
.export-bar > span {
  color: var(--green);
  font-size: 15px;
  line-height: 1.25;
  font-weight: 700;
  margin: 0 0 16px;
}

.drop-zone {
  min-height: 130px;
  border: 1px dashed #6b7166;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 22px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent),
    rgba(255, 255, 255, 0.01);
  cursor: pointer;
  text-align: center;
  transition: border-color 140ms ease, background 140ms ease;
}

[hidden] {
  display: none !important;
}

.media-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #101310;
}

.format-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #101310;
}

.media-tab {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: transform 140ms ease, color 140ms ease, background 140ms ease;
}

.format-tab {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  transition: transform 140ms ease, color 140ms ease, background 140ms ease;
}

.media-tab:last-child {
  border-right: 0;
}

.format-tab:last-child {
  border-right: 0;
}

.media-tab.is-active {
  color: var(--green);
  background: rgba(136, 215, 95, 0.08);
  box-shadow: inset 0 0 0 1px var(--green-strong);
}

.format-tab.is-active {
  color: var(--green);
  background: rgba(136, 215, 95, 0.08);
  box-shadow: inset 0 0 0 1px var(--green-strong);
}

.format-tab:disabled {
  color: var(--dim);
  cursor: not-allowed;
  transform: none;
}

.drop-zone.is-dragging,
.drop-zone:hover {
  border-color: var(--green);
  background: rgba(136, 215, 95, 0.06);
}

.drop-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.drop-zone b {
  color: var(--green);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.upload-icon {
  color: var(--green);
}

.upload-icon svg {
  width: 54px;
  height: 54px;
  stroke-width: 1.6;
}

.image-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 20px 0 10px;
  font-size: 14px;
}

.ghost-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 0;
}

.ghost-button:hover {
  color: var(--text);
}

.image-preview {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #080908;
}

.image-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 8;
  object-fit: cover;
  filter: grayscale(1) contrast(1.06);
}

.image-preview video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 8;
  object-fit: cover;
  filter: grayscale(1) contrast(1.06);
  background: #080908;
}

.image-preview figcaption {
  min-height: 34px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: var(--muted);
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
}

.control-row {
  display: grid;
  gap: 9px;
  margin-bottom: 16px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row > label,
.switch-row > label {
  color: var(--text);
  font-size: 13px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #101310;
}

.segment {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  padding: 0 8px;
}

.segment:last-child {
  border-right: 0;
}

.segment.is-active {
  color: var(--green);
  background: rgba(136, 215, 95, 0.08);
  box-shadow: inset 0 0 0 1px var(--green-strong);
}

.control-row-inline {
  grid-template-columns: 106px 58px minmax(120px, 1fr);
  align-items: center;
}

.control-row-inline label {
  align-self: center;
}

.number-input,
.number-output {
  width: 58px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #101310;
  color: var(--text);
  font-size: 13px;
  text-align: center;
}

.number-input {
  appearance: textfield;
}

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

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

.switch-row {
  grid-template-columns: 106px 1fr;
  align-items: center;
}

.message-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(136, 215, 95, 0.035);
}

.message-row label {
  display: block;
  margin-bottom: 5px;
  color: var(--text);
  font-size: 13px;
}

.switch {
  width: 42px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #20251f;
  padding: 2px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.switch span {
  width: 16px;
  height: 16px;
  display: block;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 140ms ease, background 140ms ease;
}

.switch[aria-checked="true"] {
  border-color: var(--green);
  background: rgba(136, 215, 95, 0.16);
}

.switch[aria-checked="true"] span {
  transform: translateX(18px);
  background: var(--green);
}

#customText {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #101310;
  color: var(--text);
  padding: 0 10px;
  font-size: 12px;
}

#customText:focus,
.number-input:focus,
.segment:focus-visible,
.media-tab:focus-visible,
.format-tab:focus-visible,
.button:focus-visible,
.export-button:focus-visible,
.switch:focus-visible,
.ghost-button:focus-visible {
  outline: 2px solid rgba(136, 215, 95, 0.8);
  outline-offset: 2px;
}

.hint {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.preview-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(360px, 1fr) auto;
  gap: 0;
  padding: 22px 24px 16px;
  background:
    linear-gradient(90deg, rgba(136, 215, 95, 0.035), transparent 45%),
    var(--bg-soft);
  overflow: hidden;
}

.preview-topline {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.preview-topline h1 {
  margin: 0;
  max-width: 640px;
  color: var(--text);
  font-size: 28px;
  line-height: 1.08;
  font-weight: 700;
}

.preview-stats {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.preview-stats span {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.14);
}

.preview-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.preview-label-row #modeStat {
  color: var(--muted);
  font-weight: 400;
}

.preview-window {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0d0f0d;
  box-shadow: var(--shadow);
}

.preview-scroll {
  height: 100%;
  min-height: 360px;
  display: grid;
  grid-template-columns: auto minmax(max-content, 1fr);
  align-items: start;
  overflow: auto;
  scrollbar-color: #555b52 #171a17;
  scrollbar-width: thin;
}

.line-numbers,
.glyph-art {
  margin: 0;
  padding: 12px 0;
  font-family: var(--font-mono);
  white-space: pre;
  tab-size: 2;
}

.line-numbers {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 46px;
  padding-inline: 12px 8px;
  color: #747b70;
  text-align: right;
  user-select: none;
  background: linear-gradient(90deg, #0d0f0d 78%, rgba(13, 15, 13, 0));
  border-right: 1px solid rgba(255, 255, 255, 0.035);
}

.glyph-art {
  min-width: 100%;
  padding-inline: 12px 24px;
  color: #dfe3d8;
  text-shadow: 0 0 8px rgba(136, 215, 95, 0.06);
}

.video-controls {
  margin-bottom: 16px;
}

.video-controls .control-row:last-child {
  margin-bottom: 0;
}

.video-stage {
  height: 100%;
  min-height: 360px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  gap: 12px;
  overflow: auto;
  padding: 16px;
}

.video-glyph-canvas {
  display: block;
  max-width: 100%;
  max-height: min(66vh, 680px);
  width: auto;
  height: auto;
  border: 1px solid rgba(255, 255, 255, 0.045);
  border-radius: 6px;
  background: #0d0f0d;
}

.video-status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.export-bar {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr;
  align-items: center;
  gap: 20px;
  padding-top: 18px;
}

.export-bar > span {
  margin: 0;
}

.export-actions {
  justify-content: stretch;
  gap: 20px;
}

.export-button {
  flex: 1 1 0;
  min-width: 120px;
  min-height: 56px;
  color: var(--text);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.018);
}

.export-button:hover {
  border-color: var(--green);
  color: var(--green);
  background: rgba(136, 215, 95, 0.045);
}

.video-export {
  border-color: rgba(240, 183, 67, 0.48);
}

.video-export:hover {
  border-color: var(--amber);
  color: var(--amber);
  background: rgba(240, 183, 67, 0.045);
}

.status-bar {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: rgba(14, 16, 14, 0.92);
  font-size: 13px;
}

.status-primary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--green);
}

.status-bar svg {
  width: 20px;
  height: 20px;
}

.status-divider {
  width: 1px;
  height: 16px;
  background: var(--dim);
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  }

  .segmented {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .segment:nth-child(3) {
    border-right: 0;
  }

  .segment:nth-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 900px) {
  .app-shell {
    min-height: auto;
  }

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

  .header-actions {
    width: 100%;
  }

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

  .workspace {
    display: block;
  }

  .control-panel {
    border-right: 0;
  }

  .preview-panel {
    min-height: 720px;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .app-header,
  .panel-section,
  .preview-panel,
  .status-bar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .brand {
    font-size: 24px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .control-row-inline {
    grid-template-columns: 1fr 58px;
  }

  .control-row-inline input[type="range"] {
    grid-column: 1 / -1;
  }

  .preview-topline {
    display: grid;
    align-items: start;
  }

  .preview-topline h1 {
    font-size: 24px;
  }

  .preview-stats {
    flex-wrap: wrap;
  }

  .export-bar {
    grid-template-columns: 1fr;
  }

  .export-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .status-bar {
    min-height: 64px;
    flex-wrap: wrap;
    align-content: center;
    row-gap: 6px;
  }

  .status-divider {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}
