:root {
  --bg-desktop: #1b1815;
  --bg-paper: #f6f1e7;
  --bg-paper-2: #ede4d3;
  --bg-card-light: #fffcf6;
  --ink-primary: #1f1c18;
  --ink-secondary: #685f52;
  --ink-muted: #9a8f7f;
  --crimson: #b93a2c;
  --crimson-dark: #8e2418;
  --crimson-soft: rgba(185, 58, 44, 0.12);
  --gold: #c9963b;
  --gold-bright: #f5c85c;
  --diancui: #00bfa5;
  --obsidian: #0d0c12;
  --obsidian-2: #171520;
  --border-light: rgba(104, 95, 82, 0.18);
  --border-gold: rgba(201, 150, 59, 0.45);
  --ease-out-expo: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-overshoot: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font-serif: "Songti SC", "Noto Serif SC", "Source Han Serif CN", "STSong", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;

  /* 稀有度主题色 */
  --rarity-lr: #00e5b8;
  --rarity-ur: #f6b93b;
  --rarity-ssr: #c06cff;
  --rarity-sr: #38bdf8;
  --rarity-r: #94a3b8;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-desktop);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  overflow: hidden;
}

#ambient-desktop-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 30% 20%, rgba(185, 58, 44, 0.16), transparent 45%),
    radial-gradient(circle at 75% 80%, rgba(201, 150, 59, 0.15), transparent 45%),
    linear-gradient(145deg, #161311 0%, #241e19 100%);
  pointer-events: none;
}

#app-shell {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 430px;
  max-height: 900px;
  margin: 0 auto;
  background: var(--bg-paper);
  background-image:
    radial-gradient(rgba(160, 140, 110, 0.08) 1px, transparent 0);
  background-size: 16px 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
}

@media (min-width: 500px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
  }
  #app-shell {
    height: min(94vh, 860px);
    border-radius: 28px;
    border: 1px solid rgba(255, 240, 210, 0.16);
  }
}

/* 顶部栏 */
#top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 8px;
  background: rgba(255, 252, 246, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-light);
  z-index: 5;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.seal-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--crimson);
  color: #fff8ee;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 16px;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1.5px rgba(255, 232, 195, 0.45), 0 3px 8px rgba(185, 58, 44, 0.25);
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.15;
  letter-spacing: 0.04em;
}

.brand-sub {
  display: block;
  font-size: 10px;
  color: var(--ink-secondary);
}

.header-pills {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-pill {
  width: 30px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--border-light);
  background: var(--bg-card-light);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 14px;
  transition: transform 0.15s ease;
}

.icon-pill:active {
  transform: scale(0.92);
}

.stat-pill {
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--bg-card-light);
  border: 1px solid var(--border-light);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.timer-pill .pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #16a34a;
}

.timer-pill.urgent {
  border-color: rgba(185, 58, 44, 0.5);
  color: var(--crimson);
  animation: pulseUrgent 0.9s infinite ease-in-out;
}

.timer-pill.urgent .pill-dot {
  background: var(--crimson);
}

.pt-diamond {
  color: var(--crimson);
  font-size: 10px;
}

.pt-unit {
  font-size: 10px;
  color: var(--ink-secondary);
}

/* 四席大典进度条 */
#ceremony-strip {
  padding: 7px 12px 6px;
  background: var(--bg-paper-2);
  border-bottom: 1px solid var(--border-light);
}

.slots-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.slot-pill {
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: rgba(255, 252, 246, 0.8);
  padding: 5px 6px;
  display: flex;
  align-items: center;
  gap: 5px;
  text-align: left;
  cursor: pointer;
  transition: transform 0.2s var(--ease-overshoot), border-color 0.2s ease, box-shadow 0.2s ease;
}

.slot-pill:active {
  transform: scale(0.96);
}

.slot-pill.filled {
  background: #fffdf8;
  border-color: var(--gold);
  box-shadow: 0 2px 8px rgba(201, 150, 59, 0.18);
}

.slot-pill.filled.is-fake-slotted {
  border-color: #d97706;
  background: #fffbeb;
}

.slot-icon {
  font-size: 15px;
  line-height: 1;
}

.slot-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.slot-name {
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-primary);
}

