:root {
  --primary-gold: #d4af37;
  --primary-dark: #1a1a2e;
  --secondary-dark: #16213e;
  --accent-purple: #6a4c93;
  --text-light: #f5f5f5;
  --text-gold: #ffd700;
  --shadow-dark: rgba(0, 0, 0, 0.8);
  --glow-gold: rgba(212, 175, 55, 0.6);
  --house-primary: var(--primary-gold);
  --house-secondary: var(--primary-dark);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  font-family: "Crimson Text", serif;
  background: linear-gradient(135deg, #0c0c0c 0%, #1a1a2e 50%, #16213e 100%);
  color: var(--text-light);
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  overflow-x: hidden;
  position: relative;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Magical Background - Optimized for mobile */
.magical-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
}

.stars {
  position: absolute;
  width: 100%;
  height: 100%;
}

.star {
  position: absolute;
  width: 1px;
  height: 1px;
  background: white;
  border-radius: 50%;
  animation: twinkle 3s infinite;
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

.floating-particles {
  position: absolute;
  width: 100%;
  height: 100%;
}

.particle {
  position: absolute;
  width: 3px;
  height: 3px;
  background: radial-gradient(circle, var(--primary-gold) 0%, transparent 70%);
  border-radius: 50%;
  animation: float 15s infinite linear;
}

@keyframes float {
  0% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(-100px) rotate(360deg);
    opacity: 0;
  }
}

/* Main Container - Mobile First */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Header - Mobile Optimized */
.hogwarts-header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding: 1rem 0;
}

.title {
  font-family: "Cinzel", serif;
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 700;
  color: var(--text-gold);
  text-shadow: 2px 2px 4px var(--shadow-dark);
  margin-bottom: 0.5rem;
  letter-spacing: 1px;
  line-height: 1.2;
}

.subtitle {
  font-size: clamp(1rem, 3vw, 1.2rem);
  color: var(--text-light);
  opacity: 0.9;
  font-style: italic;
  line-height: 1.4;
}

/* Sorting Hat - Mobile Responsive */
.sorting-hat-container {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
  position: relative;
  padding: 1rem 0;
}

