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

:root {
  --bg:       #f0f2f5;
  --surface:  #ffffff;
  --border:   #e4e7ec;
  --text:     #111827;
  --muted:    #6b7280;
  --primary:  #4f46e5;
  --primary-d:#4338ca;
  --radius:   14px;
  --radius-sm:8px;
  --shadow:   0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:0 4px 24px rgba(0,0,0,.10);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Screens ──────────────────────────────────────────── */
.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }

/* ── Utilities ────────────────────────────────────────── */
.hidden  { display: none !important; }
.w-full  { width: 100%; }

/* ── Buttons ──────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: .75rem 1.5rem; font-size: .95rem; font-weight: 600;
  cursor: pointer; transition: background .15s, transform .1s;
  font-family: inherit;
}
.btn-primary:hover  { background: var(--primary-d); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { background: #c7c5e8; cursor: not-allowed; }

.btn-ghost-sm {
  background: none; border: none; color: var(--muted);
  font-size: .875rem; font-weight: 500; cursor: pointer;
  padding: .35rem .6rem; border-radius: 6px;
  transition: color .15s, background .15s; font-family: inherit;
}
.btn-ghost-sm:hover { color: var(--text); background: var(--bg); }

/* ── App Header ───────────────────────────────────────── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  gap: .75rem;
}
.app-logo     { font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em; }
.header-right { display: flex; align-items: center; gap: .75rem; }
.header-user  { font-size: .875rem; font-weight: 600; color: var(--muted); }
.header-title { font-weight: 700; font-size: 1rem; }

/* ════════════════════════════════════════════════════════
   LOGIN
════════════════════════════════════════════════════════ */
#screen-login {
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f0fdf4 100%);
  min-height: 100dvh; padding: 1.5rem;
}

.login-wrap { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 1.5rem; }

.login-brand { text-align: center; }
.brand-icon  {
  display: flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; margin: 0 auto .75rem;
  background: #eef2ff; border-radius: 14px;
  color: var(--primary);
}
.brand-icon svg { width: 28px; height: 28px; }
.login-brand h1 { font-size: 2rem; font-weight: 800; letter-spacing: -.03em; }
.login-brand p  { color: var(--muted); margin-top: .25rem; }

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.75rem;
}

