/* ═══════════════════════════════════════════════════════════════════════════
   ARIA Liquid Glass — shared light design system for every student page
   Frosted translucent surfaces over a soft light backdrop, Apple-style type,
   44px touch targets, calm motion. Add <html class="ag-light"> and link this
   file after Tailwind to use it.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Backdrop */
  --ag-bg: #eef2f7;
  --ag-bg-tint-1: rgba(255, 255, 255, 0.70);
  --ag-bg-tint-2: rgba(148, 163, 184, 0.10);

  /* Glass surfaces */
  --ag-glass: rgba(255, 255, 255, 0.68);
  --ag-glass-strong: rgba(255, 255, 255, 0.86);
  --ag-glass-solid: #ffffff;
  --ag-glass-edge: rgba(255, 255, 255, 0.75);
  --ag-hairline: rgba(15, 23, 42, 0.08);
  --ag-hairline-strong: rgba(15, 23, 42, 0.14);
  --ag-fill: rgba(118, 118, 128, 0.12);        /* iOS tertiary fill */
  --ag-fill-strong: rgba(118, 118, 128, 0.20);

  /* Text */
  --ag-text: #0f172a;
  --ag-text-2: #475569;
  --ag-text-3: #64748b;
  --ag-text-inverse: #ffffff;

  /* Brand + status (AA contrast on white) */
  --ag-accent: #111111;
  --ag-accent-hover: #000000;
  --ag-accent-soft: rgba(17, 17, 17, 0.08);
  --ag-accent-bright: #111111;
  --ag-success: #15803d;
  --ag-success-soft: rgba(22, 163, 74, 0.12);
  --ag-blue: #2563eb;
  --ag-danger: #dc2626;
  --ag-danger-soft: rgba(220, 38, 38, 0.10);
  --ag-warning: #b45309;
  --ag-warning-soft: rgba(245, 158, 11, 0.14);

  /* Shape + depth */
  --ag-radius-xl: 28px;
  --ag-radius-lg: 22px;
  --ag-radius: 16px;
  --ag-radius-sm: 12px;
  --ag-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 28px rgba(15, 23, 42, 0.07);
  --ag-shadow-lg: 0 2px 6px rgba(15, 23, 42, 0.05), 0 24px 60px rgba(15, 23, 42, 0.12);
  --ag-blur: saturate(180%) blur(22px);

  /* Type */
  --ag-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  --ag-font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  --ag-ease: cubic-bezier(0.32, 0.72, 0, 1);    /* iOS spring-like ease */
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
html.ag-light { color-scheme: light; -webkit-text-size-adjust: 100%; }

html.ag-light body {
  font-family: var(--ag-font) !important;
  color: var(--ag-text) !important;
  background-color: var(--ag-bg) !important;
  background-image:
    radial-gradient(1200px 600px at 0% -10%, var(--ag-bg-tint-1), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, var(--ag-bg-tint-2), transparent 55%) !important;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

html.ag-light ::selection { background: var(--ag-accent-soft); }

html.ag-light :focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.45) !important;
  outline-offset: 2px;
  border-radius: 10px;
}

/* ── Typography ───────────────────────────────────────────────────────────── */
.ag-large-title { font-family: var(--ag-font-display); font-size: clamp(28px, 6vw, 34px); font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; color: var(--ag-text); }
.ag-title { font-family: var(--ag-font-display); font-size: 20px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; color: var(--ag-text); }
.ag-headline { font-size: 17px; font-weight: 600; color: var(--ag-text); }
.ag-body { font-size: 16px; color: var(--ag-text); }
.ag-subhead { font-size: 15px; color: var(--ag-text-2); }
.ag-footnote { font-size: 13px; color: var(--ag-text-3); }
.ag-section-label { font-size: 13px; font-weight: 600; color: var(--ag-text-3); letter-spacing: 0; text-transform: none; }

