/* Design tokens — source of truth: ../style.css */
:root {
  --bg: #fbf9f0;
  --bg-strong: #f2eee0;
  --text: #000;
  --muted: rgba(0, 0, 0, 0.6);
  --accent: #f2e84e;
  --radius: 24px;
  --pill-radius: 48px;
  --page-gutter: min(4vw, 2rem);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="dark"] {
  --bg: #111110;
  --bg-strong: #1e1e1c;
  --text: #f0ede4;
  --muted: rgba(240, 237, 228, 0.55);
}

[data-theme="dark"] .pill-accent { color: #000; }
[data-theme="dark"] .pill-outline { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15); }
[data-theme="dark"] .nav-logo img { filter: invert(1); }

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Grain */
.grain-overlay {
  position: fixed;
  inset: -50%;
  width: 200%;
  height: 200%;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.045;
  animation: grain 0.4s steps(1) infinite;
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-5%, -8%); }
  50% { transform: translate(3%, 6%); }
  75% { transform: translate(-7%, 2%); }
}

img { display: block; width: 100%; }
a { color: inherit; text-decoration: none; }

/* Nav — single compact line */
.pick-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem var(--page-gutter);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.brand-mark {
  font-family: "Instrument Serif", serif;
  font-size: clamp(1.1rem, 2vw, 1.4rem);
  font-weight: 400;
  letter-spacing: -0.6px;
  flex: 1;
}

.nav-logo {
  flex: 0 0 auto;
  display: flex;
}

.nav-logo img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.theme-toggle {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: opacity 0.2s;
  flex: 1;
  justify-content: flex-end;
}

.theme-toggle:hover { opacity: 1; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* Pill buttons */
.pill-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.8rem 1.5rem;
  border-radius: var(--pill-radius);
  font-size: 0.95rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: transform 0.28s ease;
}

.pill-button:hover { transform: translateY(-2px); }
.pill-accent { background: var(--accent); }
.pill-outline { background: rgba(0,0,0,0.03); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }

/* Pick stage — fills viewport between nav and bar */
.pick-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem var(--page-gutter);
  gap: 0.75rem;
  min-height: 0;
  position: relative;
}

/* Card area — maximize display */
.card-area {
  position: relative;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 9 / 16;
  max-height: calc(100dvh - 140px);
  flex-shrink: 1;
}

.card-stack {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Individual card */
.pick-card {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(110deg, var(--bg-strong) 30%, var(--bg) 50%, var(--bg-strong) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  touch-action: none;
  user-select: none;
  cursor: grab;
  will-change: transform;
  /* Card shadow for depth */
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.18),
    0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.4s var(--spring), opacity 0.35s ease, box-shadow 0.3s ease;
}

.pick-card:active { cursor: grabbing; }

/* Press-down effect */
.pick-card.pressing {
  transform: scale(0.97);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.15),
    0 1px 4px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}

.pick-card.dragging { transition: none; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Stack depth */
.pick-card[data-depth="1"] {
  transform: scale(0.94) translateY(12px);
  opacity: 0.5;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.pick-card[data-depth="2"] {
  transform: scale(0.88) translateY(24px);
  opacity: 0.25;
  pointer-events: none;
  box-shadow: none;
}

/* Spring-in for new top card */
.pick-card.spring-in {
  animation: springUp 0.45s var(--spring) forwards;
}

@keyframes springUp {
  from { transform: scale(0.94) translateY(12px); }
  to { transform: scale(1) translateY(0); }
}

/* Card image */
.pick-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* Card info overlay */
.card-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 3rem 1.25rem 1.25rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.5));
  color: #fff;
  pointer-events: none;
}

.card-info .card-name {
  margin: 0;
  font-family: "Instrument Serif", serif;
  font-size: 1.25rem;
  font-weight: 400;
}

