:root {
  --bg-1: #e8eef8;
  --bg-2: #f0e6f6;
  --bg-3: #e6f0fa;
  --glass: rgba(255, 255, 255, 0.12);
  --glass-strong: rgba(255, 255, 255, 0.22);
  --glass-border: rgba(255, 255, 255, 0.35);
  --glass-highlight: rgba(255, 255, 255, 0.5);
  --text: #1a1a2e;
  --text-muted: #5a5a7a;
  --primary: #5b5bf0;
  --primary-light: #8b8bf8;
  --shadow: 0 8px 32px rgba(30, 30, 80, 0.08);
  --shadow-lg: 0 20px 60px rgba(30, 30, 80, 0.12);
  --radius: 22px;
  --radius-sm: 16px;
  --blur: 40px;
  --nav-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg-1: #0a0a14;
  --bg-2: #12121f;
  --bg-3: #1a1030;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-strong: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.14);
  --glass-highlight: rgba(255, 255, 255, 0.2);
  --text: #f0f0f8;
  --text-muted: #a0a0c0;
  --primary: #8b8bf8;
  --primary-light: #a5a5ff;
  --shadow: 0 8px 32px rgba(0,0,0,0.35);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.45);
}

[data-theme="midnight"] {
  --bg-1: #020617;
  --bg-2: #0f172a;
  --bg-3: #1e1b4b;
  --glass: rgba(255, 255, 255, 0.05);
  --glass-strong: rgba(255, 255, 255, 0.09);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-highlight: rgba(255, 255, 255, 0.18);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #818cf8;
  --primary-light: #a5b4fc;
  --shadow: 0 8px 32px rgba(0,0,0,0.45);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.55);
}

[data-theme="warm"] {
  --bg-1: #fef3e2;
  --bg-2: #fce7f3;
  --bg-3: #fef9c3;
  --glass: rgba(255, 255, 255, 0.2);
  --glass-strong: rgba(255, 255, 255, 0.35);
  --glass-border: rgba(255, 255, 255, 0.4);
  --glass-highlight: rgba(255, 255, 255, 0.6);
  --text: #292524;
  --text-muted: #78716c;
  --primary: #ea580c;
  --primary-light: #fb923c;
  --shadow: 0 8px 32px rgba(120,53,15,0.08);
  --shadow-lg: 0 20px 60px rgba(120,53,15,0.12);
}

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

html, body {
  font-family: Tahoma, 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  min-height: 100%;
  min-height: 100dvh;
  color: var(--text);
  line-height: 1.7;
  background: linear-gradient(145deg, var(--bg-1), var(--bg-2), var(--bg-3));
  background-attachment: fixed;
  transition: background 0.4s, color 0.3s;
  padding-top: var(--safe-top);
}

body.has-custom-bg {
  background-size: cover !important;
  background-position: center !important;
  background-attachment: fixed !important;
}

body.has-custom-bg::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.25);
  pointer-events: none;
  z-index: 0;
}

.page { display: none; min-height: 100dvh; position: relative; z-index: 1; padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px); }
.page.active { display: block; }

/* Liquid glass */
.liquid-glass {
  background: var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), inset 0 1px 1px var(--glass-highlight), inset 0 -1px 1px rgba(0,0,0,0.04);
}

.liquid-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  font-family: inherit;
  font-size: 1rem;
  background: var(--glass);
  color: var(--text);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  box-shadow: inset 0 1px 0 var(--glass-highlight);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.liquid-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,91,240,0.2), inset 0 1px 0 var(--glass-highlight);
}

