:root {
  color-scheme: light;
  --shell: #12151a;
  --shell-2: #1d2229;
  --surface: #f7f8f4;
  --surface-2: #ebece6;
  --paper: #ffffff;
  --ink: #171a1f;
  --muted: #687079;
  --line: #c8cdd0;
  --line-dark: #323943;
  --teal: #0f8f81;
  --teal-dark: #0b665e;
  --teal-soft: #d9efeb;
  --amber: #e08a1e;
  --blue: #2467a6;
  --magenta: #bf2f62;
  --red: #b42318;
  --shadow: 0 22px 70px rgba(3, 7, 12, 0.32);
  --mono:
    "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  font-family: var(--sans);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 92px),
    linear-gradient(135deg, #101319 0%, #171c23 48%, #20252b 100%);
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10000;
  padding: 10px 14px;
  border-radius: 4px;
  color: #11161f;
  background: #f7f8f4;
  transform: translateY(-160%);
}

.skip-link:focus-visible {
  transform: none;
}

button,
input,
select {
  font: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  color: #f9fbf7;
  font-size: clamp(1.15rem, 1.8vw, 1.55rem);
  font-weight: 760;
  line-height: 1.05;
}

h2,
h3 {
  font-size: 0.98rem;
  font-weight: 760;
  line-height: 1.2;
}

p,
small,
.muted-label {
  color: var(--muted);
}

p {
  margin-top: 4px;
  color: #aeb8bf;
  font-size: 0.88rem;
  line-height: 1.45;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  min-height: 100vh;
  padding: 16px;
}

.app-topbar {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  padding: 14px 18px;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(15, 143, 129, 0.18), transparent 28%),
    #161b22;
  box-shadow: var(--shadow);
}

.product-lockup,
.panel-heading,
.canvas-title {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  position: relative;
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: #f9fbf7;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 38%),
    var(--teal-dark);
  font-family: var(--mono);
  font-weight: 800;
}

.brand-mark::before,
.brand-mark::after {
  position: absolute;
  content: "";
  background: #f9fbf7;
}

.brand-mark::before {
  width: 1px;
  height: 28px;
  transform: rotate(32deg);
}

.brand-mark::after {
  width: 1px;
  height: 28px;
  transform: rotate(-32deg);
}

.brand-mark {
  color: transparent;
}

.scope-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(54px, auto));
  gap: 2px;
  overflow: hidden;
  border: 1px solid #313943;
  border-radius: 8px;
  background: #0f1318;
}

.scope-strip span {
  min-height: 34px;
  padding: 9px 12px;
  color: #d5dbde;
  background: rgba(255, 255, 255, 0.04);
  font-family: var(--mono);
  font-size: 0.75rem;
  text-align: center;
}

.scope-strip span:nth-child(3) {
  color: #03120f;
  background: var(--teal);
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(440px, 1fr) minmax(280px, 350px);
  gap: 14px;
  min-height: 0;
}

.workspace > *,
.app-topbar > *,
.toolbar > *,
.toolbar-controls > *,
.panel-heading > *,
.product-lockup > *,
.upload-zone,
.panel-section,
.scope-strip {
  min-width: 0;
}

.side-panel,
.preview-area,
.editor-panel {
  min-width: 0;
  border: 1px solid var(--line-dark);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.side-panel,
.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  padding: 14px;
  overflow: auto;
}

.side-panel {
  border-radius: 8px 4px 4px 8px;
}

.editor-panel {
  border-radius: 4px 8px 8px 4px;
}

.preview-area {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 580px;
  border-radius: 4px;
  overflow: hidden;
  background: #dfe5e4;
}

.panel-heading {
  justify-content: space-between;
  min-height: 48px;
}

.eyebrow,
.format-pill,
.badge,
.muted-label {
  font-family: var(--mono);
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--teal-dark);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.format-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--muted);
  background: #fff;
  font-size: 0.68rem;
  font-weight: 760;
}