.card-info .card-meta {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Swipe exit animations */
.pick-card.exit-left  { transform: translateX(-140%) rotate(-18deg); opacity: 0; pointer-events: none; }
.pick-card.exit-right { transform: translateX(140%) rotate(18deg); opacity: 0; pointer-events: none; }
.pick-card.exit-up    { transform: translateY(-140%) scale(0.85); opacity: 0; pointer-events: none; }
.pick-card.exit-down  { transform: translateY(140%); opacity: 0; pointer-events: none; }

/* Direction hints */
.hint {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
  z-index: 5;
  color: var(--text);
}

.hint-left  { left: -48px; top: 50%; transform: translateY(-50%); }
.hint-right { right: -48px; top: 50%; transform: translateY(-50%); }
.hint-up    { top: -48px; left: 50%; transform: translateX(-50%); }
.hint-down  { bottom: -48px; left: 50%; transform: translateX(-50%); }
.hint-down svg { color: #e25555; }
.hint.active { opacity: 1; }

/* Bottom bar — single line */
.pick-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  flex-shrink: 0;
  padding: 0.25rem 0 calc(0.25rem + env(safe-area-inset-bottom));
}

.ctrl-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--bg-strong);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background 0.2s ease;
}

.ctrl-btn:hover { transform: scale(1.1); }
.ctrl-btn:active { transform: scale(0.95); }

/* Heart button — larger, with count */
.ctrl-fav {
  width: 56px;
  height: 56px;
  background: #fde8e8;
  color: #e25555;
  position: relative;
}

.ctrl-fav:hover { background: #fbd4d4; }
[data-theme="dark"] .ctrl-fav { background: rgba(226,85,85,0.2); }

.ctrl-fav.pop { animation: heartPop 0.35s var(--spring); }

@keyframes heartPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.fav-count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: #e25555;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  pointer-events: none;
}

.fav-count:empty { display: none; }

/* End state */
.pick-end {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
}

.pick-end h2 {
  font-family: "Instrument Serif", serif;
  font-weight: 400;
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  margin: 0;
}

.pick-end p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Drawer overlay */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Favorites drawer */
.fav-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 80dvh;
  background: var(--bg);
  border-radius: var(--radius) var(--radius) 0 0;
  z-index: 100;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.12);
}

.fav-drawer.open { transform: translateY(0); }

.drawer-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-strong);
  margin: 10px auto;
  flex-shrink: 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.5rem 1rem;
  flex-shrink: 0;
}

.drawer-header h2 {
  font-family: "Instrument Serif", serif;
  font-weight: 400;
  font-size: 1.5rem;
  margin: 0;
}

.drawer-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg-strong);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 1.5rem;
  min-height: 0;
}

.fav-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.fav-thumb {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 9 / 16;
}

.fav-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fav-thumb-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fav-thumb-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.5rem 0.5rem 0.5rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.5));
  color: #fff;
  font-size: 0.7rem;
  font-weight: 500;
}

.fav-empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem 0;
  font-size: 0.9rem;
}

.drawer-actions {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.5rem calc(1rem + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.drawer-actions .pill-button {
  flex: 1;
  text-align: center;
}

/* Responsive */
@media (min-width: 560px) {
  .card-area { max-width: 360px; }
  .hint-left  { left: -56px; }
  .hint-right { right: -56px; }
}

@media (min-width: 900px) {
  .card-area { max-width: 380px; }

  .fav-drawer {
    width: 380px;
    left: auto;
    border-radius: var(--radius) 0 0 0;
    max-height: 100dvh;
    top: 0;
    bottom: 0;
    transform: translateX(100%);
  }

  .fav-drawer.open { transform: translateX(0); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .pick-card { transition: none; }
}

/* ── InCosmos turbine logo — 脉冲 Pulse (reduced-motion 由上方通用规则兜底) ── */
/* 加速 → 峰值匀速保持 1s → 平顺减速; 每圈 720° */
@keyframes ic-logo-spin {
  0%   { transform: rotate(0deg);   animation-timing-function: cubic-bezier(0.33, 0, 0.67, 0.33); }
  40%  { transform: rotate(240deg); animation-timing-function: linear; }
  60%  { transform: rotate(480deg); animation-timing-function: cubic-bezier(0.33, 0.67, 0.67, 1); }
  100% { transform: rotate(720deg); }
}
.nav-logo img {
  animation: ic-logo-spin 5s linear infinite;
  transform-origin: 50% 50%;
  will-change: transform;
}
