:root {
  --bg-main: #f3f4f6;
  --bg-card: #ffffff;
  --text-main: #1f2937;
  --text-muted: #9ca3af;
  --brand-green: #58cc02;
  --brand-green-shadow: #58a700;
  --brand-blue: #1cb0f6;
  --brand-blue-shadow: #1899d6;
  --brand-red: #ff4b4b;
  --brand-red-shadow: #ea1515;
  --border-color: #e5e7eb;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: "Plus Jakarta Sans", sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

.app-body {
  display: flex;
  height: 100%;
}

/* SIDEBAR */
.app-sidebar {
  width: 280px;
  background: var(--bg-card);
  border-right: 2px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  z-index: 1000;
}
.app-logo a {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--brand-blue);
  text-decoration: none;
  letter-spacing: -1px;
}
.sidebar-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 800;
  text-transform: uppercase;
  margin: 8px 0 2rem;
  letter-spacing: 0.5px;
}
.lesson-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.nav-lesson-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-radius: 16px;
  background: white;
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  font-weight: 800;
  color: var(--text-muted);
  cursor: pointer;
  transition: 0.1s;
}
.nav-lesson-item:active:not(.locked) {
  transform: translateY(2px);
  border-bottom-width: 2px;
}
.nav-lesson-item.active {
  border-color: var(--brand-blue);
  border-bottom-color: var(--brand-blue-shadow);
  color: var(--brand-blue);
  background: #e0f2fe;
}
.nav-lesson-item.locked {
  background: #f9fafb;
  opacity: 0.8;
}

.premium-upsell {
  margin-top: 1rem;
  text-align: center;
  padding-top: 1rem;
  border-top: 2px solid var(--border-color);
}
.upsell-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}
.premium-upsell p {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 1rem;
}
.btn-gamified-upsell {
  display: inline-block;
  background: var(--brand-blue);
  color: white;
  padding: 10px 20px;
  border-radius: 12px;
  font-weight: 800;
  text-transform: uppercase;
  text-decoration: none;
  font-size: 0.9rem;
  border-bottom: 4px solid var(--brand-blue-shadow);
  width: 100%;
}
.btn-gamified-upsell:active {
  transform: translateY(3px);
  border-bottom-width: 0px;
}

/* HEADER */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.app-header {
  background: var(--bg-card);
  padding: 1.5rem 2rem 1rem;
  border-bottom: 2px solid var(--border-color);
  flex-shrink: 0;
}
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.title-wrap {
  display: flex;
  align-items: flex-start;
  gap: 15px;
  flex: 1 1 300px;
}
.title-wrap h1 {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -1px;
  color: #111827;
  line-height: 1.2;
}