/* Login orbs */
.login-bg {
  position: fixed;
  inset: 0;
  background: #050510;
  overflow: hidden;
  z-index: 0;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  animation: orbFloat 12s ease-in-out infinite;
}
.orb1 { width: 280px; height: 280px; background: #7c3aed; top: -5%; right: -10%; animation-duration: 14s; }
.orb2 { width: 220px; height: 220px; background: #2563eb; bottom: 10%; left: -8%; animation-duration: 11s; animation-delay: -2s; }
.orb3 { width: 180px; height: 180px; background: #db2777; top: 40%; left: 50%; animation-duration: 16s; animation-delay: -5s; }
.orb4 { width: 140px; height: 140px; background: #0891b2; bottom: -5%; right: 20%; animation-duration: 13s; animation-delay: -8s; }

@keyframes orbFloat {
  0%, 100% { transform: translate(0,0) scale(1); opacity: 0.5; }
  25% { transform: translate(30px,-40px) scale(1.15); opacity: 0.7; }
  50% { transform: translate(-20px,20px) scale(0.9); opacity: 0.45; }
  75% { transform: translate(40px,10px) scale(1.1); opacity: 0.65; }
}

.login-container {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}
.login-card {
  border-radius: 28px;
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  color: #f0f0f8;
}
.login-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; color: #fff; }
.login-subtitle { color: rgba(255,255,255,0.55); font-size: 0.9rem; margin-bottom: 24px; }
.login-card .input-group label { color: rgba(255,255,255,0.6); }
.login-card .liquid-input {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.18);
  color: #fff;
}
.login-card .liquid-input::placeholder { color: rgba(255,255,255,0.35); }
.login-hint { margin-top: 20px; font-size: 0.78rem; color: rgba(255,255,255,0.4); }
.login-hint b { color: rgba(255,255,255,0.7); }

.login-avatar-wrap {
  width: 80px; height: 80px;
  margin: 0 auto 16px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.1);
  display: flex; align-items: center; justify-content: center;
}
.login-avatar { width: 100%; height: 100%; object-fit: cover; }
.login-avatar-placeholder { font-size: 36px; }

.input-group { text-align: right; margin-bottom: 16px; }
.input-group label { display: block; font-size: 0.82rem; font-weight: 500; margin-bottom: 6px; color: var(--text-muted); }

.btn-primary {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; border: none; border-radius: 14px;
  font-family: inherit; font-size: 1rem; font-weight: 600;
  cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
  margin-top: 6px;
  box-shadow: 0 4px 20px rgba(91,91,240,0.35);
}
.btn-primary:hover { transform: translateY(-1px); }

.btn-ghost {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  padding: 8px 14px;
  border-radius: 12px;
  font-family: inherit; font-size: 0.85rem;
  cursor: pointer; color: var(--text);
  backdrop-filter: blur(12px);
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--glass-strong); }
.btn-primary-sm {
  padding: 8px 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; border: none; border-radius: 12px;
  font-family: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}

/* Header */
.top-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--glass-strong);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
  position: sticky; top: 0; z-index: 50;
  margin-top: calc(-1 * var(--safe-top));
}
.header-right h2 { font-size: 1.15rem; font-weight: 700; }
.header-sub { font-size: 0.75rem; color: var(--text-muted); }
.header-actions { display: flex; gap: 6px; }

/* Dashboard */
.dashboard-main, .class-main, .profile-main {
  max-width: 720px; margin: 0 auto; padding: 20px 14px 20px;
}
.stats-row { display: flex; gap: 10px; margin-bottom: 20px; }
.stat-card {
  flex: 1; text-align: center; padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--glass);
  backdrop-filter: blur(var(--blur));
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--glass-highlight);
}
.stat-num { display: block; font-size: 1.7rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); }

