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

:root {
  --bg-primary: #0c0b0d;
  --bg-secondary: #151419;
  --bg-tertiary: #19171d;
  --bg-card: #1a1a1f;
  --text-primary: #ffffff;
  --text-secondary: #8a8997;
  --text-muted: #646373;
  --accent: #635bff;
  --accent-hover: #7c75ff;
  --border: #24242b;
  --shadow: rgba(0, 0, 0, 0.3);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --transition: 0.3s ease;
  --max-width: 1280px;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  text-decoration: none;
  color: inherit;
  transition: color var(--transition);
}

img {
  max-width: 100%;
  display: block;
}

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.logo img {
  height: 40px;
  width: auto;
}

.logo-text {
  background: linear-gradient(90deg, #635bff, #bc56f8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-link {
  color: var(--text-secondary);
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  transition: all var(--transition);
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

/* Hero */
.hero {
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  padding: 60px 20px;
  text-align: center;
}

@media (max-width: 768px) {
  .hero {
    padding: 30px 16px;
  }
}

.hero-inner {
  max-width: 800px;
  margin: 0 auto;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  margin-bottom: 16px;
  background: linear-gradient(90deg, #fff 0%, #bc56f8 50%, #635bff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto;
}

/* Main Content */
.main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 40px 20px;
}

@media (max-width: 768px) {
  .main {
    padding: 20px 16px;
  }
}

/* Wallpaper Grid */
.wallpaper-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}

@media (max-width: 1200px) {
  .wallpaper-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 992px) {
  .wallpaper-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
  .wallpaper-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .wallpaper-grid { grid-template-columns: 1fr; gap: 12px; }
}

/* Wallpaper Card */
.wallpaper-card {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: 0 4px 12px var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
  aspect-ratio: 9/16;
}

.wallpaper-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px var(--shadow);
}

.wallpaper-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.wallpaper-card:hover img {
  transform: scale(1.05);
}

/* Loading */
.loading-container {
  display: flex;
  justify-content: center;
  padding: 40px;
}

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

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

.no-more {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ========================================
   VIEW PAGE (отдельная страница view.ejs)
   ======================================== */

.view-page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  transition: all var(--transition);
}

.back-link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.view-container {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 30px;
}

@media (max-width: 992px) {
  .view-container {
    grid-template-columns: 1fr;
  }
}

.view-page .preview-section {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 500px;
}

.view-page .preview-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px var(--shadow);
  cursor: zoom-in;
}

.view-page #preview-image {
  display: block;
  max-height: 70vh;
  width: auto;
  height: auto;
  transition: filter 0.1s ease;
  image-rendering: -webkit-optimize-contrast;
}

/* Adjustment Panel */
.adjustment-panel {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.panel-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.adjustment-group {
  margin-bottom: 24px;
}

.adjustment-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--text-secondary);
}

.adjustment-value {
  color: var(--accent);
  font-weight: 600;
}

/* Custom Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
}

.btn i {
  color: inherit;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

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

.btn-secondary:hover {
  background: var(--border);
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.resolution-info {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ========================================
   MODAL STYLES (для index.ejs)
   ======================================== */

.wallpaper-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: visibility 0s 0.3s, opacity 0.3s ease;
}

.wallpaper-modal.open {
  visibility: visible;
  opacity: 1;
  transition: visibility 0s, opacity 0.3s ease;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
}

.modal-content {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  z-index: 1;
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

.wallpaper-modal.open .modal-content {
  transform: scale(1);
}

.modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.1);
}

.modal-body {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 30px;
  height: 100%;
  padding: 80px 40px 40px;
  overflow: hidden;
}

.modal-body .preview-section {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.modal-body .preview-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px var(--shadow);
  cursor: zoom-in;
  max-height: 100%;
}

.modal-body #preview-image {
  display: block;
  max-height: 75vh;
  max-width: 100%;
  width: auto;
  height: auto;
  transition: filter 0.1s ease;
  image-rendering: -webkit-optimize-contrast;
}

.modal-body .adjustment-panel {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 24px;
  overflow-y: auto;
  max-height: calc(100vh - 120px);
}

@media (max-width: 992px) {
  .modal-body {
    display: flex;
    flex-direction: column;
    padding: 70px 20px 20px;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    height: 100%;
    gap: 20px;
  }
  
  .modal-body .preview-section {
    flex: 0 0 auto;
    min-height: auto;
  }
  
  .modal-body .preview-wrapper {
    overflow: visible;
    max-height: none;
  }
  
  .modal-body #preview-image {
    max-height: none;
    height: auto;
    width: 100%;
  }
  
  .modal-body .adjustment-panel {
    flex: 0 0 auto;
    max-height: none;
    overflow: visible;
  }
}

/* ========================================
   ADMIN STYLES
   ======================================== */

.admin-page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 40px 20px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 40px;
}

.admin-title {
  font-size: 28px;
  font-weight: 700;
}

.admin-section {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 30px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}

.upload-zone:hover {
  border-color: var(--accent);
  background: rgba(99, 91, 255, 0.05);
}

.upload-zone > i {
  font-size: 48px;
  color: var(--accent);
  margin-bottom: 16px;
}

.upload-zone p {
  color: var(--text-secondary);
  margin-bottom: 16px;
}

#zipfile {
  display: none;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
}

@media (max-width: 1400px) {
  .admin-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 992px) {
  .admin-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .admin-grid { grid-template-columns: repeat(2, 1fr); }
}

.admin-wallpaper {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 9/16;
}

.admin-wallpaper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  background: rgba(255, 59, 48, 0.9);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition);
}

.admin-wallpaper:hover .delete-btn {
  opacity: 1;
}

/* Login Page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-box {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-title {
  text-align: center;
  font-size: 24px;
  margin-bottom: 30px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 14px;
}

.form-group input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 16px;
  transition: border-color var(--transition);
}

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

.error-message {
  background: rgba(255, 59, 48, 0.1);
  color: #ff3b30;
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 14px;
}

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

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
