:root {
  --bg: #0e1110;
  --ink-on-dark: #f5f2e8;
  --muted-on-dark: #aeb4aa;
  --line: rgba(255, 253, 245, .18);
  --accent: #d6ff61;
  --accent-ink: #1d2600;
  --danger-soft: rgba(255, 127, 110, .16);
  --shadow: 0 30px 90px rgba(0, 0, 0, .36);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(214, 255, 97, .22), transparent 28vw),
    radial-gradient(circle at 86% 18%, rgba(99, 214, 198, .18), transparent 26vw),
    linear-gradient(135deg, #0d100f 0%, #191c19 48%, #101312 100%);
  color: var(--ink-on-dark);
  font-family: "Aptos Display", "Microsoft YaHei UI", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: .28;
  background-image:
    linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, #000, transparent 78%);
}

button,
a {
  color: inherit;
  font: inherit;
}

.compact-header {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid rgba(255, 253, 245, .12);
  background: rgba(14, 17, 16, .74);
  backdrop-filter: blur(22px);
}

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

.mark {
  display: grid;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgba(214, 255, 97, .42);
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  overflow: hidden;
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 820;
  line-height: 1.12;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
}

.total-chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(214, 255, 97, .32);
  border-radius: 8px;
  background: rgba(214, 255, 97, .1);
}

.total-chip span {
  color: var(--muted-on-dark);
  font-size: 12px;
}

.total-chip b {
  color: var(--ink-on-dark);
  font-size: 22px;
  line-height: 1;
}

.content-panel {
  position: relative;
  z-index: 1;
  width: min(1680px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 22px clamp(16px, 3vw, 34px) 34px;
}

.refresh-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 92px;
  height: 42px;
  padding: 0 15px;
  border: 1px solid rgba(214, 255, 97, .36);
  border-radius: 8px;
  background: rgba(214, 255, 97, .12);
  color: var(--ink-on-dark);
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}

.refresh-button:hover {
  border-color: rgba(214, 255, 97, .7);
  background: rgba(214, 255, 97, .2);
  transform: translateY(-1px);
}

.grid {
  column-count: 4;
  column-gap: 14px;
}

.card {
  position: relative;
  display: grid;
  width: 100%;
  margin: 0 0 14px;
  min-width: 0;
  aspect-ratio: var(--card-ratio, 1 / 1);
  min-height: 180px;
  overflow: hidden;
  break-inside: avoid;
  page-break-inside: avoid;
  border: 1px solid rgba(255, 253, 245, .15);
  border-radius: 8px;
  background: rgba(255, 253, 245, .08);
  color: var(--ink-on-dark);
  text-decoration: none;
  box-shadow: 0 18px 46px rgba(0, 0, 0, .16);
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}

.card::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0;
  background: linear-gradient(180deg, transparent 35%, rgba(0, 0, 0, .68) 100%);
  transition: opacity .2s ease;
}

.card:hover,
.card:focus-visible {
  border-color: rgba(214, 255, 97, .55);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .34);
  transform: translateY(-4px);
}

.card:hover::after,
.card:focus-visible::after {
  opacity: 1;
}

.thumb {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(214, 255, 97, .12), rgba(99, 214, 198, .1)),
    #242824;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(1);
  transition: transform .55s ease, filter .55s ease;
}

.card:hover .thumb img,
.card:focus-visible .thumb img {
  filter: saturate(1.08) contrast(1.03);
  transform: scale(1.035);
}

.card-body {
  position: relative;
  z-index: 1;
  display: grid;
  align-self: end;
  gap: 12px;
  padding: 16px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}

.group-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(214, 255, 97, .46);
  border-radius: 8px;
  background: rgba(14, 17, 16, .72);
  color: var(--accent);
  font-size: 12px;
  font-weight: 820;
  backdrop-filter: blur(16px);
}

.card:hover .card-body,
.card:focus-visible .card-body {
  opacity: 1;
  transform: translateY(0);
}

.card-kicker,
.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-kicker,
.meta {
  color: rgba(245, 242, 232, .72);
  font-size: 12px;
}

.prompt {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  font-size: 15px;
  font-weight: 660;
  line-height: 1.5;
  text-shadow: 0 2px 16px rgba(0, 0, 0, .44);
  word-break: break-word;
}

.empty {
  display: grid;
  min-height: 360px;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 28px;
  border: 1px dashed rgba(255, 253, 245, .2);
  border-radius: 8px;
  background: rgba(255, 253, 245, .07);
  color: var(--muted-on-dark);
  font-size: 14px;
  text-align: center;
}

.empty b {
  color: var(--ink-on-dark);
  font-size: 18px;
}

.empty span {
  display: block;
}

.loading {
  margin-top: 14px;
  color: var(--muted-on-dark);
  font-size: 13px;
}

