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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #6c63ff;
  --accent-dim: #3d3880;
  --text: #e2e4f0;
  --muted: #7c82a8;
  --radius: 10px;
  --sidebar-w: 220px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ── Login ── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 60% 40%, #1e1b4b 0%, var(--bg) 70%);
}

#login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

#login-card h1 { font-size: 26px; font-weight: 700; color: var(--accent); }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 4px; }

#login-form { display: flex; flex-direction: column; gap: 10px; }

#login-form input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  color: var(--text);
  font-size: 16px; /* prevent iOS zoom */
  outline: none;
  transition: border-color .2s;
  width: 100%;
}

#login-form input:focus { border-color: var(--accent); }

#login-btn {
  margin-top: 4px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}

#login-btn:active { opacity: .8; }
#login-btn:disabled { opacity: .5; cursor: default; }

.error { color: #f87171; font-size: 12px; text-align: center; }

/* ── App layout ── */
#app-screen {
  display: flex;
  height: 100dvh; /* dynamic viewport for mobile browsers */
  overflow: hidden;
  position: relative;
}

/* ── Sidebar overlay (mobile backdrop) ── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99;
}

body.sidebar-open #sidebar-overlay { display: block; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform .25s ease;
  z-index: 100;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo { font-size: 17px; font-weight: 700; color: var(--accent); }

#logout-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  padding: 6px 8px;
  border-radius: 6px;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#logout-btn:active { background: var(--surface2); }

#sem-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sem-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 11px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s;
  min-height: 52px;
  justify-content: center;
}

.sem-item:active { background: var(--surface2); }
.sem-item.active { background: var(--surface2); border-left-color: var(--accent); }

.sem-item-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sem-name { font-weight: 500; font-size: 13px; }
.sem-pct { font-size: 11px; color: var(--muted); }

.sem-mini-bar {
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.sem-mini-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .4s ease;
}

/* ── Main ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Header ── */
#main-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

#sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  min-width: 40px;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#sidebar-toggle:active { background: var(--surface2); }

#sem-title { font-size: 17px; font-weight: 700; flex-shrink: 0; }

#sem-progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

#sem-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  min-width: 40px;
}

#sem-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .4s ease;
}

#sem-progress-label { font-size: 11px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }

/* ── Subject tabs ── */
#subject-tabs {
  display: flex;
  gap: 2px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}

#subject-tabs::-webkit-scrollbar { display: none; }

.sub-tab {
  position: relative;
  padding: 8px 14px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  white-space: nowrap;
  transition: color .15s, background .15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 48px;
  justify-content: center;
  flex-shrink: 0;
}

.sub-tab:active { color: var(--text); }
.sub-tab.active { color: var(--text); background: var(--surface2); }

.sub-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}

.sub-tab-pct { font-size: 10px; color: var(--muted); }
.sub-tab.active .sub-tab-pct { color: var(--accent); }

/* ── Subject content ── */
#subject-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-block { display: flex; flex-direction: column; gap: 8px; }

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  user-select: none;
  min-height: 48px;
}

.item-row:active { background: var(--surface2); }
.item-row.done { border-color: var(--accent-dim); }

.item-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
  position: relative;
}

.item-row input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.item-row input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 2px; left: 5px;
  width: 6px; height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

.item-label { font-size: 14px; }
.item-row.done .item-label { color: var(--muted); text-decoration: line-through; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Mobile ── */
@media (max-width: 680px) {
  #sidebar-toggle { display: flex; }

  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
  }

  body.sidebar-open #sidebar { transform: translateX(0); }
}

/* ── Desktop hover states ── */
@media (hover: hover) {
  .sem-item:hover { background: var(--surface2); }
  .sub-tab:hover { color: var(--text); background: var(--surface2); }
  .item-row:hover { background: var(--surface2); border-color: var(--accent-dim); }
  #logout-btn:hover { color: var(--text); background: var(--surface2); }
}