.slot-val {
  font-size: 9px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-pill.filled .slot-val {
  color: var(--crimson-dark);
  font-weight: 600;
}

.synergy-bar {
  margin-top: 5px;
  font-size: 11px;
  color: var(--ink-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  min-height: 18px;
}

.syn-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(185, 58, 44, 0.12);
  color: var(--crimson-dark);
  font-weight: 700;
  font-size: 10px;
  border: 1px solid rgba(185, 58, 44, 0.28);
}

/* 视图容器 */
#views-container {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.view-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 10px 14px 12px;
  display: none;
  flex-direction: column;
}

.view-panel.active {
  display: flex;
}

/* 主界面案台 */
.hero-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.caption-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--crimson-dark);
  background: var(--crimson-soft);
  border: 1px solid rgba(185, 58, 44, 0.2);
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: 0.05em;
}

.hero-pack-wrap {
  padding: 6px 0 4px;
  cursor: pointer;
  outline: none;
}

.hero-tagline {
  margin: 0;
  font-size: 12px;
  color: var(--ink-secondary);
  text-align: center;
}

.codex-progress-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--ink-secondary);
}

.codex-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(104, 95, 82, 0.15);
  overflow: hidden;
}

.codex-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--crimson), var(--gold));
  transition: width 0.45s var(--ease-out-expo);
}

.speed-toggle {
  border: 1px solid var(--border-light);
  background: var(--bg-card-light);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--ink-secondary);
  cursor: pointer;
}

.odds-strip {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
}

.odds-chip {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bg-card-light);
  border: 1px solid var(--border-light);
  color: var(--ink-secondary);
}

