* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1d212b;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8b92a5;
  --accent: #7c5cff;
  --accent-hover: #8f73ff;
  --new: #3ea6ff;
  --learn: #f6a821;
  --rev: #4cd97b;
  --danger: #ef5b7b;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  overflow: hidden;
}

#app { height: 100vh; }

.shell, .session {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.spacer { flex: 1; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
  -webkit-app-region: no-drag;
}

.brand { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }

.topbar nav { display: flex; gap: 6px; }

.navbtn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.navbtn:hover { color: var(--text); background: var(--panel2); }
.navbtn.active { color: var(--text); background: var(--panel2); }

.topbar-right { margin-left: auto; display: flex; gap: 6px; }

/* ---------- generic controls ---------- */

.btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: #252b38; border-color: #3a4152; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.subtle { background: transparent; }
.btn.sm { padding: 6px 13px; font-size: 13px; }
.btn.xl { padding: 14px 34px; font-size: 16px; }

.ghostbtn {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.ghostbtn:hover { color: var(--text); background: var(--panel2); }
.ghostbtn.shuffle.on { color: var(--accent); background: rgba(124, 92, 255, 0.12); }

.iconbtn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  padding: 5px 7px;
  border-radius: 6px;
  cursor: pointer;
}
.iconbtn:hover { color: var(--text); background: var(--panel2); }
.iconbtn.danger:hover { color: var(--danger); background: rgba(239, 91, 123, 0.1); }

.kbd {
  font-size: 11px;
  opacity: 0.7;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
}

/* ---------- content ---------- */

.content {
  flex: 1;
  overflow-y: auto;
  padding: 26px 30px 40px;
}

/* ---------- decks view ---------- */

.hero {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 22px 26px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.14), rgba(0, 184, 169, 0.08));
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 26px;
}
.hero h1 { font-size: 22px; margin-bottom: 6px; }
.hero-actions { margin-left: auto; display: flex; gap: 10px; }

.counts { font-size: 13.5px; color: var(--muted); }
.c-new { color: var(--new); font-weight: 600; }
.c-learn { color: var(--learn); font-weight: 600; }
.c-rev { color: var(--rev); font-weight: 600; }

.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.deck-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--deck, var(--accent));
  border-radius: 13px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.deck-head { display: flex; align-items: center; gap: 9px; }
.deck-head .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--deck, var(--accent));
  flex-shrink: 0;
}
.deck-name {
  background: none;
  border: none;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deck-name:hover { color: var(--accent-hover); }

.deck-actions { display: flex; gap: 8px; }

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 60px 0;
  font-size: 15px;
}

/* ---------- browse view ---------- */

.browse-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.browse-bar select, .browse-bar input[type="search"] {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 8px;
  outline: none;
}
.browse-bar input[type="search"] { width: 260px; }
.browse-bar input[type="search"]:focus, .browse-bar select:focus { border-color: var(--accent); }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
}
.table-wrap.flat { background: transparent; border: none; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
}
td { padding: 10px 14px; border-bottom: 1px solid rgba(42, 47, 58, 0.55); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.015); }

.cell-text {
  max-width: 320px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  max-height: 5.5em;
  overflow: hidden;
}

.row-actions { white-space: nowrap; text-align: right; }

.pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--deck, #666) 18%, transparent);
  color: var(--deck, #aaa);
  white-space: nowrap;
}

.state { font-size: 12px; font-weight: 700; text-transform: capitalize; }
.s-new { color: var(--new); }
.s-learning { color: var(--learn); }
.s-review { color: var(--rev); }
.due-now { color: var(--rev); font-weight: 700; }