.day-section {
  background: var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight);
}
.day-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid var(--glass-border);
}
.day-badge {
  width: 40px; height: 40px; color: white; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.day-header h3 { font-size: 1rem; font-weight: 700; }
.day-header p { font-size: 0.7rem; color: var(--text-muted); }
.class-count {
  margin-right: auto; background: var(--glass-strong); color: var(--primary);
  font-size: 0.7rem; font-weight: 600; padding: 3px 10px; border-radius: 20px;
  border: 1px solid var(--glass-border);
}

.class-card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px; border-radius: var(--radius-sm);
  background: var(--glass-strong); border: 1px solid transparent;
  margin-bottom: 8px; cursor: pointer; transition: all 0.2s;
}
.class-card:hover { border-color: var(--primary-light); transform: translateY(-2px); }
.class-card:last-child { margin-bottom: 0; }
.class-time { min-width: 85px; text-align: center; }
.class-time .time { font-weight: 700; font-size: 0.9rem; color: var(--primary); }
.class-time .duration { font-size: 0.65rem; color: var(--text-muted); }
.class-info h4 { font-size: 0.9rem; font-weight: 600; }
.class-info .teacher { font-size: 0.75rem; color: var(--text-muted); }
.class-info .codes { font-size: 0.65rem; color: var(--text-muted); opacity: 0.7; margin-top: 2px; }
.color-bar { width: 4px; align-self: stretch; border-radius: 4px; flex-shrink: 0; }

.class-meta {
  background: var(--glass); border-radius: var(--radius-sm);
  padding: 12px 16px; margin-bottom: 14px;
  border: 1px solid var(--glass-border); font-size: 0.85rem; color: var(--text-muted);
}

.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.tab {
  flex-shrink: 0; padding: 9px 14px;
  border: 1px solid var(--glass-border); background: var(--glass);
  border-radius: 12px; font-family: inherit; font-size: 0.85rem;
  font-weight: 500; cursor: pointer; color: var(--text-muted);
  backdrop-filter: blur(8px); transition: all 0.15s;
}
.tab.active {
  background: var(--glass-strong); color: var(--primary);
  border-color: var(--primary-light); font-weight: 600;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

.content-card {
  border-radius: var(--radius); padding: 20px;
}
.content-card h3 { font-size: 1rem; margin-bottom: 6px; }
.hint-text { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 12px; }
textarea.liquid-input { min-height: 160px; resize: vertical; line-height: 1.8; }
.save-hint { font-size: 0.7rem; color: var(--text-muted); margin-top: 6px; }

/* Checklist */
.checklist { display: flex; flex-direction: column; gap: 8px; }
.check-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px; border-radius: 12px;
  background: var(--glass-strong); border: 1px solid var(--glass-border);
  cursor: pointer; transition: opacity 0.2s;
}
.check-item.done { opacity: 0.5; }
.check-item.done .check-text { text-decoration: line-through; }
.check-box {
  width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid var(--primary); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: white; margin-top: 1px;
  transition: background 0.15s;
}
.check-item.done .check-box { background: var(--primary); }
.check-text { font-size: 0.9rem; flex: 1; }

.jozve-preview { text-align: center; padding: 36px 20px; }
.jozve-preview p { color: var(--text-muted); margin-bottom: 16px; }

/* Jozve page animation */
#jozve-page {
  animation: slideUp 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: translateY(0); }
}

.jozve-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: calc(12px + var(--safe-top));
  background: var(--glass-strong);
  backdrop-filter: blur(30px);
  border-bottom: 1px solid var(--glass-border);
  position: sticky; top: 0; z-index: 50;
  margin-top: calc(-1 * var(--safe-top));
}
.jozve-header h1 { font-size: 1.1rem; font-weight: 700; }
.jozve-article { max-width: 780px; margin: 0 auto; padding: 28px 16px 100px; }
.jozve-article h1 { font-size: 1.7rem; font-weight: 800; margin-bottom: 4px; }
.jozve-article .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; }
.jozve-article h2 { font-size: 1.25rem; font-weight: 700; margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--glass-border); }
.jozve-article h3 { font-size: 1rem; font-weight: 600; margin: 18px 0 6px; color: var(--primary); }
.jozve-article p { margin-bottom: 10px; }
.jozve-article ul, .jozve-article ol { margin: 8px 0 12px; padding-right: 20px; }
.jozve-article li { margin-bottom: 4px; }
.jozve-article blockquote {
  background: var(--glass); border-right: 4px solid var(--primary);
  padding: 12px 16px; margin: 14px 0; border-radius: 0 12px 12px 0; font-style: italic;
}
.jozve-article .info-box {
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: 14px; padding: 16px; margin: 16px 0;
}
.jozve-article .info-box h4 { font-size: 0.9rem; margin-bottom: 4px; color: var(--primary); }
.jozve-article table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 0.88rem; }
.jozve-article th, .jozve-article td { border: 1px solid var(--glass-border); padding: 8px 12px; text-align: right; }
.jozve-article th { background: var(--glass-strong); font-weight: 600; }