/* ── Glass surfaces ───────────────────────────────────────────────────────── */
.ag-glass {
  background: var(--ag-glass);
  -webkit-backdrop-filter: var(--ag-blur);
  backdrop-filter: var(--ag-blur);
  border: 1px solid var(--ag-glass-edge);
  box-shadow: var(--ag-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  border-radius: var(--ag-radius-lg);
}

.ag-card {
  background: var(--ag-glass-strong);
  -webkit-backdrop-filter: var(--ag-blur);
  backdrop-filter: var(--ag-blur);
  border: 1px solid var(--ag-glass-edge);
  box-shadow: var(--ag-shadow);
  border-radius: var(--ag-radius-lg);
  padding: 20px;
  transition: transform 0.35s var(--ag-ease), box-shadow 0.35s var(--ag-ease);
}
.ag-card-interactive { cursor: pointer; }
.ag-card-interactive:hover { box-shadow: var(--ag-shadow-lg); transform: translateY(-2px); }
.ag-card-interactive:active { transform: scale(0.985); }

/* Grouped list, like iOS Settings */
.ag-list { background: var(--ag-glass-strong); border-radius: var(--ag-radius-lg); border: 1px solid var(--ag-glass-edge); box-shadow: var(--ag-shadow); overflow: hidden; }
.ag-list-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 12px 16px; color: var(--ag-text); }
.ag-list-row + .ag-list-row { border-top: 1px solid var(--ag-hairline); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.ag-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: 999px;
  font: 600 15px/1 var(--ag-font); letter-spacing: -0.01em;
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: transform 0.2s var(--ag-ease), background-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.ag-btn:active { transform: scale(0.97); }
.ag-btn:disabled, .ag-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.ag-btn-primary { background: var(--ag-accent); color: var(--ag-text-inverse); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18); }
.ag-btn-primary:hover { background: var(--ag-accent-hover); }
.ag-btn-secondary { background: #ffffff; color: var(--ag-text); border-color: var(--ag-hairline-strong); -webkit-backdrop-filter: var(--ag-blur); backdrop-filter: var(--ag-blur); }
.ag-btn-secondary:hover { background: #ffffff; }
.ag-btn-tinted { background: #ffffff; color: var(--ag-text); border-color: var(--ag-hairline-strong); }
.ag-btn-tinted:hover { background: #f8fafc; }
.ag-btn-ghost { background: transparent; color: var(--ag-text); }
.ag-btn-ghost:hover { background: var(--ag-fill); }
.ag-btn-danger { background: var(--ag-danger-soft); color: var(--ag-danger); }
.ag-btn-icon { width: 44px; padding: 0; }
.ag-btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.ag-btn-block { width: 100%; }

/* ── Inputs ───────────────────────────────────────────────────────────────── */
.ag-input, .ag-select, .ag-textarea {
  width: 100%; min-height: 48px; padding: 12px 16px;
  font: 400 16px/1.4 var(--ag-font); color: var(--ag-text);
  background: rgba(255, 255, 255, 0.9); border: 1px solid var(--ag-hairline-strong); border-radius: var(--ag-radius-sm);
  outline: none; transition: border-color 0.2s ease, box-shadow 0.2s ease;
  -webkit-appearance: none; appearance: none;
}
.ag-input::placeholder, .ag-textarea::placeholder { color: #94a3b8; }
.ag-input:focus, .ag-select:focus, .ag-textarea:focus { border-color: var(--ag-accent-bright); box-shadow: 0 0 0 4px rgba(17, 17, 17, 0.10); }
.ag-label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--ag-text-2); }

/* Segmented control */
.ag-segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--ag-fill); border-radius: 12px; }
.ag-segmented > button { min-height: 36px; padding: 0 14px; border-radius: 9px; border: 0; background: transparent; font: 600 14px var(--ag-font); color: var(--ag-text-2); cursor: pointer; transition: background 0.25s var(--ag-ease), color 0.2s; }
.ag-segmented > button[aria-selected="true"], .ag-segmented > button.is-active { background: #ffffff; color: var(--ag-text); box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12); }

/* Chips + badges */
.ag-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 999px; background: var(--ag-glass-strong); border: 1px solid var(--ag-hairline); color: var(--ag-text); font: 500 14px var(--ag-font); white-space: nowrap; cursor: pointer; transition: background 0.2s, transform 0.2s var(--ag-ease); }
.ag-chip:active { transform: scale(0.97); }
.ag-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font: 600 12px var(--ag-font); background: var(--ag-fill); color: var(--ag-text-2); }
.ag-badge-accent { background: rgba(17, 17, 17, 0.08); color: #111111; }
.ag-badge-success { background: var(--ag-success-soft); color: var(--ag-success); }

/* Horizontal scroller that shows a hint of the next item instead of cutting cards */
.ag-scroller { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 16px; padding: 4px 16px 12px; margin-inline: -16px; scrollbar-width: none; }
.ag-scroller::-webkit-scrollbar { display: none; }
.ag-scroller > * { scroll-snap-align: start; flex-shrink: 0; }

/* ── Bars ─────────────────────────────────────────────────────────────────── */
.ag-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(238, 242, 247, 0.72); -webkit-backdrop-filter: var(--ag-blur); backdrop-filter: var(--ag-blur);
  border-bottom: 1px solid var(--ag-hairline);
  padding-top: env(safe-area-inset-top, 0);
}

