/* ===== CSS Variables ===== */
:root {
  --bg: #0a0a0f;
  --surface: #141419;
  --text-primary: #f0f0f5;
  --text-secondary: #b0b0c0;
  --text-muted: #55556a;
  --accent: #3b82f6;
  --border: rgba(255, 255, 255, 0.06);
  --glass-bg: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Button System — Neutral (matches local viewer, darker for legibility on bright images) */
  --btn-bg: rgba(20, 20, 30, 0.65);
  --btn-border: rgba(255, 255, 255, 0.12);
  --btn-color: var(--text-primary);
  --btn-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  --btn-active-bg: rgba(255, 255, 255, 0.14);

  /* Button System — Gold (favorites) */
  --gold: #eab308;
  --btn-gold-bg: rgba(234, 179, 8, 0.45);
  --btn-gold-border: rgba(234, 179, 8, 0.75);
  --btn-gold-color: #fff;
  --btn-gold-active-bg: rgba(234, 179, 8, 0.55);
  --btn-gold-shadow: 0 2px 12px rgba(234, 179, 8, 0.25);

  /* Legacy gold glass (for grid fav star only) */
  --glass-gold-bg: rgba(234, 179, 8, 0.15);
  --glass-gold-border: rgba(234, 179, 8, 0.35);
}

/* ===== Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Body ===== */
body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  height: 100dvh;
  width: 100vw;
  position: fixed;
  top: 0;
  left: 0;
}

/* ===== Screen System ===== */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.screen.active {
  display: flex;
  opacity: 1;
}

/* ===== Portrait Lock ===== */
@media (orientation: landscape) {
  #landscape-overlay {
    display: flex !important;
  }
}

#landscape-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: var(--text-secondary);
  font-size: 16px;
}

#landscape-overlay svg {
  width: 64px;
  height: 64px;
  stroke: var(--text-muted);
  animation: rotate-hint 2s ease-in-out infinite;
}

@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

/* ===== Mobile Gate ===== */
#mobile-gate {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 24px;
  padding: 32px;
}

#mobile-gate .gate-logo {
  height: 32px;
  width: auto;
  opacity: 0.7;
  margin-bottom: 8px;
}

#mobile-gate .gate-icon {
  width: 80px;
  height: 80px;
  stroke: var(--text-muted);
}

#mobile-gate .gate-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

#mobile-gate .gate-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

#mobile-gate .gate-url {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.5px;
}

/* ===== Team Screen ===== */
#team-screen {
  padding-top: var(--safe-top);
}

.screen-header {
  flex-shrink: 0;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}

.screen-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.screen-header .header-logo {
  height: 22px;
  width: auto;
  opacity: 0.85;
  display: block;
}

.screen-header .header-back {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  box-shadow: var(--btn-shadow);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.15s ease;
}

.screen-header .header-back:active {
  transform: scale(0.92);
  background: var(--btn-active-bg);
}

.screen-header .header-back svg {
  width: 20px;
  height: 20px;
  stroke: var(--text-primary);
}

.screen-header .team-name {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Team Grid ===== */
#team-grid {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px;
  align-content: start;
  touch-action: pan-y;
}

.team-card {
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  box-shadow: var(--btn-shadow);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.team-card:active {
  transform: scale(0.97);
  background: var(--btn-active-bg);
}

.team-card .team-card-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}

.team-card .team-card-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--border);
  padding: 2px 8px;
  border-radius: 20px;
}

/* ===== Gallery Screen ===== */
#gallery-screen {
  padding-top: var(--safe-top);
}

/* ===== Game Switcher ===== */
.game-switcher {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  padding: 0 16px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.game-switcher::-webkit-scrollbar {
  display: none;
}

.game-pill {
  flex-shrink: 0;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  box-shadow: var(--btn-shadow);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

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

#photo-grid {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  align-content: start;
  touch-action: pan-y;
}

.photo-cell {
  position: relative;
  cursor: pointer;
  aspect-ratio: 2/3;
  background: var(--surface);
}

.photo-cell-wide {
  grid-column: span 2;
  aspect-ratio: 3/2;
}

.photo-cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.photo-id {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 4px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

/* ===== Fullscreen View ===== */
#fullscreen-view {
  background: #000;
}

#fullscreen-view .swiper {
  width: 100%;
  height: 100dvh;
}

#fullscreen-view .swiper-slide {
  display: flex;
  align-items: center;
  justify-content: center;
}