/* Manage */
.manage-list { display: flex; flex-direction: column; gap: 8px; }
.manage-card {
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
  backdrop-filter: blur(var(--blur));
}
.manage-card .color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.manage-info { flex: 1; min-width: 0; }
.manage-info h4 { font-size: 0.9rem; font-weight: 600; }
.manage-info p { font-size: 0.75rem; color: var(--text-muted); }
.manage-actions { display: flex; gap: 4px; }
.btn-icon {
  width: 34px; height: 34px; border: 1px solid var(--glass-border);
  background: var(--glass-strong); border-radius: 10px;
  cursor: pointer; font-size: 0.95rem;
  display: flex; align-items: center; justify-content: center;
}
.btn-icon.danger:hover { background: rgba(239,68,68,0.15); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 14px; overflow-y: auto; }
.modal.hidden { display: none; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(5,5,20,0.55); backdrop-filter: blur(8px); }
.modal-card {
  position: relative; border-radius: 24px; padding: 24px 20px;
  width: 100%; max-width: 500px; margin-bottom: 40px; color: var(--text);
}
.modal-card h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 16px; }
.form-row { display: flex; gap: 10px; }
.form-row .input-group { flex: 1; }
.modal-card select, .modal-card input[type="color"] {
  width: 100%; padding: 12px; border: 1px solid var(--glass-border);
  border-radius: 14px; font-family: inherit; font-size: 0.95rem;
  background: var(--glass); color: var(--text);
}
.modal-card input[type="color"] { height: 44px; padding: 3px; cursor: pointer; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
.modal-actions .btn-primary { width: auto; padding: 11px 24px; }

/* Profile */
.profile-card { border-radius: var(--radius); padding: 24px 20px; }
.profile-avatar-section { text-align: center; margin-bottom: 20px; }
.profile-avatar-wrap {
  width: 90px; height: 90px; border-radius: 50%; overflow: hidden;
  margin: 0 auto 12px; border: 2px solid var(--glass-border);
  background: var(--glass-strong);
  display: flex; align-items: center; justify-content: center;
}
.profile-avatar-wrap img { width: 100%; height: 100%; object-fit: cover; }
#profile-avatar-emoji { font-size: 40px; }
.avatar-upload-btn { display: inline-block; cursor: pointer; }
.theme-options-inline { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-btn {
  padding: 10px 6px; border-radius: 14px; border: 1.5px solid var(--glass-border);
  background: var(--glass); cursor: pointer; font-family: inherit;
  font-size: 0.75rem; font-weight: 500; color: var(--text); text-align: center;
}
.theme-btn.active, .theme-btn:hover { border-color: var(--primary); }
.theme-btn .swatch { width: 100%; height: 24px; border-radius: 8px; margin-bottom: 4px; }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 80;
  display: flex; justify-content: space-around; align-items: center;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--glass-strong);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border-top: 1px solid var(--glass-border);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; cursor: pointer; padding: 8px;
  font-family: inherit; color: var(--text-muted); transition: color 0.15s;
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 1.35rem; }
.nav-label { font-size: 0.68rem; font-weight: 500; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }

@media (max-width: 500px) {
  .form-row { flex-direction: column; gap: 0; }
  .class-card { flex-direction: column; gap: 6px; }
  .class-time { text-align: right; display: flex; gap: 8px; align-items: baseline; }
}
