/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: rgba(255,255,255,0.08);
  --text: #f0f0f0;
  --text-muted: #888;
  --like: #2ecc71;
  --dislike: #e74c3c;
  --fav: #f39c12;
  --radius: 20px;
  --card-h: min(58vh, 460px);
}

html, body {
  height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ===== LAYOUT ===== */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ===== HEADER ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0 0.5rem;
  gap: 8px;
}

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

.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  white-space: nowrap;
}

.header h1 span { color: var(--like); }

/* Session badge — small pill under the title */
.session-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 7px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  cursor: default;
}

.session-badge:empty { display: none; }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.stats {
  display: flex;
  gap: 14px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 15px;
  font-weight: 600;
}

.stat svg { width: 16px; height: 16px; }
.stat-like    { color: var(--like); }
.stat-dislike { color: var(--dislike); }
.stat-fav     { color: var(--fav); }

/* Stats toggle button */
.stats-toggle-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.stats-toggle-btn svg { width: 16px; height: 16px; }

.stats-toggle-btn:hover,
.stats-toggle-btn[aria-expanded="true"] {
  background: var(--surface);
  color: var(--text);
  border-color: rgba(255,255,255,0.2);
}

/* ===== CARD AREA ===== */
.card-area {
  position: relative;
  width: 100%;
}

.card-stack {
  position: relative;
  width: 100%;
  height: var(--card-h);
}

/* ===== CARDS ===== */
.card {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  cursor: grab;
  user-select: none;
  touch-action: none;
  will-change: transform;
}

.card:active { cursor: grabbing; }

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  display: block;
}

.card-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 3rem 1.25rem 1.25rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.72));
  color: #fff;
}

.card-label h3 { font-size: 18px; font-weight: 600; text-transform: capitalize; }
.card-label small { font-size: 13px; opacity: 0.7; }

.card-back-1 {
  transform: scale(0.95) translateY(10px);
  z-index: 1;
  pointer-events: none;
  filter: brightness(0.7);
}

.card-back-2 {
  transform: scale(0.90) translateY(20px);
  z-index: 0;
  pointer-events: none;
  filter: brightness(0.4);
}

.card-front { z-index: 2; }

/* ===== DIRECTION HINTS ===== */
.direction-hint {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 10px;
  border: 2px solid;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
  z-index: 10;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.direction-hint svg { width: 18px; height: 18px; }

.hint-left {
  top: 24px; left: 20px;
  color: var(--dislike);
  border-color: var(--dislike);
  transform: rotate(-15deg);
}

.hint-right {
  top: 24px; right: 20px;
  color: var(--like);
  border-color: var(--like);
  transform: rotate(15deg);
}

.hint-down {
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  color: var(--fav);
  border-color: var(--fav);
  white-space: nowrap;
}

/* ===== ACTION BUTTONS ===== */
.action-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 0.25rem 0;
}

.action-btn {
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:active { transform: scale(0.88) !important; }
.action-btn svg { width: 28px; height: 28px; }

.btn-dislike {
  width: 60px; height: 60px;
  background: rgba(231, 76, 60, 0.12);
  color: var(--dislike);
  border: 1.5px solid rgba(231,76,60,0.3);
}
.btn-dislike svg { width: 24px; height: 24px; }
.btn-dislike:hover { background: rgba(231,76,60,0.22); transform: scale(1.08); }

.btn-fav {
  width: 52px; height: 52px;
  background: rgba(243, 156, 18, 0.12);
  color: var(--fav);
  border: 1.5px solid rgba(243,156,18,0.3);
}
.btn-fav svg { width: 20px; height: 20px; }
.btn-fav:hover { background: rgba(243,156,18,0.22); transform: scale(1.08); }

.btn-like {
  width: 60px; height: 60px;
  background: rgba(46, 204, 113, 0.12);
  color: var(--like);
  border: 1.5px solid rgba(46,204,113,0.3);
}
.btn-like svg { width: 24px; height: 24px; }
.btn-like:hover { background: rgba(46,204,113,0.22); transform: scale(1.08); }

/* ===== SWIPE GUIDE ===== */
.swipe-guide {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 12px;
  color: var(--text-muted);
}

.guide-item { display: flex; align-items: center; gap: 4px; }
.guide-arrow { font-weight: 700; font-size: 14px; }

/* ===== STATS PANEL ===== */
.stats-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.4s ease, opacity 0.3s ease;
}

.stats-panel.open {
  max-height: 1200px;
  opacity: 1;
}

.stats-panel-inner {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stats-panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-sub-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 0.25rem;
}

.top-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.top-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border-radius: 12px;
  padding: 8px;
}

.top-rank {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 24px;
  text-align: center;
}

.top-item img {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}

.top-info { flex: 1; min-width: 0; }

.top-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.top-badges { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
}

.badge-like    { background: rgba(46,204,113,0.15);  color: var(--like); }
.badge-fav     { background: rgba(243,156,18,0.15);  color: var(--fav); }
.badge-dislike { background: rgba(231,76,60,0.15);   color: var(--dislike); }

.recent-list { display: flex; flex-direction: column; gap: 6px; }

.recent-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.recent-item:last-child { border-bottom: none; }
.recent-action { flex-shrink: 0; }

.recent-title {
  flex: 1;
  color: var(--text);
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-date {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

.stats-empty, .stats-error { font-size: 13px; color: var(--text-muted); padding: 0.5rem 0; }
.stats-error { color: var(--dislike); }

/* ===== FAVORITES ===== */
.favorites-section h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fav-count-badge {
  background: var(--surface2);
  color: var(--fav);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 20px;
}

.fav-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.fav-empty {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 13px;
  padding: 1rem 0;
}

.fav-item {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  background: var(--surface);
}

.fav-item:hover { transform: scale(1.05); opacity: 0.9; }

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

/* ===== STATES ===== */
.loading-state, .empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 15px;
}

.empty-state .empty-icon { font-size: 48px; }
.empty-state h3 { font-size: 18px; font-weight: 600; color: var(--text); }
.empty-state p { font-size: 14px; color: var(--text-muted); text-align: center; padding: 0 2rem; }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--like);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== LIGHTBOX ===== */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  z-index: 1000;
  padding: 1rem;
}

.lightbox.open { display: flex; }

.lightbox img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 12px;
  object-fit: contain;
}

.lightbox p { color: #fff; font-size: 14px; opacity: 0.7; text-transform: capitalize; }

.lightbox-close {
  position: absolute;
  top: 1.5rem; right: 1.5rem;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2000;
  white-space: nowrap;
  pointer-events: none;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== RESPONSIVE ===== */
@media (max-height: 700px) {
  :root { --card-h: 46vh; }
}
