@import url('admin.css');

/* 
  AlefBet 3D CSS Design System
  Theme: Sleek Glassmorphic Dark Mode with Neon Violet Accents
*/

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Heebo:wght@300;400;700;900&family=Outfit:wght@300;400;600;800&display=swap');

/* --- CSS Variables & Tokens --- */
:root {
  /* Colors */
  --bg-gradient: radial-gradient(circle at 50% 30%, #111827 0%, #030712 100%);
  --panel-bg: rgba(17, 24, 39, 0.65);
  --card-bg: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.12);
  
  --accent-color: #7c3aed;
  --accent-glow: rgba(124, 58, 237, 0.4);
  
  --success-color: #10b981;
  --success-glow: rgba(16, 185, 129, 0.4);
  
  --review-color: #f43f5e;
  --review-glow: rgba(244, 63, 94, 0.4);
  
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  /* Sizing and Layout */
  --card-width: clamp(200px, 55vw, 280px);
  --border-radius-lg: 24px;
  --border-radius-md: 16px;
  --border-radius-sm: 8px;
  
  /* Fonts */
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-hebrew: 'Heebo', -apple-system, sans-serif;
  
  /* Transitions */
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  --transition-slow: 0.6s cubic-bezier(0.34, 1.56, 0.64, 1); /* Bounce flip */
}

/* --- Global Reset & Core Styling --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: #030712;
  background-image: var(--bg-gradient);
  color: var(--text-primary);
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 0;
}

/* --- Ambient Glowing Orbs --- */
.glow-orb {
  position: absolute;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(120px);
  z-index: 0;
  opacity: 0.45;
  animation: orbFloat 20s infinite alternate ease-in-out;
}

.orb-primary {
  background: var(--accent-color);
  top: 15%;
  left: 5%;
}

.orb-secondary {
  background: #06b6d4;
  bottom: 15%;
  right: 5%;
  animation-delay: -10s;
}

@keyframes orbFloat {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, -60px) scale(1.2); }
  100% { transform: translate(-30px, 40px) scale(0.9); }
}

/* --- Game Wrapper --- */
.game-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: calc(10px + env(safe-area-inset-top)) 20px calc(10px + env(safe-area-inset-bottom)) 20px;
  overflow: hidden;
}

/* --- HUD Header --- */
.game-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas:
    "logo lang stats"
    "mode mode mode";
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  overflow: visible;
}

.header-logo {
  grid-area: logo;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.logo-accent {
  font-family: var(--font-hebrew);
  font-size: 24px;
  font-weight: 900;
  background: linear-gradient(135deg, #a78bfa, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  padding: 4px 8px;
  border-radius: 10px;
  background-color: rgba(124, 58, 237, 0.15);
  border: 1px solid rgba(124, 58, 237, 0.25);
  box-shadow: 0 0 15px rgba(124, 58, 237, 0.1);
}

.header-logo h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(to right, #ffffff, #e2e8f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stats-panel {
  grid-area: stats;
  display: flex;
  gap: 8px;
  justify-self: end;
}

.stat-badge {
  background: var(--panel-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(8px);
  padding: 6px 12px;
  border-radius: var(--border-radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 65px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 15px;
  font-weight: 800;
  color: #fff;
}

/* --- Progress Bar --- */
.progress-bar-wrapper {
  margin-bottom: 20px;
}

.progress-bar-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.02);
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-color) 0%, #06b6d4 100%);
  box-shadow: 0 0 12px var(--accent-glow);
  border-radius: 10px;
  transition: width var(--transition-normal);
}

.progress-text {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: right;
  margin-top: 6px;
  font-weight: 500;
}

/* --- Main 3D Card Scene --- */
.scene-container {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 1200px; /* High depth perspective */
  margin: 8px 0;
  position: relative;
}

.deck-container {
  width: var(--card-width);
  height: auto;
  position: relative;
  transform-style: preserve-3d;
  /* Premium static 3D top-down tilt */
  transform: rotateX(14deg) rotateY(-8deg) rotateZ(-3deg);
  transition: transform var(--transition-slow);
  will-change: transform;
  aspect-ratio: 0.82;
}

/* Subtle deck shadow matching the physical angle */
.deck-shadow {
  position: absolute;
  top: 15px;
  left: 15px;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  filter: blur(25px);
  border-radius: var(--border-radius-lg);
  transform: translateZ(-60px);
  pointer-events: none;
  z-index: 0;
}

/* --- Card Object Styles --- */
.card-stack-item {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  cursor: pointer;
  will-change: transform, opacity, filter;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), opacity var(--transition-normal), filter var(--transition-normal);
}