.tabs {
  display: flex; background: var(--bg);
  border-radius: var(--radius-sm); padding: 3px; margin-bottom: 1.5rem;
}
.tab {
  flex: 1; padding: .5rem; border: none; background: transparent;
  border-radius: 6px; cursor: pointer; font-size: .875rem; font-weight: 500;
  color: var(--muted); transition: all .15s; font-family: inherit;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-form label {
  display: flex; flex-direction: column; gap: .35rem;
  font-size: .875rem; font-weight: 500; color: var(--muted);
}
.auth-form input {
  padding: .65rem .9rem; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 1rem; outline: none;
  transition: border-color .15s; color: var(--text); font-family: inherit;
}
.auth-form input:focus { border-color: var(--primary); }

.error-msg {
  background: #fff1f2; color: #be123c; border: 1px solid #fecdd3;
  border-radius: var(--radius-sm); padding: .6rem .85rem; font-size: .85rem;
}

.success-msg {
  background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0;
  border-radius: var(--radius-sm); padding: .6rem .85rem; font-size: .85rem;
}

/* ════════════════════════════════════════════════════════
   HOME
════════════════════════════════════════════════════════ */
.home-main {
  flex: 1; max-width: 680px; width: 100%;
  margin: 0 auto; padding: 1.25rem 1rem 4rem;
  display: flex; flex-direction: column; gap: 1.25rem;
}

/* Today Banner */
.today-banner {
  background: var(--primary);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  box-shadow: 0 4px 20px rgba(79,70,229,.3);
  flex-wrap: wrap;
}
.today-banner.empty { background: #ecfdf5; box-shadow: 0 2px 8px rgba(0,0,0,.06); }

.today-text { display: flex; flex-direction: column; }
.today-count {
  font-size: 2.5rem; font-weight: 800; color: #fff; line-height: 1;
}
.today-banner.empty .today-count { color: #16a34a; }
.today-label { font-size: .875rem; color: rgba(255,255,255,.8); margin-top: .2rem; }
.today-banner.empty .today-label { color: #15803d; }

.btn-banner {
  background: rgba(255,255,255,.2); color: #fff;
  border: 1.5px solid rgba(255,255,255,.4);
  border-radius: var(--radius-sm); padding: .65rem 1.25rem;
  font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: background .15s; white-space: nowrap; font-family: inherit;
  backdrop-filter: blur(4px);
}
.btn-banner:hover { background: rgba(255,255,255,.3); }

/* Overall progress */
.overall-progress {
  background: var(--surface); border-radius: var(--radius);
  padding: 1rem 1.25rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: .5rem;
}
.progress-label {
  display: flex; justify-content: space-between;
  font-size: .875rem; font-weight: 600; color: var(--muted);
}
.progress-track {
  background: var(--bg); border-radius: 99px; height: 8px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--primary); border-radius: 99px;
  transition: width .5s ease;
}
.progress-sub { font-size: .8rem; color: var(--muted); }

/* Topics Section */
.section-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .5rem; }

.topic-list { display: flex; flex-direction: column; gap: .75rem; }

.topic-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  border: 1px solid var(--border);
  transition: box-shadow .15s, transform .1s;
  cursor: pointer;
}
.topic-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.topic-card-inner {
  display: flex; gap: 1rem; padding: 1rem 1.25rem;
  border-left: 4px solid var(--topic-color, var(--primary));
}

.topic-icon-wrap {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--topic-color, var(--primary));
  background: color-mix(in srgb, var(--topic-color, var(--primary)) 10%, white);
}
.topic-icon-wrap svg { width: 20px; height: 20px; }

.topic-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .4rem; }

.topic-header-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem;
}
.topic-name { font-size: .95rem; font-weight: 700; line-height: 1.3; }

.due-pill {
  background: color-mix(in srgb, var(--topic-color, var(--primary)) 12%, white);
  color: var(--topic-color, var(--primary));
  font-size: .75rem; font-weight: 700; padding: .2rem .55rem;
  border-radius: 99px; white-space: nowrap; flex-shrink: 0;
}

.topic-subtopics { font-size: .78rem; color: var(--muted); line-height: 1.4; }

.topic-progress-row {
  display: flex; align-items: center; gap: .6rem;
}
.topic-track {
  flex: 1; background: var(--bg); border-radius: 99px; height: 5px; overflow: hidden;
}
.topic-fill {
  height: 100%; background: var(--topic-color, var(--primary)); border-radius: 99px;
  transition: width .5s ease; opacity: .7;
}
.topic-pct { font-size: .75rem; color: var(--muted); font-weight: 600; white-space: nowrap; }

.topic-card-footer {
  padding: .6rem 1.25rem .6rem calc(1.25rem + 4px);
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}
.btn-topic-learn {
  font-size: .8rem; font-weight: 700; color: var(--topic-color, var(--primary));
  background: none; border: none; cursor: pointer; font-family: inherit;
  padding: .2rem .4rem; border-radius: 4px; transition: background .15s;
}
.btn-topic-learn:hover {
  background: color-mix(in srgb, var(--topic-color, var(--primary)) 10%, white);
}

/* Editor */
.editor-main {
  flex: 1;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem 4rem;
}
.editor-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
}
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .9rem;
}
.editor-form label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--muted);
}
.editor-form input,
.editor-form select,
.editor-form textarea {
  padding: .65rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
  color: var(--text);
  font-family: inherit;
  background: #fff;
}
.editor-form textarea { resize: vertical; }
.editor-form input:focus,
.editor-form select:focus,
.editor-form textarea:focus { border-color: var(--primary); }
@media (max-width: 640px) {
  .editor-grid { grid-template-columns: 1fr; }
}

