:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #f1f5f9;
  --text: #111827;
  --muted: #64748b;
  --border: #d9e2ef;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #ccfbf1;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --success: #047857;
  --success-soft: #d1fae5;
  --warning-soft: #fef3c7;
  --shadow: 0 18px 60px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111827;
  --surface-strong: #1e293b;
  --text: #e5edf7;
  --muted: #9fb0c8;
  --border: #273449;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.14);
  --danger: #fca5a5;
  --danger-soft: rgba(185, 28, 28, 0.18);
  --success: #86efac;
  --success-soft: rgba(4, 120, 87, 0.2);
  --warning-soft: rgba(245, 158, 11, 0.18);
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 8%, rgba(45, 212, 191, 0.16), transparent 28rem),
    linear-gradient(180deg, var(--bg), var(--bg));
  color: var(--text);
  min-width: 320px;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto minmax(230px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  color: white;
  background: linear-gradient(135deg, #0f766e, #2563eb);
  flex: 0 0 auto;
}

.brand-mark svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  line-height: 1.1;
  font-size: 1rem;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.topnav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.topnav a {
  color: var(--muted);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 650;
  white-space: nowrap;
}

.topnav a:hover,
.topnav a:focus-visible,
.topnav a.active {
  color: var(--text);
  background: var(--surface);
  outline: none;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.icon-button,
.segmented button,
.ghost-button,
.primary-button,
.secondary-button {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 7px;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.icon-button:hover,
.segmented button:hover,
.ghost-button:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.icon-button {
  display: grid;
  width: 40px;
  place-items: center;
  color: var(--text);
  background: var(--surface);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.segmented button {
  min-height: 32px;
  padding: 0 11px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 700;
}

.segmented button.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.1);
}

main {
  padding: 36px 0 24px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 440px);
  align-items: end;
  gap: 28px;
  min-height: 270px;
  padding: 34px 8px 30px;
}

.hero-copy {
  min-width: 0;
  max-width: 100%;
}

.hero-copy * {
  max-width: 100%;
}

.hero h1 {
  max-width: 780px;
  margin: 0;
  font-size: clamp(2.25rem, 5vw, 4.9rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.hero p {
  max-width: 690px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
  line-height: 1.8;
}

.home-hero {
  min-height: 330px;
}

.page-heading {
  display: grid;
  gap: 10px;
  max-width: 920px;
  padding: 46px 8px 26px;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(2.15rem, 4vw, 4rem);
  line-height: 1.04;
  letter-spacing: 0;
}

.page-heading p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.6vw, 1.14rem);
  line-height: 1.75;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.home-card {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 300px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.home-card:hover,
.home-card:focus-visible {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--accent) 46%, var(--border));
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
  outline: none;
}

.home-icon {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: var(--radius);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.home-icon svg {
  width: 23px;
  height: 23px;
  fill: currentColor;
}

.home-card h2 {
  margin: 4px 0 0;
  font-size: 1.35rem;
  line-height: 1.2;
}

.home-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.72;
}

.home-card strong {
  align-self: end;
  margin-top: 10px;
  color: var(--accent-strong);
  font-size: 0.92rem;
}

.hero-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--border);
  box-shadow: var(--shadow);
}

.hero-panel div {
  min-width: 0;
  padding: 18px;
  background: var(--surface);
}

.hero-panel span,
.result-item span,
.field label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.hero-panel strong {
  display: block;
  margin-top: 8px;
  font-size: 1.05rem;
  line-height: 1.2;
}

.workspace {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.rail {
  position: sticky;
  top: 91px;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.rail-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 720;
}

.rail-link svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
  flex: 0 0 auto;
}

.rail-link.active,
.rail-link:hover,
.rail-link:focus-visible {
  color: var(--accent-strong);
  background: var(--accent-soft);
  outline: none;
}

.tools {
  display: grid;
  gap: 18px;
}

.tool-section {
  scroll-margin-top: 96px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 18px;
  margin: 0 0 14px;
}

.section-heading h2 {
  margin: 0;
  font-size: clamp(1.35rem, 2.4vw, 2rem);
  letter-spacing: 0;
}

