:root {
  color-scheme: dark light;
  --bg: #0a0b0d;
  --panel: #101216;
  --panel-soft: #15181d;
  --line: #252a31;
  --line-strong: #363d47;
  --text: #f2f4f7;
  --text-soft: #cbd0d7;
  --muted: #8d96a3;
  --muted-strong: #687385;
  --control-active: #22262d;
  --output-bg: #0d0f12;
  --output-text: #e7ebef;
  --empty-text: #5f6874;
  --disabled-text: #626a76;
  --toast-bg: #191c21;
  --accent-text: #0b0c0e;
  --primary-hover: #dfe3e8;
  --danger: #ff7676;
  --focus: #8fb7ff;
  --shadow: rgba(0, 0, 0, 0.4);
  --radius: 14px;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", Menlo, monospace;
}

:root[data-theme="light"] {
  --bg: #f5f5f3;
  --panel: #ffffff;
  --panel-soft: #f0f0ed;
  --line: #deded9;
  --line-strong: #c8c8c1;
  --text: #171816;
  --text-soft: #454842;
  --muted: #747970;
  --muted-strong: #8b9187;
  --control-active: #e8e8e4;
  --output-bg: #ffffff;
  --output-text: #111318;
  --empty-text: #989d94;
  --disabled-text: #a4a8a0;
  --toast-bg: #ffffff;
  --accent-text: #ffffff;
  --primary-hover: #30322f;
  --danger: #c93f3f;
  --focus: #376dd8;
  --shadow: rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

button,
input,
select {
  font: inherit;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.upload-card:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button {
  border: 0;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 0 20px 20px;
}

.app-header {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 780;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: -0.06em;
}

.segmented-switcher {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.segmented-switcher button {
  padding: 7px 10px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

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

.segmented-switcher button.is-active {
  background: var(--text);
  color: var(--accent-text);
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: calc(100vh - 89px);
}

.control-panel {
  padding: 24px 24px 24px 0;
  border-right: 1px solid var(--line);
}

.panel-section {
  padding-bottom: 22px;
}

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

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

.section-heading h1,
.panel-section h2,
.result-header h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 760;
  letter-spacing: -0.01em;
}

.quiet-button {
  padding: 4px 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
}

.quiet-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.upload-card {
  position: relative;
  display: grid;
  width: 100%;
  height: 180px;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.upload-card:hover,
.upload-card.is-dragging {
  border-color: var(--muted-strong);
  background: var(--panel-soft);
}

.upload-placeholder {
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 20px;
  text-align: center;
}

.upload-symbol {
  display: grid;
  width: 34px;
  height: 34px;
  margin-bottom: 5px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 300;
}

.upload-placeholder strong {
  font-size: 0.78rem;
}

.upload-placeholder span:last-child {
  color: var(--muted);
  font-size: 0.66rem;
}

.image-preview {
  position: absolute;
  inset: 8px;
  width: calc(100% - 16px);
  height: calc(100% - 16px);
  max-width: calc(100% - 16px);
  max-height: calc(100% - 16px);
  object-fit: contain;
  object-position: center;
  border-radius: 9px;
  opacity: 0;
  pointer-events: none;
}

.upload-card.has-image .image-preview {
  opacity: 1;
}

.upload-card.has-image .upload-placeholder {
  visibility: hidden;
}

.image-info {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  color: var(--muted);
  font-size: 0.64rem;
}

.image-info span:first-child {
  min-width: 0;
  overflow: hidden;
  color: var(--text-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-info span:last-child {
  flex: 0 0 auto;
  font-family: var(--mono);
}

.panel-section h2,
.section-label {
  display: block;
  margin: 0 0 10px;
  color: var(--text-soft);
  font-size: 0.72rem;
  font-weight: 740;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  margin-bottom: 10px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.mode-switch label {
  position: relative;
  cursor: pointer;
}

.mode-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-switch span {
  display: grid;
  min-height: 32px;
  place-items: center;
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
}

.mode-switch input:checked + span {
  background: var(--control-active);
  color: var(--text);
}

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

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 650;
}

.field input,
.select-input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: 0;
  background: var(--panel);
  color: var(--text);
  font-size: 0.74rem;
}

.field input {
  padding: 0 10px;
}

.field input:disabled {
  color: var(--disabled-text);
  cursor: not-allowed;
}

.size-warning {
  margin-top: 10px;
  padding: 9px 10px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line));
  border-radius: 9px;
  background: color-mix(in srgb, var(--danger) 8%, var(--panel));
  color: var(--danger);
  font-size: 0.64rem;
  font-weight: 680;
  line-height: 1.45;
}


.select-input {
  padding: 0 30px 0 10px;
  cursor: pointer;
}

.custom-field {
  margin-top: 10px;
}

.primary-button {
  width: 100%;
  min-height: 42px;
  border-radius: 10px;
  background: var(--text);
  color: var(--accent-text);
  font-size: 0.75rem;
  font-weight: 800;
  cursor: pointer;
}

.primary-button:hover:not(:disabled) {
  background: var(--primary-hover);
}

.primary-button:disabled {
  opacity: 0.32;
  cursor: default;
}

.result-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: 24px 0 0 24px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
}

.result-header > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.output-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.62rem;
  white-space: nowrap;
}

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

.action-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text-soft);
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
}

.action-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  color: var(--text);
}

.action-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.output-window {
  position: relative;
  min-width: 0;
  min-height: 420px;
  flex: 1;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--output-bg);
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--empty-text);
  font-size: 0.72rem;
}

.ascii-art {
  min-width: max-content;
  margin: 0;
  padding: 22px;
  color: var(--output-text);
  font-family: var(--mono);
  font-size: 7px;
  font-variant-ligatures: none;
  line-height: 0.78;
  white-space: pre;
  user-select: text;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(320px, calc(100vw - 36px));
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--toast-bg);
  color: var(--text);
  box-shadow: 0 16px 40px var(--shadow);
  font-size: 0.7rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-error {
  border-color: var(--danger);
}

.is-hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .workspace {
    display: block;
  }

  .control-panel {
    padding: 20px 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .result-panel {
    min-height: 520px;
    padding: 20px 0 0;
  }

  .upload-card {
    height: 220px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 0 12px 12px;
  }

  .app-header {
    min-height: 60px;
  }

  .brand > span:last-child {
    display: none;
  }

  .segmented-switcher button {
    padding: 7px 8px;
    font-size: 0.66rem;
  }

  .upload-card {
    height: 170px;
  }

  .result-header {
    align-items: flex-start;
  }

  .result-header > div:first-child {
    display: grid;
    gap: 3px;
  }

  .output-meta {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .output-window {
    min-height: 390px;
  }
}

@media (max-width: 430px) {
  .app-header {
    align-items: flex-start;
    padding: 10px 0;
  }

  .header-controls {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }
}