/* PROGRESS & 3 STAGES */
.progress-wrapper {
  display: flex;
  flex-direction: column;
  width: 250px;
  flex: 0 0 250px;
}
.progress-container {
  display: flex;
  align-items: flex-start;
  gap: 15px;
  width: 100%;
}
.track-group {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.progress-track {
  width: 100%;
  height: 16px;
  background: #e5e7eb;
  border-radius: 20px;
  position: relative;
}
.progress-fill {
  height: 100%;
  background: var(--brand-green);
  width: 0%;
  transition: width 0.4s ease-out;
  border-radius: 20px;
}
.progress-text {
  font-weight: 900;
  color: var(--brand-green);
  font-size: 1rem;
  min-width: 45px;
  text-align: right;
  line-height: 16px;
}
.stage-circles {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 8px;
}
.stage-circle {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e5e7eb;
  border: 2px solid #d1d5db;
  transition: all 0.3s;
}
.stage-circle.completed {
  animation: stagePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes stagePop {
  0% {
    transform: scale(1);
    background: #e5e7eb;
    border-color: #d1d5db;
  }
  50% {
    transform: scale(1.6);
    background: var(--brand-green);
    border-color: var(--brand-green-shadow);
  }
  100% {
    transform: scale(1);
    background: var(--brand-green);
    border-color: var(--brand-green-shadow);
  }
}

/* TABS */
.segmented-control {
  display: flex;
  gap: 8px;
}
.seg-tab {
  background: white;
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  padding: 10px 20px;
  border-radius: 14px;
  font-weight: 900;
  color: var(--text-muted);
  cursor: pointer;
  transition: 0.1s;
  text-transform: uppercase;
  font-size: 0.85rem;
}
.seg-tab:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}
.seg-tab.active {
  border-color: var(--brand-blue);
  border-bottom-color: var(--brand-blue-shadow);
  color: var(--brand-blue);
  background: #e0f2fe;
}

/* CONTENT AREA */
.app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2rem;
  background: var(--bg-main);
}
.content-safe-wrapper {
  margin: 0 auto;
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

/* FLASHCARDS */
.card-stack {
  perspective: 1000px;
  width: 100%;
  margin: 0 auto 1.5rem;
}
.flashcard-3d {
  width: 100%;
  height: 280px;
  position: relative;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  cursor: pointer;
}
.flashcard-3d.flipped {
  transform: rotateY(180deg);
}
.fc-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  background: white;
  border: 2px solid var(--border-color);
  border-bottom: 6px solid var(--border-color);
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
}
.fc-back {
  transform: rotateY(180deg);
  border-color: var(--brand-blue);
  border-bottom-color: var(--brand-blue-shadow);
  background: #e0f2fe;
}
.fc-phonetic-main {
  font-size: 4rem;
  font-weight: 900;
  color: #111827;
  margin-bottom: 5px;
  letter-spacing: -2px;
}
.fc-hebrew-sub {
  font-size: 1.4rem;
  color: #9ca3af;
  font-weight: 800;
}
.fc-translation {
  font-size: 2.6rem;
  font-weight: 900;
  color: var(--brand-blue);
  line-height: 1.1;
}
.tap-hint {
  position: absolute;
  bottom: 15px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 800;
  text-transform: uppercase;
}

/* GAMIFIED EXERCISES */
.practice-card {
  background: white;
  border: 2px solid var(--border-color);
  border-bottom: 5px solid var(--border-color);
  border-radius: 28px;
  padding: 2rem 1.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
  width: 100%;
}
.pr-question {
  font-size: 1.4rem;
  color: #111827;
  font-weight: 800;
  line-height: 1.5;
  margin-bottom: 2rem;
}

.slot {
  display: inline-block;
  min-width: 120px;
  height: 40px;
  border-bottom: 3px solid #e5e7eb;
  background: #f3f4f6;
  border-radius: 10px;
  margin: 0 6px;
  vertical-align: middle;
  cursor: pointer;
  font-weight: 900;
  color: var(--brand-blue);
  line-height: 40px;
}
.slot.filled {
  border-bottom-color: var(--brand-blue);
  background: #e0f2fe;
  border: 2px solid var(--brand-blue);
  border-bottom: 4px solid var(--brand-blue-shadow);
  line-height: 36px;
}

.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 1.5rem;
  min-height: 50px;
}
.word-pill {
  background: white;
  border: 2px solid var(--border-color);
  border-bottom: 4px solid var(--border-color);
  border-radius: 14px;
  padding: 12px 20px;
  font-size: 1.1rem;
  font-weight: 900;
  color: #374151;
  cursor: pointer;
  transition: 0.1s;
  font-family: inherit;
}
.word-pill:active {
  transform: translateY(4px);
  border-bottom-width: 0;
}
.word-pill.used {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

.btn-check {
  width: 100%;
  background: #e5e7eb;
  color: #9ca3af;
  border: none;
  padding: 16px;
  border-radius: 18px;
  font-size: 1.2rem;
  font-weight: 900;
  text-transform: uppercase;
  cursor: not-allowed;
  font-family: inherit;
  margin: 0 auto;
  display: block;
}
.btn-check.ready {
  background: var(--brand-blue);
  color: white;
  cursor: pointer;
  border-bottom: 5px solid var(--brand-blue-shadow);
}
.btn-check.success-state {
  background: var(--brand-green);
  color: white;
  border-bottom: 5px solid var(--brand-green-shadow);
}

.practice-card.success {
  border-color: var(--brand-green);
  border-bottom-color: var(--brand-green-shadow);
  background: #f0fdf4;
  animation: pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.practice-card.error {
  border-color: var(--brand-red);
  border-bottom-color: var(--brand-red-shadow);
  background: #fef2f2;
  animation: shake 0.4s ease;
}

@keyframes pop {
  50% {
    transform: scale(1.03);
  }
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-10px);
  }
  75% {
    transform: translateX(10px);
  }
}

