:root {
  color-scheme: dark;
  --bg: #0b1014;
  --sidebar: #0f161b;
  --surface: #121b21;
  --surface-hover: #18242b;
  --surface-active: #203139;
  --preview: #0a0e11;
  --line: #26343c;
  --line-soft: #1c282f;
  --text: #f2f7f7;
  --text-soft: #c8d2d6;
  --muted: #87969e;
  --accent: #42d7c2;
  --accent-hover: #64e5d2;
  --accent-dark: #082b28;
  --error: #ff8a80;
  --checker-a: #10171b;
  --checker-b: #182126;
  --font: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7f6;
  --sidebar: #eef2f1;
  --surface: #ffffff;
  --surface-hover: #e5ecea;
  --surface-active: #d8f1ec;
  --preview: #e7ecea;
  --line: #c3ceca;
  --line-soft: #dce4e1;
  --text: #13201d;
  --text-soft: #344943;
  --muted: #6c7c76;
  --accent: #087f70;
  --accent-hover: #0a9684;
  --accent-dark: #d6f0eb;
  --error: #b42318;
  --checker-a: #ebefed;
  --checker-b: #dde4e1;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-width: 1100px;
  min-height: 700px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: 100%;
  height: 100dvh;
  min-height: 700px;
  background: var(--bg);
  overflow: hidden;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px #9da4a6;
  opacity: 0;
  animation: app-enter 240ms ease-out forwards;
}

.window-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  background: #fbf6fb;
  border-bottom: 1px solid #f7f3f7;
  color: #17191a;
  font-family: "Segoe UI", var(--font);
  font-size: 18px;
  user-select: none;
}

:root[data-theme="dark"] .window-titlebar {
  background: #171218;
  border-bottom-color: #211a22;
  color: #f2f0f2;
}

:root[data-theme="dark"] .window-controls span:hover {
  background: #2b252c;
}

.window-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 15px;
}

.title-app-icon {
  display: grid;
  grid-template-columns: repeat(2, 7px);
  grid-template-rows: repeat(2, 7px);
  gap: 2px;
  width: 23px;
  height: 23px;
  padding: 3px;
  background: #102127;
  border: 1px solid #566268;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px #20343b;
}

.title-app-icon i {
  background: #29434a;
}

.title-app-icon i:first-child,
.title-app-icon i:last-child {
  background: #42d7c2;
}

.window-controls {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  height: 44px;
}

.window-controls span {
  display: grid;
  place-items: center;
  height: 44px;
  font-family: "Segoe UI Symbol", "Segoe UI", sans-serif;
  font-size: 23px;
  line-height: 1;
}

.window-minimize {
  padding-bottom: 11px;
  font-size: 19px !important;
}

.window-maximize {
  font-size: 20px !important;
}

.window-controls span:hover {
  background: #e8e3e8;
}

.window-controls .window-close:hover {
  background: #c42b1c;
  color: #fff;
}

@keyframes app-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

.app-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 74px;
  padding: 0 25px 0 27px;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 15px;
}

.brand-mark {
  display: grid;
  flex: 0 0 38px;
  grid-template-columns: 15px 15px;
  grid-template-rows: 15px 15px;
  gap: 4px;
  width: 38px;
  height: 38px;
  padding: 2px;
}

.brand-mark i {
  display: block;
  background: var(--line);
}

.brand-mark i:first-child,
.brand-mark i:last-child {
  background: var(--accent);
}

.brand-name {
  color: var(--text);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.35px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 24px;
}

.theme-control {
  position: relative;
}

.theme-menu {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  z-index: 30;
  width: 136px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgb(0 0 0 / 24%);
}

.theme-menu button {
  display: grid;
  grid-template-columns: 22px 1fr;
  width: 100%;
  padding: 8px 9px;
  background: transparent;
  border: 0;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.theme-menu button:hover,
.theme-menu button:focus-visible {
  background: var(--accent-dark);
  outline: 0;
}

.status-pill {
  max-width: min(360px, 34vw);
  overflow: hidden;
  padding: 9px 14px;
  background: var(--accent-dark);
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 150ms ease, color 150ms ease;
}

.status-pill.working {
  background: var(--surface-active);
  color: var(--text-soft);
}

.status-pill.error {
  background: #351b1b;
  color: var(--error);
}

:root[data-theme="light"] .status-pill.error {
  background: #fce8e6;
}

.app-body {
  display: grid;
  grid-template-columns: 354px minmax(0, 1fr);
  height: calc(100dvh - 118px);
  min-height: 582px;
}

.sidebar {
  min-width: 0;
  overflow: hidden auto;
  background: var(--sidebar);
  border-right: 1px solid var(--line-soft);
  scrollbar-color: var(--line) var(--sidebar);
  scrollbar-width: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
  width: 0;
}

.sidebar::-webkit-scrollbar-track {
  background: var(--sidebar);
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--line);
}

