/* ============================================================
   Catnip Tycoon - Main Stylesheet
   Dark theme with cat-inspired warm accents.
   Mobile-first, responsive design.
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --cat-orange: #f4a261;
  --cat-orange-light: #f7b87a;
  --cat-brown: #8b5e3c;
  --gold: #ffd700;
  --text-primary: #eee;
  --text-secondary: #aaa;
  --text-muted: #777;
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --border-radius: 8px;
  --transition: 0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* --- Background Canvas --- */
#bgCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* --- App Container --- */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  padding-bottom: 70px; /* Space for mobile bottom nav */
}

/* --- Top Bar --- */
#topBar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--bg-tertiary);
  position: sticky;
  top: 0;
  z-index: 10;
}

#userStatus {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* --- Main Layout (mobile: stack, desktop: row) --- */
#mainLayout {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* --- Sidebar / Bottom Nav --- */
#sidebar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: var(--bg-secondary);
  border-top: 2px solid var(--bg-tertiary);
  padding: 8px 4px;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  max-width: 960px;
  margin: 0 auto;
}

.nav-btn {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: var(--border-radius);
  transition: background var(--transition), transform var(--transition);
  position: relative;
  color: var(--text-secondary);
}

.nav-btn:hover,
.nav-btn:focus-visible {
  background: var(--bg-tertiary);
  transform: scale(1.1);
}

.nav-btn.active {
  background: var(--accent);
  color: #fff;
}

.nav-btn.admin-only {
  display: none;
}

.nav-btn.admin-only.visible {
  display: inline-block;
}

/* --- Panel Container --- */
#panelContainer {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

/* --- Panels --- */
.panel {
  display: none;
  animation: fadeIn 0.3s ease;
}

.panel.active {
  display: block;
}

.panel h2 {
  font-size: 1.3rem;
  margin-bottom: 12px;
  color: var(--cat-orange);
  border-bottom: 2px solid var(--bg-tertiary);
  padding-bottom: 6px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Clicker Area --- */
#clickerArea {
  text-align: center;
  padding: 20px 0;
}

#catCanvas {
  cursor: pointer;
  transition: transform 0.1s ease;
  border-radius: 50%;
}

#catCanvas:active {
  transform: scale(0.9);
}

#catCanvas.bounce {
  animation: bounce 0.3s ease;
}

@keyframes bounce {
  0% { transform: scale(1); }
  30% { transform: scale(0.85); }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

#clickHint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* --- Stats Bar --- */
#statsBar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.stat {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  padding: 12px;
  text-align: center;
  transition: background var(--transition);
}

.stat:hover {
  background: var(--bg-tertiary);
}

.stat-icon {
  font-size: 1.5rem;
  display: block;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--cat-orange-light);
}

/* --- Buttons --- */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: #1a4a80;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn-link {
  background: transparent;
  color: var(--cat-orange);
  text-decoration: underline;
  padding: 6px;
  font-size: 0.8rem;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-warning {
  background: var(--warning);
  color: #333;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn:disabled:hover {
  transform: none;
  box-shadow: none;
}

/* --- Cat & Upgrade Cards --- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color var(--transition), background var(--transition);
}

.card:hover {
  border-color: var(--cat-orange);
}

.card.unlocked {
  border-color: var(--success);
}

.card.locked {
  opacity: 0.5;
}

.card-info {
  flex: 1;
}

.card-name {
  font-weight: bold;
  font-size: 0.95rem;
}

.card-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.card-count {
  font-size: 0.8rem;
  color: var(--cat-orange-light);
  margin-top: 2px;
}

.card-cost {
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--gold);
}

.card-btn {
  margin-left: 10px;
  white-space: nowrap;
}

/* --- Prestige Panel --- */
.prestige-progress {
  background: var(--bg-tertiary);
  border-radius: 20px;
  height: 24px;
  margin: 12px 0;
  overflow: hidden;
}

.prestige-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 20px;
  transition: width 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #fff;
  min-width: 0;
}

.prestige-tier {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  padding: 12px;
  margin-top: 8px;
}

.prestige-tier.active {
  border-color: var(--gold);
}

.prestige-tier.earned {
  border-color: var(--success);
  background: rgba(46, 204, 113, 0.1);
}

/* --- Shop --- */
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.shop-item {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  padding: 12px;
  text-align: center;
  transition: border-color var(--transition);
}

.shop-item:hover {
  border-color: var(--cat-orange);
}

.shop-item-icon {
  font-size: 2.5rem;
  display: block;
}

.shop-item-name {
  font-size: 0.85rem;
  font-weight: bold;
  margin: 6px 0;
}

.shop-item-price {
  font-size: 0.8rem;
  color: var(--gold);
}

/* --- Achievements --- */
.achievement {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  padding: 10px;
  margin-bottom: 6px;
}

.achievement.earned {
  border-color: var(--success);
  background: rgba(46, 204, 113, 0.05);
}

.achievement-icon {
  font-size: 1.5rem;
  width: 36px;
  text-align: center;
}

.achievement-info {
  flex: 1;
}

.achievement-name {
  font-weight: bold;
  font-size: 0.85rem;
}

.achievement-desc {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.achievement-progress {
  font-size: 0.7rem;
  color: var(--cat-orange-light);
}

/* --- Modals --- */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  position: relative;
  animation: slideUp 0.3s ease;
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 14px;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.modal-close:hover {
  color: var(--accent);
}

.modal-content h2 {
  color: var(--cat-orange);
  margin-bottom: 16px;
}

.modal-content input {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.modal-content input:focus {
  outline: none;
  border-color: var(--accent);
}

.error-msg {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 8px;
  min-height: 20px;
}

/* --- Toast Notification --- */
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #fff;
  padding: 10px 24px;
  border-radius: 20px;
  font-weight: bold;
  z-index: 200;
  display: none;
  animation: toastIn 0.4s ease, toastOut 0.4s ease 2.6s forwards;
}

.toast.show {
  display: block;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateX(-50%) translateY(-20px); }
}

/* --- Admin Panel --- */
.admin-section {
  margin-bottom: 20px;
}

.admin-section h3 {
  font-size: 1rem;
  color: var(--cat-orange);
  margin-bottom: 8px;
}

.admin-section label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.admin-section input,
.admin-section select {
  width: 100%;
  padding: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
}

/* --- Floating fish particles (for click effect) --- */
.particle {
  position: fixed;
  pointer-events: none;
  font-size: 1.5rem;
  z-index: 50;
  animation: particleFade 0.8s ease-out forwards;
}

@keyframes particleFade {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); }
}

/* ============================================================
   Desktop Layout (min-width: 768px)
   Sidebar moves to the left, bottom nav disappears.
   ============================================================ */
@media (min-width: 768px) {
  #app {
    padding-bottom: 0;
  }

  #mainLayout {
    flex-direction: row;
  }

  #sidebar {
    position: sticky;
    top: 56px; /* Below top bar */
    flex-direction: column;
    justify-content: flex-start;
    width: 60px;
    height: calc(100vh - 56px);
    border-top: none;
    border-right: 2px solid var(--bg-tertiary);
    padding: 12px 4px;
    gap: 8px;
  }

  .nav-btn {
    font-size: 1.3rem;
    padding: 10px;
  }

  #panelContainer {
    padding: 20px;
  }

  #statsBar {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1024px) {
  #sidebar {
    width: 70px;
  }

  .nav-btn {
    font-size: 1.5rem;
  }
}

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

/* --- Focus styles --- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}