/* 3D Stack Mechanics based on index */
/* (Offsets will be set dynamically via JS, fallback static definitions for preview) */
.card-stack-item[data-depth="0"] {
  transform: translateZ(0px) rotateZ(0deg);
  z-index: 10;
  filter: brightness(1);
}
.card-stack-item[data-depth="1"] {
  transform: translateZ(-8px) translateY(-3px) rotateZ(1deg);
  z-index: 9;
  opacity: 1;
  filter: brightness(0.88);
}
.card-stack-item[data-depth="2"] {
  transform: translateZ(-16px) translateY(-6px) rotateZ(-1.5deg);
  z-index: 8;
  opacity: 1;
  filter: brightness(0.76);
}
.card-stack-item[data-depth="3"] {
  transform: translateZ(-24px) translateY(-9px) rotateZ(0.8deg);
  z-index: 7;
  opacity: 1;
  filter: brightness(0.64);
}
.card-stack-item[data-depth="4"] {
  transform: translateZ(-32px) translateY(-12px) rotateZ(-0.5deg);
  z-index: 6;
  opacity: 1;
  filter: brightness(0.52);
}

/* Inner card wrapper for 3D flip */
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--transition-slow);
}

/* Flipping rotation class */
.card-inner.flipped {
  transform: rotateY(180deg);
}

/* Card Faces */
.card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--card-border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25), 
              inset 0 1px 1px rgba(255,255,255,0.1);
  overflow: hidden;
}

/* Front Face Styling (Fully Opaque Deep Slate) */
.card-front {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  justify-content: space-between;
}

/* Glass/Backlight Border Effect on Hover */
.card-stack-item:hover .card-front {
  border-color: rgba(124, 58, 237, 0.35);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.35),
              0 0 25px rgba(124, 58, 237, 0.15),
              inset 0 1px 1px rgba(255, 255, 255, 0.15);
}

/* Back Face Styling (Fully Opaque Deep Violet) */
.card-back {
  background: linear-gradient(135deg, #4c1d95 0%, #0d1117 100%);
  transform: rotateY(180deg);
  justify-content: space-between;
  border-color: rgba(139, 92, 246, 0.25);
}

/* Card Visual Frame (Image area) */
.card-media {
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  border-radius: var(--border-radius-md);
  overflow: hidden;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.04);
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: inset 0 4px 15px rgba(0,0,0,0.5);
}

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

.card-stack-item:hover .card-media img {
  transform: scale(1.05);
}

/* Card Typography */
.card-text {
  text-align: center;
  padding: 8px 4px 4px 4px;
  flex-shrink: 0;
}

.card-front .english-word {
  font-size: clamp(18px, 4.5vw, 26px);
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
  text-transform: uppercase;
  background: linear-gradient(to right, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.card-sentence .english-word {
  font-size: clamp(16px, 4vw, 22px);
  text-transform: none;
  line-height: 1.25;
}

/* Obscured/Back Face Details */
.card-back-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 15px;
}

.hebrew-word {
  font-family: var(--font-hebrew);
  font-size: clamp(32px, 8vw, 58px);
  font-weight: 900;
  color: #fff;
  text-align: center;
  direction: rtl;
  letter-spacing: 1px;
  /* Text glow for premium style */
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.2), 
               0 0 35px var(--accent-glow);
  line-height: 1.2;
}

