/* =========================================================
   Java Tutor — Webapp Styles
   Dark IDE-inspired theme
   ========================================================= */

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-surface: #1c2333;
  --bg-hover: #21283b;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-muted: #6e7681;
  --accent: #f0883e;
  --accent-dark: #d67528;
  --java: #f89820;
  --java-dark: #5382a1;
  --green: #3fb950;
  --green-dim: #238636;
  --blue: #58a6ff;
  --red: #f85149;
  --border: rgba(240,246,252,0.1);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.25);

  --font: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset ───────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 800; }
a { color: var(--blue); text-decoration: none; }

/* ── Screen architecture ─────────────────────────────── */

#app { height: 100%; overflow: hidden; position: relative; }
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  padding: 0 16px 24px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  -webkit-overflow-scrolling: touch;
}
.screen.active { opacity: 1; pointer-events: auto; z-index: 1; }
.hidden { display: none !important; }

/* ── Auth screen ─────────────────────────────────────── */

.auth-loader, .auth-login {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; text-align: center; gap: 12px;
}
.logo { font-size: 72px; filter: drop-shadow(0 4px 20px rgba(248,152,32,0.4)); }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--java);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.subtitle { color: var(--text-dim); font-size: 14px; margin-bottom: 16px; }

/* ── Buttons ─────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 28px; border-radius: var(--r-md);
  font-weight: 700; font-size: 15px;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn-primary { background: var(--java); color: #000; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-green { background: var(--green-dim); color: #fff; }
.btn-green:hover { background: var(--green); }
.btn-outline {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim);
}

/* ── Header ──────────────────────────────────────────── */

.main-header {
  padding: 20px 0 12px;
  padding-top: calc(var(--safe-top) + 20px);
}
.user-info { display: flex; align-items: center; gap: 12px; }
.user-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--java), var(--java-dark));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; color: #fff;
}
.user-name { font-weight: 700; font-size: 17px; display: block; }
.user-level { font-size: 12px; color: var(--text-dim); display: block; }

.sub-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 0 8px;
  padding-top: calc(var(--safe-top) + 16px);
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
}
.sub-header h2 { font-size: 18px; font-weight: 700; }
.back-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-card); display: flex;
  align-items: center; justify-content: center;
  font-size: 18px; color: var(--text-dim);
  border: 1px solid var(--border);
}

/* ── Stats bar ───────────────────────────────────────── */

.stats-bar { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.stat-chip {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 20px;
  font-size: 13px; font-weight: 600;
  white-space: nowrap;
}

/* ── Progress card ───────────────────────────────────── */

.progress-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 16px;
  margin: 8px 0 16px;
}
.progress-label { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.progress-track {
  height: 8px; background: var(--bg-surface);
  border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--java-dark), var(--java));
  transition: width 0.4s ease;
}
.progress-text {
  font-size: 12px; color: var(--text-muted);
  margin-top: 6px; text-align: right;
  font-family: var(--mono); font-weight: 600;
}

/* ── Menu grid ───────────────────────────────────────── */

.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-btn {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 20px 16px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  transition: background 0.15s, border-color 0.15s;
}
.menu-btn:hover { background: var(--bg-hover); border-color: var(--java); }
.menu-icon { font-size: 28px; }
.menu-label { font-weight: 700; font-size: 14px; }

/* ── Cards ───────────────────────────────────────────── */

.card-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 20px; }
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 16px;
  transition: background 0.15s, border-color 0.15s;
}
.card-clickable { cursor: pointer; }
.card-clickable:hover { background: var(--bg-hover); border-color: var(--java); }
.card-done { border-left: 3px solid var(--green); }
.card-accent { border-left: 3px solid var(--java); }
.card-locked { opacity: 0.5; }

.card-head { display: flex; align-items: center; gap: 12px; }
.card-emoji { font-size: 28px; flex-shrink: 0; }
.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 700; font-size: 15px; }
.card-desc { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.card-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-family: var(--mono); }
.card-chevron { color: var(--text-muted); font-size: 20px; flex-shrink: 0; }

/* ── Lesson view ─────────────────────────────────────── */

.lesson-content {
  flex: 1; padding-bottom: 20px;
  font-size: 15px; line-height: 1.65;
}
.lesson-content h3 { margin: 20px 0 10px; color: var(--java); font-size: 17px; }
.lesson-content b { color: var(--java); }
.lesson-content code {
  font-family: var(--mono); font-size: 13px;
  background: var(--bg-surface); padding: 2px 6px;
  border-radius: 4px; color: var(--green);
}
.lesson-content pre {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 14px;
  overflow-x: auto; font-family: var(--mono); font-size: 13px;
  line-height: 1.6; color: var(--green);
  margin: 12px 0;
}
.lesson-content .task-block {
  background: rgba(248,152,32,0.08); border: 1px solid rgba(248,152,32,0.2);
  border-radius: var(--r-sm); padding: 14px; margin: 12px 0;
}
.lesson-content .hint-block {
  background: rgba(88,166,255,0.08); border: 1px solid rgba(88,166,255,0.15);
  border-radius: var(--r-sm); padding: 14px; margin: 12px 0;
  color: var(--text-dim);
}

.lesson-actions {
  display: flex; gap: 10px; padding: 12px 0;
  padding-bottom: calc(var(--safe-bottom) + 12px);
  flex-wrap: wrap;
}
.lesson-actions .btn { flex: 1; min-width: 120px; }

/* ── Quiz ────────────────────────────────────────────── */

.quiz-question {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 20px; margin-bottom: 12px;
}
.quiz-q-text { font-weight: 700; font-size: 16px; margin-bottom: 14px; }
.quiz-option {
  display: block; width: 100%;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 12px 16px;
  margin-bottom: 8px; font-size: 14px; text-align: left;
  transition: background 0.15s, border-color 0.15s;
}
.quiz-option:hover { background: var(--bg-hover); border-color: var(--java); }
.quiz-option.correct { border-color: var(--green); background: rgba(63,185,80,0.1); }
.quiz-option.wrong { border-color: var(--red); background: rgba(248,81,73,0.1); }
.quiz-option.disabled { pointer-events: none; }
.quiz-nav { display: flex; gap: 10px; justify-content: space-between; margin-top: 16px; }
.quiz-counter { font-size: 13px; color: var(--text-muted); font-family: var(--mono); margin-bottom: 12px; }

.quiz-results {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 24px; text-align: center;
}
.quiz-results .score { font-size: 48px; font-weight: 800; color: var(--java); }
.quiz-results .score-label { font-size: 14px; color: var(--text-dim); margin-top: 4px; }

/* ── Stats screen ────────────────────────────────────── */

.detail-content { padding-bottom: 20px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.stats-item {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 16px;
}
.stats-value { font-size: 24px; font-weight: 800; font-family: var(--mono); color: var(--java); }
.stats-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* ── Achievements ────────────────────────────────────── */

.ach-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 14px;
}
.ach-card.locked { opacity: 0.4; }
.ach-emoji { font-size: 32px; }
.ach-info { flex: 1; }
.ach-name { font-weight: 700; font-size: 14px; }
.ach-desc { font-size: 12px; color: var(--text-dim); }