/* Floating glass tab bar (phones) */
.ag-tabbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom, 0)); z-index: 50;
  display: flex; justify-content: space-around; align-items: center; height: 64px; padding: 0 6px;
  background: rgba(255, 255, 255, 0.72); -webkit-backdrop-filter: var(--ag-blur); backdrop-filter: var(--ag-blur);
  border: 1px solid var(--ag-glass-edge); border-radius: 26px; box-shadow: var(--ag-shadow-lg);
}
.ag-tabbar a, .ag-tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; border-radius: 18px; color: var(--ag-text-3); font: 600 12px var(--ag-font); text-decoration: none; transition: color 0.2s, background 0.25s var(--ag-ease); }
.ag-tabbar .is-active, .ag-tabbar [aria-current="page"] { color: #111111; background: rgba(17, 17, 17, 0.07); }

/* ── Sheets + modals ──────────────────────────────────────────────────────── */
.ag-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.28); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.ag-sheet {
  background: rgba(255, 255, 255, 0.9); -webkit-backdrop-filter: var(--ag-blur); backdrop-filter: var(--ag-blur);
  border: 1px solid var(--ag-glass-edge); border-radius: var(--ag-radius-xl); box-shadow: var(--ag-shadow-lg); color: var(--ag-text);
  animation: ag-sheet-in 0.45s var(--ag-ease) both;
}
@media (max-width: 640px) {
  .ag-sheet-bottom { border-radius: var(--ag-radius-xl) var(--ag-radius-xl) 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom, 0)); }
}
@keyframes ag-sheet-in { from { opacity: 0; transform: translateY(24px) scale(0.98); } to { opacity: 1; transform: none; } }

/* Skeleton loading */
.ag-skeleton { background: linear-gradient(90deg, var(--ag-fill) 0%, var(--ag-fill-strong) 50%, var(--ag-fill) 100%); background-size: 200% 100%; animation: ag-shimmer 1.4s ease-in-out infinite; border-radius: 10px; }
@keyframes ag-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ── Chat ─────────────────────────────────────────────────────────────────── */
.ag-bubble-user { max-width: 85%; margin-left: auto; padding: 10px 16px; border-radius: 22px 22px 6px 22px; background: var(--ag-accent); color: var(--ag-text-inverse); font-size: 15.5px; line-height: 1.5; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16); }
.ag-bubble-aria { max-width: 100%; padding: 12px 16px; border-radius: 22px 22px 22px 6px; background: var(--ag-glass-strong); border: 1px solid var(--ag-glass-edge); color: var(--ag-text); box-shadow: var(--ag-shadow); font-size: 15.5px; line-height: 1.6; }
.ag-composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 16px; border-radius: 26px; background: rgba(255, 255, 255, 0.82); -webkit-backdrop-filter: var(--ag-blur); backdrop-filter: var(--ag-blur); border: 1px solid var(--ag-glass-edge); box-shadow: var(--ag-shadow-lg); }

