/* 1. Base Variables */
:root {
  /* Colors */
  --primary-color: #486581;
  --primary-dark: #334e68;
  --text-color: #102a43;
  --bg-gradient-start: #f0f4f8;
  --bg-gradient-end: #d9e2ec;
  
  /* Category Colors - Match with main.js COLORS object */
  --color-v: #8B44F7; /* Violet/Purple */
  --color-o: #FF7F27; /* Orange */
  --color-m: #7AB55C; /* Mint/Green */
  --color-i: #3B82F6; /* Indigo/Blue */
  --color-t: #FFD700; /* Tangerine/Yellow */
  
  /* Sizing */
  --container-width: 800px;
  --wheel-size-desktop: 300px;
  --wheel-size-mobile: 200px;
  --footer-height-desktop: 60px;
  --footer-height-mobile: 50px;
  
  /* Mobile Sizes */
  --mobile-header-size: 2em;
  --mobile-padding: 12px;
  --mobile-margin: 20px;
  
  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
  
  /* Mobile Safe Areas */
  --mobile-safe-top: env(safe-area-inset-top, 20px);
  --mobile-safe-bottom: env(safe-area-inset-bottom, 15px);
  
  /* Common Transitions */
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
}

/* 2. Reset & Global Styles */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
  background-attachment: fixed;
}

body {
  font-family: system-ui, -apple-system, 'Roboto', sans-serif; /* Improved system font stack */
  color: var(--text-color);
  position: relative;
  min-height: 100vh;
  width: 100%;
  -webkit-font-smoothing: antialiased; /* Better text rendering */
  -moz-osx-font-smoothing: grayscale;
}

/* 3. Layout Components */
.container {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 160px 20px 100px;
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* 4. Header & Logo Styles */
header {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: var(--container-width);
  padding: 0 20px;
  box-sizing: border-box;
}

.logo-link {
  text-decoration: none;
  color: inherit;
  transition: transform var(--transition-fast);
}

.logo-link:hover {
  transform: translateY(-2px);
}

.logo-icon {
  width: 40px;
  height: 40px;
  margin-right: 10px;
}

h1 {
  font-size: 3em;
  margin: 0;
  font-weight: 700;
  color: var(--text-color);
  position: static;
}

h1 span {
  color: var(--primary-color);
}

h1 span span {
  display: inline-block;
  transition: all var(--transition-normal);
  font-weight: 800;
  padding: 0 1px;
}

h1 span .v, 
h1 span .o, 
h1 span .m, 
h1 span .i, 
h1 span .t { 
  font-weight: 700;
  transition: transform var(--transition-fast);
  display: inline-block;
}

/* Generic Letter Colors & Effects */
span .v { 
  color: var(--color-v);
  text-shadow: 1px 1px 2px rgba(139, 68, 247, 0.3);
}
span .o { 
  color: var(--color-o);
  text-shadow: 1px 1px 2px rgba(255, 127, 39, 0.3);
}
span .m { 
  color: var(--color-m);
  text-shadow: 1px 1px 2px rgba(122, 181, 92, 0.3);
}
span .i { 
  color: var(--color-i);
  text-shadow: 1px 1px 2px rgba(59, 130, 246, 0.3);
}
span .t { 
  color: var(--color-t);
  text-shadow: 1px 1px 2px rgba(255, 215, 0, 0.3);
}

h1 span span:hover {
  transform: scale(1.2) rotate(calc(var(--random-rotation) * 1deg));
}

.subheading {
  font-size: 1.2em;
  color: var(--primary-color);
  margin: 8px 0 0 0;
  font-weight: 400;
  letter-spacing: 0.5px;
  opacity: 0.9;
}

/* 5. Wheel Layout & Components */
.wheel-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--container-width);
}

.wheel-content {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: center;
}

.wheel-container {
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: var(--wheel-size-desktop);
  flex: 1;
}

#wheel {
  width: var(--wheel-size-desktop);
  height: var(--wheel-size-desktop);
  background: url('wheel.png') no-repeat center center;
  background-size: contain;
  margin: 0;
  will-change: transform; /* Optimize animation performance */
}

/* 6. Category Legend */
.category-legend-wrapper {
  flex: 1;
  background: rgba(255, 255, 255, 0.95);
  padding: 15px;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  transition: box-shadow var(--transition-normal), background var(--transition-normal);
}

.wheel-spinning .category-legend-wrapper {
  box-shadow: var(--shadow-lg);
  background: rgba(255, 255, 255, 0.98);
}

.category-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9em;
  line-height: 1.2;
  padding: 4px 0;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Category Dots */
.dot.v { background-color: var(--color-v); }
.dot.o { background-color: var(--color-o); }
.dot.m { background-color: var(--color-m); }
.dot.i { background-color: var(--color-i); }
.dot.t { background-color: var(--color-t); }

/* 7. Results Section */
#result {
  opacity: 0;
  transform: translateY(-20px);
  transition: all var(--transition-slow);
  width: 100%;
  max-width: var(--container-width);
  margin: 0 auto 10px;
  text-align: center;
}

