:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: rgba(255, 255, 255, .94);
  --panel-strong: #ffffff;
  --soft: #eef2f6;
  --line: rgba(17, 24, 39, .12);
  --text: #111827;
  --muted: #5b6472;
  --accent: #0d9488;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --danger: #c42b1c;
  --success: #107c10;
  --warn: #f97316;
  --gold: #d99b16;
  --silver: #8b95a3;
  --bronze: #b7652d;
  --radius: 8px;
  font-family: "Segoe UI", "Microsoft YaHei UI", Arial, sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111315;
  --panel: rgba(33, 35, 39, .9);
  --panel-strong: #272a2f;
  --soft: rgba(255, 255, 255, .07);
  --line: rgba(255, 255, 255, .14);
  --text: #f7f7f8;
  --muted: #a9b0bb;
  --accent-soft: color-mix(in srgb, var(--accent) 18%, transparent);
}

* { box-sizing: border-box; }

.drag-light *,
.drag-light *::before,
.drag-light *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

html {
  min-height: 100%;
  overflow: auto;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: auto;
}

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 24%, transparent);
  outline-offset: 1px;
}

button.ghost {
  background: transparent;
}

button.compact {
  min-height: 30px;
  padding: 5px 9px;
  color: var(--muted);
}

.result-page {
  display: grid;
  gap: 14px;
}

.result-chrome,
.details-drawer,
.block,
.metric,
.table-wrap,
.code-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.result-chrome {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
}

.result-chrome .identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.result-chrome .mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  flex: 0 0 auto;
}

.result-chrome .title {
  min-width: 0;
}

.result-chrome .title h1 {
  margin: 0;
  font-size: clamp(1.05rem, 1.25vw, 1.45rem);
  line-height: 1.18;
}

.result-chrome .meta,
.result-chrome .muted {
  color: var(--muted);
}

.result-chrome .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.result-chrome .metrics {
  grid-column: 1 / -1;
  margin: 0;
}

.blocks {
  display: grid;
  gap: 12px;
}

.details-drawer {
  overflow: hidden;
  padding: 0;
}

.details-drawer > summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 700;
}

.details-drawer > summary::-webkit-details-marker {
  display: none;
}

.details-drawer[open] > summary {
  border-bottom: 1px solid var(--line);
}

.details-drawer .raw-card {
  border: 0;
  border-radius: 0;
  border-top: 1px solid var(--line);
}

.result-shell {
  min-height: 100vh;
  padding: clamp(12px, 2vw, 24px);
}

.hero,
.metric,
.block,
.table-wrap,
.code-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: clamp(14px, 2vw, 20px);
}

.identity {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 36%, transparent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.title {
  min-width: 0;
}

.eyebrow,
.meta,
.muted {
  color: var(--muted);
}

.eyebrow {
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

h1 {
  font-size: clamp(1.35rem, 2.4vw, 2.1rem);
  line-height: 1.12;
}

h2 {
  font-size: 1rem;
}

.actions,
.link-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.actions {
  justify-content: flex-end;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.metric {
  padding: 12px;
  min-height: 74px;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.1rem, 2vw, 1.55rem);
  overflow-wrap: anywhere;
}

.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, .32fr);
  gap: 12px;
}

.blocks,
.side {
  display: grid;
  gap: 12px;
  align-content: start;
}

.block {
  padding: 14px;
  overflow: hidden;
}

.side-card {
  background: color-mix(in srgb, var(--panel) 84%, var(--soft));
}

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

.block-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.block-icon {
  width: 20px;
  height: 20px;
  color: var(--accent);
  flex: 0 0 auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 7px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
  background: var(--accent-soft);
  font-size: .74rem;
  font-weight: 800;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.kv,
.list-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
}

.kv {
  padding: 10px;
  min-width: 0;
}

.kv span,
.list-item span {
  display: block;
  color: var(--muted);
  font-size: .76rem;
}

.kv strong,
.list-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.metric-grid .primary-kv {
  grid-column: 1 / -1;
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  background: color-mix(in srgb, var(--panel-strong) 84%, var(--accent-soft));
}

.metric-grid .primary-kv strong {
  color: var(--accent);
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  line-height: 1.08;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
}

td,
th {
  padding: 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 800;
}

.list {
  display: grid;
  gap: 8px;
}

.card-list,
.ranked-list {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.list-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
}

.ranked-item {
  grid-template-columns: 42px minmax(0, 1fr);
  min-height: 84px;
  border-color: color-mix(in srgb, var(--accent) 22%, var(--line));
}

.card-list .list-item {
  grid-template-columns: 42px minmax(0, 1fr);
}

.list-item.clickable {
  cursor: pointer;
}

.list-item.clickable:hover,
.list-item.clickable:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 56%, var(--line));
  background: color-mix(in srgb, var(--panel-strong) 84%, var(--accent-soft));
  outline: 2px solid color-mix(in srgb, var(--accent) 20%, transparent);
  outline-offset: 1px;
}