/* ════════════════════════════════════════════════════════
   TOPIC SELECT
════════════════════════════════════════════════════════ */
.select-main {
  flex: 1; overflow-y: auto;
  padding: 1rem 1rem 0;
  max-width: 680px; width: 100%; margin: 0 auto;
  display: flex; flex-direction: column; gap: 1rem;
}

/* Toggle */
.select-mode-toggle {
  background: var(--surface); border-radius: var(--radius);
  padding: .9rem 1.25rem; box-shadow: var(--shadow);
}
.toggle-label {
  display: flex; align-items: center; gap: .75rem;
  cursor: pointer; font-size: .9rem; font-weight: 600; user-select: none;
}
.toggle-label input { display: none; }
.toggle-track {
  width: 42px; height: 24px; background: var(--border);
  border-radius: 99px; position: relative; transition: background .2s; flex-shrink: 0;
}
.toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; background: #fff;
  border-radius: 50%; transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-label input:checked ~ .toggle-track { background: var(--primary); }
.toggle-label input:checked ~ .toggle-track .toggle-thumb { transform: translateX(18px); }

/* Select list */
.select-topic-list { display: flex; flex-direction: column; gap: .75rem; padding-bottom: 1rem; }

.select-topic-section {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  border: 1px solid var(--border);
}

.select-topic-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .9rem 1.25rem;
  border-left: 4px solid var(--topic-color, var(--primary));
  cursor: pointer; user-select: none;
}
.select-topic-header:hover { background: var(--bg); }

.select-topic-icon {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex-shrink: 0;
  color: var(--topic-color, var(--primary));
}
.select-topic-icon svg { width: 18px; height: 18px; }
.select-topic-name { font-weight: 700; font-size: .95rem; flex: 1; }
.select-topic-meta { font-size: .8rem; color: var(--muted); }
.select-topic-chevron { color: var(--muted); font-size: .8rem; transition: transform .2s; }
.select-topic-section.open .select-topic-chevron { transform: rotate(90deg); }

.select-subtopic-list { display: none; border-top: 1px solid var(--border); }
.select-topic-section.open .select-subtopic-list { display: block; }

.select-subtopic-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1.25rem; cursor: pointer;
  transition: background .1s; border-bottom: 1px solid var(--border);
}
.select-subtopic-item:last-child { border-bottom: none; }
.select-subtopic-item:hover:not(.disabled) { background: var(--bg); }
.select-subtopic-item.disabled { opacity: .45; cursor: not-allowed; }

.select-subtopic-item input[type="checkbox"] { display: none; }

.custom-checkbox {
  width: 20px; height: 20px; border-radius: 5px; flex-shrink: 0;
  border: 2px solid var(--border); transition: all .15s;
  display: flex; align-items: center; justify-content: center;
}
.select-subtopic-item:not(.disabled) input:checked + .custom-checkbox {
  background: var(--topic-color, var(--primary));
  border-color: var(--topic-color, var(--primary));
}
.custom-checkbox::after {
  content: '✓'; font-size: .7rem; color: #fff; opacity: 0; transition: opacity .1s;
}
.select-subtopic-item input:checked + .custom-checkbox::after { opacity: 1; }

.subtopic-name { flex: 1; font-size: .9rem; font-weight: 500; }
.subtopic-meta { font-size: .78rem; color: var(--muted); text-align: right; line-height: 1.4; }
.subtopic-due  { font-weight: 700; color: var(--topic-color, var(--primary)); }

/* Footer */
.select-footer {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: .9rem 1.25rem; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; position: sticky; bottom: 0;
  max-width: 680px; width: 100%; margin: 0 auto;
}
.select-count { font-size: .875rem; font-weight: 600; color: var(--muted); }

/* ════════════════════════════════════════════════════════
   STUDY
════════════════════════════════════════════════════════ */
.study-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .8rem 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.study-progress-bar {
  flex: 1; height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden;
}
.study-progress-fill {
  height: 100%; background: var(--primary); border-radius: 99px;
  transition: width .3s ease;
}
.study-progress-text { font-size: .8rem; font-weight: 600; color: var(--muted); white-space: nowrap; }