.hat-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sorting-hat {
  width: clamp(100px, 20vw, 140px);
  height: clamp(120px, 24vw, 160px);
  /* Textura de arrugas sobre el gradiente base del sombrero */
  background-image: radial-gradient(ellipse at 30% 20%, rgba(139, 69, 19, 0.3) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 40%, rgba(0, 0, 0, 0.2) 0%, transparent 50%),
    radial-gradient(ellipse at 20% 80%, rgba(139, 69, 19, 0.2) 0%, transparent 50%),
    linear-gradient(145deg, #4a3728, #2d1f17, #1a0f0a);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  position: relative;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8), inset 0 3px 10px rgba(139, 69, 19, 0.3), inset 0 -3px 10px
    rgba(0, 0, 0, 0.5);
  transition: all 0.3s ease;
  cursor: pointer;
  transform-origin: center bottom;
  touch-action: manipulation;
}

.sorting-hat::before {
  content: "";
  position: absolute;
  top: -15px;
  left: 15%;
  width: 70%;
  height: clamp(25px, 5vw, 40px);
  background: linear-gradient(145deg, #4a3728, #2d1f17);
  border-radius: 50% 50% 50% 50% / 80% 80% 20% 20%;
  transform: rotate(-15deg);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.6);
}

.sorting-hat::after {
  content: "";
  position: absolute;
  top: -25px;
  left: 25%;
  width: 50%;
  height: clamp(18px, 4vw, 25px);
  background: linear-gradient(145deg, #3d2b1f, #2d1f17);
  border-radius: 50% 50% 50% 50% / 90% 90% 10% 10%;
  transform: rotate(-25deg);
  box-shadow: inset 0 1px 5px rgba(0, 0, 0, 0.7);
}

.sorting-hat:hover {
  transform: scale(1.05) translateY(-3px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.9), inset 0 3px 10px rgba(139, 69, 19, 0.4);
}

.sorting-hat.speaking {
  animation: hatBounce 0.6s ease-in-out infinite alternate;
}

@keyframes hatBounce {
  0% {
    transform: translateY(0px) scale(1) rotate(0deg);
  }
  100% {
    transform: translateY(-5px) scale(1.02) rotate(1deg);
  }
}

/* Hat Face - Responsive */
.hat-face {
  position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.hat-eyes {
  width: clamp(8px, 2vw, 12px);
  height: clamp(8px, 2vw, 12px);
  background: radial-gradient(circle, #ffff00, #ffa500);
  border-radius: 50%;
  position: relative;
  margin-bottom: clamp(10px, 3vw, 15px);
  box-shadow: 0 0 8px rgba(255, 255, 0, 0.6), inset 0 1px 3px rgba(0, 0, 0, 0.3);
  animation: eyeGlow 2s ease-in-out infinite alternate;
}

.hat-eyes::after {
  content: "";
  position: absolute;
  right: clamp(-15px, -4vw, -20px);
  top: 0;
  width: clamp(8px, 2vw, 12px);
  height: clamp(8px, 2vw, 12px);
  background: radial-gradient(circle, #ffff00, #ffa500);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(255, 255, 0, 0.6), inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

@keyframes eyeGlow {
  0% {
    box-shadow: 0 0 8px rgba(255, 255, 0, 0.6), inset 0 1px 3px rgba(0, 0, 0, 0.3);
  }
  100% {
    box-shadow: 0 0 15px rgba(255, 255, 0, 0.9), inset 0 1px 3px rgba(0, 0, 0, 0.3);
  }
}

.hat-mouth {
  width: clamp(25px, 6vw, 35px);
  height: clamp(12px, 3vw, 18px);
  border: 2px solid #2d1f17;
  border-top: none;
  border-radius: 0 0 35px 35px;
  background: linear-gradient(to bottom, #1a0f0a, #000);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.hat-mouth::before,
.hat-mouth::after {
  content: "";
  position: absolute;
  top: 2px;
  width: 3px;
  height: 3px;
  background: #fff;
  border-radius: 50%;
  opacity: 0.7;
}

.hat-mouth::before {
  left: 20%;
}

.hat-mouth::after {
  right: 20%;
}

.hat-mouth.talking {
  animation: mouthMove 0.2s ease-in-out infinite alternate;
}

@keyframes mouthMove {
  0% {
    height: clamp(12px, 3vw, 18px);
    border-radius: 0 0 35px 35px;
  }
  100% {
    height: clamp(18px, 4vw, 25px);
    border-radius: 0 0 25px 25px;
  }
}

/* Hat Glow - Mobile Optimized */
.hat-glow {
  position: absolute;
  top: -20px;
  left: -20px;
  right: -20px;
  bottom: -20px;
  background: radial-gradient(circle, rgba(212, 175, 55, 0.4) 0%, rgba(255, 215, 0, 0.2) 30%, transparent 70%);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  animation: glowPulse 3s ease-in-out infinite;
}

@keyframes glowPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* Chat Container - Mobile First Design */
.chat-container {
  flex: 1;
  background: rgba(26, 26, 46, 0.95);
  border-radius: 15px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(212, 175, 55, 0.3);
  box-shadow: 0 15px 30px var(--shadow-dark);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(100vh - 300px);
  max-height: calc(100dvh - 300px);
  min-height: 400px;
}

.messages-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  opacity: 0;
  transform: translateY(15px);
  transition: all 0.3s ease;
}

.message.show {
  opacity: 1;
  transform: translateY(0);
}

.message-content {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.user-message .message-content {
  flex-direction: row-reverse;
}

.message-avatar {
  width: clamp(32px, 8vw, 40px);
  height: clamp(32px, 8vw, 40px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  flex-shrink: 0;
  background: rgba(212, 175, 55, 0.2);
  border: 2px solid var(--primary-gold);
}

.message-text {
  background: rgba(255, 255, 255, 0.1);
  padding: 0.75rem 1rem;
  border-radius: 15px;
  max-width: 85%;
  word-wrap: break-word;
  line-height: 1.5;
  backdrop-filter: blur(5px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: clamp(0.9rem, 2.5vw, 1rem);
  hyphens: auto;
  overflow-wrap: break-word;
}

.user-message .message-text {
  background: rgba(212, 175, 55, 0.2);
  border: 1px solid rgba(212, 175, 55, 0.3);
  color: var(--text-light);
}

.hat-message .message-text {
  background: rgba(106, 76, 147, 0.2);
  border: 1px solid rgba(106, 76, 147, 0.3);
  color: var(--text-light);
}

.message-text.system {
  background: rgba(255, 0, 0, 0.1);
  border: 1px solid rgba(255, 0, 0, 0.3);
  color: #ffcccb;
  font-style: italic;
  text-align: center;
  max-width: 100%;
}

/* Typing Indicator - Mobile Optimized */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  color: var(--text-gold);
  font-style: italic;
  font-size: clamp(0.8rem, 2vw, 0.9rem);
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary-gold);
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Input Section - Mobile Optimized */
.input-section {
  padding: 1rem;
  border-top: 1px solid rgba(212, 175, 55, 0.3);
  background: rgba(22, 33, 62, 0.9);
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.audio-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border: 2px solid var(--primary-gold);
  background: rgba(212, 175, 55, 0.1);
  color: var(--text-gold);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
  min-height: 44px; /* iOS touch target minimum */
}

.audio-btn:hover:not(:disabled) {
  background: rgba(212, 175, 55, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(212, 175, 55, 0.3);
}

.audio-btn:active {
  transform: translateY(0) scale(0.98);
}

.audio-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.record-btn.recording {
  background: rgba(255, 0, 0, 0.2);
  border-color: #ff4444;
  color: #ff4444;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.7);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(255, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 68, 68, 0);
  }
}

.audio-level {
  width: clamp(60px, 15vw, 100px);
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.level-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-gold), #ff4444);
  border-radius: 3px;
  width: calc(var(--level, 0) * 100%);
  transition: width 0.1s ease;
}

.text-input-container {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
}

#messageInput {
  flex: 1;
  padding: 1rem;
  border: 2px solid rgba(212, 175, 55, 0.3);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-light);
  border-radius: 20px;
  font-family: inherit;
  font-size: clamp(0.9rem, 2.5vw, 1rem);
  transition: all 0.3s ease;
  backdrop-filter: blur(5px);
  resize: none;
  min-height: 50px;
  line-height: 1.4;
}

#messageInput:focus {
  outline: none;
  border-color: var(--primary-gold);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.2);
}

#messageInput::placeholder {
  color: rgba(245, 245, 245, 0.6);
}

.send-btn {
  width: 50px;
  height: 50px;
  min-width: 50px;
  border: 2px solid var(--primary-gold);
  background: linear-gradient(135deg, var(--primary-gold), #b8941f);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
  touch-action: manipulation;
}

.send-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 20px rgba(212, 175, 55, 0.4);
}

.send-btn:active {
  transform: translateY(0) scale(0.95);
}

/* House Result - Mobile Responsive */
.house-result {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: linear-gradient(135deg, var(--house-primary), var(--house-secondary));
  padding: 1.5rem;
  border-radius: 15px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  border: 3px solid var(--primary-gold);
  z-index: 1000;
  opacity: 0;
  transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  backdrop-filter: blur(10px);
  max-width: min(400px, 90vw);
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.house-result.show {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  animation: houseReveal 1s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes houseReveal {
  0% {
    transform: translate(-50%, -50%) scale(0) rotate(-180deg);
    opacity: 0;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.1) rotate(-90deg);
    opacity: 0.8;
  }
  100% {
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
    opacity: 1;
  }
}

.house-crest {
  font-size: clamp(3rem, 12vw, 5rem);
  margin-bottom: 1rem;
  animation: crestGlow 2s ease-in-out infinite alternate;
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
  line-height: 1;
}

@keyframes crestGlow {
  0% {
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
  }
  100% {
    text-shadow: 0 0 25px rgba(255, 255, 255, 1), 0 0 35px rgba(212, 175, 55, 0.6);
  }
}

.house-name {
  font-family: "Cinzel", serif;
  font-size: clamp(1.5rem, 6vw, 2.5rem);
  font-weight: 700;
  color: var(--text-gold);
  margin-bottom: 1rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8), 0 0 20px rgba(212, 175, 55, 0.6);
  animation: nameGlow 1.5s ease-in-out infinite alternate;
  line-height: 1.2;
}

@keyframes nameGlow {
  0% {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8), 0 0 20px rgba(212, 175, 55, 0.6);
  }
  100% {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8), 0 0 30px rgba(212, 175, 55, 0.9), 0 0 40px rgba(255, 215, 0, 0.5);
  }
}

.house-description {
  font-size: clamp(1rem, 3vw, 1.2rem);
  line-height: 1.5;
  color: var(--text-light);
  opacity: 0.9;
}

/* Loading Overlay - Mobile Optimized */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 2000;
  backdrop-filter: blur(5px);
  padding: 1rem;
}

