:root {
  color-scheme: dark;
  --ink-950: rgba(7, 14, 13, 0.9);
  --ink-900: rgba(10, 23, 21, 0.79);
  --ink-800: rgba(16, 35, 31, 0.7);
  --jade-200: #d0eadc;
  --jade-300: #a8d5c0;
  --jade-400: #72b798;
  --jade-500: #3d8d6c;
  --jade-700: #1e5845;
  --gold-200: #f2dfad;
  --gold-300: #dec181;
  --gold-500: #a9803e;
  --paper: #f2e7c9;
  --paper-ink: #3b2d20;
  --line: rgba(223, 194, 126, 0.33);
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: #f3eddf;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #dfe3dc;
}

button { font: inherit; }

.scene,
.scene iframe,
.scene-vignette {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene { z-index: 0; }

.scene iframe {
  border: 0;
  background: #dfe3dc;
}

.scene-vignette {
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(6, 17, 15, 0.27), transparent 34%, transparent 68%, rgba(6, 17, 15, 0.12)),
    linear-gradient(180deg, rgba(6, 17, 15, 0.28), transparent 22%, transparent 72%, rgba(6, 17, 15, 0.3));
}

.topbar {
  position: fixed;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: max(18px, env(safe-area-inset-top)) 24px 0;
  pointer-events: none;
}

.brand-card,
.top-actions {
  display: flex;
  align-items: center;
  pointer-events: auto;
}

.brand-card {
  gap: 11px;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}

.brand-seal {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #f7eac7;
  font: 700 22px/1 "STKaiti", "KaiTi", serif;
  border: 1px solid rgba(244, 226, 183, 0.8);
  background: rgba(125, 39, 28, 0.82);
  box-shadow: inset 0 0 0 3px rgba(72, 17, 13, 0.35), 0 8px 24px rgba(0, 0, 0, 0.28);
  transform: rotate(-2deg);
}

.brand-card strong {
  display: block;
  font: 600 21px/1.2 "STKaiti", "KaiTi", serif;
  letter-spacing: 0.2em;
}

.brand-card small {
  display: block;
  margin-top: 4px;
  color: rgba(248, 242, 226, 0.7);
  font-size: 9px;
  letter-spacing: 0.17em;
}

.top-actions { gap: 10px; }

.safe-badge,
.ghost-button,
.return-ui {
  border: 1px solid rgba(238, 220, 178, 0.36);
  background: rgba(9, 25, 22, 0.58);
  color: rgba(250, 245, 232, 0.9);
  backdrop-filter: blur(15px) saturate(1.2);
  -webkit-backdrop-filter: blur(15px) saturate(1.2);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.17);
}

.safe-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.08em;
}

.safe-badge i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8fdbad;
  box-shadow: 0 0 12px #8fdbad;
}

.ghost-button,
.return-ui {
  min-height: 34px;
  padding: 0 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 180ms, border-color 180ms, transform 180ms;
}

.ghost-button:hover,
.return-ui:hover {
  border-color: rgba(242, 223, 173, 0.72);
  background: rgba(16, 45, 38, 0.76);
  transform: translateY(-1px);
}

.hud {
  position: fixed;
  z-index: 5;
  inset: 86px 24px 28px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: clamp(24px, 4vw, 70px);
  pointer-events: none;
  transition: opacity 280ms ease, transform 320ms ease;
}

.hud.is-hidden {
  opacity: 0;
  transform: translateY(14px);
  visibility: hidden;
}

body.is-immersive .topbar {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 220ms, transform 260ms, visibility 220ms;
}

.panel {
  position: relative;
  pointer-events: auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(145deg, rgba(29, 56, 48, 0.66), rgba(6, 18, 16, 0.86)),
    radial-gradient(circle at 15% 0%, rgba(133, 188, 159, 0.2), transparent 42%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
}

.panel::before {
  content: "";
  position: absolute;
  inset: 8px;
  pointer-events: none;
  border: 1px solid rgba(225, 199, 137, 0.1);
  border-radius: 9px;
}

.panel-corners::before,
.panel-corners::after {
  content: "";
  position: absolute;
  z-index: 1;
  width: 30px;
  height: 30px;
  pointer-events: none;
  border-color: rgba(226, 196, 126, 0.62);
}

.panel-corners::before {
  top: 7px;
  left: 7px;
  border-top: 1px solid;
  border-left: 1px solid;
  border-radius: 8px 0 0;
}

.panel-corners::after {
  right: 7px;
  bottom: 7px;
  border-right: 1px solid;
  border-bottom: 1px solid;
  border-radius: 0 0 8px;
}

.inventory-panel {
  width: min(480px, 42vw);
  max-height: calc(100vh - 114px);
  padding: 25px;
}

.insight-panel {
  width: min(405px, 36vw);
  max-height: calc(100vh - 114px);
  padding: 23px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(210, 180, 112, 0.35) transparent;
}

.panel-heading {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(229, 207, 154, 0.18);
}

.panel-heading.compact { align-items: center; }

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold-300);
  font-size: 9px;
  letter-spacing: 0.24em;
}

