@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&family=Battambang:wght@400;700&display=swap');

@supports (-webkit-touch-callout: none) {
  :root { --font-kh: sans-serif; }
}

:root {
  --bg: #f7f7f5;
  --bg2: #ffffff;
  --bg3: #efefec;
  --border: #e4e4e0;
  --text: #1a1a1a;
  --text2: #6b6b6b;
  --text3: #9b9b9b;
  --accent: #4f6ef7;
  --accent-soft: #eef0fe;
  --green: #22c55e;
  --green-soft: #f0fdf4;
  --red: #ef4444;
  --red-soft: #fef2f2;
  --yellow: #f59e0b;
  --yellow-soft: #fffbeb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --font: 'DM Sans', sans-serif;
  --font-kh: 'Battambang', sans-serif;
  --mono: 'DM Mono', monospace;
  --nav-h: 60px;
  --bottom-nav-h: 64px;
}

[data-theme="dark"] {
  --bg: #111110;
  --bg2: #1a1a18;
  --bg3: #222220;
  --border: #2e2e2b;
  --text: #f0f0ee;
  --text2: #a0a09e;
  --text3: #666664;
  --accent: #6b84f8;
  --accent-soft: #1a1f3a;
  --green-soft: #0f2318;
  --red-soft: #2a1010;
  --yellow-soft: #241c08;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }

nav {
  height: var(--nav-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 32px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.nav-brand {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-brand span { color: var(--accent); }

.nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-links a {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  transition: all 0.15s;
}

.nav-links a:hover, .nav-links a.active {
  color: var(--text);
  background: var(--bg3);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.nav-username {
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
}

.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-inner {
  display: flex;
  height: 100%;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text3);
  font-size: 10px;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item.active { color: var(--accent); }

.bottom-nav-icon {
  font-size: 20px;
  line-height: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  min-height: 36px;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { opacity: 0.88; }
.btn-ghost { background: var(--bg3); color: var(--text2); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.theme-toggle {
  background: var(--bg3);
  border: none;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  transition: all 0.15s;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover { color: var(--text); }

.page {
  max-width: 1000px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-sm { max-width: 640px; margin: 0 auto; padding: 32px 24px; }

.page-header {
  margin-bottom: 28px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.4px;
}

.page-sub {
  font-size: 13px;
  color: var(--text2);
  margin-top: 2px;
}

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 12px; }

.card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
  margin-bottom: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 12px;
  color: var(--text2);
  margin-top: 2px;
}

.filters {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  text-decoration: none;
  display: inline-block;
  min-height: 34px;
  -webkit-tap-highlight-color: transparent;
}

.filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.hw-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
  margin: 20px 0 10px;
}

.hw-list { display: flex; flex-direction: column; gap: 8px; }

.hw-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.hw-item:hover { border-color: var(--accent); }
.hw-item.done { opacity: 0.5; }
.hw-item.done .hw-question { text-decoration: line-through; }
.hw-item.overdue { border-left: 3px solid var(--red); }

.hw-type {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
  margin-top: 1px;
  flex-shrink: 0;
}

.hw-body { flex: 1; min-width: 0; }

.hw-subject {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  margin-bottom: 2px;
}

.hw-question {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.hw-date {
  font-size: 12px;
  color: var(--text3);
  margin-top: 3px;
  font-family: var(--mono);
}

.hw-date.overdue { color: var(--red); }

.classes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.class-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: all 0.15s;
  cursor: pointer;
  display: block;
  -webkit-tap-highlight-color: transparent;
}

.class-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.class-code {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--accent);
  font-family: var(--mono);
}

.class-role {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 6px;
}

.class-role.handler { background: var(--yellow-soft); color: var(--yellow); }
.class-role.member { background: var(--bg3); color: var(--text3); }

.class-meta {
  font-size: 12px;
  color: var(--text3);
  margin-top: 10px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.profile-name {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.4px;
}

.profile-grade {
  font-size: 13px;
  color: var(--text2);
  margin-top: 2px;
}

.subject-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.subject-tag {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  background: var(--bg3);
  border-radius: 20px;
  color: var(--text2);
  border: 1px solid var(--border);
}

.exam-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.exam-item:last-child { border-bottom: none; }

.exam-date {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
}

.review-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.review-item:last-child { border-bottom: none; }
.review-subject { font-weight: 600; font-size: 14px; }
.review-lessons { font-size: 13px; color: var(--text2); margin-top: 2px; }
.review-exam { font-size: 12px; color: var(--accent); font-family: var(--mono); margin-top: 4px; }

.landing {
  min-height: calc(100vh - var(--nav-h));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
}

.landing-title {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1.1;
  margin-bottom: 12px;
}

.landing-title span { color: var(--accent); }

.landing-sub {
  font-size: 16px;
  color: var(--text2);
  max-width: 400px;
  margin-bottom: 32px;
  line-height: 1.6;
}

.discord-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #5865f2;
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 15px;
  transition: opacity 0.15s;
}

.discord-btn:hover { opacity: 0.88; }

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text3);
}

.empty-icon { font-size: 32px; margin-bottom: 8px; }
.empty-text { font-size: 14px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 640px) {

  
  .nav-links { display: none; }
  .nav-username { display: none; }
  .nav-avatar { display: none; }
  .btn-ghost.btn-sm { display: none; } 
  .bottom-nav { display: block; }

  
  nav { gap: 0; justify-content: space-between; padding: 0 16px; }
  .nav-right { gap: 8px; }
  .nav-right .btn { display: none; } 
  .nav-right .nav-avatar { display: none; }

  
  .page {
    padding: 20px 16px;
    padding-bottom: calc(var(--bottom-nav-h) + 20px);
  }

  .page-sm {
    padding: 20px 16px;
    padding-bottom: calc(var(--bottom-nav-h) + 20px);
  }

  
  .landing {
    padding-bottom: calc(var(--bottom-nav-h) + 40px);
  }
  
  .landing-title { font-size: 30px; letter-spacing: -1px; }
  .landing-sub { font-size: 15px; }
  
  .page-header { flex-direction: column; gap: 8px; }
  .page-title { font-size: 19px; }
  
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 24px; }
  
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }
  .filters::-webkit-scrollbar { display: none; }
  .filter-btn { flex-shrink: 0; }
  .classes-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .class-card { padding: 14px; }
  .class-code { font-size: 20px; }
  .grid-2 { grid-template-columns: 1fr; }
  
  .hw-item { padding: 12px 14px; gap: 10px; }
  .hw-question { font-size: 13px; }
  
  .card { padding: 14px; }
}

@media (min-width: 641px) and (max-width: 900px) {
  .page { padding: 24px 20px; }
  .nav-username { display: none; }
  .classes-grid { grid-template-columns: repeat(2, 1fr); }
}