:root {
  --bg: #0f1020;
  --panel: #17182d;
  --panel-2: #20223c;
  --text: #f6f7ff;
  --muted: #b7bbd8;
  --accent: #8b5cf6;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 22px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #32215f, var(--bg) 42%), var(--bg);
  color: var(--text);
  min-height: 100vh;
}

button, input, textarea, select { font: inherit; }

button {
  border: 0;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  transition: transform .15s ease, background .15s ease, opacity .15s ease;
}
button:hover { transform: translateY(-1px); background: #2b2e50; }
button:active { transform: translateY(0); }
button:disabled { opacity: .5; cursor: not-allowed; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  outline: none;
}
textarea { min-height: 110px; resize: vertical; }
select option { color: #111; }
label { display: block; color: var(--muted); margin-bottom: .45rem; }
code { color: #d8c7ff; }

.app {
  display: grid;
  grid-template-columns: 315px 1fr;
  min-height: 100vh;
}
.app.menu-hidden { grid-template-columns: 0 1fr; }

.sidebar {
  background: rgba(23, 24, 45, .88);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--line);
  padding: 1.2rem;
  overflow: hidden;
  transition: width .2s ease, padding .2s ease, transform .2s ease;
}
.app.menu-hidden .sidebar {
  width: 0;
  padding: 0;
  border-right: 0;
}

.brand {
  display: flex;
  gap: .9rem;
  align-items: center;
  margin-bottom: 1.2rem;
}
.logo {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, #8b5cf6, #22c55e);
  box-shadow: var(--shadow);
  font-size: 2rem;
}
.brand h1 { margin: 0; font-size: 1.75rem; line-height: 1; }
.brand p { margin: .35rem 0 0; color: var(--muted); font-size: .88rem; line-height: 1.25; }
.search-wrap { margin: 1rem 0; }
.nav { display: grid; gap: .55rem; margin-top: 1.2rem; }
.nav button { text-align: left; display: flex; align-items: center; gap: .7rem; justify-content: flex-start; }
.nav button.active { background: var(--accent); }
.sidebar-note {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.45;
}

.main { padding: 1.25rem; overflow: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.menu-toggle { display: none; background: var(--accent); white-space: nowrap; }
.app.menu-hidden .menu-toggle { display: inline-block; }
.status { color: var(--muted); min-height: 1.5rem; }

.hero {
  background: linear-gradient(135deg, rgba(139, 92, 246, .35), rgba(34, 197, 94, .18));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.hero h2 { margin: 0 0 .35rem; font-size: clamp(1.8rem, 4vw, 3.1rem); }
.hero p { margin: 0; color: var(--muted); font-size: 1.05rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(245px, 1fr)); gap: 1rem; }
.card, .deck-card, .panel {
  background: rgba(23, 24, 45, .82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.deck-card h3, .panel h3 { margin: 0 0 .4rem; }
.deck-card p, .panel p { color: var(--muted); margin: .25rem 0; }
.actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: .9rem; }
.primary { background: var(--accent); }
.success { background: var(--accent-2); }
.danger { background: var(--danger); }
.warning { background: var(--warning); }
.ghost { background: rgba(255, 255, 255, 0.07); }
.form-grid { display: grid; gap: 1rem; max-width: 850px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.small { font-size: .9rem; color: var(--muted); }
.hidden { display: none !important; }
.list { display: grid; gap: .75rem; }

.study-wrap { display: grid; gap: 1rem; place-items: center; min-height: 65vh; }
.flashcard { width: min(760px, 100%); min-height: 330px; perspective: 1000px; }
.flashcard-inner { width: 100%; min-height: 330px; position: relative; transform-style: preserve-3d; transition: transform .55s ease; }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 2rem;
  border-radius: 30px;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
  box-shadow: var(--shadow);
  font-size: clamp(1.35rem, 4vw, 2.25rem);
  line-height: 1.25;
  white-space: pre-wrap;
}
.back { transform: rotateY(180deg); }
.stats-row { display: flex; gap: .7rem; flex-wrap: wrap; justify-content: center; color: var(--muted); }
.pill { padding: .45rem .75rem; background: rgba(255,255,255,.07); border: 1px solid var(--line); border-radius: 999px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 1rem; z-index: 20; }
.modal { width: min(760px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; max-height: 88vh; overflow: auto; }
.modal h3 { margin-top: 0; }
.file-input { border: 1px dashed var(--line); padding: 1rem; border-radius: var(--radius); background: rgba(255,255,255,.04); }
.missed-list { width: min(760px, 100%); }
.missed-item { border: 1px solid var(--line); border-radius: 16px; padding: .8rem; margin: .5rem 0; background: rgba(255,255,255,.04); }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(315px, 90vw); z-index: 10; }
  .app.menu-hidden .sidebar { transform: translateX(-100%); width: min(315px, 90vw); padding: 1.2rem; }
  .menu-toggle { display: inline-block; }
  .two { grid-template-columns: 1fr; }
}