#result.visible {
  opacity: 1;
  transform: translateY(0);
}

.result-layout {
  width: 100%;
  max-width: var(--container-width);
}

.result-content {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 25px;
  padding: 40px;
  box-shadow: 
    0 10px 30px rgba(0, 0, 0, 0.08),
    0 2px 8px rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.8);
  margin-bottom: 40px;
}

.result-main {
  padding: 20px 40px 40px;
}

#category {
  font-size: 3.2em;
  margin: 0 0 5px 0;
  font-weight: 800;
}

#category-description {
  font-size: 1.4em;
  color: rgba(72, 101, 129, 0.9);
  margin: 5px 0 25px;
  font-weight: 500;
  letter-spacing: 0.5px;
  transform: translateY(-5px);
}

#prompt {
  font-size: 1.8em;
  line-height: 1.5;
  color: var(--primary-dark);
  max-width: 600px;
  font-weight: 500;
  margin: 25px auto 0;
}

hr {
  width: 50%;
  border: none;
  border-top: 1px solid rgba(0,0,0,0.1);
  margin: 25px auto;
}

/* 8. Button Styles */
.spin-button-container {
  display: flex;
  justify-content: center;
  margin-top: 40px;
}

button {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: #fff;
  border: none;
  padding: 16px 38px;
  font-size: 1.2em;
  border-radius: 50px;
  cursor: pointer;
  transition: all var(--transition-normal);
  margin-top: 20px;
  box-shadow: 
    0 4px 12px rgba(72, 101, 129, 0.2),
    0 2px 4px rgba(72, 101, 129, 0.1);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 700;
  position: relative;
  z-index: 5;
  border: 1px solid rgba(255, 255, 255, 0.1);
  -webkit-tap-highlight-color: transparent; /* Remove mobile tap highlight */
}

#spinButton,
#spinAgainButton {
  margin: 0 auto;
  width: 100%;
  max-width: 600px;
}

button:hover {
  background-color: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* 9. Footer */
footer {
  width: 100%;
  height: var(--footer-height-desktop);
  padding: 15px;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  box-sizing: border-box;
  position: fixed;
  bottom: 10px;
  left: 0;
  z-index: 100;
}

.footer-content {
  max-width: var(--container-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.footer-links {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.footer-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.footer-created-by {
  font-size: 0.9em;
  color: var(--text-color);
  opacity: 0.5;
}

.footer-links a {
  color: var(--text-color);
  text-decoration: none;
  font-size: 0.9em;
  opacity: 0.8;
  transition: all var(--transition-fast);
}

.footer-links a:hover {
  opacity: 1;
  transform: translateY(-2px);
}

.separator {
  color: var(--text-color);
  opacity: 0.5;
}

.ko-fi {
  color: #FF5E5B !important;
  font-weight: 500;
}

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

/* 11. Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 12. Media Queries */
@media (max-width: 600px) {
  /* Header */
  header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    transform: none;
    padding: 15px var(--mobile-padding);
    z-index: 50;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }

  h1 {
    font-size: var(--mobile-header-size);
  }

  /* Container */
  .container {
    padding: 110px var(--mobile-padding) 70px;
  }

  /* Wheel */
  .wheel-layout {
    margin-top: 20px;
  }

  .wheel-content {
    flex-direction: column;
    align-items: center;
    gap: 15px;
  }

  .wheel-container {
    height: var(--wheel-size-mobile);
    margin: 0 auto;
  }

  #wheel {
    width: var(--wheel-size-mobile);
    height: var(--wheel-size-mobile);
  }

  /* Results */
  #result {
    width: 100%;
    margin-top: 10px;
    margin-bottom: 60px;
  }

  .result-content {
    margin: 0 15px;
    padding: 20px;
    border-radius: 15px;
  }

  .result-main {
    padding: 10px;
  }

  #category {
    font-size: 2.4em;
  }

  #prompt {
    font-size: 1.4em;
    line-height: 1.4;
  }

  /* Category Legend */
  .category-legend-wrapper {
    width: auto;
    margin: 0 15px;
    padding: 15px;
  }

  .legend-intro {
    font-size: 0.85em;
  }

  .legend-item {
    font-size: 0.85em;
    padding: 3px 0;
  }

  /* Buttons */
  .spin-button-container {
    margin-top: 25px;
    padding: 0 15px;
  }

  button {
    padding: 14px 28px;
    font-size: 1.1em;
  }

  /* Footer */
  footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    padding: 5px;
    z-index: 1000;
    height: auto;
  }

  .footer-content {
    padding: 0;
  }

  .footer-links {
    gap: 10px;
  }

  .footer-created-by {
    font-size: 0.7em;
  }

  .footer-links a {
    font-size: 0.8em;
  }
}

/* Update legend intro styling */
.legend-intro {
  font-size: 0.9em;
  line-height: 1.2;
  margin: 0 0 8px 0;
  padding: 4px 0;
}

/* Remove bold from legend intro */
.legend-intro b {
  font-weight: normal;
}