.htmx-indicator {
  opacity: 0;
  transition: opacity .16s ease;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

dialog {
  width: min(1180px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid rgba(255, 253, 245, .18);
  border-radius: 8px;
  background: rgba(20, 23, 21, .92);
  color: var(--ink-on-dark);
  box-shadow: var(--shadow);
  backdrop-filter: blur(28px);
}

dialog::backdrop {
  background: rgba(6, 8, 7, .7);
  backdrop-filter: blur(10px);
}

.detail-shell {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 0;
  overflow-x: hidden;
}

.detail-shell > .merged-records {
  margin: 0 18px 18px;
  min-width: 0;
}

.modal {
  display: grid;
  grid-template-columns: minmax(300px, 1.08fr) minmax(340px, .92fr);
  min-width: 0;
  min-height: min(700px, calc(100vh - 28px));
}

.preview {
  display: grid;
  min-width: 0;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 20% 15%, rgba(214, 255, 97, .18), transparent 34%),
    radial-gradient(circle at 90% 80%, rgba(99, 214, 198, .14), transparent 32%),
    #111412;
}

.preview a {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
}

.preview img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 84px);
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .36);
}

.placeholder {
  width: 100%;
  padding: 18px;
  color: var(--muted-on-dark);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
  word-break: break-word;
}

.detail {
  min-width: 0;
  padding: 22px;
  border-left: 1px solid rgba(255, 253, 245, .13);
  background: rgba(255, 253, 245, .06);
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.detail h2 {
  margin-top: 4px;
  font-size: 30px;
  line-height: 1.05;
}

.detail-actions {
  display: none;
  margin-bottom: 14px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid rgba(214, 255, 97, .34);
  border-radius: 8px;
  background: rgba(214, 255, 97, .12);
  color: var(--ink-on-dark);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.back-link:hover {
  border-color: rgba(214, 255, 97, .68);
  background: rgba(214, 255, 97, .2);
  transform: translateY(-1px);
}

.close {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(255, 253, 245, .18);
  border-radius: 8px;
  background: rgba(255, 253, 245, .08);
  color: var(--ink-on-dark);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.close:hover {
  border-color: rgba(214, 255, 97, .54);
}

.section {
  min-width: 0;
  padding: 16px;
  margin-top: 12px;
  border: 1px solid rgba(255, 253, 245, .12);
  border-radius: 8px;
  background: rgba(255, 253, 245, .06);
}

.prompt-section {
  border-color: rgba(214, 255, 97, .28);
}

.group-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-color: rgba(99, 214, 198, .28);
}

.group-count {
  display: grid;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(99, 214, 198, .35);
  border-radius: 8px;
  background: rgba(99, 214, 198, .12);
  color: #c9fff6;
  font-size: 22px;
  font-weight: 860;
}

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

.label {
  margin-bottom: 9px;
  color: var(--muted-on-dark);
  font-size: 12px;
}

.section-head .label {
  margin-bottom: 0;
}

.copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid rgba(214, 255, 97, .32);
  border-radius: 8px;
  background: rgba(214, 255, 97, .1);
  color: var(--ink-on-dark);
  cursor: pointer;
  font-size: 12px;
  font-weight: 780;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.copy-button:hover,
.copy-button.copied {
  border-color: rgba(214, 255, 97, .68);
  background: rgba(214, 255, 97, .2);
}

.copy-button:hover {
  transform: translateY(-1px);
}

.prompt-copy-source {
  width: 100%;
  min-height: 132px;
  padding: 12px;
  border: 1px solid rgba(214, 255, 97, .28);
  border-radius: 8px;
  background: rgba(0, 0, 0, .18);
  color: var(--ink-on-dark);
  font: inherit;
  line-height: 1.55;
  outline: none;
  resize: vertical;
  -webkit-user-select: text;
  user-select: text;
}

.prompt-copy-source:focus,
.prompt-copy-source.manual-copy-active {
  border-color: rgba(214, 255, 97, .7);
  background: rgba(214, 255, 97, .08);
}

.text {
  font-size: 14px;
  line-height: 1.68;
  white-space: pre-wrap;
  word-break: break-word;
}

.refs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 9px;
}

.refs a {
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 1px solid rgba(255, 253, 245, .15);
  border-radius: 8px;
  background: rgba(255, 253, 245, .08);
}

.refs img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.merged-records {
  border-color: rgba(255, 253, 245, .16);
  background: rgba(255, 253, 245, .05);
  overflow-x: hidden;
}

.nested-grid {
  column-count: 4;
  column-gap: 12px;
  min-width: 0;
  overflow-x: hidden;
}

.nested-card {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 160px;
  margin: 0 0 12px;
  aspect-ratio: var(--card-ratio, 1 / 1);
  overflow: hidden;
  break-inside: avoid;
  page-break-inside: avoid;
  border: 1px solid rgba(255, 253, 245, .14);
  border-radius: 8px;
  background: rgba(255, 253, 245, .08);
  color: var(--ink-on-dark);
  text-decoration: none;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.nested-card::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0;
  background: linear-gradient(180deg, transparent 28%, rgba(0, 0, 0, .72) 100%);
  transition: opacity .2s ease;
}

.nested-card:hover,
.nested-card:focus-visible {
  border-color: rgba(214, 255, 97, .62);
  box-shadow: 0 18px 46px rgba(0, 0, 0, .26);
  transform: translateY(-2px);
}

.nested-card:hover::after,
.nested-card:focus-visible::after {
  opacity: 1;
}

.nested-card.active {
  border-color: rgba(214, 255, 97, .62);
  box-shadow: inset 0 0 0 2px rgba(214, 255, 97, .46);
}

.nested-thumb {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(214, 255, 97, .12), rgba(99, 214, 198, .1)),
    #242824;
}