/* ---------- stats view ---------- */

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 18px 20px;
}
.tile-num { font-size: 28px; font-weight: 800; }
.tile-label { color: var(--muted); font-size: 13px; margin-top: 4px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 18px 20px;
  margin-bottom: 20px;
}
.panel h2 { font-size: 15px; margin-bottom: 14px; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 130px;
}
.bar-col {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.bar-space { flex: 1; display: flex; align-items: flex-end; }
.bar {
  width: 100%;
  background: linear-gradient(180deg, var(--accent), #5b40cc);
  border-radius: 5px 5px 2px 2px;
  min-height: 0;
}
.bar-label {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding-top: 6px;
}

/* ---------- session ---------- */

.session-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.session-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 10px; }

.mode-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 3px 9px;
  border-radius: 999px;
}
.m-study { background: rgba(124, 92, 255, 0.18); color: #a891ff; }
.m-learn { background: rgba(0, 184, 169, 0.16); color: #35d6c8; }
.m-test { background: rgba(246, 168, 33, 0.16); color: #ffc45e; }

.c-miss { color: var(--danger); font-weight: 600; }

.progress { height: 4px; background: var(--panel2); flex-shrink: 0; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #00b8a9); transition: width 0.25s; }

.card-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  overflow: hidden;
}

.study-card {
  width: min(780px, 94%);
  max-height: 100%;
  min-height: 280px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 38px 42px;
  font-size: 20px;
  line-height: 1.55;
  overflow-y: auto;
  cursor: pointer;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.card-side { white-space: pre-wrap; overflow-wrap: break-word; }
.card-side.back { color: #cfd6e6; }

.card-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.session-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 6px 30px 10px;
  flex-shrink: 0;
}

.grade {
  flex: 1;
  max-width: 190px;
  padding: 13px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel2);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
.grade:hover { transform: translateY(-1px); }
.grade:active { transform: translateY(0); }
.grade-label { font-size: 15px; font-weight: 700; }
.grade-sub { font-size: 12px; color: var(--muted); }

.g-again .grade-label { color: var(--danger); }
.g-again:hover { border-color: var(--danger); background: rgba(239, 91, 123, 0.1); }
.g-hard .grade-label { color: var(--learn); }
.g-hard:hover { border-color: var(--learn); background: rgba(246, 168, 33, 0.1); }
.g-good .grade-label { color: var(--rev); }
.g-good:hover { border-color: var(--rev); background: rgba(76, 217, 123, 0.1); }
.g-easy .grade-label { color: var(--new); }
.g-easy:hover { border-color: var(--new); background: rgba(62, 166, 255, 0.1); }

.hint {
  text-align: center;
  font-size: 12px;
  padding: 6px 0 14px;
  flex-shrink: 0;
}

/* ---------- test mode ---------- */

.test-stage {
  overflow-y: auto;
  padding: 30px;
}

.test-inner {
  margin: auto;
  width: min(780px, 94%);
  display: flex;
  flex-direction: column;
}

.study-card.test-question {
  width: 100%;
  min-height: 0;
  cursor: default;
  padding: 26px 30px;
  font-size: 19px;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  text-align: left;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.45;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.option:hover:not(:disabled) { border-color: var(--accent); background: #222736; }
.option:disabled { cursor: default; }

.opt-key {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.opt-text { flex: 1; white-space: pre-wrap; overflow-wrap: break-word; }

.opt-mark { font-weight: 800; font-size: 16px; }
.opt-mark.ok { color: var(--rev); }
.opt-mark.bad { color: var(--danger); }

.opt-correct { border-color: var(--rev); background: rgba(76, 217, 123, 0.09); }
.opt-correct .opt-key { border-color: var(--rev); color: var(--rev); }
.opt-wrong { border-color: var(--danger); background: rgba(239, 91, 123, 0.09); }
.opt-wrong .opt-key { border-color: var(--danger); color: var(--danger); }
.opt-dim { opacity: 0.5; }

.missed-list {
  margin: 26px auto 0;
  width: min(560px, 86vw);
  max-height: 240px;
  overflow-y: auto;
  text-align: left;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.missed-list h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 10px;
}
.missed-item {
  padding: 8px 0;
  border-bottom: 1px solid rgba(42, 47, 58, 0.55);
}
.missed-item:last-child { border-bottom: none; }
.missed-q { font-weight: 600; font-size: 13.5px; white-space: pre-wrap; }
.missed-a { color: var(--rev); font-size: 13px; margin-top: 3px; white-space: pre-wrap; }

/* ---------- session done ---------- */

.done-panel {
  margin: auto;
  text-align: center;
  padding: 40px;
  max-height: 100%;
  overflow-y: auto;
}
.done-emoji { font-size: 52px; margin-bottom: 18px; }
.done-panel h1 { font-size: 24px; margin-bottom: 10px; }
.done-panel p { font-size: 15px; max-width: 420px; margin: 0 auto; line-height: 1.5; }
.done-actions { display: flex; gap: 10px; justify-content: center; margin-top: 26px; }

/* ---------- modal ---------- */

#modal-root { display: none; }
#modal-root.open { display: block; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 24px 26px;
  width: min(520px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

.modal h2 { font-size: 18px; margin-bottom: 18px; }

.modal form { display: flex; flex-direction: column; gap: 14px; }

.modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.modal input[type="text"], .modal input[type="number"], .modal textarea, .modal select {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  padding: 9px 12px;
  border-radius: 9px;
  outline: none;
  resize: vertical;
}
.modal input:focus, .modal textarea:focus, .modal select:focus { border-color: var(--accent); }

.modal .chk {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
}

.import-meta { margin-bottom: 12px; }

.preview-wrap {
  max-height: 190px;
  margin-bottom: 16px;
}
.preview-wrap td { font-size: 13px; }
.preview-wrap.ai-preview { max-height: 280px; }

.wrong-preview {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.settings-sub {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 4px;
}

.small { font-size: 12px; line-height: 1.45; }

.label-note { font-weight: 400; opacity: 0.75; }

.form-row { display: flex; gap: 14px; }
.form-row label { flex: 1; }
.form-row label:first-child { flex: 0 0 90px; }

.ai-status { font-size: 13px; min-height: 18px; }

.mc-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0 4px;
  vertical-align: 1px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.colorrow { display: flex; gap: 9px; flex-wrap: wrap; }
.colordot input { display: none; }
.colordot span {
  display: block;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s;
}
.colordot span:hover { transform: scale(1.12); }
.colordot input:checked + span { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

/* ---------- scrollbars ---------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2c3240; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4152; }

/* AI generation is intentionally unavailable in the shared web preview. */
[data-action='ai-open'] { display: none !important; }


/* AI generation is intentionally unavailable in the shared web preview. */
[data-action='ai-open'] { display: none !important; }

#auth-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: #0f1115; }
#auth-overlay section { width: min(100%, 410px); padding: 30px; border: 1px solid #313844; border-radius: 16px; background: #191d25; box-shadow: 0 24px 80px #0008; }
#auth-overlay h1 { margin: 0 0 10px; } #auth-overlay p { color: #aeb7c7; line-height: 1.5; } #auth-overlay label { display: grid; gap: 7px; margin-top: 16px; color: #dbe1ec; } #auth-overlay input { min-height: 42px; padding: 8px 10px; border: 1px solid #475062; border-radius: 8px; color: #fff; background: #10131a; } #auth-overlay button { margin-top: 18px; width: 100%; min-height: 42px; border: 0; border-radius: 8px; color: white; background: #7c5cff; font-weight: 700; cursor: pointer; } #auth-overlay .link { margin-top: 9px; color: #bac4d7; background: transparent; } #auth-overlay .auth-error { min-height: 1.5em; margin: 12px 0 0; color: #ff9cae; } #auth-overlay .auth-note { font-size: .86rem; }
#account-bar { position: fixed; right: 14px; bottom: 12px; z-index: 50; display: flex; gap: 9px; align-items: center; padding: 7px 9px; border: 1px solid #394252; border-radius: 8px; color: #bfc8d8; background: #161a22eF; font-size: .75rem; } #account-bar button { border: 0; color: #cfd8ff; background: transparent; cursor: pointer; }
#auth-overlay button.secondary { color: #d8dfff; background: #2a3040; }
#auth-overlay button:disabled, #account-bar button:disabled { opacity: .6; cursor: wait; }
#account-bar { max-width: calc(100vw - 28px); flex-wrap: wrap; }
#account-bar .account-email { overflow-wrap: anywhere; }
#sync-status { max-width: min(420px, 80vw); color: #a9d6ba; }
#sync-status.sync-error { color: #ffbdc8; }