.odds-chip.lr b { color: #008e76; }
.odds-chip.ur b { color: #b7791f; }
.odds-chip.ssr b { color: #7e22ce; }
.odds-chip.sr b { color: #0369a1; }
.odds-chip.r b { color: #475569; }

/* 三按钮操作栏 */
.action-bar {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.action-btn {
  border: none;
  border-radius: 13px;
  padding: 9px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.16s var(--ease-overshoot), box-shadow 0.2s ease, opacity 0.2s ease;
}

.action-btn:active {
  transform: scale(0.95);
}

.action-btn .btn-main {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
}

.action-btn .btn-sub {
  font-size: 10px;
  opacity: 0.88;
}

.btn-crimson {
  background: linear-gradient(160deg, #cf4636, var(--crimson-dark));
  color: #fff9f2;
  box-shadow: 0 6px 14px rgba(185, 58, 44, 0.28);
}

.btn-ink {
  background: linear-gradient(160deg, #2b2622, #151210);
  color: #f8ecd5;
  box-shadow: 0 6px 14px rgba(31, 28, 24, 0.24);
}

.btn-gold {
  background: var(--bg-card-light);
  color: var(--ink-primary);
  border: 1.5px solid var(--gold);
  box-shadow: 0 4px 10px rgba(201, 150, 59, 0.15);
}

.btn-gold.ready-finale {
  background: linear-gradient(145deg, #f7d176, #d4942a);
  color: #241706;
  border-color: #fff1c2;
  box-shadow: 0 0 18px rgba(246, 185, 59, 0.55);
  animation: pulseGold 1.4s infinite ease-in-out;
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 最近启封 */
.recent-section {
  margin-top: 10px;
  flex: 1;
  min-height: 82px;
  display: flex;
  flex-direction: column;
}

.recent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-secondary);
  margin-bottom: 6px;
}

.text-link-btn {
  border: none;
  background: transparent;
  color: var(--crimson);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.recent-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.recent-empty {
  width: 100%;
  border: 1px dashed var(--border-light);
  border-radius: 12px;
  padding: 14px 10px;
  font-size: 11px;
  color: var(--ink-muted);
  text-align: center;
  background: rgba(255, 252, 246, 0.5);
}

.recent-thumb {
  flex: 0 0 74px;
  border-radius: 10px;
  background: var(--bg-card-light);
  border: 1px solid var(--border-light);
  padding: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.recent-thumb:active {
  transform: scale(0.95);
}

.recent-thumb .thumb-art {
  width: 56px;
  height: 52px;
}

.recent-thumb .thumb-name {
  font-size: 10px;
  font-weight: 600;
  width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-thumb .thumb-rarity {
  font-size: 9px;
  font-weight: 800;
  padding: 0 5px;
  border-radius: 4px;
  background: #1f1c18;
  color: #fff;
}

/* 图鉴视图 */
.codex-header h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 18px;
}

.codex-header p {
  margin: 2px 0 8px;
  font-size: 12px;
  color: var(--ink-secondary);
}

.filter-pills {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.filter-pill {
  border: 1px solid var(--border-light);
  background: var(--bg-card-light);
  color: var(--ink-secondary);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.filter-pill.active {
  background: var(--crimson);
  color: #fff;
  border-color: var(--crimson);
}

.codex-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-bottom: 14px;
}

.codex-item {
  background: var(--bg-card-light);
  border: 1px solid var(--border-light);
  border-radius: 11px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.codex-item.locked {
  opacity: 0.45;
  filter: grayscale(0.85);
  cursor: default;
}

.codex-item-art {
  width: 100%;
  aspect-ratio: 1 / 0.9;
}

.codex-item-title {
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  line-height: 1.25;
}

.codex-item-meta {
  font-size: 9px;
  color: var(--ink-secondary);
}

/* 典册指南视图 */
.guide-scroll {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
}

.guide-card {
  background: var(--bg-card-light);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 12px;
}

.guide-card h3 {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--crimson-dark);
}

.guide-card p, .guide-steps, .synergy-guide-list {
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-secondary);
}

.guide-steps, .synergy-guide-list {
  padding-left: 16px;
}

.guide-actions-row {
  display: flex;
  gap: 8px;
}

.guide-btn {
  flex: 1;
  border-radius: 11px;
  padding: 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.guide-btn.primary {
  border: none;
  background: var(--crimson);
  color: #fff;
}

.guide-btn.ghost {
  border: 1px solid var(--border-light);
  background: var(--bg-card-light);
  color: var(--ink-secondary);
}

/* 底部导航 */
#tabbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(255, 252, 246, 0.96);
  border-top: 1px solid var(--border-light);
  padding: 5px 8px max(6px, env(safe-area-inset-bottom));
}

.tab-btn {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  color: var(--ink-muted);
  cursor: pointer;
}

.tab-btn.active {
  color: var(--crimson);
  font-weight: 700;
}

.tab-ico {
  font-size: 16px;
}

.tab-label {
  font-size: 11px;
}

/* 暗场展柜覆盖层 */
.stage-overlay {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 18%, rgba(45, 38, 66, 0.65), transparent 55%),
    linear-gradient(180deg, #0b0a0f 0%, #14111b 60%, #09080c 100%);
  color: #f8f5ef;
  z-index: 30;
  display: flex;
  flex-direction: column;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.stage-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.spotlight-beam {
  position: absolute;
  top: -10%;
  left: 50%;
  width: 78%;
  height: 70%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at top, rgba(255, 240, 200, 0.16) 0%, rgba(255, 240, 200, 0.03) 45%, transparent 72%);
  pointer-events: none;
}

#fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 40;
}

#stage-topbar {
  position: relative;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 6px;
}

.stage-close-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

.stage-progress-text {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 248, 232, 0.86);
  letter-spacing: 0.04em;
}

.stage-pt-pill {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(246, 185, 59, 0.35);
  font-size: 12px;
  font-weight: 700;
  color: #fde68a;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.stage-phase {
  position: relative;
  z-index: 42;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px 16px;
}

.stage-phase.hidden {
  display: none;
}

.stage-bottom-hint {
  margin: 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.65);
  text-align: center;
}

.stage-btn {
  border: none;
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s var(--ease-overshoot);
}

.stage-btn:active {
  transform: scale(0.95);
}

.stage-btn.crimson {
  background: linear-gradient(155deg, #d84b3a, #9b2217);
  color: #fff8ef;
  box-shadow: 0 6px 18px rgba(185, 58, 44, 0.45);
}

.stage-btn.danger {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, 0.45);
}

.stage-btn.gold {
  background: linear-gradient(145deg, #f6c967, #c68627);
  color: #1f1404;
}

.stage-btn.secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.stage-btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.78);
}

.stage-btn.ghost-dark {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--ink-secondary);
}

.hidden {
  display: none !important;
}
