:root{
  --bg0:#0b1020;
  --bg1:#0b1223;
  --card:rgba(255,255,255,.92);
  --line:rgba(15,23,42,.14);
  --ink:#0f172a;
  --muted:rgba(15,23,42,.72);
  --muted2:rgba(15,23,42,.56);
  --accent:#2563eb;
  --shadow:0 18px 50px rgba(2,6,23,.25);
  --radius:18px;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  color:var(--ink);
  font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,"Noto Sans SC";
  background:
    radial-gradient(900px 520px at 18% -10%, rgba(37,99,235,.35) 0%, transparent 60%),
    radial-gradient(900px 520px at 88% -15%, rgba(16,185,129,.22) 0%, transparent 60%),
    radial-gradient(900px 520px at 65% 115%, rgba(245,158,11,.18) 0%, transparent 60%),
    linear-gradient(180deg,var(--bg0),var(--bg1));
}
.app{max-width:1200px;margin:0 auto;padding:18px}
.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:16px;
  box-shadow:var(--shadow);
  backdrop-filter:saturate(1.1) blur(10px);
}
.hero{display:flex;gap:14px;align-items:flex-start;justify-content:space-between}
.heroMain h1{margin:0 0 6px;font-size:1.55rem;letter-spacing:-.01em}
.lead{margin:0 0 6px;color:var(--muted);line-height:1.65}
.subtle{margin:0;color:var(--muted2);line-height:1.6;font-size:.95rem}
.heroActions{display:flex;gap:10px;flex-wrap:wrap}

.grid{display:grid;grid-template-columns:1.05fr .95fr;gap:14px;margin-top:14px}
@media(max-width:980px){.grid{grid-template-columns:1fr}}

h2{margin:0 0 10px;font-size:1.05rem}

.toolbar{
  display:flex;
  gap:10px;
  align-items:flex-end;
  flex-wrap:wrap;
  margin-bottom:12px;
}
.toolbar label{display:grid;gap:6px;font-weight:700;color:var(--muted)}
select,input[type="search"]{
  border:1px solid var(--line);
  border-radius:12px;
  padding:10px 12px;
  font:inherit;
  background:#fff;
  color:var(--ink);
  min-width:160px;
}
input[type="search"]{min-width:260px;flex:1}

.pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:8px 12px;
  border-radius:999px;
  border:1px solid var(--line);
  background:linear-gradient(180deg,#ffffff,#f8fafc);
  color:var(--muted);
  font-weight:750;
  white-space:nowrap;
}