.card-sentence .hebrew-word {
  font-size: clamp(24px, 6vw, 38px);
  line-height: 1.25;
  max-width: 100%;
}

.card-sentence .spanish-pronunciation {
  font-size: clamp(11px, 2.7vw, 14px);
  line-height: 1.25;
  text-align: center;
}

.spanish-pronunciation {
  font-size: clamp(13px, 3vw, 18px);
  color: #c084fc;
  font-weight: 600;
  letter-spacing: 0.5px;
  background: rgba(124, 58, 237, 0.15);
  border: 1px solid rgba(124, 58, 237, 0.2);
  padding: 5px 14px;
  border-radius: 30px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pronunciation-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 800;
}

.card-back .english-translation {
  font-size: 16px;
  color: var(--text-secondary);
  font-weight: 500;
  text-align: center;
  border-top: 1px solid rgba(255,255,255,0.06);
  width: 80%;
  margin: 0 auto;
  padding-top: 12px;
}

/* --- Course script/direction modifiers (layered onto the base word classes) --- */
.english-word.script-hebrew,
.english-translation.script-hebrew {
  font-family: var(--font-hebrew);
  direction: rtl;
  text-transform: none;
}

.hebrew-word.script-latin {
  font-family: var(--font-sans);
  direction: ltr;
  letter-spacing: -0.5px;
}

/* --- Auto-fit card content (driven by fitVisibleCards() in app.js) ----------
   Long/unbreakable words wrap instead of overflowing horizontally; the script
   then shrinks the font so the content always fits the fixed-size card at any
   resolution. If text is so long it cannot fit even at the minimum size, the
   clipped edge is faded rather than hard-cut. */
.english-word,
.hebrew-word,
.english-translation,
.spanish-pronunciation {
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  max-width: 100%;
}

