/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f8f8ff;
  color: #1e1b4b;
  min-height: 100vh;
}

/* ===== Layout helpers ===== */
.hidden { display: none !important; }
.centered {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 1rem; min-height: 60vh;
  text-align: center; padding: 2rem;
}
.view { display: flex; flex-direction: column; min-height: 100vh; }

/* ===== Header ===== */
header {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.25rem;
  /* safe-area: push content below notch in standalone PWA mode */
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
  background: #4f46e5;
  color: white;
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 1.5rem; font-weight: 700; flex: 1; }
header h2 { font-size: 1.25rem; font-weight: 600; flex: 1; }
#study-progress { font-size: 0.9rem; opacity: 0.85; }

/* ===== Buttons ===== */
.btn {
  padding: 0.75rem 1.5rem; border: none; border-radius: 0.75rem;
  font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: #4f46e5; color: white; }
.btn-secondary { background: #e0e7ff; color: #3730a3; }
.btn-icon {
  background: none; border: none; color: white; font-size: 1.4rem;
  cursor: pointer; padding: 0.25rem 0.5rem; border-radius: 0.5rem;
  /* ensure 44×44px minimum touch target */
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: rgba(255,255,255,0.15); }

/* ===== Home ===== */
.home-main { flex: 1; padding: 2rem 1.25rem; display: flex; flex-direction: column; gap: 2rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stat-card {
  background: white; border-radius: 1rem; padding: 1.5rem 1rem;
  text-align: center; box-shadow: 0 2px 8px rgba(79,70,229,0.1);
}
.stat-card.due { background: #ede9fe; }
.stat-number { display: block; font-size: 2.5rem; font-weight: 700; color: #4f46e5; }
.stat-label { font-size: 0.85rem; color: #6b7280; margin-top: 0.25rem; }
.home-actions { display: flex; flex-direction: column; gap: 1rem; }
.home-actions .btn { width: 100%; }

/* ===== Flashcard ===== */
.study-main { flex: 1; padding: 1.5rem 1.25rem; display: flex; flex-direction: column; gap: 1.5rem; }
.flashcard-scene {
  width: 100%; max-width: 420px; margin: 0 auto;
  /* clamp so the card never overflows on landscape phones */
  height: clamp(200px, 40vh, 320px); perspective: 1000px; cursor: pointer;
}
.flashcard-card {
  width: 100%; height: 100%;
  position: relative; transform-style: preserve-3d;
  transition: transform 0.5s ease;
  border-radius: 1.25rem;
}
.flashcard-scene.flipped .flashcard-card { transform: rotateY(180deg); }
.flashcard-front,
.flashcard-back {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 1.25rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2rem; text-align: center;
  box-shadow: 0 4px 20px rgba(79,70,229,0.15);
}
.flashcard-front { background: white; }
.flashcard-back { background: #ede9fe; transform: rotateY(180deg); }
.card-lang { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: #6b7280; margin-bottom: 0.5rem; }
.card-word { font-size: 2rem; font-weight: 700; color: #1e1b4b; word-break: break-word; overflow-wrap: anywhere; }
.card-hint { margin-top: 1rem; font-size: 0.8rem; color: #9ca3af; }
.card-definition { font-size: 1.1rem; color: #1e1b4b; font-weight: 500; margin-bottom: 1rem; }
.card-example { font-size: 0.9rem; color: #6b7280; font-style: italic; }

/* ===== Rating buttons ===== */
.rating-buttons { max-width: 420px; margin: 0 auto; width: 100%; }
.rating-label { text-align: center; font-size: 0.85rem; color: #6b7280; margin-bottom: 0.75rem; }
.rating-row { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.btn-rating {
  flex: 1; min-width: 0; padding: 0.6rem 0.25rem;
  border: none; border-radius: 0.75rem; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: transform 0.1s;
  min-height: 44px; /* 44px minimum touch target */
}
.btn-rating:active { transform: scale(0.95); }
.btn-rating-again { background: #fee2e2; color: #b91c1c; }
.btn-rating-hard  { background: #fef3c7; color: #92400e; }
.btn-rating-okay  { background: #e0f2fe; color: #0369a1; }
.btn-rating-good  { background: #d1fae5; color: #065f46; }
.btn-rating-easy  { background: #ede9fe; color: #4f46e5; }

/* ===== Browse ===== */
.browse-main { flex: 1; padding: 1.25rem; overflow-y: auto; }
.lang-group { margin-bottom: 2rem; }
.lang-heading {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: #6b7280; padding: 0.5rem 0; border-bottom: 1px solid #e5e7eb; margin-bottom: 0.75rem;
}
.word-item {
  background: white; border-radius: 0.875rem; margin-bottom: 0.75rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07); overflow: hidden;
}
.word-summary { display: flex; align-items: center; gap: 0.75rem; padding: 1rem; cursor: pointer; }
.word-text { flex: 1; min-width: 0; }
.word-title { font-size: 1.05rem; font-weight: 600; }
.word-def {
  font-size: 0.85rem; color: #6b7280; margin-top: 0.2rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.word-due { font-size: 0.75rem; color: #9ca3af; white-space: nowrap; }
.word-expand-icon { font-size: 0.9rem; color: #9ca3af; transition: transform 0.2s; }
.word-item.expanded .word-expand-icon { transform: rotate(180deg); }
.word-detail { padding: 0 1rem 1rem; border-top: 1px solid #f3f4f6; display: none; }
.word-item.expanded .word-detail { display: block; }
.word-example { font-size: 0.9rem; color: #6b7280; font-style: italic; margin: 0.75rem 0; }
.btn-delete {
  font-size: 0.8rem; padding: 0.4rem 0.9rem;
  background: #fee2e2; color: #b91c1c;
  border: none; border-radius: 0.5rem; cursor: pointer; font-weight: 600;
}
.btn-delete:hover { background: #fecaca; }

/* ===== Login overlay ===== */
.login-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: #4f46e5;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.login-card {
  background: white; border-radius: 1.5rem;
  padding: 2.5rem 2rem; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 1.25rem;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
  text-align: center;
}
.login-card h1 { font-size: 2rem; font-weight: 700; color: #4f46e5; }
.login-subtitle { font-size: 0.95rem; color: #6b7280; }
.login-input {
  width: 100%; padding: 0.75rem 1rem;
  border: 2px solid #e5e7eb; border-radius: 0.75rem;
  font-size: 1rem; outline: none;
  transition: border-color 0.15s;
}
.login-input:focus { border-color: #4f46e5; }
.login-btn { width: 100%; }

/* ===== Offline banner ===== */
.offline-banner {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #374151; color: white;
  text-align: center; padding: 0.6rem; font-size: 0.85rem; z-index: 100;
  /* push above home-indicator on iPhone */
  padding-bottom: max(0.6rem, env(safe-area-inset-bottom));
}

/* ===== Error message ===== */
.error-msg {
  background: #fee2e2; color: #b91c1c;
  padding: 0.75rem 1rem; border-radius: 0.75rem;
  font-size: 0.9rem; text-align: center; margin: 0.5rem 0;
}

/* ===== Landscape phones: reduce heights so nothing overflows ===== */
@media (max-height: 500px) and (orientation: landscape) {
  .home-main { padding: 1rem 1.25rem; gap: 1rem; }
  .stat-number { font-size: 1.75rem; }
  .stat-card { padding: 1rem; }
  .centered { min-height: 40vh; }
}

/* ===== Tablet and up (≥640px): center content in a max-width column ===== */
@media (min-width: 640px) {
  body { background: #eef0ff; }

  /* Wrap each view in a centered column */
  .view {
    max-width: 640px;
    margin: 0 auto;
    box-shadow: 0 0 60px rgba(79,70,229,0.1);
    background: #f8f8ff;
  }

  header {
    /* Remove safe-area padding on wide viewports — no notch concern */
    padding-top: 1rem;
    border-radius: 0 0 0 0; /* keep square for the column card */
  }

  .flashcard-scene { height: 300px; }
  .card-word { font-size: 2.5rem; }
  .stat-number { font-size: 3rem; }

  .browse-main { padding: 1.5rem 2rem; }

  .offline-banner {
    max-width: 640px;
    left: 50%; right: auto;
    transform: translateX(-50%);
    border-radius: 0.5rem 0.5rem 0 0;
    padding-bottom: 0.6rem;
  }
}