.sidebar-inner {
  padding: 20px 21px 20px 23px;
}

.drop-card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.drop-card:hover,
.drop-card:focus-visible {
  background: var(--surface-hover);
  border-color: var(--accent);
  outline: 0;
}

.drop-card h1 {
  margin: 0;
  color: var(--text);
  font-size: 24px;
  line-height: 31px;
}

.drop-card p {
  min-height: 52px;
  margin: 8px 0 11px;
  color: var(--muted);
  font-size: 18px;
  line-height: 26px;
}

.button-row,
.export-actions,
.export-row {
  display: flex;
  align-items: center;
}

.button-row {
  gap: 8px;
}

.ui-button {
  min-height: 55px;
  padding: 11px 21px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--text-soft);
  font-size: 20px;
  font-weight: 700;
  line-height: 20px;
  cursor: pointer;
  transition: background 110ms ease, border-color 110ms ease, color 110ms ease;
}

.ui-button:hover:not(:disabled),
.ui-button:focus-visible:not(:disabled) {
  background: var(--surface-hover);
  outline: 0;
}

.ui-button:focus-visible:not(:disabled) {
  border-color: var(--accent);
}

.ui-button.small {
  min-height: 41px;
  padding: 7px 13px;
  font-size: 18px;
}

.sidebar .ui-button.small {
  min-height: 45px;
}

.ui-button.primary {
  background: var(--accent);
  border-color: var(--line);
  color: var(--bg);
}

.ui-button.primary:hover:not(:disabled),
.ui-button.primary:focus-visible:not(:disabled) {
  background: var(--accent-hover);
}

.ui-button.selected:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent);
  color: var(--accent);
}

.ui-button:disabled {
  background: var(--surface);
  border-color: var(--line);
  color: var(--muted);
  cursor: default;
  opacity: 0.68;
}

.section-kicker {
  margin: 21px 2px 11px;
  color: var(--muted);
  font-size: 17px;
  line-height: 24px;
  text-transform: uppercase;
}

.core-kicker {
  margin-top: 21px;
  margin-bottom: 18px;
}

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

.preset-grid .ui-button {
  width: 100%;
}

.control-field,
.range-field {
  display: block;
  margin: 0 2px 13px;
  color: var(--text-soft);
  font-size: 18px;
}

.control-field > span:first-child {
  display: block;
  margin-bottom: 7px;
}

.select-wrap {
  position: relative;
  display: block;
}

.select-wrap::after {
  position: absolute;
  top: 50%;
  right: 10px;
  color: var(--accent);
  content: "▾";
  font-size: 11px;
  pointer-events: none;
  transform: translateY(-50%);
}

select,
.entry-grid input,
.mono-input {
  width: 100%;
  height: 44px;
  padding: 0 10px;
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  font-size: 18px;
  outline: 0;
}

select:focus,
.entry-grid input:focus,
.mono-input:focus {
  border-color: var(--accent);
}

.range-field {
  margin-top: 20px;
}

.range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 25px;
}

.range-label strong {
  color: var(--accent);
  font-size: 18px;
}

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

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: linear-gradient(to right, var(--accent) 0 var(--fill, 0%), var(--line) var(--fill, 0%) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -6px;
  appearance: none;
  background: var(--accent);
  border: 0;
  border-radius: 0;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--line);
}

input[type="range"]::-moz-range-progress {
  height: 4px;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: 0;
  border-radius: 0;
}

.process-button {
  width: 100%;
  margin-top: 0;
}

.core-scale {
  margin-top: 23px;
  margin-bottom: 15px;
}

.shortcut,
.field-help,
.version {
  color: var(--muted);
  font-size: 16px;
}

.shortcut {
  margin: 10px 0 0;
  text-align: center;
}

.collapsible {
  border-bottom: 1px solid var(--line-soft);
}

.collapsible:first-of-type {
  margin-top: 12px;
}

.collapse-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 50px;
  padding: 6px 0;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.collapse-header b {
  width: 22px;
  color: var(--accent);
  font-size: 18px;
  line-height: 18px;
  text-align: center;
}

.collapse-header:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

.collapse-body {
  display: none;
  padding: 4px 0 10px;
}

.collapsible.open .collapse-body {
  display: block;
  animation: section-open 140ms ease-out both;
}