/* Thinking indicator: the black ARIA spark (petals light up one after another) and a shimmering status line */
.ag-thinking { display: inline-flex; align-items: center; gap: 10px; min-height: 28px; max-width: 100%; animation: ag-sheet-in 0.35s var(--ag-ease) both; }
.ag-spark { position: relative; display: inline-block; flex-shrink: 0; width: 1em; height: 1em; font-size: var(--ag-spark-size, 22px); color: var(--ag-text); }
.ag-spark i { position: absolute; left: 50%; top: 50%; width: 0.14em; height: 0.36em; margin: -0.5em 0 0 -0.07em; border-radius: 0.1em; background: currentColor; transform-origin: 50% calc(100% + 0.14em); transform: rotate(calc(var(--n) * 45deg)) scaleY(0.85); }
.ag-spark.is-live i { animation: ag-spark-chase 0.67s linear infinite; animation-delay: calc(var(--n) * 0.084s - 0.67s); }
@keyframes ag-spark-chase {
  0% { transform: rotate(calc(var(--n) * 45deg)) scaleY(1); opacity: 1; }
  70%, 100% { transform: rotate(calc(var(--n) * 45deg)) scaleY(0.55); opacity: 0.16; }
}
.ag-thinking-text { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 600 15px var(--ag-font); background: linear-gradient(90deg, var(--ag-text-3) 0%, var(--ag-text) 45%, var(--ag-text-3) 90%); background-size: 220% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: ag-text-shimmer 1.3s linear infinite; }
@keyframes ag-text-shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

/* Gentle entrance for new content */
.ag-fade-in { animation: ag-sheet-in 0.45s var(--ag-ease) both; }