h1, h2 {
  margin: 0;
  font-family: "STKaiti", "KaiTi", serif;
  font-weight: 500;
  letter-spacing: 0.14em;
}

h1 { font-size: clamp(23px, 2vw, 30px); }
h2 { font-size: 23px; }

.capacity {
  color: rgba(239, 226, 197, 0.58);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.capacity b {
  color: var(--gold-200);
  font-size: 18px;
  font-weight: 500;
}

.intro {
  position: relative;
  z-index: 2;
  margin: 15px 0 17px;
  color: rgba(240, 237, 224, 0.67);
  font-size: 12px;
  line-height: 1.75;
}

.inventory-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px;
}

.item-slot {
  position: relative;
  min-width: 0;
  aspect-ratio: 0.9;
  padding: 5px;
  overflow: hidden;
  border: 1px solid rgba(222, 194, 128, 0.17);
  border-radius: 7px;
  background: linear-gradient(155deg, rgba(234, 226, 201, 0.13), rgba(0, 0, 0, 0.24));
  cursor: pointer;
  transition: transform 170ms, border-color 170ms, box-shadow 170ms, opacity 250ms;
}

.item-slot:hover,
.item-slot.is-selected {
  z-index: 3;
  transform: translateY(-3px) scale(1.03);
  border-color: rgba(238, 211, 147, 0.75);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.27), 0 0 15px rgba(108, 185, 146, 0.17);
}

.item-slot.is-scanning {
  border-color: #9de1bb;
  box-shadow: 0 0 20px rgba(111, 218, 164, 0.65), inset 0 0 18px rgba(111, 218, 164, 0.18);
  animation: scan-pulse 400ms ease;
}

.item-slot::after {
  content: "";
  position: absolute;
  inset: auto 6px 4px;
  height: 2px;
  border-radius: 3px;
  background: var(--slot-accent, rgba(230, 206, 151, 0.35));
  opacity: 0;
  transition: opacity 200ms;
}

.item-slot.is-sorted::after { opacity: 1; }

.item-slot img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 4px;
  filter: saturate(0.84) contrast(1.03);
}

.item-slot span {
  position: absolute;
  inset: auto 3px 7px;
  overflow: hidden;
  color: #f8f0dc;
  font: 10px/1.2 "STKaiti", "KaiTi", serif;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 5px #000, 0 0 4px #000;
}

@keyframes scan-pulse {
  0% { transform: scale(1); }
  45% { transform: translateY(-4px) scale(1.08); }
  100% { transform: scale(1); }
}

.lens-console {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  padding: 16px 10px 4px 4px;
  border-top: 1px solid rgba(229, 207, 154, 0.15);
}

.lens-copy { min-width: 0; }

.status-kicker {
  display: block;
  margin-bottom: 5px;
  color: rgba(221, 199, 148, 0.52);
  font-size: 9px;
  letter-spacing: 0.18em;
}

.lens-copy strong {
  display: block;
  color: var(--jade-200);
  font: 500 16px/1.35 "STKaiti", "KaiTi", serif;
  letter-spacing: 0.08em;
}

.lens-copy p {
  max-width: 275px;
  margin: 5px 0 0;
  color: rgba(232, 230, 216, 0.48);
  font-size: 10px;
  line-height: 1.55;
}

.lens-button {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  padding: 0;
  color: var(--gold-200);
  border: 1px solid rgba(235, 210, 150, 0.77);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, #68b98f, #286f54 45%, #12382d 74%, #091d19);
  box-shadow: 0 0 0 7px rgba(42, 108, 83, 0.2), 0 0 34px rgba(74, 177, 131, 0.37), inset 0 2px 2px rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 180ms, box-shadow 180ms, opacity 180ms;
}

.lens-button::before,
.lens-button::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(239, 214, 155, 0.26);
  border-radius: 50%;
}

.lens-button::before { inset: 8px; }
.lens-button::after { inset: -9px; border-style: dashed; }

.lens-button:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.025);
  box-shadow: 0 0 0 8px rgba(42, 108, 83, 0.23), 0 0 50px rgba(79, 195, 143, 0.52), inset 0 2px 2px rgba(255, 255, 255, 0.22);
}

.lens-button:disabled { cursor: wait; opacity: 0.76; }
.lens-button.is-reading { animation: jade-breathe 1.15s ease-in-out infinite; }

.lens-glyph {
  position: absolute;
  top: 12px;
  font-size: 28px;
  opacity: 0.75;
}

.lens-label {
  position: relative;
  z-index: 1;
  margin-top: 28px;
  font: 500 13px/1 "STKaiti", "KaiTi", serif;
  letter-spacing: 0.13em;
}

@keyframes jade-breathe {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); box-shadow: 0 0 0 10px rgba(42, 108, 83, 0.17), 0 0 64px rgba(105, 224, 166, 0.7); }
}

.icon-button {
  width: 34px;
  height: 34px;
  color: rgba(241, 226, 194, 0.75);
  border: 1px solid rgba(229, 207, 154, 0.22);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: background 160ms, transform 160ms;
}