.card-face.fit-overflow .card-text,
.card-face.fit-overflow .card-back-wrapper {
  -webkit-mask-image: linear-gradient(to bottom, #000 82%, transparent);
  mask-image: linear-gradient(to bottom, #000 82%, transparent);
}

/* --- Swipe Animations (CSS Keyframes) --- */
.swiped-right {
  animation: swipeRightAnim 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: none;
}

.swiped-left {
  animation: swipeLeftAnim 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: none;
}

@keyframes swipeRightAnim {
  0% {
    transform: translate3d(0, 0, 0) rotateZ(0deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(400px, 30px, 50px) rotateZ(20deg);
    opacity: 0;
  }
}

@keyframes swipeLeftAnim {
  0% {
    transform: translate3d(0, 0, 0) rotateZ(0deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(-400px, 30px, 50px) rotateZ(-20deg);
    opacity: 0;
  }
}

/* Dragging visual indicators */
.card-stack-item.drag-right .card-front {
  border-color: var(--success-color);
  box-shadow: 0 0 35px var(--success-glow), inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

.card-stack-item.drag-left .card-front {
  border-color: var(--review-color);
  box-shadow: 0 0 35px var(--review-glow), inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

/* --- Instruction Hints --- */
.interaction-hints {
  text-align: center;
  margin: 10px 0;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.interaction-hints kbd {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--border-radius-sm);
  padding: 2px 6px;
  margin: 0 2px;
  font-size: 10px;
  color: var(--text-secondary);
}

.hint-desktop {
  display: inline;
}

.hint-mobile {
  display: none;
}

/* --- Bottom Controls Panel (Premium Glassmorphism) --- */
.controls-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  background: var(--panel-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  padding: 14px 24px;
  border-radius: 40px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.btn {
  border: none;
  cursor: pointer;
  outline: none;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  transition: all var(--transition-fast);
}

.btn-action {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-action svg {
  width: 22px;
  height: 22px;
  transition: transform var(--transition-fast);
}

/* Hover/Active states */
.btn-review:hover {
  background: rgba(244, 63, 94, 0.15);
  border-color: var(--review-color);
  box-shadow: 0 0 15px var(--review-glow);
  color: var(--review-color);
}

.btn-review:active {
  transform: scale(0.9);
}

.btn-learned:hover {
  background: rgba(16, 185, 129, 0.15);
  border-color: var(--success-color);
  box-shadow: 0 0 15px var(--success-glow);
  color: var(--success-color);
}

.btn-learned:active {
  transform: scale(0.9);
}

/* Premium Primary Flip Button */
.btn-flip {
  width: auto;
  flex-grow: 1;
  border-radius: 30px;
  background: linear-gradient(135deg, var(--accent-color) 0%, #6366f1 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 1px;
  gap: 8px;
}

.btn-flip svg {
  width: 16px;
  height: 16px;
}

.btn-flip:hover {
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.45), 
              0 0 15px var(--accent-glow);
  transform: translateY(-2px);
}

.btn-flip:active {
  transform: translateY(1px) scale(0.98);
}

.btn-flip:hover svg {
  transform: rotate(45deg);
}

/* Tooltip on long hover (for desktop) */
.btn-tooltip {
  position: absolute;
  bottom: 70px;
  background: #1e293b;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all var(--transition-fast);
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  white-space: nowrap;
}

.btn-action:hover .btn-tooltip {
  opacity: 1;
  transform: translateY(0);
}

/* --- Completion Modal --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 7, 18, 0.85);
  backdrop-filter: blur(15px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
  padding: 20px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  max-height: 92vh;
  overflow-y: auto;
  background: rgba(17, 24, 39, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-lg);
  padding: 30px 24px;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  transform: scale(0.9) translateY(20px);
  transition: transform var(--transition-slow);
  position: relative;
}

.modal-overlay.active .modal-card {
  transform: scale(1) translateY(0);
}

.modal-glow {
  position: absolute;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  height: 160px;
  background: var(--accent-color);
  filter: blur(60px);
  opacity: 0.3;
  pointer-events: none;
}

.modal-emoji {
  font-size: 54px;
  margin-bottom: 12px;
  animation: emojiWiggle 1.5s infinite ease-in-out;
}

@keyframes emojiWiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-10deg) scale(1.1); }
  40% { transform: rotate(10deg); }
  60% { transform: rotate(-5deg); }
  80% { transform: rotate(5deg); }
}

.modal-card h2 {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 6px;
}

.modal-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.modal-stat {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--border-radius-md);
  padding: 10px;
}

.modal-stat .stat-label {
  font-size: 9px;
}

.modal-stat .stat-number {
  font-size: 18px;
  font-weight: 800;
  display: block;
  margin-top: 4px;
}

.text-success {
  color: var(--success-color) !important;
}

.text-review {
  color: var(--review-color) !important;
}

/* SVG Radial Accuracy Ring */
.completion-ring-container {
  width: 120px;
  height: 120px;
  position: relative;
  margin: 0 auto 28px auto;
}

.completion-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: rgba(255,255,255,0.04);
  stroke-width: 8;
}

.ring-fill {
  fill: none;
  stroke: url(#ring-gradient);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.5s ease-out;
}

/* Linear gradients work with SVG using definitions in script or linearGradient element */
/* Let's inject a beautiful gradient inside the SVG structure or fall back to CSS stroke color */
.ring-fill {
  stroke: var(--accent-color);
  filter: drop-shadow(0 0 5px var(--accent-glow));
}

.ring-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ring-percentage {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
}

.ring-label {
  font-size: 9px;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Restart Button */
.btn-restart {
  width: 100%;
  border: none;
  outline: none;
  cursor: pointer;
  background: #fff;
  color: #030712;
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 15px;
  padding: 14px;
  border-radius: var(--border-radius-md);
  box-shadow: 0 4px 15px rgba(255,255,255,0.15);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.btn-restart svg {
  width: 16px;
  height: 16px;
  transition: transform 0.6s ease;
}

.btn-restart:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255,255,255,0.25);
}

.btn-restart:hover svg {
  transform: rotate(180deg);
}

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

/* Floating Audio Toggle */
.audio-toggle-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: 1px solid var(--card-border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: all var(--transition-fast);
  backdrop-filter: blur(8px);
}

.audio-toggle-btn:hover {
  color: #fff;
  border-color: rgba(255,255,255,0.3);
  transform: scale(1.05);
}

.audio-toggle-btn svg {
  width: 16px;
  height: 16px;
}

/* --- Mobile / Small Screens Responsive --- */
@media (max-width: 480px) {
  .game-wrapper {
    padding: calc(8px + env(safe-area-inset-top)) 12px calc(8px + env(safe-area-inset-bottom)) 12px;
  }
  
  .game-header {
    margin-bottom: 4px;
  }
  
  .progress-bar-wrapper {
    margin-bottom: 8px;
  }
  
  .controls-panel {
    padding: 10px 16px;
    gap: 12px;
  }
  
  .btn-action {
    width: 46px;
    height: 46px;
  }
  
  .btn-flip {
    font-size: 13px;
    padding: 0 16px;
  }
  
  .hint-desktop {
    display: none;
  }
  
  .hint-mobile {
    display: inline;
  }
  
  .audio-toggle-btn {
    bottom: 85px;
    right: 12px;
  }
}

/* --- Short Viewport Adaptation --- */
@media (max-height: 760px) {
  .game-wrapper {
    padding: calc(4px + env(safe-area-inset-top)) 16px calc(6px + env(safe-area-inset-bottom)) 16px;
  }
  
  .game-header {
    margin-bottom: 2px;
  }
  
  .header-logo h1 {
    font-size: 16px;
  }
  
  .logo-accent {
    font-size: 18px;
    padding: 2px 6px;
  }
  
  .stat-badge {
    padding: 4px 8px;
    min-width: 50px;
  }
  
  .stat-label {
    font-size: 8px;
  }
  
  .stat-value {
    font-size: 12px;
  }
  
  .progress-bar-wrapper {
    margin-bottom: 4px;
  }
  
  .progress-text {
    font-size: 10px;
    margin-top: 2px;
  }
  
  .scene-container {
    margin: 4px 0;
  }
  
  .interaction-hints {
    margin: 2px 0;
    font-size: 10px;
  }
  
  .controls-panel {
    padding: 6px 12px;
    gap: 8px;
  }
  
  .btn-action {
    width: 42px;
    height: 42px;
  }
  
  .btn-flip {
    font-size: 12px;
    padding: 0 12px;
  }

  /* Compact Modal Styles */
  .modal-card {
    padding: 16px 20px;
  }
  .modal-emoji {
    font-size: 36px;
    margin-bottom: 6px;
  }
  .modal-card h2 {
    font-size: 18px;
    margin-bottom: 2px;
  }
  .modal-subtitle {
    margin-bottom: 12px;
    font-size: 11px;
  }
  .modal-stats {
    gap: 8px;
    margin-bottom: 12px;
  }
  .modal-stat {
    padding: 6px;
  }
  .modal-stat .stat-number {
    font-size: 14px;
    margin-top: 2px;
  }
  .completion-ring-container {
    width: 80px;
    height: 80px;
    margin-bottom: 14px;
  }
  .ring-percentage {
    font-size: 14px;
  }
  .ring-label {
    font-size: 8px;
  }
  .btn-restart {
    padding: 10px;
    font-size: 13px;
  }
}

/* --- Tall Screens --- */
@media (min-height: 800px) {
  .scene-container {
    margin: 15px 0;
  }
  .deck-container {
    max-height: 450px;
  }
}

/* --- Floating Card Speaker Button (Voice Pronunciation) --- */
.btn-speaker {
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.25);
  color: #c084fc;
  cursor: pointer;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.15);
  transition: all var(--transition-fast);
  margin-top: 5px;
}

.btn-speaker:hover {
  background: rgba(124, 58, 237, 0.2);
  border-color: var(--accent-color);
  color: #fff;
  transform: scale(1.1);
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-speaker:active {
  transform: scale(0.95);
}

.btn-speaker svg {
  width: 18px;
  height: 18px;
}

.btn-speaker.playing {
  animation: pulseSpeaker 1s infinite ease-in-out;
  background: var(--accent-color);
  color: #fff;
  border-color: #fff;
}

@keyframes pulseSpeaker {
  0% { box-shadow: 0 0 8px var(--accent-glow); }
  50% { box-shadow: 0 0 20px var(--accent-glow); }
  100% { box-shadow: 0 0 8px var(--accent-glow); }
}

/* --- Speech Practice Mode Styles --- */
.btn-mic-practice {
  background: rgba(14, 165, 233, 0.1);
  border: 1px solid rgba(14, 165, 233, 0.25);
  color: #38bdf8;
  cursor: pointer;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 12px rgba(14, 165, 233, 0.15);
  transition: all var(--transition-fast);
  margin-top: 5px;
}

.btn-mic-practice:hover {
  background: rgba(14, 165, 233, 0.2);
  border-color: #38bdf8;
  color: #fff;
  transform: scale(1.1);
  box-shadow: 0 0 20px rgba(14, 165, 233, 0.4);
}

.btn-mic-practice:active {
  transform: scale(0.95);
}

.btn-mic-practice svg {
  width: 18px;
  height: 18px;
}

.btn-mic-practice.recording {
  animation: pulseMicRecording 1s infinite ease-in-out;
  background: #ef4444;
  color: #fff;
  border-color: #fff;
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.6);
}

.btn-mic-practice.analyzing {
  animation: spinMicAnalyzing 1.5s infinite linear;
  background: rgba(168, 85, 247, 0.2);
  border-color: #a855f7;
  color: #c084fc;
  cursor: wait;
}

.card-stack-item.recording-voice .card-inner {
  box-shadow: 0 0 30px rgba(239, 68, 68, 0.4);
}

.speech-feedback-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  width: 90%;
  box-sizing: border-box;
  animation: fadeIn var(--transition-fast) forwards;
  backdrop-filter: blur(8px);
}

.speech-feedback-popup {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 70;
  width: min(320px, calc(100vw - 24px));
  max-height: min(30vh, 160px);
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  transform: translateX(-50%);
  pointer-events: none;
  overflow-y: auto;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
  animation: speechPopupFadeIn var(--transition-fast) forwards;
}

.speech-feedback-container.success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.2);
}

.speech-feedback-container.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.2);
}

.speech-feedback-container.info {
  background: rgba(14, 165, 233, 0.15);
  border: 1px solid rgba(14, 165, 233, 0.3);
  color: #38bdf8;
}

.speech-feedback-container.warning {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fbbf24;
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.2);
}

