/* ===== RESET & ROOT ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Nunito — rounded, warm, very readable for students
   Plus Jakarta Sans — clean but has personality, great for UI labels */

:root {
  --font-display: 'Nunito', sans-serif;
  --font-body:    'Plus Jakarta Sans', sans-serif;

  --bg:           #0a0b0f;
  --surface:      #111318;
  --surface2:     #181b23;
  --border:       rgba(255, 255, 255, 0.07);
  --border-hover: rgba(255, 255, 255, 0.15);
  --accent:       #6ee7b7;
  --accent2:      #818cf8;
  --accent3:      #f472b6;
  --text:         #e8eaf0;
  --text-muted:   #6b7280;
  --text-dim:     #374151;
}

/* ===== BASE ===== */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  overflow-x: hidden;
}

/* background ambient glow */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 80% 10%,  rgba(110, 231, 183, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 50% 50% at 10% 80%,  rgba(129, 140, 248, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 40% 30% at 50% 50%,  rgba(244, 114, 182, 0.03) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ===== APP WRAPPER ===== */
.app {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

/* ===== HEADER ===== */
.header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 36px;
  animation: fadeUp 0.6s ease both;
}

.logo-box {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: none;
  flex-shrink: 0;
}

.header-text h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--text) 40%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-text p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ===== MODE BUTTONS ===== */
.mode-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  animation: fadeUp 0.6s 0.1s ease both;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn .mode-icon {
  font-size: 14px;
}

.mode-btn:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface2);
}

/* active states per mode — toggled via JS */
.mode-btn.active {
  background: rgba(110, 231, 183, 0.1);
  border-color: rgba(110, 231, 183, 0.4);
  color: var(--accent);
}

.mode-btn.active-quiz {
  background: rgba(129, 140, 248, 0.1);
  border-color: rgba(129, 140, 248, 0.4);
  color: var(--accent2);
}

.mode-btn.active-terms {
  background: rgba(244, 114, 182, 0.1);
  border-color: rgba(244, 114, 182, 0.4);
  color: var(--accent3);
}

/* ===== MAIN INPUT CARD ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 16px;
  animation: fadeUp 0.6s 0.2s ease both;
}

.card-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

textarea {
  width: 100%;
  min-height: 180px;
  max-height: 340px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.7;
  padding: 16px 18px;
  resize: vertical; /* capped by max-height */
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea:focus {
  border-color: rgba(110, 231, 183, 0.35);
  box-shadow: 0 0 0 3px rgba(110, 231, 183, 0.07);
}

textarea::placeholder {
  color: var(--text-dim);
}

/* ===== TOP ACTIONS (word count + buttons) ===== */
.top-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  gap: 12px;
  flex-wrap: wrap;
}

.top-actions p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0;
}

.action-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* secondary (clear) */
.secondary-btn {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.secondary-btn:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface2);
}

/* primary (generate) */
.primary-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent) 0%, #34d399 100%);
  color: #0a0b0f;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(110, 231, 183, 0.25);
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(110, 231, 183, 0.35);
}

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