.section-heading p {
  max-width: 820px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tool-grid {
  display: grid;
  gap: 18px;
}

.two-col {
  grid-template-columns: minmax(0, 1.03fr) minmax(300px, 0.97fr);
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field + .field,
.controls-grid,
.button-row {
  margin-top: 14px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.field label {
  letter-spacing: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-strong);
  color: var(--text);
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

input[type="color"] {
  padding: 4px;
}

input[type="range"] {
  padding: 0;
}

textarea {
  min-height: 120px;
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.codearea {
  min-height: 310px;
  font-family: var(--mono);
  font-size: 0.88rem;
  tab-size: 2;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button {
  padding: 0 14px;
  font-size: 0.88rem;
  font-weight: 760;
}

.primary-button {
  border-color: var(--accent-strong);
  color: white;
  background: linear-gradient(135deg, var(--accent), #2563eb);
}

.secondary-button,
.ghost-button {
  color: var(--text);
  background: var(--surface);
}

.ghost-button {
  background: var(--surface-strong);
}

.preview-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.qr-preview {
  display: grid;
  min-height: 300px;
  width: 100%;
  place-items: center;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, color-mix(in srgb, var(--surface-strong) 76%, transparent) 25%, transparent 25%),
    linear-gradient(-45deg, color-mix(in srgb, var(--surface-strong) 76%, transparent) 25%, transparent 25%),
    var(--surface);
  background-size: 18px 18px;
}

.qr-preview canvas,
.qr-preview svg {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

.status {
  color: var(--muted);
  min-height: 22px;
  line-height: 1.5;
  font-size: 0.88rem;
}

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--success);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
  padding: 5px;
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.tab {
  min-height: 36px;
  padding: 0 13px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 0.88rem;
  font-weight: 760;
}

.tab.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.diff-output {
  display: grid;
  gap: 4px;
  max-height: 420px;
  overflow: auto;
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-strong);
  font-family: var(--mono);
  font-size: 0.84rem;
}

.diff-line {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 10px;
  padding: 6px 10px;
  border-left: 3px solid transparent;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-line.add {
  background: var(--success-soft);
  border-left-color: var(--success);
}

.diff-line.remove {
  background: var(--danger-soft);
  border-left-color: var(--danger);
}

.diff-line.change {
  background: var(--warning-soft);
  border-left-color: #d97706;
}

.diff-line.same {
  color: var(--muted);
}

.diff-line span:first-child {
  color: var(--muted);
  user-select: none;
}

.result-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.result-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-strong);
}

.result-item strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 0.94rem;
  line-height: 1.45;
}

@media (max-width: 1050px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .topnav {
    grid-column: 1 / -1;
    order: 3;
  }

  .hero,
  .workspace,
  .two-col,
  .home-grid {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 10px;
  }

  .brand {
    min-width: 0;
  }

  .brand strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand strong,
  .brand small {
    display: none;
  }

  .topnav {
    display: flex;
    flex: 0 0 100%;
    grid-column: 1 / -1;
    order: 3;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .topnav::-webkit-scrollbar {
    display: none;
  }

  .hero {
    min-height: auto;
    padding: 24px 2px;
  }

  .page-heading {
    padding: 28px 2px 18px;
  }

  .page-heading h1 {
    font-size: clamp(1.8rem, 8vw, 2.35rem);
    overflow-wrap: anywhere;
  }

  .hero h1 {
    max-width: min(10em, calc(100vw - 24px));
    font-size: clamp(1.55rem, 6.6vw, 1.85rem);
    line-height: 1.08;
    overflow-wrap: anywhere;
    word-break: break-all;
  }

  .hero p,
  .section-heading p {
    max-width: 22em;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .hero-panel,
  .editor-grid,
  .controls-grid,
  .rail {
    grid-template-columns: 1fr;
  }

  .rail-link {
    min-height: 40px;
  }

  .section-heading {
    display: grid;
  }

  .panel {
    padding: 14px;
  }

  .codearea {
    min-height: 240px;
  }
}

@media (max-width: 420px) {
  .topbar {
    padding: 10px;
  }

  .brand strong {
    display: none;
  }

  .top-actions {
    gap: 6px;
    justify-content: flex-start;
  }

  .icon-button {
    width: 36px;
    min-height: 36px;
  }

  .segmented button {
    padding: 0 6px;
    font-size: 0.76rem;
  }
}
