:root {
    color-scheme: light;
    --page: #eef1f7;
    --surface: #fff;
    --field: #f4f6fa;
    --text: #172039;
    --muted: #54627a;
    --line: #dce3ee;
    --accent: #4c42cb;
    --accent-hover: #3e32b5;
    --accent-soft: #eeedff;
    --accent-text: #fff;
    --selected: #fff;
    --row-alt: #f8faff;
    --row-hover: #eeedff;
    --notice: #fff5e6;
    --notice-text: #834300;
    --error: #ad241b;
    --shadow: 0 4px 16px #1f2b4510;
  }
  :root[data-theme="dark"] {
      color-scheme: dark;
      --page: #101422;
      --surface: #1a2031;
      --field: #232b40;
      --text: #f0f3ff;
      --muted: #b0bdd5;
      --line: #343e56;
      --accent: #b7b0ff;
      --accent-hover: #cfcbff;
      --accent-soft: #302d54;
      --accent-text: #171338;
      --selected: #323c55;
      --row-alt: #1f2638;
      --row-hover: #302d54;
      --notice: #3b2d1b;
      --notice-text: #ffce92;
      --error: #ff968d;
      --shadow: 0 2px 12px #0002;
    }
  * { box-sizing: border-box; }
  body {
    margin: 0;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    background: var(--page);
    color: var(--text);
    font: 0.875rem/1.45 Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  }
  header, main {
    width: min(100%, 1536px);
    margin-inline: auto;
    padding-inline: clamp(16px, 3vw, 40px);
  }
  header { display: flex; align-items: center; gap: 12px; padding-block: 18px 16px; }
  .product-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: var(--accent);
    color: var(--accent-text);
  }
  .product-mark::before {
    content: "";
    width: 17px;
    height: 15px;
    border: 1.5px solid currentColor;
    border-radius: 3px;
    background: linear-gradient(currentColor, currentColor) 0 36% / 100% 1px no-repeat,
      linear-gradient(currentColor, currentColor) 40% 0 / 1px 100% no-repeat;
  }
  h1 { margin: 0; font-size: clamp(1.375rem, 2.3vw, 1.75rem); line-height: 1.15; font-weight: 700; letter-spacing: -.03em; }
  #theme-toggle { margin-inline-start: auto; gap: 7px; background: var(--surface); border-color: var(--line); color: var(--text); }
  #theme-toggle:hover { background: var(--accent-soft); }
  #theme-icon { font-size: 1rem; color: var(--accent); line-height: 1; }
  main {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 14px;
    min-height: 0;
    padding-bottom: 18px;
  }
  .controls {
    display: grid;
    grid-template-columns: minmax(0, 1.68fr) minmax(0, 1fr);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
  }
  #xp-form { display: grid; grid-template-columns: minmax(0, .68fr) minmax(0, 1fr); }
  .step { min-width: 0; padding: clamp(10px, 1.4vw, 20px); }
  .step + .step, .controls > form + form { border-inline-start: 1px solid var(--line); }
  .step-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; min-height: 34px; }
  h2 { margin: 0; font-size: 1rem; line-height: 1.3; font-weight: 650; letter-spacing: -.015em; }
  .step-number {
    color: var(--accent);
    background: var(--accent-soft);
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 25px;
    height: 25px;
    border-radius: 7px;
    margin-right: 8px;
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
  }
  textarea {
    width: 100%;
    display: block;
    height: clamp(60px, 11dvh, 92px);
    resize: none;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--field);
    color: var(--text);
    font: inherit;
    font-size: .875rem;
  }
  textarea::placeholder { color: var(--muted); }
  textarea:focus { border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 23%, transparent); }
  .file-field { position: relative; }
  .source-picker { min-width: 0; }
  .filename { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  button, .btn, .file-button {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 6px 13px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-size: .8125rem;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    color: var(--accent);
    background: var(--field);
  }
  .file-button { flex: none; }
  .source-button {
    width: 100%;
    height: clamp(60px, 11dvh, 92px);
    flex-direction: column;
    gap: 4px;
    color: var(--accent);
    background: var(--field);
    border: 1px dashed var(--line);
  }
  .source-button.primary { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
  .source-button:hover { background: var(--accent-soft); }
  .source-button .filename { font-weight: 400; }
  .import-button { padding-inline: 7px; background: transparent; min-height: 28px; }
  .import-button:hover { background: var(--field); }
  .primary { color: var(--accent-text); background: var(--accent); }
  .primary:hover:not(.source-button) { background: var(--accent-hover); }
  button:disabled, .btn[aria-disabled="true"] { color: var(--muted); background: var(--field); opacity: .69; cursor: default; }
  .row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  .actions .hint { flex: 1 1 54px; }
  .hint { color: var(--muted); font-size: .75rem; }
  .inline-status { display: block; margin-top: 4px; }
  .hint:empty { display: none; }
  [data-error] { color: var(--error); }
  .preview {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
  }
  .preview-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
  }
  .preview-toggle { display: inline-flex; padding: 3px; gap: 2px; background: var(--field); border-radius: 9px; }
  .preview-toggle button { background: transparent; color: var(--muted); min-height: 28px; padding: 4px 13px; }
  .preview-toggle button[aria-pressed="true"] { background: var(--selected); color: var(--accent); box-shadow: 0 1px 3px #0002; }
  .preview-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .preview-summary { margin: 0; padding: 8px 20px; border-bottom: 1px solid var(--line); }
  .missing {
    margin: 6px 12px;
    padding: 6px 8px;
    background: var(--notice);
    color: var(--notice-text);
    border-radius: 8px;
    font-size: .75rem;
    overflow-wrap: anywhere;
    max-height: 64px;
    overflow: auto;
  }
  .table-wrap { flex: 1; min-height: 0; overflow: auto; }
  .table-wrap, textarea { scrollbar-width: thin; scrollbar-color: var(--muted) transparent; }
  table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .8125rem; }
  th, td { padding: 8px 16px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
  th { position: sticky; top: 0; background: var(--field); font-weight: 630; z-index: 1; }
  tbody tr:nth-child(even) { background: var(--row-alt); }
  tbody tr:hover { background: var(--row-hover); }
  td.num { text-align: right; font-variant-numeric: tabular-nums; }
  td.url { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
  .empty-preview {
    flex: 1;
    min-height: 0;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 5px;
    padding: 10px;
    margin: 0;
    text-align: center;
  }
  .empty-preview strong { font-size: 1rem; font-weight: 650; }
  .table-icon {
    display: block;
    width: 44px;
    height: 36px;
    margin-bottom: 6px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background:
      linear-gradient(var(--accent), var(--accent)) 0 33% / 100% 1px no-repeat,
      linear-gradient(var(--line), var(--line)) 0 66% / 100% 1px no-repeat,
      linear-gradient(var(--line), var(--line)) 38% 0 / 1px 100% no-repeat var(--accent-soft);
  }
  .hidden { display: none !important; }
  :focus-visible, .file-input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
  @media (max-width: 46rem) {
    header, main { padding-inline: 12px; }
    header { padding-block: 8px; }
    .product-mark { width: 30px; height: 30px; border-radius: 8px; }
    main { grid-template-rows: auto minmax(126px, 1fr); gap: 8px; padding-bottom: 8px; }
    .controls, #xp-form { display: block; }
    .step { padding: 7px 10px; }
    .step + .step, .controls > form + form { border-inline-start: 0; border-top: 1px solid var(--line); }
    .source-button { height: 35px; flex-direction: row; }
    .source-button .filename { min-width: 0; }
    textarea { height: 50px; }
    .row { margin-top: 5px; }
    .preview-bar { padding: 6px 12px; }
    .table-icon { width: 27px; height: 22px; margin: 0; }
  }
  @media (max-height: 42.5rem) {
    header { padding-block: 8px; }
    main { padding-bottom: 8px; }
    .step-heading { margin-bottom: 5px; }
    textarea { padding-block: 5px; }
    .row { margin-top: 5px; }
  }
  @media (pointer: coarse) and (min-height: 44rem) {
    button, .btn, .file-button, .preview-toggle button { min-height: 44px; }
  }