button{
  border:0;
  border-radius:999px;
  padding:10px 14px;
  color:#fff;
  cursor:pointer;
  background:linear-gradient(180deg,#2563eb,#1d4ed8);
  font:inherit;
  font-weight:800;
  letter-spacing:.01em;
}
button.ghost{
  color:var(--ink);
  background:linear-gradient(180deg,#ffffff,#f8fafc);
  border:1px solid var(--line);
}
button.danger{
  color:#991b1b;
  background:linear-gradient(180deg,#ffffff,#fff1f2);
  border:1px solid rgba(220,38,38,.25);
}
button:active{transform:translateY(1px)}
button:focus,select:focus,input:focus,.flashcard:focus{outline:2px solid rgba(37,99,235,.35);outline-offset:2px}

.flashcard{
  border:1px solid var(--line);
  border-radius:22px;
  padding:18px;
  background:linear-gradient(180deg,#ffffff,#f8fafc);
  min-height:240px;
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  cursor:pointer;
  user-select:none;
  position:relative;
  overflow:hidden;
}
.flashcard::before{
  content:"";
  position:absolute;
  inset:-1px;
  background:radial-gradient(600px 240px at 30% 10%, rgba(37,99,235,.18), transparent 55%);
  opacity:.75;
  pointer-events:none;
}
.face{
  position:relative;
  z-index:1;
  font-size:1.22rem;
  line-height:1.6;
  letter-spacing:-.01em;
  padding:8px;
}

.actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:12px}
.stats{display:flex;gap:10px;flex-wrap:wrap;margin-top:12px}
.status{margin:10px 0 0;color:var(--muted);min-height:1.2em}

.learn{margin-top:10px}
.learn summary{cursor:pointer;font-weight:800;color:var(--ink)}
.learnPanel{
  margin-top:10px;
  border:1px dashed rgba(15,23,42,.18);
  border-radius:16px;
  padding:12px;
  color:var(--muted);
  line-height:1.7;
  background:rgba(255,255,255,.65);
}
.learnPanel .k{font-weight:800;color:var(--ink)}

.explain{
  border:1px solid var(--line);
  border-radius:16px;
  padding:12px;
  background:linear-gradient(180deg,#ffffff,#fbfdff);
  color:var(--muted);
  line-height:1.7;
  min-height:160px;
}
.wrongList{margin:10px 0 0;padding-left:18px;color:var(--muted);line-height:1.7}
.wrongList li{margin:6px 0}

.summary{margin-top:14px}
.summary.hidden{display:none}
.summaryHead{display:flex;align-items:center;justify-content:space-between;gap:10px}
.summaryGrid{
  display:grid;
  grid-template-columns:repeat(4, minmax(160px, 1fr));
  gap:10px;
  margin:10px 0 12px;
}
@media(max-width:900px){.summaryGrid{grid-template-columns:repeat(2, minmax(160px, 1fr))}}

.metric{
  border:1px solid var(--line);
  border-radius:16px;
  padding:12px;
  background:linear-gradient(180deg,#ffffff,#f8fafc);
}
.metric .v{font-size:1.5rem;font-weight:900;letter-spacing:-.02em}
.metric .k{color:var(--muted2);font-weight:750;margin-top:4px}

.filterBar{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-top:12px}
.summaryList{display:grid;gap:10px;margin-top:12px}
.row{
  border:1px solid var(--line);
  border-radius:16px;
  padding:12px;
  background:linear-gradient(180deg,#ffffff,#fbfdff);
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
}
.row .t{font-weight:900;line-height:1.5}
.row .m{color:var(--muted);line-height:1.55;margin-top:4px}
.badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background:linear-gradient(180deg,#ffffff,#f8fafc);
  color:var(--muted);
  font-weight:850;
}
.badge.good{border-color:rgba(16,185,129,.35);color:#065f46;background:linear-gradient(180deg,#ffffff,#ecfdf5)}
.badge.warn{border-color:rgba(245,158,11,.35);color:#7c2d12;background:linear-gradient(180deg,#ffffff,#fffbeb)}
.badge.bad{border-color:rgba(239,68,68,.35);color:#7f1d1d;background:linear-gradient(180deg,#ffffff,#fff1f2)}

.footer{margin-top:14px}

@media (prefers-reduced-motion: reduce){
  *{scroll-behavior:auto}
  button:active{transform:none}
}

/* === Dark Mode Override (auto-generated) === */
:root[data-theme="dark"] {
  --bg0: #e8e8f0;
  --bg1: #e8e8f0;
  --card: #242438;
  --line: #3a3a50;
  --ink: #e8e8f0;
  --accent: #ff7b54;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg0: #e8e8f0;
  --bg1: #e8e8f0;
  --card: #242438;
  --line: #3a3a50;
  --ink: #e8e8f0;
  --accent: #ff7b54;
  }
}

/* === CSS Professor Upgrade (Round 20) === */

/* Card system */
.card, [class*="card"], section, .panel, .container > div { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.card:hover, [class*="card"]:hover { transform: translateY(-2px); }

/* Button polish */
button, .btn, [type="submit"], [type="button"] {
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
button:hover, .btn:hover, [type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
button:active, .btn:active { transform: scale(0.98); }

/* Input polish */
input, textarea, select {
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input:focus, textarea:focus, select:focus {
  box-shadow: 0 0 0 3px rgba(199,73,31,0.15);
}

/* Link hover */
a { transition: color 0.15s ease; }

/* Focus outline */
:focus-visible { outline: 2px solid var(--accent, #c7491f); outline-offset: 2px; }

/* Mobile responsive */
@media (max-width: 600px) {
  body { padding: 8px; }
  .app, main, .container { padding: 12px; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.2rem; }
  button, .btn { width: 100%; }
}

/* === CSS Professor Animation Upgrade (Round 22) === */

/* Page entrance */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.app, main, body > .container { animation: fadeInUp 0.4s ease-out; }

/* Staggered card entrance */
@keyframes cardReveal {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.card, [class*="card"], .mission-card, .module-card, .stat-card {
  animation: cardReveal 0.35s ease-out both;
}
.card:nth-child(2), [class*="card"]:nth-child(2) { animation-delay: 0.05s; }
.card:nth-child(3), [class*="card"]:nth-child(3) { animation-delay: 0.1s; }
.card:nth-child(4), [class*="card"]:nth-child(4) { animation-delay: 0.15s; }
.card:nth-child(5), [class*="card"]:nth-child(5) { animation-delay: 0.2s; }

/* Subtle pulse for primary buttons */
@keyframes btnPulse {
  0%, 100% { box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
  50% { box-shadow: 0 2px 12px rgba(199,73,31,0.25); }
}
button[id*="Btn"]:not(:disabled), .btn-primary {
  animation: btnPulse 3s ease-in-out infinite;
}
button:disabled { animation: none; opacity: 0.6; }

/* Smooth height transitions for collapsible sections */
details { transition: all 0.2s ease; }
details[open] summary { margin-bottom: 8px; }

/* Tooltip fade */
[title] { position: relative; }

/* Progress bar animation */
@keyframes progressFill {
  from { width: 0; }
}
.mc-bar-fill, .mod-progress-fill, .bar-fill, progress::-webkit-progress-value {
  animation: progressFill 0.6s ease-out;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* === Contrast Fix === */
.card-front, .card-back, .flashcard {
  color: #1a1a2e !important;
}
:root[data-theme="dark"] .card-front,
:root[data-theme="dark"] .card-back,
:root[data-theme="dark"] .flashcard {
  color: #e8e8f0 !important;
}
.btn-fuzzy, .btn-unknown, [class*="btn-"] {
  color: #333 !important;
  border: 1px solid #999 !important;
}
:root[data-theme="dark"] .btn-fuzzy,
:root[data-theme="dark"] .btn-unknown,
:root[data-theme="dark"] [class*="btn-"] {
  color: #ddd !important;
  border: 1px solid #666 !important;
}

/* === Loading & Feedback States === */
@keyframes spin { to { transform: rotate(360deg); } }
.btn-loading { position: relative; pointer-events: none; opacity: 0.7; }
.btn-loading::after {
  content: '';
  position: absolute;
  right: 8px; top: 50%;
  width: 14px; height: 14px;
  margin-top: -7px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.toast-msg {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 0.9rem; z-index: 9999; opacity: 0;
  transition: opacity 0.3s ease;
}
.toast-msg.show { opacity: 1; }
