/* app.css — ENT Brain shell styles. Mobile-first: base rules target a ~390px
   phone; @media (min-width: ...) widens things up from there. Dark theme is
   the default; [data-theme="light"] on <html> overrides the variables below
   (see src/app.js applyTheme()). Card-flip and rating-button styling ported
   from the old Chrome extension (src/app.css / FlashcardPanel.js). */

/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg:        #0f1923;
  --surface:   #1a2637;
  --surface-2: #1e2e42;
  --surface-3: #253548;
  --border:    #2d4060;
  --text:      #e2e8f0;
  --text-2:    #94a3b8;
  --text-3:    #64748b;
  --accent:    #38bdf8;
  --accent-hv: #0ea5e9;
  --success:   #34d399;
  --warning:   #fbbf24;
  --danger:    #f87171;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
  --radius:    10px;
  --radius-sm: 6px;
  --tap:       44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #e2e8f0;
  --border:    #cbd5e1;
  --text:      #0f172a;
  --text-2:    #475569;
  --text-3:    #94a3b8;
  --accent:    #0284c7;
  --accent-hv: #0369a1;
  --shadow:    0 4px 16px rgba(0,0,0,0.1);
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html, body { height: 100%; }

html {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { list-style: none; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

/* Accessible focus ring everywhere, only shown for keyboard nav */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #06232f;
  padding: 10px 16px;
  z-index: 2000;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

.hidden { display: none !important; }

/* ── Top bar ───────────────────────────────────────────────────────────── */
#topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  min-height: calc(52px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 17px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.3px;
  white-space: nowrap;
}
.logo:hover { text-decoration: none; }

#main-nav {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
#main-nav::-webkit-scrollbar { display: none; }

#main-nav a {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
#main-nav a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
#main-nav a.active { color: var(--accent); background: rgba(56,189,248,0.12); }

.topbar-more { position: relative; flex-shrink: 0; }

#more-menu-btn {
  width: var(--tap);
  height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-2);
  border-radius: var(--radius-sm);
}
#more-menu-btn:hover { background: var(--surface-3); color: var(--text); }

.more-menu {
  position: absolute;
  right: 0;
  top: calc(var(--tap) + 4px);
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  padding: 6px;
  z-index: 150;
}
.more-menu-user {
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.more-menu a, .more-menu button {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  text-align: left;
  width: 100%;
}
.more-menu a:hover, .more-menu button:hover { background: var(--surface-3); text-decoration: none; }
.more-menu-logout { color: var(--danger); }

/* ── Main content area ─────────────────────────────────────────────────── */
#view {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + var(--safe-bottom));
}

.screen-title { font-size: 20px; font-weight: 800; margin-bottom: 16px; }
.loading, .error-text { color: var(--text-2); padding: 24px 0; text-align: center; }
.error-text { color: var(--danger); }
.text-muted { color: var(--text-3); font-size: 13px; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}
.btn-primary:hover, .btn-secondary:hover, .btn-danger:hover { text-decoration: none; }
.btn-primary:active, .btn-secondary:active, .btn-danger:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #06232f;
}
.btn-primary:hover { background: var(--accent-hv); color: #06232f; }

.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
button:disabled, a.btn-primary[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 18px;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.link-more { font-weight: 600; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.field-hint { font-size: 12px; color: var(--text-3); margin: -8px 0 12px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], select, textarea {
  min-height: var(--tap);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  width: 100%;
}
textarea { min-height: 96px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.card-textarea { min-height: 96px; }

.settings-row { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.toggle-row { cursor: pointer; }
.toggle-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }

.settings-section { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: none; }
.settings-section h3 { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-2); margin-bottom: 12px; }

/* ── Auth screens ──────────────────────────────────────────────────────── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 100px);
  padding: 16px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
  box-shadow: var(--shadow);
}
.auth-logo { font-size: 22px; font-weight: 800; color: var(--accent); text-align: center; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--text-2); font-size: 13px; margin-bottom: 20px; }
.auth-form { margin-top: 16px; }
.auth-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--danger); }

.offline-indicator {
  position: fixed;
  top: calc(8px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--warning);
  color: #3a2a00;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  z-index: 1500;
}

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}
.modal-overlay.visible { opacity: 1; }
body.modal-open { overflow: hidden; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(12px);
  transition: transform 0.2s;
}
.modal-overlay.visible .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 800; }
.modal-close {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); font-size: 20px; border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--text); background: var(--surface-3); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.overflow-menu-body { display: flex; flex-direction: column; gap: 8px; }

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius); }
}

/* ── Home ──────────────────────────────────────────────────────────────── */
.home-top { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 24px; }

.catchup-banner {
  width: 100%;
  text-align: center;
  background: rgba(251,191,36,0.12);
  color: var(--warning);
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-weight: 700;
  font-size: 13px;
}

.btn-study-primary {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1 / 1;
  max-height: 220px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, var(--accent-hv), var(--accent));
  color: #06232f;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 8px 30px rgba(56,189,248,0.35);
  margin: 8px auto 0;
}
.btn-study-primary:active { transform: scale(0.98); }
.study-cta { font-size: 18px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px; }
.study-count { font-size: 48px; font-weight: 800; line-height: 1; }

.btn-five { margin-top: 4px; }

.done-for-today {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 32px 16px;
}
.done-icon { font-size: 40px; color: var(--success); }

.unit-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}
.unit-tile-title { font-weight: 700; margin-bottom: 12px; }
.unit-tile-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.badge-done, .badge-current {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(52,211,153,0.15);
  color: var(--success);
}
.badge-current { background: rgba(56,189,248,0.15); color: var(--accent); }

.streak-row { display: flex; align-items: center; justify-content: center; gap: 10px; }
.streak-dots { display: flex; gap: 6px; }
.streak-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border);
}
.streak-dot.filled { background: var(--accent); border-color: var(--accent); }
.streak-dot.goal { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--text-3); }
.streak-weeks { font-size: 12px; color: var(--text-3); font-weight: 600; }