.upload-zone {
  position: relative;
  display: grid;
  gap: 8px;
  place-items: center;
  min-height: 186px;
  padding: 24px 18px;
  border: 1px dashed #8f999d;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(15, 143, 129, 0.12) 1px, transparent 1px),
    linear-gradient(rgba(15, 143, 129, 0.12) 1px, transparent 1px),
    #fbfcfa;
  background-size: 18px 18px;
  text-align: center;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.upload-zone::before {
  position: absolute;
  top: 10px;
  right: 10px;
  bottom: 10px;
  left: 10px;
  border: 1px solid rgba(15, 143, 129, 0.22);
  border-radius: 6px;
  content: "";
  pointer-events: none;
}

.upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-zone.is-dragging {
  border-color: var(--teal);
  background-color: var(--teal-soft);
  transform: translateY(-1px);
}

.upload-icon {
  position: relative;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid #0b665e;
  border-radius: 8px;
  background: var(--teal);
}

.upload-icon::before,
.upload-icon::after {
  position: absolute;
  content: "";
  background: #f9fbf7;
}

.upload-icon::before {
  width: 20px;
  height: 2px;
}

.upload-icon::after {
  width: 2px;
  height: 20px;
}

.upload-zone strong {
  font-size: 1.02rem;
}

.upload-zone small {
  max-width: 230px;
  line-height: 1.45;
}

.file-card,
.engine-options,
.panel-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.file-card {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.engine-options {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.engine-options .section-title {
  margin-bottom: 2px;
}

.option-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 38px;
  color: var(--muted);
  font-size: 0.86rem;
}

.option-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.option-row select {
  min-width: 82px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 28px 0 10px;
  color: var(--ink);
  background: #fbfcfa;
}

.api-config-row {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
}

.api-config-row input {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #fbfcfa;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.text-button {
  justify-self: start;
  min-height: 30px;
  border: 0;
  padding: 0;
  color: var(--teal-dark);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 800;
}

.option-help {
  margin-top: 0;
  color: #59616a;
  font-size: 0.78rem;
  line-height: 1.45;
}

.file-card strong {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

dl {
  margin: 0;
}

.file-card dl,
.analysis-list {
  display: grid;
  gap: 0;
}

.file-card dl div,
.analysis-list div {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 34px;
  border-top: 1px solid #e3e7e8;
}

dt {
  color: var(--muted);
  font-size: 0.82rem;
}

dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 760;
  text-align: right;
}

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

.primary-button,
.ghost-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.primary-button {
  color: #f9fbf7;
  background: var(--teal-dark);
}

.primary-button:hover:not(:disabled),
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: not-allowed;
  color: #e5e7e8;
  background: #8f999d;
}

.ghost-button {
  color: var(--shell);
  background: #fff;
  border-color: var(--line);
}

.notice {
  border-radius: 8px;
  padding: 12px;
  line-height: 1.45;
  font-size: 0.88rem;
}

.notice.error {
  color: var(--red);
  background: #fff0ed;
  border: 1px solid #f0b8ae;
}

.notice.warning {
  color: #6f3a07;
  background: #fff5df;
  border: 1px solid #e8bd79;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  min-height: 66px;
  padding: 12px 14px;
  border-bottom: 1px solid #bac4c5;
  background: #f9faf7;
}

.canvas-title {
  display: grid;
  gap: 0;
}

.canvas-title strong {
  font-size: 1rem;
}

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segmented-control button {
  min-height: 38px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segmented-control button + button {
  border-left: 1px solid var(--line);
}

.segmented-control button.active {
  color: #f9fbf7;
  background: var(--shell-2);
}

.opacity-control {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.84rem;
}

.opacity-control input {
  width: 142px;
  accent-color: var(--teal);
}

.preview-stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  padding: 36px;
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(18, 21, 26, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(18, 21, 26, 0.08) 1px, transparent 1px),
    linear-gradient(45deg, #d5dcdd 25%, transparent 25%),
    linear-gradient(-45deg, #d5dcdd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d5dcdd 75%),
    linear-gradient(-45deg, transparent 75%, #d5dcdd 75%),
    #edf1ef;
  background-position:
    0 0,
    0 0,
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size:
    48px 48px,
    48px 48px,
    20px 20px,
    20px 20px,
    20px 20px,
    20px 20px;
}

.preview-stage::before,
.preview-stage::after {
  position: absolute;
  z-index: 0;
  content: "";
  pointer-events: none;
}

.preview-stage::before {
  top: 0;
  right: 0;
  left: 0;
  height: 20px;
  border-bottom: 1px solid rgba(18, 21, 26, 0.18);
  background:
    repeating-linear-gradient(90deg, rgba(18, 21, 26, 0.36) 0 1px, transparent 1px 24px),
    rgba(255, 255, 255, 0.48);
}

.preview-stage::after {
  top: 0;
  bottom: 0;
  left: 0;
  width: 20px;
  border-right: 1px solid rgba(18, 21, 26, 0.18);
  background:
    repeating-linear-gradient(0deg, rgba(18, 21, 26, 0.36) 0 1px, transparent 1px 24px),
    rgba(255, 255, 255, 0.48);
}

.empty-state {
  z-index: 1;
  display: grid;
  gap: 8px;
  place-items: center;
  max-width: 340px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  text-align: center;
}

.empty-state strong {
  font-size: 1.08rem;
}

.empty-state span {
  color: var(--muted);
  line-height: 1.5;
}

#originalPreview,
.svg-preview,
.svg-preview svg {
  z-index: 1;
}

#originalPreview,
.svg-preview svg {
  display: block;
  max-width: min(100%, 920px);
  max-height: calc(100vh - 180px);
  width: auto;
  height: auto;
  object-fit: contain;
  border: 1px solid rgba(18, 21, 26, 0.26);
  background: #fff;
  box-shadow:
    0 18px 54px rgba(18, 21, 26, 0.22),
    0 0 0 8px rgba(255, 255, 255, 0.42);
}

.preview-stage[data-mode="overlay"] #originalPreview,
.preview-stage[data-mode="overlay"] .svg-preview {
  position: absolute;
  inset: 36px;
  display: grid !important;
  place-items: center;
}

.preview-stage[data-mode="overlay"] #originalPreview {
  opacity: 1;
}

.preview-stage[data-mode="overlay"] .svg-preview {
  opacity: var(--overlay-opacity, 0.55);
  mix-blend-mode: multiply;
}

.preview-stage[data-mode="overlay"] .svg-preview svg {
  background: transparent;
  box-shadow: none;
}

.panel-section {
  padding: 14px;
}

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

.badge {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 800;
}

.badge.simple {
  color: #053f35;
  background: #cbeee6;
}

.badge.moderate {
  color: #693604;
  background: #ffe0a6;
}

.badge.complex {
  color: #7f1d1d;
  background: #ffd4dc;
}

.badge.muted {
  color: #59616a;
  background: #e5e8e8;
}

.palette-list,
.layer-list {
  display: grid;
  gap: 9px;
}

.palette-empty,
.layer-empty {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.palette-row {
  display: grid;
  grid-template-columns: 38px 1fr 70px;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid #e3e7e8;
  border-radius: 8px;
  background: #fbfcfa;
}

.palette-row input[type="color"] {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
}

.palette-meta {
  min-width: 0;
}

.palette-name,
.layer-name {
  display: block;
  overflow: hidden;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-hex,
.layer-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.76rem;
}

.palette-role {
  color: var(--blue);
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 800;
  text-align: right;
}

.layer-row {
  position: relative;
  padding: 10px 10px 10px 14px;
  border: 1px solid #e3e7e8;
  border-radius: 8px;
  background: #fbfcfa;
}

.layer-row::before {
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 7px;
  width: 3px;
  border-radius: 999px;
  background: var(--teal);
  content: "";
}

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

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

  .editor-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-radius: 8px;
  }

  .editor-panel > .panel-heading {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  body {
    overflow-x: hidden;
  }

  .app-shell {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    padding: 10px;
  }

  .app-topbar,
  .toolbar,
  .toolbar-controls {
    align-items: stretch;
  }

  .app-topbar,
  .workspace,
  .editor-panel {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    min-width: 0;
  }

  .scope-strip {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    width: 100%;
  }

  .scope-strip span {
    min-width: 0;
    padding-right: 4px;
    padding-left: 4px;
    font-size: 0.7rem;
  }

  .side-panel,
  .preview-area,
  .editor-panel {
    width: 100%;
    min-width: 0;
    border-radius: 8px;
  }

  .preview-area {
    min-height: 520px;
  }

  .toolbar-controls,
  .segmented-control,
  .opacity-control,
  .opacity-control input {
    width: 100%;
  }

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

  .panel-heading,
  .product-lockup {
    min-width: 0;
  }

  .format-pill {
    display: none;
    max-width: 112px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

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

  .segmented-control button {
    min-width: 0;
  }

  .opacity-control {
    align-items: center;
    justify-content: space-between;
  }

  .preview-stage {
    padding: 30px 22px;
  }

  .preview-stage[data-mode="overlay"] #originalPreview,
  .preview-stage[data-mode="overlay"] .svg-preview {
    inset: 30px 22px;
  }

  #originalPreview,
  .svg-preview svg {
    max-height: 420px;
  }
}

@media (max-width: 460px) {
  .scope-strip {
    grid-template-columns: 1fr;
  }

  .palette-row {
    grid-template-columns: 38px 1fr;
  }

  .palette-role {
    grid-column: 2;
    text-align: left;
  }
}