.rank-badge {
  width: 36px;
  height: 36px;
  position: relative;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 900;
  font-size: .88rem;
}

.rank-badge::before {
  content: "";
  position: absolute;
  inset: -40%;
  opacity: 0;
  transform: translateX(-45%) rotate(24deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .7), transparent);
}

.rank-core {
  position: relative;
  z-index: 1;
}

.rank-1 {
  color: #4a3300;
  border-color: color-mix(in srgb, var(--gold) 72%, #fff);
  background: linear-gradient(145deg, #fff2b8, #e1a21c 58%, #9f6611);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 18%, transparent);
}

.rank-2 {
  color: #26303b;
  border-color: color-mix(in srgb, var(--silver) 72%, #fff);
  background: linear-gradient(145deg, #f9fbff, #b8c0cc 58%, #687386);
}

.rank-3 {
  color: #3e1f0d;
  border-color: color-mix(in srgb, var(--bronze) 72%, #fff);
  background: linear-gradient(145deg, #ffe0c2, #c87536 58%, #7e3c1c);
}

.rank-badge.plain {
  border-radius: 7px;
}

.item-body {
  min-width: 0;
}

.item-body strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-subtitle {
  margin-top: 4px;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.status-error {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
}

.status-ok {
  border-color: color-mix(in srgb, var(--success) 45%, var(--line));
}

.file-card,
.link-card {
  grid-template-columns: 48px minmax(0, 1fr) auto;
}

.code-wrap {
  max-height: 420px;
  overflow: auto;
  background: var(--panel-strong);
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 12px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: .84rem;
  line-height: 1.55;
}

.media-frame {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background:
    linear-gradient(45deg, color-mix(in srgb, var(--soft) 72%, transparent) 25%, transparent 25%),
    linear-gradient(-45deg, color-mix(in srgb, var(--soft) 72%, transparent) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, color-mix(in srgb, var(--soft) 72%, transparent) 75%),
    linear-gradient(-45deg, transparent 75%, color-mix(in srgb, var(--soft) 72%, transparent) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  overflow: hidden;
}

img,
video {
  display: block;
  max-width: 100%;
  max-height: 440px;
  margin: auto;
  border-radius: 7px;
}

.media-frame img {
  width: min(420px, 88%);
  height: auto;
  object-fit: contain;
  background: #fff;
  padding: 10px;
}

.swatch {
  width: 100%;
  min-height: 150px;
  border-radius: 7px;
  border: 1px solid var(--line);
}

.raw summary {
  cursor: pointer;
  margin-bottom: 0;
}

.raw[open] summary {
  margin-bottom: 10px;
}

.empty-card {
  min-height: 180px;
  display: grid;
  align-content: center;
  gap: 8px;
}

.empty-state {
  min-height: 280px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

@media (prefers-reduced-motion: no-preference) {
  .rank-1,
  .rank-2,
  .rank-3 {
    animation: rankGlow 2.8s ease-in-out infinite;
  }

  .rank-1::before,
  .rank-2::before,
  .rank-3::before {
    animation: rankShimmer 3.2s ease-in-out infinite;
  }

  @keyframes rankGlow {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-1px); }
  }

  @keyframes rankShimmer {
    0%, 45% { opacity: 0; transform: translateX(-45%) rotate(24deg); }
    60% { opacity: .75; }
    100% { opacity: 0; transform: translateX(45%) rotate(24deg); }
  }
}

@media (max-width: 900px) {
  .hero,
  .content,
  .result-chrome {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: flex-start;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .metrics,
  .card-list,
  .ranked-list {
    grid-template-columns: 1fr;
  }

  .list-item,
  .file-card,
  .link-card {
    grid-template-columns: 1fr;
  }

  .link-actions {
    width: 100%;
  }

  .result-chrome {
    padding: 12px;
  }

  .result-chrome .actions,
  .actions {
    justify-content: flex-start;
  }
}

@media (max-height: 760px) {
  .result-shell {
    padding: 10px;
  }

  .result-chrome,
  .block,
  .metric,
  .table-wrap,
  .code-wrap {
    padding: 12px;
  }

  .metrics {
    margin: 10px 0;
  }

  .block-head {
    margin-bottom: 8px;
  }
}

@media (max-width: 560px) {
  .card-list {
    grid-template-columns: 1fr;
  }
}

.drag-strong .result-chrome,
.drag-strong .details-drawer,
.drag-strong .block,
.drag-strong .metric,
.drag-strong .table-wrap,
.drag-strong .code-wrap,
.drag-strong .kv,
.drag-strong .list-item {
  box-shadow: none !important;
  filter: none !important;
  backdrop-filter: none !important;
}

.drag-strong .rank-badge::before {
  display: none !important;
}

.drag-strong .list-item.clickable:hover {
  background: var(--panel-strong);
}

@media (prefers-reduced-motion: reduce) {
  *,
  .rank-1,
  .rank-2,
  .rank-3 {
    animation: none !important;
    transition: none !important;
  }
}