.icon-button:hover { background: rgba(255, 255, 255, 0.1); transform: rotate(-22deg); }

.item-detail {
  position: relative;
  min-height: 188px;
  padding: 18px 0 4px;
}

.detail-placeholder {
  display: grid;
  min-height: 155px;
  place-content: center;
  color: rgba(235, 226, 202, 0.43);
  text-align: center;
}

.detail-placeholder span { font: 46px/1 serif; color: rgba(127, 190, 160, 0.48); }
.detail-placeholder p { margin: 12px 0 0; font: 14px/1.8 "STKaiti", "KaiTi", serif; letter-spacing: 0.1em; }

.detail-card {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 18px;
  align-items: center;
  animation: detail-in 240ms ease both;
}

.detail-card img {
  width: 112px;
  height: 112px;
  object-fit: cover;
  border: 1px solid rgba(234, 207, 143, 0.34);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

.detail-card h3 {
  margin: 0 0 7px;
  color: var(--gold-200);
  font: 500 24px/1.2 "STKaiti", "KaiTi", serif;
  letter-spacing: 0.12em;
}

.detail-tag {
  display: inline-block;
  padding: 3px 8px;
  color: var(--jade-200);
  border: 1px solid rgba(122, 190, 157, 0.3);
  border-radius: 999px;
  background: rgba(78, 139, 110, 0.12);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.detail-card p {
  margin: 10px 0 0;
  color: rgba(240, 232, 212, 0.69);
  font-size: 11px;
  line-height: 1.7;
}

@keyframes detail-in {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}

.result-section[hidden] { display: none; }

.result-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2px 0 14px;
  color: var(--gold-300);
  font: 13px/1 "STKaiti", "KaiTi", serif;
  letter-spacing: 0.16em;
}

.result-divider::before,
.result-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(222, 193, 128, 0.44));
}

.result-divider::after { transform: scaleX(-1); }

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

.category-card {
  display: grid;
  grid-template-columns: 4px 78px 1fr;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 9px 0;
  overflow: hidden;
  border: 1px solid rgba(229, 207, 154, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  opacity: 0;
  transform: translateX(12px);
}

.category-card.is-visible {
  opacity: 1;
  transform: none;
  transition: opacity 340ms, transform 340ms;
}

.category-accent { align-self: stretch; background: var(--category-color); box-shadow: 0 0 12px var(--category-color); }

.category-title strong {
  display: block;
  color: #f2e7ca;
  font: 500 14px/1.2 "STKaiti", "KaiTi", serif;
  letter-spacing: 0.08em;
}

.category-title small { color: rgba(237, 225, 198, 0.43); font-size: 9px; }

.category-items {
  color: rgba(239, 232, 215, 0.65);
  font-size: 10px;
  line-height: 1.55;
}

.scene-tip {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: 20px;
  padding: 8px 13px;
  color: rgba(21, 50, 42, 0.75);
  border: 1px solid rgba(31, 69, 57, 0.12);
  border-radius: 999px;
  background: rgba(245, 246, 238, 0.55);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 10px;
  letter-spacing: 0.08em;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 240ms;
}

.return-ui {
  position: fixed;
  z-index: 12;
  top: max(22px, env(safe-area-inset-top));
  right: 24px;
}

@media (max-width: 1080px) {
  .inventory-panel { width: min(455px, 48vw); padding: 22px; }
  .insight-panel { width: min(370px, 40vw); }
  .inventory-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  body { overflow-y: auto; }
  .scene,
  .scene iframe,
  .scene-vignette { height: 100svh; }
  .topbar { padding: max(13px, env(safe-area-inset-top)) 14px 0; }
  .brand-card small,
  .safe-badge { display: none; }
  .brand-seal { width: 36px; height: 36px; font-size: 19px; }
  .brand-card strong { font-size: 17px; }
  .ghost-button { min-height: 32px; padding: 0 11px; font-size: 11px; }
  .hud {
    position: relative;
    inset: auto;
    z-index: 5;
    display: grid;
    gap: 12px;
    min-height: 100svh;
    padding: 70px 12px 24px;
  }
  .inventory-panel,
  .insight-panel {
    width: 100%;
    max-height: none;
  }
  .inventory-panel { align-self: end; padding: 20px; margin-top: 18vh; }
  .insight-panel { padding: 20px; }
  .inventory-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .item-slot span { display: none; }
  .lens-console { align-items: flex-end; }
  .lens-button { width: 78px; height: 78px; }
  .lens-glyph { top: 8px; }
  .lens-label { font-size: 11px; }
  .scene-tip { display: none; }
  .return-ui { top: max(14px, env(safe-area-inset-top)); right: 14px; }
}

@media (max-width: 460px) {
  .intro { margin-bottom: 13px; }
  .inventory-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
  .item-slot { padding: 3px; border-radius: 5px; }
  .lens-copy p { max-width: 220px; }
  .detail-card { grid-template-columns: 90px 1fr; gap: 13px; }
  .detail-card img { width: 90px; height: 90px; }
}

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