.nested-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform .45s ease, filter .45s ease;
}

.nested-card:hover .nested-thumb img,
.nested-card:focus-visible .nested-thumb img {
  filter: saturate(1.08) contrast(1.03);
  transform: scale(1.035);
}

.nested-body {
  position: relative;
  z-index: 1;
  display: grid;
  align-self: end;
  gap: 10px;
  padding: 12px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}

.nested-card:hover .nested-body,
.nested-card:focus-visible .nested-body {
  opacity: 1;
  transform: translateY(0);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-avatar {
  display: grid;
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(214, 255, 97, .36);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 25%, rgba(255,255,255,.5), transparent 24px),
    linear-gradient(135deg, rgba(214,255,97,.95), rgba(99,214,198,.86));
  color: var(--accent-ink);
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.user-avatar-img,
.user-avatar-fallback {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
}

.user-avatar-img {
  display: block;
  object-fit: cover;
}

.user-avatar-fallback {
  display: grid;
  place-items: center;
}

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

.user-name {
  overflow: hidden;
  color: var(--ink-on-dark);
  font-size: 16px;
  font-weight: 780;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#records.htmx-settling .card,
#modal-root.htmx-settling dialog {
  animation: settle-in .24s ease both;
}

.detail-page {
  overflow-x: hidden;
}

.standalone-detail {
  position: relative;
  z-index: 1;
  width: min(1240px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 34px);
}

.page-back {
  margin-bottom: 14px;
}

.standalone-modal {
  overflow: hidden;
  border: 1px solid rgba(255, 253, 245, .18);
  border-radius: 8px;
  background: rgba(20, 23, 21, .86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(28px);
}

.standalone-modal .detail {
  max-height: none;
}

@keyframes settle-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1060px) {
  .grid {
    column-count: 3;
  }
}

@media (max-width: 760px) {
  .compact-header {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .brand-lockup {
    align-items: center;
    flex-direction: row;
  }

  .mark {
    width: 36px;
    height: 36px;
  }

  .header-actions {
    width: 100%;
  }

  .content-panel {
    padding-inline: 12px;
  }

  .grid {
    column-count: 2;
    column-gap: 10px;
  }

  .card {
    margin-bottom: 10px;
    min-height: 160px;
  }

  .prompt {
    font-size: 13px;
  }

  dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .modal {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .preview {
    min-height: 0;
    padding: 12px;
  }

  .preview img {
    max-height: 58vh;
  }

  .detail {
    max-height: none;
    padding: 16px;
    overflow: visible;
    border-left: 0;
    border-top: 1px solid rgba(255, 253, 245, .13);
  }

  .standalone-detail {
    padding: 12px;
  }

  .standalone-modal {
    overflow: visible;
  }

  .detail-shell > .merged-records {
    margin: 0;
  }

  .detail-actions {
    display: block;
  }

  .nested-grid {
    column-count: 2;
    column-gap: 10px;
  }
}

@media (max-width: 480px) {
  .header-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .refresh-button,
  .total-chip {
    width: auto;
    min-width: 0;
    justify-content: center;
    padding-inline: 11px;
  }

  .total-chip {
    justify-content: space-between;
  }

  .total-chip span {
    white-space: nowrap;
  }

  .grid {
    column-count: 1;
  }

  .group-summary {
    align-items: flex-start;
  }

  .nested-grid {
    column-count: 1;
  }
}

@media (max-width: 820px), (pointer: coarse) {
  .compact-header .brand-lockup {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    width: 100%;
  }

  .compact-header .mark {
    position: static !important;
    width: 36px !important;
    height: 36px !important;
    margin: 0 !important;
  }

  .compact-header .header-actions {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    width: 100% !important;
    gap: 8px !important;
  }

  .compact-header .total-chip,
  .compact-header .refresh-button {
    width: auto !important;
    min-width: 0 !important;
    justify-content: center !important;
  }

  .compact-header .total-chip {
    justify-content: space-between !important;
  }

  #detail-dialog {
    inset: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    border-radius: 0 !important;
    padding: 0 !important;
  }

  #detail-dialog .modal,
  .standalone-modal {
    display: grid !important;
    grid-template-columns: 1fr !important;
    min-height: auto !important;
    overflow: visible !important;
  }

  #detail-dialog .preview,
  .standalone-modal .preview {
    min-height: 0 !important;
    padding: 12px !important;
  }

  #detail-dialog .preview img,
  .standalone-modal .preview img {
    max-height: 52vh !important;
  }

  #detail-dialog .detail,
  .standalone-modal .detail {
    max-height: none !important;
    overflow: visible !important;
    padding: 16px !important;
    border-left: 0 !important;
    border-top: 1px solid rgba(255, 253, 245, .13) !important;
  }
}
