:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --ink: #17202a;
  --muted: #68727e;
  --border: #d8dde3;
  --border-strong: #b9c1ca;
  --accent: #df4d34;
  --accent-hover: #c73d28;
  --teal: #137d73;
  --teal-soft: #e9f5f2;
  --focus: #1d70b8;
  --preview: #111820;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

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

button {
  color: inherit;
}

button:focus-visible,
label:has(input:focus-visible),
select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 28%, transparent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.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;
}

.app-header {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1180px, calc(100% - 40px));
  height: 100%;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 750;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 5px);
  grid-template-rows: repeat(3, 5px);
  gap: 2px;
  width: 19px;
  height: 19px;
}

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

.brand-mark i:nth-child(2),
.brand-mark i:nth-child(6) {
  background: var(--accent);
}

.brand-mark i:nth-child(4),
.brand-mark i:nth-child(8) {
  background: var(--teal);
}

.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #38605b;
  font-size: 13px;
  font-weight: 650;
}

.local-badge i {
  width: 8px;
  height: 8px;
  background: #20a88f;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #dff4ee;
}

.app-main {
  width: min(1180px, calc(100% - 40px));
  margin: 44px auto 24px;
}

.workspace {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgb(23 32 42 / 6%);
}

.mode-switch {
  display: flex;
  gap: 4px;
  padding: 10px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.mode-button {
  min-height: 40px;
  padding: 0 18px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
}

.mode-button:hover {
  color: var(--ink);
  background: #eceff2;
}

.mode-button.is-active {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--border);
  box-shadow: 0 1px 2px rgb(23 32 42 / 5%);
}

.workspace-body {
  display: grid;
  grid-template-columns: minmax(0, 1.03fr) minmax(380px, 0.97fr);
  min-height: 630px;
}

.control-pane {
  padding: 38px 42px 42px;
}

.preview-pane {
  min-width: 0;
  padding: 38px;
  background: var(--surface-soft);
  border-left: 1px solid var(--border);
}

.panel-heading,
.preview-heading {
  margin-bottom: 26px;
}

.preview-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 1.25;
}

h1 {
  font-size: 25px;
}

h2 {
  font-size: 18px;
}

.preview-state {
  max-width: 150px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 176px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background: #fbfcfd;
  border: 1px dashed var(--border-strong);
  border-radius: 7px;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  color: var(--ink);
  background: #f3f8f7;
  border-color: var(--teal);
}

.drop-zone strong {
  margin: 10px 0 3px;
  color: var(--ink);
  font-size: 15px;
}

.drop-zone > span:last-child {
  font-size: 13px;
}

.drop-symbol {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--teal);
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
  background: var(--teal-soft);
  border-radius: 50%;
}

.file-summary {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.file-type {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  color: var(--surface);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 10px;
  font-weight: 800;
  background: #32404d;
  border-radius: 4px;
}

.file-copy {
  min-width: 0;
}

.file-copy strong,
.file-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-copy strong {
  margin-bottom: 4px;
  font-size: 14px;
}

.file-copy small,
.result-block small {
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.icon-button:hover {
  color: var(--ink);
  background: #e7eaee;
}

.settings {
  padding: 0;
  margin: 28px 0 24px;
  border: 0;
}

.settings legend {
  width: 100%;
  padding: 0 0 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  border-bottom: 1px solid var(--border);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 70px;
  border-bottom: 1px solid var(--border);
}

.setting-row strong,
.setting-row small {
  display: block;
}

.setting-row strong {
  margin-bottom: 3px;
  font-size: 14px;
}

.setting-row small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.setting-row select {
  flex: 0 0 112px;
  min-height: 38px;
  padding: 0 32px 0 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  cursor: pointer;
}

.toggle {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
}

.toggle input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.toggle span {
  position: absolute;
  inset: 0;
  background: #adb5be;
  border-radius: 12px;
  transition: background-color 140ms ease;
}

.toggle span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  content: "";
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgb(23 32 42 / 24%);
  transition: transform 140ms ease;
}

.toggle input:checked + span {
  background: var(--teal);
}

.toggle input:checked + span::after {
  transform: translateX(18px);
}

.primary-button,
.download-button {
  min-height: 44px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 750;
  border-radius: 5px;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  color: #ffffff;
  background: var(--accent);
  border: 1px solid var(--accent);
}

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

.primary-button:disabled {
  color: #929aa3;
  background: #e5e8ec;
  border-color: #e5e8ec;
  cursor: not-allowed;
}

.primary-button.is-busy {
  color: #ffffff;
  background-image: linear-gradient(
    90deg,
    var(--accent) 0 42%,
    #ee735d 42% 58%,
    var(--accent) 58% 100%
  );
  background-size: 220% 100%;
  animation: busy 1.2s linear infinite;
}

@keyframes busy {
  to {
    background-position: -220% 0;
  }
}

.result-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.result-block > div {
  min-width: 0;
}

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

.result-block strong {
  margin-bottom: 4px;
  font-size: 14px;
}

.result-label {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.download-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
}

.download-button:hover {
  background: var(--surface-soft);
  border-color: #8d98a4;
}

.download-button span {
  color: var(--teal);
  font-size: 19px;
  line-height: 1;
}

.canvas-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 8 / 5;
  overflow: hidden;
  background: var(--preview);
  border: 1px solid #273441;
  border-radius: 6px;
}