@media (prefers-reduced-motion: reduce) {
  .ag-spark i, .ag-thinking-text, .ag-skeleton, .ag-sheet, .ag-fade-in, .ag-thinking { animation: none !important; }
  .ag-thinking-text { color: var(--ag-text-2); background: none; }
  .ag-card, .ag-btn, .ag-chip { transition: none !important; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   COMPATIBILITY LAYER — turns the old dark Tailwind classes light, including
   markup generated by scripts. Pages should still move to the ag-* classes;
   this keeps anything not yet migrated readable.
   ═══════════════════════════════════════════════════════════════════════════ */
html.ag-light .bg-black,
html.ag-light [class*="bg-[#0"],
html.ag-light [class*="bg-[#1"],
html.ag-light .bg-gray-900, html.ag-light .bg-gray-950, html.ag-light .bg-gray-800,
html.ag-light .bg-slate-900, html.ag-light .bg-slate-950, html.ag-light .bg-slate-800,
html.ag-light .bg-zinc-900, html.ag-light .bg-zinc-950, html.ag-light .bg-neutral-900, html.ag-light .bg-neutral-950 {
  background-color: var(--ag-glass-strong) !important;
  -webkit-backdrop-filter: var(--ag-blur);
  backdrop-filter: var(--ag-blur);
}
html.ag-light body.bg-black, html.ag-light main.bg-black { background-color: transparent !important; -webkit-backdrop-filter: none; backdrop-filter: none; }

html.ag-light [class*="bg-white/5"], html.ag-light [class*="bg-white/10"], html.ag-light [class*="bg-white/[0.0"] { background-color: var(--ag-fill) !important; }

html.ag-light .text-white,
html.ag-light .text-gray-100, html.ag-light .text-gray-200, html.ag-light .text-slate-100, html.ag-light .text-slate-200,
html.ag-light [class*="text-[#e"], html.ag-light [class*="text-[#d"], html.ag-light [class*="text-[#f"] { color: var(--ag-text) !important; }
html.ag-light .text-gray-300, html.ag-light .text-gray-400, html.ag-light .text-slate-300, html.ag-light .text-slate-400,
html.ag-light [class*="text-white/6"], html.ag-light [class*="text-white/7"], html.ag-light [class*="text-white/8"], html.ag-light [class*="text-[#9"], html.ag-light [class*="text-[#8"] { color: var(--ag-text-2) !important; }
html.ag-light .text-gray-500, html.ag-light .text-gray-600, html.ag-light .text-slate-500,
html.ag-light [class*="text-white/4"], html.ag-light [class*="text-white/5"], html.ag-light [class*="text-[#5"], html.ag-light [class*="text-[#6"], html.ag-light [class*="text-[#7"] { color: var(--ag-text-3) !important; }

/* Keep white text where it sits on a coloured or accent background */
html.ag-light [class*="bg-emerald-5"] .text-white, html.ag-light [class*="bg-emerald-6"].text-white,
html.ag-light [class*="bg-emerald-5"].text-white, html.ag-light [class*="bg-blue-6"].text-white,
html.ag-light [class*="bg-red-6"].text-white, html.ag-light .ag-btn-primary, html.ag-light .ag-btn-primary *,
html.ag-light .ag-bubble-user, html.ag-light .ag-bubble-user * { color: var(--ag-text-inverse) !important; }

/* Light buttons that were "white on black" now need dark text */
html.ag-light .bg-white.text-black, html.ag-light .bg-white .text-black { color: var(--ag-text) !important; }

html.ag-light [class*="border-[#1"], html.ag-light [class*="border-[#2"], html.ag-light [class*="border-[#3"],
html.ag-light .border-gray-700, html.ag-light .border-gray-800, html.ag-light .border-slate-700, html.ag-light .border-slate-800,
html.ag-light [class*="border-white/"] { border-color: var(--ag-hairline-strong) !important; }

html.ag-light .font-mono:not(code):not(pre):not(pre *) { font-family: var(--ag-font) !important; letter-spacing: 0 !important; }
html.ag-light input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), html.ag-light select, html.ag-light textarea {
  background-color: rgba(255, 255, 255, 0.92) !important; color: var(--ag-text) !important; border-color: var(--ag-hairline-strong) !important; font-size: max(16px, 1em);
}
html.ag-light input::placeholder, html.ag-light textarea::placeholder { color: #94a3b8 !important; }

html.ag-light [class*="shadow-[0_0"] { box-shadow: var(--ag-shadow) !important; }
html.ag-light .animate-pulse:not(.ag-skeleton) { animation: none !important; }

/* Code blocks stay dark for legibility */
html.ag-light pre, html.ag-light pre code { background-color: #0f172a !important; color: #e2e8f0 !important; border-radius: 14px; }

/* Monochrome buttons: old green Tailwind buttons become black with white text */
html.ag-light button[class*="bg-emerald-"], html.ag-light a[class*="bg-emerald-"], html.ag-light button[class*="bg-green-"], html.ag-light a[class*="bg-green-"] {
  background-color: #111111 !important; color: #ffffff !important; border-color: #111111 !important; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16) !important;
}
html.ag-light button[class*="bg-emerald-"] *, html.ag-light a[class*="bg-emerald-"] *, html.ag-light button[class*="bg-green-"] *, html.ag-light a[class*="bg-green-"] * { color: #ffffff !important; }


/* ── Dark theme (chosen by the student; light stays the default) ──────────── */
html[data-theme="dark"] {
  color-scheme: dark;
  --ag-bg: #0c0e13;
  --ag-bg-tint-1: rgba(255, 255, 255, 0.03);
  --ag-bg-tint-2: rgba(148, 163, 184, 0.06);
  --ag-glass: rgba(26, 29, 36, 0.72);
  --ag-glass-strong: rgba(26, 29, 36, 0.92);
  --ag-glass-solid: #1a1d24;
  --ag-glass-edge: rgba(255, 255, 255, 0.08);
  --ag-hairline: rgba(255, 255, 255, 0.08);
  --ag-hairline-strong: rgba(255, 255, 255, 0.14);
  --ag-fill: rgba(255, 255, 255, 0.08);
  --ag-fill-strong: rgba(255, 255, 255, 0.14);
  --ag-text: #f1f5f9;
  --ag-text-2: #cbd5e1;
  --ag-text-3: #94a3b8;
  --ag-text-inverse: #0c0e13;
  --ag-accent: #f5f5f5;
  --ag-accent-hover: #ffffff;
  --ag-accent-soft: rgba(255, 255, 255, 0.1);
  --ag-accent-bright: #f5f5f5;
  --ag-success: #4ade80;
  --ag-success-soft: rgba(74, 222, 128, 0.14);
  --ag-danger: #f87171;
  --ag-danger-soft: rgba(248, 113, 113, 0.14);
  --ag-warning: #fbbf24;
  --ag-warning-soft: rgba(251, 191, 36, 0.14);
  --ag-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
  --ag-shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.35), 0 24px 60px rgba(0, 0, 0, 0.5);
}
html[data-theme="dark"],
html[data-theme="dark"] body { background-color: #0c0e13 !important; color: #f1f5f9; }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #64748b !important; }
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
html.ag-theme-switching,
html.ag-theme-switching * {
  transition: background-color 0.45s ease, color 0.45s ease, border-color 0.45s ease, fill 0.45s ease, stroke 0.45s ease !important;
}
@media (prefers-reduced-motion: reduce) {
  html.ag-theme-switching, html.ag-theme-switching * { transition: none !important; }
}
