/* Modern Theme System with CSS Custom Properties */
:root {
  /* Theme: Sunset (Default - Original Pink) */
  --primary-start: #f093fb;
  --primary-end: #f5576c;
  --card-bg: #12192c;
  --card-secondary: #1e2a42;
  --text-primary: #ffffff;
  --text-secondary: #dadada;
  --text-muted: #a0a8b8;
  --accent: #ff7eb3;
  --accent-secondary: #ff758c;
  --button-bg: rgba(255, 255, 255, 0.95);
  --button-text: #333;
  --button-hover: rgba(255, 255, 255, 1);
  --reset-button-bg: rgba(255, 123, 179, 0.95);
  --reset-button-hover: rgba(255, 123, 179, 1);
  --shadow-light: rgba(0, 0, 0, 0.15);
  --shadow-medium: rgba(0, 0, 0, 0.2);
  --shadow-heavy: rgba(0, 0, 0, 0.3);
  --loading-bg: rgba(0, 0, 0, 0.8);
  --gradient-text: linear-gradient(120deg, var(--primary-start) 0%, var(--primary-end) 100%);
  --background-gradient: linear-gradient(120deg, var(--primary-start) 0%, var(--primary-end) 100%);
}

/* Theme: Ocean */
[data-theme="ocean"] {
  --primary-start: #667eea;
  --primary-end: #764ba2;
  --card-bg: #0f1419;
  --card-secondary: #1a252f;
  --text-primary: #e8f4f8;
  --text-secondary: #b8d4da;
  --text-muted: #8ba6ac;
  --accent: #5fb3d4;
  --accent-secondary: #4a9eff;
  --button-bg: rgba(255, 255, 255, 0.9);
  --button-text: #2c3e50;
  --button-hover: rgba(255, 255, 255, 1);
  --reset-button-bg: rgba(95, 179, 212, 0.9);
  --reset-button-hover: rgba(95, 179, 212, 1);
  --gradient-text: linear-gradient(120deg, var(--primary-start) 0%, var(--primary-end) 100%);
  --background-gradient: linear-gradient(120deg, var(--primary-start) 0%, var(--primary-end) 100%);
}

/* Theme: Forest */
[data-theme="forest"] {
  --primary-start: #56ab2f;
  --primary-end: #a8e6cf;
  --card-bg: #1a2f1a;
  --card-secondary: #2d4a2d;
  --text-primary: #f0f8f0;
  --text-secondary: #c8e6c8;
  --text-muted: #9bb89b;
  --accent: #7ed321;
  --accent-secondary: #56ab2f;
  --button-bg: rgba(255, 255, 255, 0.92);
  --button-text: #2d5016;
  --button-hover: rgba(255, 255, 255, 1);
  --reset-button-bg: rgba(126, 211, 33, 0.9);
  --reset-button-hover: rgba(126, 211, 33, 1);
  --gradient-text: linear-gradient(120deg, var(--primary-start) 0%, var(--primary-end) 100%);
  --background-gradient: linear-gradient(120deg, var(--primary-start) 0%, var(--primary-end) 100%);
}