.canvas-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  color: #8f9ba7;
  font-size: 12px;
}

.empty-grid {
  display: grid;
  width: 54px;
  height: 42px;
  margin-bottom: 12px;
  opacity: 0.8;
  background:
    linear-gradient(#111820 0 0) padding-box,
    repeating-linear-gradient(90deg, #394552 0 8px, transparent 8px 11px),
    repeating-linear-gradient(0deg, #394552 0 8px, transparent 8px 11px);
}

.canvas-empty p {
  margin: 0;
}

.preview-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 24px 0 0;
  border-top: 1px solid var(--border);
}

.preview-stats > div {
  min-width: 0;
  padding: 17px 0;
  border-bottom: 1px solid var(--border);
}

.preview-stats > div:nth-child(odd) {
  padding-right: 18px;
}

.preview-stats > div:nth-child(even) {
  padding-left: 18px;
  border-left: 1px solid var(--border);
}

.preview-stats dt {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.preview-stats dd {
  min-height: 18px;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.integrity-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  padding: 13px 14px;
  color: #245c54;
  background: var(--teal-soft);
  border: 1px solid #b8ddd5;
  border-radius: 6px;
}

.integrity-status > span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: #ffffff;
  font-weight: 800;
  background: var(--teal);
  border-radius: 50%;
}

.integrity-status strong,
.integrity-status small {
  display: block;
}

.integrity-status strong {
  margin-bottom: 2px;
  font-size: 13px;
}

.integrity-status small {
  color: #4b736e;
  font-size: 11px;
}

.protocol-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  width: min(360px, calc(100% - 48px));
  padding: 13px 15px;
  color: #ffffff;
  font-size: 13px;
  line-height: 1.45;
  background: #28333e;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgb(23 32 42 / 22%);
}

.toast.is-error {
  background: #9f3427;
}

@media (max-width: 900px) {
  .workspace-body {
    grid-template-columns: 1fr;
  }

  .preview-pane {
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (max-width: 600px) {
  .app-header {
    height: 58px;
  }

  .header-inner,
  .app-main {
    width: calc(100% - 24px);
  }

  .app-main {
    margin-top: 20px;
  }

  .mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .mode-button {
    min-width: 0;
    padding: 0 8px;
  }

  .control-pane,
  .preview-pane {
    padding: 26px 20px 30px;
  }

  .workspace-body {
    min-height: 0;
  }

  .drop-zone {
    min-height: 150px;
  }

  .setting-row {
    gap: 14px;
  }

  .setting-row small {
    max-width: 210px;
  }

  .result-block {
    align-items: stretch;
    flex-direction: column;
  }

  .download-button {
    justify-content: center;
    width: 100%;
  }

  .preview-stats {
    grid-template-columns: 1fr;
  }

  .preview-stats > div:nth-child(odd),
  .preview-stats > div:nth-child(even) {
    padding-right: 0;
    padding-left: 0;
    border-left: 0;
  }

  .toast {
    right: 12px;
    bottom: 12px;
    width: calc(100% - 24px);
  }
}

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