.writing-practice-container {
  display: flex;
  gap: 8px;
  width: 90%;
  max-width: 260px;
  margin: 12px auto 4px auto;
  justify-content: center;
  align-items: center;
  animation: fadeIn var(--transition-fast) forwards;
}

.writing-practice-input {
  flex: 1 1 auto;
  min-width: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  color: #fff;
  padding: 10px 16px;
  font-size: 15px;
  text-align: center;
  outline: none;
  transition: all var(--transition-fast);
  font-family: var(--font-hebrew);
  font-weight: 700;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.25);
}

.writing-practice-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 12px var(--accent-glow), inset 0 2px 5px rgba(0, 0, 0, 0.25);
  background: rgba(0, 0, 0, 0.5);
}

.writing-practice-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
  font-size: 13px;
  font-weight: 400;
}

.writing-practice-input:disabled {
  opacity: 0.72;
  cursor: wait;
}

.writing-practice-input.script-latin {
  font-family: var(--font-sans);
}

.writing-input-close {
  border-color: #fbbf24 !important;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.4), inset 0 2px 5px rgba(0, 0, 0, 0.25) !important;
}

.btn-writing-check {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-color) 0%, #6366f1 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 10px rgba(124, 58, 237, 0.25);
}

.btn-writing-check svg {
  width: 16px;
  height: 16px;
}