@keyframes section-open {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: translateY(0); }
}

.control-field.compact {
  margin-top: 10px;
}

.compact-range {
  margin: 8px 0 0;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 37px;
  color: var(--text-soft);
  font-size: 17px;
  cursor: pointer;
}

.check-field input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
}

.entry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.entry-grid label > span {
  display: block;
  margin-bottom: 5px;
  color: var(--text-soft);
  font-size: 15px;
}

.field-help {
  margin: 5px 0 8px;
}

.color-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.mono-input {
  font-family: Consolas, monospace;
}

#backgroundColor {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.version {
  margin: 22px 0 8px;
}

.workspace {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 64px minmax(180px, 1fr) 174px;
  background: var(--bg);
}

.workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 25px 0 24px;
}

.view-tabs {
  display: flex;
  gap: 8px;
}

.view-tabs .ui-button {
  width: 138px;
}

.file-meta {
  max-width: 42%;
  overflow: hidden;
  color: var(--muted);
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-frame {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 0 25px 0 24px;
  overflow: hidden;
  background-color: var(--preview);
  background-image:
    linear-gradient(45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-b) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  border: 1px solid var(--line-soft);
}

.preview-frame.empty {
  background-image: none;
}

#previewCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

#previewCanvas.image-enter {
  animation: image-enter 160ms ease-out;
}

@keyframes image-enter {
  from { opacity: 0; transform: scale(0.995); }
  to { opacity: 1; transform: scale(1); }
}

.empty-preview {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.empty-preview[hidden] {
  display: none;
}

.empty-preview strong {
  position: absolute;
  top: calc(50% - 47px);
  color: var(--text-soft);
  font-size: 32px;
}

.empty-preview span {
  position: absolute;
  top: calc(50% - 1px);
  margin-top: 0;
  color: var(--muted);
  font-size: 18px;
}

.result-panel {
  min-width: 0;
  padding: 0 25px 18px 24px;
}

.progress-track {
  width: 100%;
  height: 3px;
  overflow: hidden;
  background: var(--line-soft);
}

.progress-track > span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.progress-track > span.indeterminate {
  width: 32%;
  animation: progress-move 900ms ease-in-out infinite;
}

@keyframes progress-move {
  from { transform: translateX(-110%); }
  to { transform: translateX(340%); }
}

.metrics {
  display: grid;
  grid-template-columns:
    calc((100% - 57px) / 4)
    repeat(3, calc((100% + 19px) / 4));
  margin: 14px 0 12px;
}

.metrics > div {
  min-width: 0;
  padding-left: 18px;
  border-left: 1px solid var(--line-soft);
}

.metrics > div:first-child {
  padding-left: 0;
  border-left: 0;
}

.metrics span,
.metrics strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics span {
  color: var(--muted);
  font-size: 17px;
}

.metrics strong {
  margin-top: 3px;
  color: var(--text);
  font-size: 24px;
}

.export-row {
  justify-content: space-between;
  gap: 14px;
  transform: translateY(7px);
}

.export-actions {
  min-width: 0;
  gap: 10px;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  background: rgb(8 18 20 / 78%);
  backdrop-filter: blur(4px);
}

.drop-overlay.visible {
  display: grid;
  animation: overlay-enter 120ms ease-out;
}

@keyframes overlay-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

.drop-overlay > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(440px, 70vw);
  padding: 44px;
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--text);
}

.drop-overlay strong {
  margin: 18px 0 7px;
  font-size: 20px;
}

.drop-overlay > div > span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 120;
  max-width: 420px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text-soft);
  box-shadow: 0 12px 36px rgb(0 0 0 / 28%);
  font-size: 12px;
}

.toast:not([hidden]) {
  animation: toast-enter 180ms ease-out;
}

@keyframes toast-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1050px) {
  .app-body { grid-template-columns: 354px minmax(0, 1fr); }
  .sidebar-inner { padding: 16px; }
  .workspace-toolbar,
  .result-panel { padding-left: 18px; padding-right: 18px; }
  .preview-frame { margin-left: 18px; margin-right: 18px; }
  .export-actions .ui-button { padding-left: 12px; padding-right: 12px; }
}

@media (max-height: 699px) {
  .window-titlebar { height: 38px; }
  .app-header { height: 64px; }
  .app-body { height: calc(100dvh - 102px); }
  .workspace { grid-template-rows: 54px minmax(150px, 1fr) 156px; }
  .metrics { margin-top: 10px; margin-bottom: 8px; }
  .ui-button { min-height: 36px; }
}

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