/* ── Study / card view ─────────────────────────────────────────────────── */
.study-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.study-progress { font-size: 13px; color: var(--text-3); }

.cv-root { display: flex; flex-direction: column; align-items: center; gap: 16px; }

.fc-card-area {
  width: 100%;
  display: flex;
  justify-content: center;
  perspective: 1200px;
}

.fc-card {
  width: 100%;
  max-width: 460px;
  min-height: 280px;
  cursor: pointer;
  position: relative;
}

.fc-card-inner {
  width: 100%;
  height: 100%;
  min-height: 280px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4,0,0.2,1);
}
.fc-card-inner.flipped { transform: rotateY(180deg); }

.fc-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 12px;
  overflow: auto;
}
.fc-back { transform: rotateY(180deg); }
.fc-card-content { font-size: 16px; line-height: 1.6; text-align: center; width: 100%; }
.fc-flip-hint { font-size: 12px; color: var(--text-3); position: absolute; bottom: 12px; }

/* MCQ */
.mcq-choices { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 460px; }
.mcq-choice {
  min-height: var(--tap);
  text-align: left;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.mcq-choice:hover:not(:disabled) { border-color: var(--accent); }
.mcq-choice:disabled { cursor: default; }
.mcq-choice.correct { border-color: var(--success); background: rgba(52,211,153,0.15); }
.mcq-choice.incorrect { border-color: var(--danger); background: rgba(248,113,113,0.15); }
.mcq-explanation {
  width: 100%;
  max-width: 460px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
}

/* Rating buttons */
.fc-ratings {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 460px;
}
.rating-btn {
  flex: 1;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 12px;
  gap: 2px;
  transition: opacity 0.15s, transform 0.1s;
}
.rating-btn:hover { opacity: 0.85; }
.rating-btn:active { transform: translateY(1px); }
.rating-1 { background: rgba(248,113,113,0.12); border-color: var(--danger);  color: var(--danger); }
.rating-2 { background: rgba(251,191,36,0.12); border-color: var(--warning); color: var(--warning); }
.rating-3 { background: rgba(52,211,153,0.12); border-color: var(--success); color: var(--success); }
.rating-4 { background: rgba(56,189,248,0.12); border-color: var(--accent);  color: var(--accent); }
.rating-label { font-weight: 700; font-size: 12px; }
.rating-interval { font-size: 10px; color: var(--text-3); }

.session-end {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 48px 16px;
}
.session-tally { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; font-size: 13px; color: var(--text-2); }

/* ── Plan ──────────────────────────────────────────────────────────────── */
.unit-list { display: flex; flex-direction: column; gap: 12px; }
.unit-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.unit-card.is-current { border-color: var(--accent); }
.unit-card-header {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.unit-card-header:hover { background: var(--surface-2); }
.unit-card-title-row { display: flex; align-items: center; gap: 8px; }
.unit-ordinal {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.unit-title { font-weight: 700; flex: 1; }
.progress-bar { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); }
.unit-meta { font-size: 12px; color: var(--text-3); display: flex; gap: 4px; }
.unit-card-body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.chapter-list { display: flex; flex-direction: column; gap: 8px; }
.chapter-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.chapter-title { font-size: 14px; }
.unit-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── Scrollbars ────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Wider viewports ───────────────────────────────────────────────────── */
@media (min-width: 640px) {
  #view { padding: 24px 24px 40px; }
  #main-nav a { padding: 0 14px; }
}

@media (min-width: 900px) {
  #view { max-width: 760px; }
}