/* BUTTONS */
.btn-action {
  background: var(--brand-blue);
  color: white;
  border: none;
  padding: 16px 28px;
  border-radius: 16px;
  font-size: 1.1rem;
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
  border-bottom: 5px solid var(--brand-blue-shadow);
  transition: 0.1s;
  width: 100%;
  font-family: inherit;
}
.btn-action:active {
  transform: translateY(5px);
  border-bottom-width: 0;
}
.btn-action.success-btn {
  background: var(--brand-green);
  border-bottom-color: var(--brand-green-shadow);
}

/* MOBILE TOGGLE BUTTONS */
.mobile-toggle {
  display: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--brand-blue);
  line-height: 1;
}
.close-sidebar {
  display: none;
  position: absolute;
  top: 15px;
  right: 15px;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* MOBILE RESPONSIVENESS */
@media (max-width: 900px) {
  /* 
     גלילה טבעית של כל העמוד - עוקף בעיות גלילה פנימית בספארי 
  */
  body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
  }
  .app-body {
    height: auto;
    display: block;
  }
  .app-main {
    height: auto;
    display: block;
    overflow: visible;
  }

  /* הופך את הכותרת העליונה ל-Sticky כדי שתישאר זמינה בגלילה */
  .app-header {
    position: sticky;
    top: 0;
    z-index: 500;
    padding: 1rem;
    background: var(--bg-card); /* מבטיח הסתרה של התוכן שעובר מתחת */
  }

  /* מבטל גלילה פנימית ומגדיר ריווח בטוח מעל הבר הקבוע */
  .app-content {
    overflow: visible;
    padding: 1rem 1rem 140px 1rem;
  }

  .mobile-toggle {
    display: block;
  }
  .close-sidebar {
    display: block;
  }

  /* Sidebar Slide Overlay */
  .app-sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    width: 280px;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.15);
    transition: left 0.3s ease;
    z-index: 2000;
  }
  .app-sidebar.open {
    left: 0;
  }

  .header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .title-wrap {
    flex: 0 0 auto;
    width: 100%;
  }

  .title-wrap h1 {
    font-size: 1.2rem;
    margin-top: 4px;
  }

  /* Progress scaling for mobile */
  .progress-wrapper {
    width: 100%;
    max-width: 100%;
    flex: 0 0 auto;
    margin-top: 5px;
  }

  /* Bottom Tab Bar (Fixed) */
  .segmented-control {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 10px 10px 20px;
    background: white;
    border-top: 2px solid var(--border-color);
    z-index: 100;
    justify-content: space-between;
    border-radius: 0;
    gap: 6px;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05);
  }
  .seg-tab {
    flex: 1;
    padding: 10px 0;
    font-size: 0.75rem;
    border-radius: 10px;
    border-width: 1px;
    border-bottom-width: 3px;
  }

  .fc-phonetic-main {
    font-size: 3rem;
  }
  .fc-translation {
    font-size: 2rem;
  }
  .flashcard-3d {
    height: 220px;
  }
  .practice-card {
    padding: 1.5rem 1rem;
    border-width: 2px;
    border-bottom-width: 4px;
  }
  .pr-question {
    font-size: 1.15rem;
    line-height: 1.4;
  }
  .slot {
    min-width: 100px;
    height: 36px;
    line-height: 36px;
    font-size: 0.95rem;
  }
  .slot.filled {
    line-height: 32px;
    border-bottom-width: 3px;
  }
  .word-pill {
    padding: 10px 16px;
    font-size: 1rem;
    border-bottom-width: 3px;
  }
  .btn-check,
  .btn-action {
    padding: 14px;
    font-size: 1.1rem;
    border-radius: 14px;
    border-bottom-width: 4px;
  }
}