.magical-spinner {
  position: relative;
  width: clamp(60px, 15vw, 80px);
  height: clamp(60px, 15vw, 80px);
  margin-bottom: 1rem;
}

.wand {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: clamp(30px, 8vw, 40px);
  background: linear-gradient(to bottom, #8b4513, #d2691e);
  border-radius: 2px;
  transform-origin: bottom center;
  animation: wandRotate 2s linear infinite;
}

@keyframes wandRotate {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

.sparkles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.sparkles::before,
.sparkles::after {
  content: "✨";
  position: absolute;
  font-size: clamp(1rem, 3vw, 1.5rem);
  animation: sparkle 1.5s ease-in-out infinite;
}

.sparkles::before {
  top: 10px;
  left: 10px;
  animation-delay: 0s;
}

.sparkles::after {
  bottom: 10px;
  right: 10px;
  animation-delay: 0.75s;
}

@keyframes sparkle {
  0%,
  100% {
    opacity: 0;
    transform: scale(0.5);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.loading-overlay p {
  color: var(--text-gold);
  font-size: clamp(1rem, 3vw, 1.2rem);
  font-style: italic;
  text-align: center;
  line-height: 1.4;
}

/* Mode Switch - Mobile Friendly */
.mode-switch {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 1rem;
  padding: 0 0.5rem;
}

.mode-btn {
  flex: 1;
  max-width: 150px;
  padding: 0.75rem 1rem;
  border: 2px solid var(--primary-gold);
  background: var(--primary-dark);
  color: var(--text-light);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.3s ease;
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  font-family: inherit;
  touch-action: manipulation;
  text-align: center;
}

.mode-btn:active {
  transform: scale(0.98);
}

.mode-btn.active {
  background: var(--primary-gold);
  color: #000;
  font-weight: 600;
}

/* Scrollbar Styling - Mobile Friendly */
.messages-wrapper::-webkit-scrollbar {
  width: 6px;
}

.messages-wrapper::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.messages-wrapper::-webkit-scrollbar-thumb {
  background: var(--primary-gold);
  border-radius: 3px;
}

.messages-wrapper::-webkit-scrollbar-thumb:hover {
  background: #b8941f;
}

/* Mobile Specific Optimizations */
@media (max-width: 768px) {
  .main-container {
    padding: 0.75rem;
  }

  .chat-container {
    border-radius: 12px;
    max-height: calc(100vh - 250px);
    max-height: calc(100dvh - 250px);
  }

  .messages-wrapper {
    padding: 0.75rem;
  }

  .input-section {
    padding: 0.75rem;
  }

  .audio-controls {
    gap: 0.5rem;
  }

  .message-text {
    max-width: 90%;
    padding: 0.75rem;
  }

  .house-result {
    padding: 1.25rem;
    border-radius: 12px;
  }
}

@media (max-width: 480px) {
  .main-container {
    padding: 0.5rem;
  }

  .hogwarts-header {
    margin-bottom: 1rem;
    padding: 0.75rem 0;
  }

  .sorting-hat-container {
    margin-bottom: 1rem;
    padding: 0.5rem 0;
  }

  .chat-container {
    border-radius: 10px;
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
  }

  .messages-wrapper {
    padding: 0.5rem;
  }

  .messages {
    gap: 0.5rem;
  }

  .input-section {
    padding: 0.5rem;
  }

  .audio-controls {
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
  }

  .audio-btn {
    justify-content: center;
    min-height: 48px;
  }

  .audio-level {
    order: -1;
    width: 100%;
    margin-bottom: 0.5rem;
  }

  .text-input-container {
    flex-direction: column;
    gap: 0.5rem;
  }

  .send-btn {
    width: 100%;
    height: 48px;
    border-radius: 20px;
    font-size: 1rem;
  }

  .house-result {
    padding: 1rem;
    border-radius: 10px;
    width: 95%;
  }

  .mode-switch {
    margin: 0.75rem;
    gap: 0.25rem;
  }

  .mode-btn {
    padding: 0.75rem 0.5rem;
    min-height: 44px;
  }
}

/* Landscape Mobile Optimization */
@media (max-height: 500px) and (orientation: landscape) {
  .main-container {
    padding: 0.5rem;
  }

  .hogwarts-header {
    margin-bottom: 0.5rem;
    padding: 0.5rem 0;
  }

  .sorting-hat-container {
    margin-bottom: 0.5rem;
    padding: 0.25rem 0;
  }

  .chat-container {
    max-height: calc(100vh - 150px);
    max-height: calc(100dvh - 150px);
  }

  .input-section {
    padding: 0.5rem;
  }

  .audio-controls {
    margin-bottom: 0.5rem;
  }

  .mode-switch {
    margin: 0.5rem;
  }
}

/* High DPI Display Optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .star {
    width: 0.5px;
    height: 0.5px;
  }

  .particle {
    width: 2px;
    height: 2px;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .sorting-hat.speaking {
    animation: none;
  }

  .hat-glow {
    animation: none;
  }

  .typing-indicator span {
    animation: none;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    --text-light: #f8f9fa;
    --primary-dark: #0d1117;
    --secondary-dark: #161b22;
  }
}

/* Focus Styles for Accessibility */
.audio-btn:focus,
.mode-btn:focus,
.send-btn:focus,
#messageInput:focus {
  outline: 2px solid var(--primary-gold);
  outline-offset: 2px;
}

/* Touch Target Improvements */
@media (pointer: coarse) {
  .audio-btn,
  .mode-btn,
  .send-btn {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ===========================================
   Ceremonia: lectura en vivo del Sombrero
   =========================================== */
.ceremony-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 10px;
  background: rgba(26, 26, 46, 0.55);
  backdrop-filter: blur(6px);
}

.ceremony-panel[hidden] {
  display: none;
}

.ceremony-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ceremony-step {
  font-family: "Cinzel", serif;
  font-size: clamp(0.8rem, 2.2vw, 0.95rem);
  color: var(--text-gold);
  letter-spacing: 0.03em;
}

.ceremony-hint {
  font-size: clamp(0.7rem, 2vw, 0.8rem);
  color: var(--text-light);
  opacity: 0.6;
  font-style: italic;
}

.ceremony-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(245, 245, 245, 0.12);
  overflow: hidden;
}

.ceremony-fill {
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent-purple), var(--primary-gold));
  transition: width 0.6s ease;
}

.reading {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.reading-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr 2.5rem;
  align-items: center;
  gap: 0.5rem;
}

.reading-label {
  font-size: clamp(0.68rem, 1.9vw, 0.78rem);
  color: var(--text-light);
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-bar {
  height: 7px;
  border-radius: 4px;
  background: rgba(245, 245, 245, 0.1);
  overflow: hidden;
}

.reading-fill {
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: var(--bar-color, var(--primary-gold));
  box-shadow: 0 0 8px var(--bar-color, var(--glow-gold));
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.reading-value {
  font-size: clamp(0.65rem, 1.8vw, 0.75rem);
  color: var(--text-gold);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ===========================================
   Veredicto ampliado
   =========================================== */
.house-traits {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  list-style: none;
  margin: 0.9rem 0 0;
  padding: 0;
}

.house-trait {
  padding: 0.2rem 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  font-size: clamp(0.68rem, 2vw, 0.78rem);
  color: var(--text-light);
  background: rgba(0, 0, 0, 0.25);
}

.house-verdict {
  margin-top: 0.9rem;
  font-size: clamp(0.85rem, 2.6vw, 1rem);
  line-height: 1.5;
  color: var(--text-light);
  font-style: italic;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7);
}

.house-scores {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.house-scores .reading-bar {
  background: rgba(0, 0, 0, 0.35);
}

.house-close {
  margin-top: 1.1rem;
  padding: 0.55rem 1.6rem;
  border: 2px solid var(--primary-gold);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-gold);
  font-family: "Cinzel", serif;
  font-size: clamp(0.8rem, 2.2vw, 0.9rem);
  cursor: pointer;
  transition: all 0.3s ease;
  touch-action: manipulation;
}

.house-close:hover {
  background: var(--primary-gold);
  color: #000;
}

.house-close:focus {
  outline: 2px solid var(--primary-gold);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  .reading-row {
    grid-template-columns: 4.6rem 1fr 2.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ceremony-fill,
  .reading-fill {
    transition: none;
  }
}