/* Theme: Midnight */
[data-theme="midnight"] {
  --primary-start: #2c3e50;
  --primary-end: #4a6741;
  --card-bg: #0a0a0a;
  --card-secondary: #1a1a1a;
  --text-primary: #ecf0f1;
  --text-secondary: #bdc3c7;
  --text-muted: #95a5a6;
  --accent: #3498db;
  --accent-secondary: #2980b9;
  --button-bg: rgba(52, 152, 219, 0.9);
  --button-text: #ffffff;
  --button-hover: rgba(52, 152, 219, 1);
  --reset-button-bg: rgba(41, 128, 185, 0.9);
  --reset-button-hover: rgba(41, 128, 185, 1);
  --gradient-text: linear-gradient(120deg, #3498db 0%, #2c3e50 100%);
  --background-gradient: linear-gradient(120deg, var(--primary-start) 0%, var(--primary-end) 100%);
}

/* Theme: Golden */
[data-theme="golden"] {
  --primary-start: #f7971e;
  --primary-end: #ffd200;
  --card-bg: #2c1810;
  --card-secondary: #3d2317;
  --text-primary: #fff8e1;
  --text-secondary: #ffe0b2;
  --text-muted: #ffcc80;
  --accent: #ff9800;
  --accent-secondary: #f57c00;
  --button-bg: rgba(255, 255, 255, 0.95);
  --button-text: #e65100;
  --button-hover: rgba(255, 255, 255, 1);
  --reset-button-bg: rgba(255, 152, 0, 0.9);
  --reset-button-hover: rgba(255, 152, 0, 1);
  --gradient-text: linear-gradient(120deg, var(--primary-start) 0%, var(--primary-end) 100%);
  --background-gradient: linear-gradient(120deg, var(--primary-start) 0%, var(--primary-end) 100%);
}

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

* {
  transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease, 
              transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
}

body {
  overflow-y: auto;
  background: var(--background-gradient);
  display: grid;
  place-items: center;
  min-height: 100vh;
  margin: 0;
  font-family: 'Inter', sans-serif;
  padding: 8px;
  
  /* Hide scrollbar but keep scrolling functionality */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* Internet Explorer 10+ */
}

body::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

/* Control Panel */
.control-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

/* Main Controls */
.main-controls {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 8px 32px var(--shadow-heavy);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Theme Selector (Collapsible) */
.theme-selector {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 8px 32px var(--shadow-heavy);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
  transform-origin: bottom right;
  opacity: 1;
  transform: scale(1);
  max-height: 100px;
  overflow: hidden;
}

.theme-selector.collapsed {
  opacity: 0;
  transform: scale(0.8);
  max-height: 0;
  padding: 0;
  margin: 0;
  border: none;
  box-shadow: none;
  pointer-events: none;
}

.theme-option {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.theme-option:hover {
  transform: scale(1.1);
  border-color: rgba(255, 255, 255, 0.3);
}

.theme-option.active {
  border-color: var(--accent);
  transform: scale(1.15);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.theme-option[data-theme="sunset"] {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.theme-option[data-theme="ocean"] {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.theme-option[data-theme="forest"] {
  background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%);
}

.theme-option[data-theme="midnight"] {
  background: linear-gradient(135deg, #2c3e50 0%, #4a6741 100%);
}

.theme-option[data-theme="golden"] {
  background: linear-gradient(135deg, #f7971e 0%, #ffd200 100%);
}

/* Main Card */
.card {
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 90vh;
  background: var(--card-bg);
  border-radius: 30px;
  width: 80vw;
  max-width: 900px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3), 0 6px 6px rgba(0, 0, 0, 0.2);
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1.5em 1.5em 1.5em 1.5em;
  color: var(--text-primary);
  opacity: 0;
  transform: translateY(20px);
  animation: cardEntrance 1s ease-out forwards;
  
  /* Hide scrollbar but keep scrolling functionality */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* Internet Explorer 10+ */
}

.card::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

@keyframes cardEntrance {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Viewer Container */
.viewer-container {
  width: 100%;
  height: 0;
  padding-bottom: 80%;
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  margin: 0;
}

.viewer-container .background-image {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 5%;
  height: 5%;
  object-fit: contain;
  opacity: 0.5;
  z-index: 1;
  border-radius: inherit;
  pointer-events: none;
}

.three-viewer {
  border-radius: inherit;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 1;
  transition: opacity 1s ease-in-out;
  z-index: 2;
  background: rgba(0, 0, 0, 0.2);
}

.three-viewer canvas {
  border-radius: inherit;
  width: 100% !important;
  height: 100% !important;
}

/* Control Buttons */
.control-button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--button-bg);
  color: var(--button-text);
  box-shadow: 0 2px 8px var(--shadow-light);
}

.control-button:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px var(--shadow-medium);
  background: var(--button-hover);
}

.control-button svg {
  transition: all 0.3s ease;
}

.control-button:hover svg {
  transform: scale(1.1);
}

.upload-button {
  background: var(--accent);
  color: white;
}

.upload-button:hover {
  background: var(--accent-secondary);
}

.reset-button {
  background: var(--accent);
  color: white;
}

.reset-button:hover {
  background: var(--accent-secondary);
}

.theme-toggle-button {
  background: var(--accent-secondary);
  color: white;
}

.theme-toggle-button:hover {
  background: var(--accent);
}

/* Loading State */
.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--loading-bg);
  color: white;
  padding: 15px 25px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 20;
  box-shadow: 0 4px 12px var(--shadow-heavy);
}

/* Text Content */
.text {
  padding: 1em;
  background: var(--gradient-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 300;
  font-size: 16px;
  text-align: left;
}

.text h1 {
  font-family: 'Poppins', sans-serif;
  font-size: 38px;
  font-weight: 700;
}

/* Credit Section */
.credit {
  display: flex;
  align-items: center;
  margin-top: 64px;
  font-size: 14px;
}

.credit-content {
  text-align: left;
}

.credit-content p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.highlight {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

.emoji {
  color: var(--accent);
}

.date {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 10px;
}

.vertical-line {
  width: 3px;
  height: 40px;
  background: linear-gradient(to bottom, var(--accent-secondary), var(--accent));
  border-radius: 1.5px;
  margin-right: 10px;
}

.space {
  height: 5px;
}

/* Responsive Design */
@media only screen and (max-width: 600px) {
  body {
    padding: 6px;
  }
  
  .control-panel {
    bottom: 16px;
    right: 16px;
    gap: 6px;
  }
  
  .main-controls {
    padding: 6px;
    gap: 6px;
  }
  
  .theme-selector {
    padding: 8px;
    gap: 6px;
  }
  
  .theme-option {
    width: 28px;
    height: 28px;
  }
  
  .control-button {
    width: 32px;
    height: 32px;
  }
  
  .control-button svg {
    width: 14px;
    height: 14px;
  }
  
  .viewer-container {
    padding-bottom: 85%;
  }
  
  .card {
    width: 85vw;
    max-width: 400px;
    max-height: 85vh;
    padding: 1em;
  }
  
  .text h1 {
    font-size: 28px;
  }
  
  .text {
    font-size: 14px;
  }
}

/* Mobile landscape specific styles */
@media only screen and (max-width: 900px) and (orientation: landscape) {
  body {
    padding: 6px;
    min-height: 100vh;
  }
  
  .card {
    width: 90vw;
    max-width: 800px;
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: hidden;
    flex-direction: row;
    align-items: flex-start;
    padding: 1em;
  }
  
  .viewer-container {
    flex: 1;
    padding-bottom: 0;
    height: 60vh;
    min-height: 250px;
    max-height: 70vh;
    margin-right: 1em;
  }
  
  .text {
    flex: 1;
    padding: 0.5em;
    min-width: 200px;
  }
  
  .text h1 {
    font-size: 24px;
  }
  
  .text p {
    font-size: 14px;
    line-height: 1.4;
  }
  
  .credit {
    margin-top: 32px;
  }
  
  .control-panel {
    bottom: 10px;
    right: 10px;
  }
}

/* Very small screens (height < 500px) */
@media only screen and (max-height: 500px) {
  body {
    padding: 4px;
  }
  
  .card {
    max-height: 95vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75em;
    width: 92vw;
    max-width: 380px;
  }
  
  .viewer-container {
    height: 40vh;
    padding-bottom: 0;
    min-height: 200px;
    max-height: 45vh;
  }
  
  .text {
    padding: 0.5em;
  }
  
  .text h1 {
    font-size: 20px;
    margin-bottom: 0.5em;
  }
  
  .text p {
    font-size: 12px;
    line-height: 1.3;
  }
  
  .credit {
    margin-top: 20px;
  }
  
  .credit-content p {
    font-size: 12px;
  }
  
  .date {
    font-size: 10px;
  }
}

/* Tablet portrait */
@media only screen and (min-width: 601px) and (max-width: 900px) {
  .card {
    width: 85vw;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
  }
  
  .viewer-container {
    padding-bottom: 80%;
  }
  
  .text h1 {
    font-size: 32px;
  }
}

@media only screen and (min-width: 900px) {
  .card {
    flex-direction: row-reverse;
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: hidden;
  }
  
  .viewer-container {
    padding-bottom: 80%;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .card {
    border: 2px solid var(--text-primary);
  }
  
  .upload-button, .reset-button {
    border: 2px solid var(--button-text);
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .card {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* Focus styles for accessibility */
.control-button:focus-visible,
.theme-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Dark mode detection (fallback) */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
  }
}

/* Print styles */
@media print {
  .control-panel {
    display: none;
  }
  
  .card {
    box-shadow: none;
    border: 1px solid #000;
  }
}

/* Global scrollbar hide for all elements */
* {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* Internet Explorer 10+ */
}

*::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}