.btn-writing-check:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 15px rgba(124, 58, 237, 0.4), 0 0 10px var(--accent-glow);
}

.btn-writing-check:active {
  transform: scale(0.95);
}

.feedback-status {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.feedback-text {
  font-style: italic;
  font-size: 12px;
  text-align: center;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

@keyframes fadeIn {
  0% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes speechPopupFadeIn {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  100% { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes pulseMicRecording {
  0% { box-shadow: 0 0 10px rgba(239, 68, 68, 0.4); transform: scale(1); }
  50% { box-shadow: 0 0 25px rgba(239, 68, 68, 0.8); transform: scale(1.08); }
  100% { box-shadow: 0 0 10px rgba(239, 68, 68, 0.4); transform: scale(1); }
}

@keyframes spinMicAnalyzing {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* --- Extreme Height Adaptation (e.g. Landscape Phone Viewports) --- */
@media (max-height: 520px) {
  .game-wrapper {
    padding: calc(4px + env(safe-area-inset-top)) 12px calc(4px + env(safe-area-inset-bottom)) 12px;
  }

  .game-header {
    margin-bottom: 2px;
  }

  .progress-bar-wrapper {
    margin-bottom: 2px;
  }

  .interaction-hints {
    display: none !important;
  }

  .controls-panel {
    padding: 6px 16px;
    gap: 8px;
    border-radius: 20px;
  }

  .btn-action {
    width: 36px;
    height: 36px;
  }

  .btn-action svg {
    width: 16px;
    height: 16px;
  }

  .btn-flip {
    font-size: 11px;
    padding: 0 16px;
    height: 36px;
  }

  .scene-container {
    margin: 2px 0;
  }

  .card-face {
    padding: 8px !important;
  }

  .card-back-wrapper {
    gap: 4px !important;
  }

  .btn-speaker {
    width: 30px !important;
    height: 30px !important;
    margin-top: 2px !important;
  }

  .btn-speaker svg {
    width: 14px !important;
    height: 14px !important;
  }

  .card-back .english-translation {
    font-size: clamp(10px, 2vh, 12px) !important;
    padding-top: 4px !important;
    margin-top: 0 !important;
  }
  
  .audio-toggle-btn {
    bottom: 60px;
    right: 12px;
    width: 30px;
    height: 30px;
  }

  .speech-feedback-popup {
    bottom: calc(54px + env(safe-area-inset-bottom));
    width: min(300px, calc(100vw - 20px));
    max-height: min(34vh, 120px);
    padding: 8px 12px;
  }

  .deck-container {
    max-height: none;
  }
}

/* ============================================================ */
/* Language selector, practice-mode control & onboarding (Task 13) */
/* Mascot <img>s hide themselves on error (see app.js onerror),   */
/* so the emoji flag remains a graceful fallback when per-language */
/* assets in /assets/lang/ are absent.                            */
/* ============================================================ */

/* --- Language switcher (top bar) --- */
.language-control { grid-area: lang; position: relative; justify-self: start; min-width: 0; }
.lang-switcher { display: inline-flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 999px; padding: 4px 12px 4px 6px; cursor: pointer; color: #fff; }
.lang-switcher:hover { background: rgba(255, 255, 255, 0.1); }
.lang-switcher-mascot { width: 32px; height: 32px; object-fit: contain; }
.lang-switcher-flag { font-size: 18px; }
.lang-switcher-name { font-weight: 600; font-size: 14px; }
.lang-picker { position: absolute; z-index: 80; top: calc(100% + 6px); left: 0; min-width: 100%; width: max-content; max-width: min(240px, calc(100vw - 24px)); background: #1c2230; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 16px; padding: 8px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45); }
.lang-picker[hidden] { display: none; }
.lang-option { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: none; color: #fff; padding: 8px 12px; border-radius: 12px; cursor: pointer; font: inherit; white-space: nowrap; }
.lang-option:hover { background: rgba(255, 255, 255, 0.08); }
.lang-option-mascot { width: 28px; height: 28px; object-fit: contain; }
.lang-option-flag { font-size: 18px; }

/* --- Practice-mode segmented control --- */
.mode-switcher { grid-area: mode; width: 100%; display: flex; background: rgba(0, 0, 0, 0.25); border-radius: 999px; padding: 3px; gap: 2px; box-sizing: border-box; }
.mode-option { flex: 1 1 0; min-width: 0; background: none; border: none; color: rgba(255, 255, 255, 0.7); padding: 6px 14px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600; transition: all var(--transition-fast); text-align: center; white-space: nowrap; }
.mode-option:hover { color: #fff; }
.mode-option.active { background: var(--accent-color, #7c5cff); color: #fff; }

@media (max-width: 420px) {
  .header-logo h1 {
    display: none;
  }
}

@media (max-width: 360px) {
  .lang-switcher-name {
    display: none;
  }
}

/* --- First-launch onboarding overlay --- */
.onboarding-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(8, 10, 18, 0.92); backdrop-filter: blur(4px); }
.onboarding-overlay[hidden] { display: none; }
.onboarding-card { max-width: 460px; text-align: center; padding: 32px; }
.onboarding-mascot { width: 140px; height: 140px; object-fit: contain; }
.onboarding-card h2 { margin: 12px 0; }
.onboarding-known { color: rgba(255, 255, 255, 0.75); }
.onboarding-known-btn { background: none; border: none; color: var(--accent-color, #7c5cff); font-weight: 700; cursor: pointer; font: inherit; }
.onboarding-known-picker { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0; }
.onboarding-known-picker[hidden] { display: none; }
.onboarding-known-option { background: rgba(255, 255, 255, 0.08); border: none; color: #fff; padding: 8px 14px; border-radius: 999px; cursor: pointer; font: inherit; }
.onboarding-known-option:hover { background: rgba(255, 255, 255, 0.16); }
.onboarding-pronoun-group { margin-top: 18px; }
.onboarding-pronoun-label { font-weight: 700; }
.onboarding-pronoun-help { color: rgba(255, 255, 255, 0.65); font-size: 13px; line-height: 1.4; margin: 6px auto 10px auto; max-width: 360px; }
.onboarding-pronoun-options { display: inline-flex; gap: 4px; padding: 4px; background: rgba(0, 0, 0, 0.25); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 999px; }
.onboarding-pronoun-option { border: none; border-radius: 999px; background: transparent; color: rgba(255, 255, 255, 0.74); cursor: pointer; font: inherit; font-weight: 700; padding: 8px 18px; transition: all var(--transition-fast); }
.onboarding-pronoun-option:hover { color: #fff; }
.onboarding-pronoun-option.active { background: var(--accent-color, #7c5cff); color: #fff; box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25); }
.onboarding-prompt { font-weight: 700; margin-top: 20px; }
.onboarding-targets { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 16px; }
.onboarding-target { display: flex; flex-direction: column; align-items: center; gap: 6px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 18px; padding: 16px 20px; cursor: pointer; color: #fff; min-width: 110px; font: inherit; }
.onboarding-target:hover { border-color: var(--accent-color, #7c5cff); transform: translateY(-2px); }
.onboarding-target-mascot { width: 72px; height: 72px; object-fit: contain; }
.onboarding-target-flag { font-size: 22px; }
.onboarding-target-name { font-weight: 600; }