.study-main {
  flex: 1; display: flex; flex-direction: column;
  max-width: 660px; width: 100%; margin: 0 auto;
  padding: 1.25rem 1rem 2rem; gap: 1rem;
}

.study-breadcrumb {
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--primary);
}

.flashcard {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.5rem;
  display: flex; flex-direction: column; gap: 0;
  border: 1px solid var(--border);
}

.card-front {
  font-size: 1.1rem; font-weight: 600; line-height: 1.55;
  min-height: 3rem;
}

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

.card-back {
  font-size: .95rem; line-height: 1.7;
  white-space: pre-wrap; color: #1a3a2a;
  background: #f0fdf4; border-radius: var(--radius-sm);
  padding: 1rem; margin-top: .5rem;
  border: 1px solid #bbf7d0;
}

/* Study actions */
#study-actions { display: flex; flex-direction: column; gap: .75rem; }

.btn-reveal {
  width: 100%; padding: .85rem;
  background: var(--surface); color: var(--primary);
  border: 2px solid var(--primary); border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 700; cursor: pointer;
  transition: all .15s; font-family: inherit;
}
.btn-reveal:hover { background: var(--primary); color: #fff; }

.rating-area { display: flex; flex-direction: column; gap: .6rem; }
.rating-label { text-align: center; font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

.rating-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

.btn-rate {
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  padding: .85rem .5rem; border-radius: var(--radius-sm);
  border: 2px solid var(--border); background: var(--surface);
  cursor: pointer; transition: all .12s; font-family: inherit;
}
.btn-rate:active { transform: scale(.96); }
.btn-rate:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.r-icon { font-size: 1.3rem; line-height: 1; }
.r-text { font-size: .78rem; font-weight: 700; color: var(--text); }

.r1 { border-color: #fecaca; }
.r1:hover:not(:disabled) { background: #fff1f2; border-color: #f87171; }
.r1 .r-icon { color: #ef4444; }

.r2 { border-color: #fed7aa; }
.r2:hover:not(:disabled) { background: #fff7ed; border-color: #fb923c; }
.r2 .r-icon { color: #f97316; }

.r3 { border-color: #bbf7d0; }
.r3:hover:not(:disabled) { background: #f0fdf4; border-color: #4ade80; }
.r3 .r-icon { color: #22c55e; }

.r4 { border-color: #bae6fd; }
.r4:hover:not(:disabled) { background: #f0f9ff; border-color: #38bdf8; }
.r4 .r-icon { color: #0ea5e9; }

/* ════════════════════════════════════════════════════════
   DONE
════════════════════════════════════════════════════════ */
#screen-done {
  align-items: center; justify-content: center;
  background: var(--bg); padding: 1.5rem;
}
.done-wrap { width: 100%; max-width: 420px; }
.done-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 2.5rem 2rem;
  text-align: center; display: flex; flex-direction: column; gap: 1rem; align-items: center;
}
.done-emoji { font-size: 3.5rem; }
.done-card h2 { font-size: 1.5rem; font-weight: 800; }
.done-msg { color: var(--muted); font-size: .95rem; }
.done-stats {
  display: flex; gap: .75rem; width: 100%;
}
.done-stat {
  flex: 1; background: var(--bg); border-radius: var(--radius-sm);
  padding: .75rem; text-align: center;
}
.done-stat-num { display: block; font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.done-stat-label { display: block; font-size: .75rem; color: var(--muted); margin-top: .15rem; }

/* ── Responsive ───────────────────────────────────────── */
@media (min-width: 560px) {
  .rating-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 400px) {
  .today-banner { flex-direction: column; align-items: flex-start; }
  .btn-banner   { width: 100%; text-align: center; }
}

/* Overrides (avoid charset issues in older sections) */
.custom-checkbox::after { content: '✓' !important; }
.select-subtopic-item.subsection { padding-left: 2.25rem; }
.select-subtopic-item.all .subtopic-name { font-weight: 700; }