#fullscreen-view .swiper-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* Image ID pill at bottom-center */
#image-counter {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  box-shadow: var(--btn-shadow);
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 20px;
  font-weight: 700;
  color: var(--btn-color);
  z-index: 50;
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ===== Numpad Overlay ===== */
#numpad-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.numpad-panel {
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 24px;
  width: min(320px, calc(100vw - 48px));
}

#numpad-display {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 4px;
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}

#numpad-display .cursor {
  display: inline-block;
  width: 2px;
  height: 28px;
  background: var(--accent);
  margin-left: 2px;
  animation: cursor-blink 1s step-end infinite;
}

@keyframes cursor-blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

#numpad-error {
  text-align: center;
  font-size: 13px;
  color: #ef4444;
  min-height: 20px;
  margin-bottom: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}

#numpad-error.visible {
  opacity: 1;
}

.numpad-keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.numpad-key {
  height: 56px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-primary);
  font-size: 22px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.numpad-key:active {
  background: rgba(255, 255, 255, 0.18);
}

.numpad-key.key-action {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

.numpad-key.key-action svg {
  width: 22px;
  height: 22px;
  stroke: var(--text-secondary);
}

/* Numpad shake animation */
@keyframes numpad-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.numpad-panel.shake {
  animation: numpad-shake 0.4s ease;
}

/* ===== Floating Buttons ===== */
.floating-btn {
  position: fixed;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  box-shadow: var(--btn-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  transition: transform 0.15s ease, background 0.15s ease;
}

.floating-btn:active {
  transform: scale(0.92);
  background: var(--btn-active-bg);
}

.floating-btn svg {
  width: 20px;
  height: 20px;
  stroke: var(--text-primary);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#btn-back {
  top: calc(16px + var(--safe-top));
  left: 16px;
}

/* ===== Search Pill (fullscreen, top-center) ===== */
.search-pill {
  --search-shift: 0px;
  position: fixed;
  top: calc(16px + var(--safe-top));
  left: 50%;
  transform: translateX(calc(-50% - var(--search-shift)));
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 999px;
  color: var(--btn-color);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--btn-shadow);
  font-family: inherit;
  transition: transform 0.25s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

/* When favorites exist, shift search pill left to clear the favorites panel */
.search-pill.shifted {
  --search-shift: 30px;
}

.search-pill svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.search-pill:active {
  transform: translateX(calc(-50% - var(--search-shift))) scale(0.95);
  background: var(--btn-active-bg);
}

/* ===== Favorites Panel (fullscreen, top-right) ===== */
.favorites-panel {
  position: fixed;
  right: 16px;
  top: calc(16px + var(--safe-top));
  z-index: 100;
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 8px;
}

.favorites-panel .floating-btn {
  position: relative;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
}

/* ===== Star Button (Favorite) ===== */
#btn-star svg {
  width: 22px;
  height: 22px;
  stroke: var(--text-primary);
  fill: none;
  transition: fill 0.15s, stroke 0.15s;
}

#btn-star.favorited {
  background: var(--btn-gold-bg);
  border-color: var(--btn-gold-border);
  box-shadow: var(--btn-gold-shadow);
}

#btn-star.favorited svg {
  fill: var(--gold);
  stroke: var(--gold);
}

/* ===== Fav Count Button (fullscreen, next to star) ===== */
.btn-fav-count {
  font-size: 16px;
  font-weight: 700;
  color: var(--btn-gold-color);
  background: var(--btn-gold-bg);
  border-color: var(--btn-gold-border);
  box-shadow: var(--btn-gold-shadow);
  font-family: inherit;
}

.btn-fav-count:active {
  transform: scale(0.92);
  background: var(--btn-gold-active-bg);
}

/* ===== Favorites Badge (gallery header, right) ===== */
.favorites-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  box-shadow: var(--btn-shadow);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  margin-left: auto;
  flex-shrink: 0;
  transition: background 0.15s;
  pointer-events: none;
  cursor: default;
}

.favorites-badge svg {
  width: 14px;
  height: 14px;
  fill: var(--text-muted);
  stroke: none;
  transition: fill 0.15s;
}

.favorites-badge.has-favs {
  background: var(--btn-gold-bg);
  border-color: var(--btn-gold-border);
  color: var(--btn-gold-color);
  pointer-events: auto;
  cursor: pointer;
}

.favorites-badge.has-favs svg {
  fill: var(--gold);
}

.favorites-badge.has-favs:active {
  background: var(--btn-gold-active-bg);
}

/* ===== Grid favorite star overlay ===== */
.photo-fav-star {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  fill: var(--gold);
  stroke: none;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Scrollbar (hide on mobile) ===== */
::-webkit-scrollbar {
  display: none;
}

* {
  scrollbar-width: none;
}