/* color variants switched via JS */
.primary-btn.quiz-mode {
  background: linear-gradient(135deg, var(--accent2) 0%, #a78bfa 100%);
  box-shadow: 0 4px 16px rgba(129, 140, 248, 0.25);
}

.primary-btn.quiz-mode:hover {
  box-shadow: 0 6px 24px rgba(129, 140, 248, 0.35);
}

.primary-btn.terms-mode {
  background: linear-gradient(135deg, var(--accent3) 0%, #fb7185 100%);
  box-shadow: 0 4px 16px rgba(244, 114, 182, 0.25);
}

.primary-btn.terms-mode:hover {
  box-shadow: 0 6px 24px rgba(244, 114, 182, 0.35);
}

/* ===== SAMPLE BUTTONS ===== */
.samples {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.samples span {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.sample-btn {
  padding: 5px 12px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.sample-btn:hover {
  border-color: rgba(110, 231, 183, 0.3);
  color: var(--accent);
  background: rgba(110, 231, 183, 0.06);
}

/* ===== STATS CARDS ===== */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  animation: fadeUp 0.6s 0.3s ease both;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 18px;
  transition: border-color 0.2s;
}

.stat-card:hover {
  border-color: var(--border-hover);
}

.stat-card h2 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

.stat-card p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-green h2 { color: var(--accent); }
.stat-purple h2 { color: var(--accent2); }
.stat-pink h2 { color: var(--accent3); }

/* ===== RESULT CARD ===== */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  animation: fadeUp 0.6s 0.4s ease both;
  min-height: 110px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.result-badge {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(110, 231, 183, 0.1);
  border: 1px solid rgba(110, 231, 183, 0.2);
  padding: 4px 10px;
  border-radius: 100px;
}

.result-badge.quiz-badge {
  color: var(--accent2);
  background: rgba(129, 140, 248, 0.1);
  border-color: rgba(129, 140, 248, 0.2);
}

.result-badge.terms-badge {
  color: var(--accent3);
  background: rgba(244, 114, 182, 0.1);
  border-color: rgba(244, 114, 182, 0.2);
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

/* empty state */
#result.result-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
}

.empty-icon {
  font-size: 30px;
  opacity: 0.4;
}

/* text output */
.result-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--text);
}

/* loading dots */
.loading-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 0;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
  background: var(--accent2);
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
  background: var(--accent3);
}

/* ===== QUIZ STYLES ===== */
.quiz-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.quiz-q {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}

.quiz-q .q-text {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text);
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-option {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.quiz-option:hover {
  border-color: rgba(129, 140, 248, 0.4);
  color: var(--accent2);
  background: rgba(129, 140, 248, 0.06);
}

.quiz-option.correct {
  border-color: rgba(110, 231, 183, 0.5);
  color: var(--accent);
  background: rgba(110, 231, 183, 0.08);
}

.quiz-option.wrong {
  border-color: rgba(244, 114, 182, 0.5);
  color: var(--accent3);
  background: rgba(244, 114, 182, 0.08);
}

/* ===== KEY TERMS ===== */
.terms-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.term-chip {
  padding: 6px 14px;
  border-radius: 100px;
  border: 1px solid rgba(244, 114, 182, 0.25);
  background: rgba(244, 114, 182, 0.07);
  color: var(--accent3);
  font-size: 13px;
  font-weight: 500;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 520px) {
  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .stats .stat-card:last-child {
    grid-column: span 2;
  }

  .action-buttons {
    width: 100%;
    justify-content: flex-end;
  }
}

/* ===== FULL RESPONSIVE BREAKPOINTS ===== */

/* --- Tablet landscape & small laptops (max 1024px) --- */
@media (max-width: 1024px) {
  .app {
    max-width: 700px;
    padding: 40px 28px 70px;
  }
}

/* --- iPad / tablet portrait (max 768px) --- */
@media (max-width: 768px) {
  .app {
    max-width: 100%;
    padding: 32px 20px 60px;
  }
  .header-text h1 { font-size: 20px; }
  .header-text p  { font-size: 12.5px; }
  .stats          { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .stat-card h2   { font-size: 22px; }
  .card           { padding: 20px; }
  .result-card    { padding: 20px; }
  textarea        { font-size: 14px; min-height: 160px; max-height: 300px; }
  .mode-btn       { padding: 9px 15px; font-size: 13px; }
}

/* --- Large phones / small tablets (max 600px) --- */
@media (max-width: 600px) {
  .app { padding: 24px 16px 60px; }

  .header        { margin-bottom: 24px; gap: 12px; }
  .logo-box      { width: 40px; height: 40px; font-size: 18px; border-radius: 10px; }
  .header-text h1 { font-size: 18px; }

  .mode-buttons  { gap: 6px; margin-bottom: 16px; }
  .mode-btn      { padding: 8px 13px; font-size: 12.5px; gap: 5px; }
  .mode-btn .mode-icon { font-size: 13px; }

  .card          { padding: 16px; border-radius: 16px; }
  .card-label    { font-size: 10px; letter-spacing: 1.2px; }

  textarea       { min-height: 140px; max-height: 260px; font-size: 14px; padding: 13px 15px; }

  .top-actions   { flex-direction: column; align-items: flex-start; gap: 10px; }
  .action-buttons { width: 100%; justify-content: flex-end; }
  .secondary-btn { padding: 9px 16px; font-size: 13px; }
  .primary-btn   { padding: 9px 18px; font-size: 13px; }

  .samples       { gap: 6px; margin-top: 12px; }
  .sample-btn    { padding: 5px 11px; font-size: 11.5px; }

  .stats         { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stats .stat-card:last-child { grid-column: span 2; }
  .stat-card     { padding: 14px 16px; border-radius: 14px; }
  .stat-card h2  { font-size: 22px; }
  .stat-card p   { font-size: 11px; }

  .result-card   { padding: 16px; border-radius: 16px; }
  .result-badge  { font-size: 10px; padding: 3px 9px; }
  .result-text   { font-size: 14px; }

  .quiz-q        { padding: 14px 15px; border-radius: 12px; }
  .quiz-q .q-text { font-size: 13.5px; }
  .quiz-option   { font-size: 13px; padding: 9px 12px; }

  .term-chip     { font-size: 12px; padding: 5px 12px; }
}

/* --- Small Android phones (max 400px) --- */
@media (max-width: 400px) {
  .app           { padding: 20px 12px 50px; }
  .header-text h1 { font-size: 16px; }
  .header-text p  { font-size: 11.5px; }
  .logo-box      { width: 36px; height: 36px; font-size: 16px; }
  .mode-btn      { padding: 7px 11px; font-size: 12px; }
  .stat-card h2  { font-size: 20px; }
  .primary-btn   { width: 100%; justify-content: center; }
  .secondary-btn { flex: 1; }
  .action-buttons { width: 100%; }
}

/* --- Touch device improvements (Android & iPhone) --- */
@media (hover: none) and (pointer: coarse) {
  .mode-btn,
  .sample-btn,
  .secondary-btn,
  .quiz-option   { min-height: 44px; }
  .primary-btn   { min-height: 46px; }
  .icon-btn      { width: 36px; height: 36px; }

  /* disable hover lift on touch — looks janky */
  .primary-btn:hover { transform: none; }
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  padding: 32px 24px 40px;
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font-body);
  position: relative;
  z-index: 1;
}

.footer p {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.heart {
  color: var(--accent3);
  animation: heartbeat 1.8s ease-in-out infinite;
  display: inline-block;
  font-size: 14px;
}

.footer-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-family: var(--font-display);
  position: relative;
  transition: color 0.2s;
}

.footer-link::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 0;
  height: 1.5px;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.25s ease;
}

.footer-link:hover {
  color: #a7f3d0;
}

.footer-link:hover::after {
  width: 100%;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14%       { transform: scale(1.2); }
  28%       { transform: scale(1); }
  42%       { transform: scale(1.15); }
  56%       { transform: scale(1); }
}

/* ===== CUSTOM SCROLLBAR (textarea) ===== */

/* Chrome, Edge, Safari */
textarea::-webkit-scrollbar {
  width: 6px;
}

textarea::-webkit-scrollbar-track {
  background: transparent;
  margin: 8px 0;
}

textarea::-webkit-scrollbar-thumb {
  background: rgba(110, 231, 183, 0.25);
  border-radius: 100px;
  transition: background 0.2s;
}

textarea::-webkit-scrollbar-thumb:hover {
  background: rgba(110, 231, 183, 0.5);
}

/* Firefox */
textarea {
  scrollbar-width: thin;
  scrollbar-color: rgba(110, 231, 183, 0.25) transparent;
}

/* ===== LOGO IMAGE ===== */
.logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}