/* ==========================================================================
   Redovalnica 7 — theme.css
   The whole design system (app + login). Mobile-first.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

/* ==========================================================================
   1. Tokens
   ========================================================================== */
:root {
  color-scheme: light;

  /* Brand */
  --primary: #5b5bd6;
  --primary-2: #7c5cff;
  --primary-strong: #4646c0;
  --primary-soft: #ecebff;
  --primary-contrast: #ffffff;
  --primary-gradient: linear-gradient(135deg, #5b5bd6 0%, #7c5cff 100%);
  --accent: #ff9f43;
  --accent-2: #ff6b6b;
  --accent-soft: #fff1e3;
  --accent-gradient: linear-gradient(135deg, #ffb547 0%, #ff7a59 100%);
  --gold: #f5b301;
  --gold-gradient: linear-gradient(135deg, #ffd86b 0%, #f5b301 45%, #ff9f43 100%);

  /* Surfaces & text */
  --bg: #f5f4ff;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, #ffeedd 0%, transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, #e7e5ff 0%, transparent 60%),
                 #f5f4ff;
  --surface: #ffffff;
  --surface-2: #f8f7ff;
  --surface-3: #efeefb;
  --surface-glass: rgba(255, 255, 255, 0.72);
  --header-bg: rgba(245, 244, 255, 0.78);
  --border: #e4e2f5;
  --border-strong: #cfcceb;
  --text: #22213a;
  --text-2: #4a4866;
  --muted: #77759a;
  --input-bg: #ffffff;
  --overlay: rgba(25, 22, 60, 0.45);

  /* Status */
  --success: #1fae6b;
  --success-soft: #e2f7ec;
  --danger: #e5484d;
  --danger-strong: #c8353a;
  --danger-soft: #fde8e8;
  --warning: #f59e0b;
  --warning-soft: #fff4dc;
  --info: #3b82f6;
  --info-soft: #e5efff;

  /* Grades: solid (rings/bars), bg + fg (pills) */
  --g0: #a3a1ba;  --g0-bg: #eeedf5;  --g0-fg: #5f5d7a;
  --g1: #ef4444;  --g1-bg: #fde4e4;  --g1-fg: #b91c1c;
  --g2: #f97316;  --g2-bg: #ffead9;  --g2-fg: #c2410c;
  --g3: #f5b301;  --g3-bg: #fff4cc;  --g3-fg: #a16207;
  --g4: #14b8a6;  --g4-bg: #d8f6f1;  --g4-fg: #0f766e;
  --g5: #22c55e;  --g5-bg: #dcf8e6;  --g5-fg: #15803d;

  /* Ring */
  --ring-track: #e9e7f7;
  --ring-color: var(--primary);

  /* Shape & elevation */
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(40, 30, 110, 0.06), 0 1px 3px rgba(40, 30, 110, 0.05);
  --shadow: 0 2px 4px rgba(40, 30, 110, 0.05), 0 8px 24px -6px rgba(40, 30, 110, 0.12);
  --shadow-lg: 0 4px 10px rgba(40, 30, 110, 0.08), 0 24px 48px -12px rgba(40, 30, 110, 0.25);
  --shadow-primary: 0 6px 16px -4px rgba(91, 91, 214, 0.55);
  --focus-ring: 0 0 0 3px rgba(124, 92, 255, 0.45);

  /* Layout */
  --gutter: 16px;
  --max-w: 1100px;
  --header-h: 60px;
  --bottom-nav-h: 64px;
  --sidebar-w: 240px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --primary: #8b8bff;
    --primary-2: #a78bfa;
    --primary-strong: #a5a5ff;
    --primary-soft: rgba(139, 139, 255, 0.16);
    --primary-contrast: #ffffff;
    --primary-gradient: linear-gradient(135deg, #6464e6 0%, #8b6cff 100%);
    --accent: #ffb366;
    --accent-2: #ff8a80;
    --accent-soft: rgba(255, 159, 67, 0.15);
    --gold: #ffc940;

    --bg: #12111f;
    --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(255, 140, 80, 0.10) 0%, transparent 60%),
                   radial-gradient(900px 500px at -10% 0%, rgba(124, 92, 255, 0.18) 0%, transparent 60%),
                   #12111f;
    --surface: #1c1b2e;
    --surface-2: #232238;
    --surface-3: #2c2a45;
    --surface-glass: rgba(32, 30, 54, 0.72);
    --header-bg: rgba(18, 17, 31, 0.78);
    --border: #2f2d4a;
    --border-strong: #423f63;
    --text: #eceaff;
    --text-2: #c4c1e6;
    --muted: #9592bb;
    --input-bg: #17162a;
    --overlay: rgba(5, 4, 15, 0.65);

    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.15);
    --danger: #f87171;
    --danger-strong: #ef4444;
    --danger-soft: rgba(248, 113, 113, 0.15);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.15);
    --info: #60a5fa;
    --info-soft: rgba(96, 165, 250, 0.15);

    --g0: #6f6c8f;  --g0-bg: rgba(160, 158, 190, 0.14); --g0-fg: #b5b2d4;
    --g1: #f87171;  --g1-bg: rgba(248, 113, 113, 0.18); --g1-fg: #fca5a5;
    --g2: #fb923c;  --g2-bg: rgba(251, 146, 60, 0.18);  --g2-fg: #fdba74;
    --g3: #fbbf24;  --g3-bg: rgba(251, 191, 36, 0.18);  --g3-fg: #fcd34d;
    --g4: #2dd4bf;  --g4-bg: rgba(45, 212, 191, 0.18);  --g4-fg: #5eead4;
    --g5: #4ade80;  --g5-bg: rgba(74, 222, 128, 0.18);  --g5-fg: #86efac;

    --ring-track: #2c2a45;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 10px 28px -8px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 6px 14px rgba(0, 0, 0, 0.4), 0 28px 56px -12px rgba(0, 0, 0, 0.7);
    --shadow-primary: 0 6px 18px -4px rgba(124, 92, 255, 0.6);
    --focus-ring: 0 0 0 3px rgba(167, 139, 250, 0.55);
  }
}

/* ==========================================================================
   2. Reset & base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  word-break: normal;
}

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; font-weight: 800; color: var(--text); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .75em; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, canvas { max-width: 100%; }
small { font-size: .85em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

::selection { background: var(--primary-soft); color: var(--text); }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--primary-2);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

/* ==========================================================================
   3. Forms
   ========================================================================== */
input, select, textarea, button { font: inherit; color: inherit; }

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--input-bg);
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  transition: border-color .15s, box-shadow .15s, background .15s;
  -webkit-appearance: none;
  appearance: none;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.4; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }

input:hover, select:hover, textarea:hover { border-color: var(--primary); }
input:focus, select:focus, textarea:focus,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }

select {
  padding-right: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}

input[type="color"] {
  width: 56px; height: 44px; padding: 4px;
  border: 1.5px solid var(--border-strong); border-radius: 12px;
  background: var(--input-bg); cursor: pointer;
}
input[type="checkbox"], input[type="radio"] {
  width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer;
}
input[type="range"] { width: 100%; accent-color: var(--primary); }
input[type="date"] { min-width: 0; }

label { font-weight: 700; font-size: .92rem; color: var(--text-2); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > label { display: block; }
.field .hint { margin-top: -2px; }

.form-row { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.form-row > * { min-width: 0; }
@media (min-width: 560px) {
  .form-row { grid-template-columns: 1fr 1fr; }
}

/* ==========================================================================
   4. Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  font-weight: 800; font-size: .95rem; line-height: 1.1;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s var(--ease), box-shadow .15s, background .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary {
  color: var(--primary-contrast);
  background: var(--primary-gradient);
  border-color: transparent;
  box-shadow: var(--shadow-primary);
}
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--primary-soft); color: var(--primary-strong); border-color: transparent; }

.btn-danger {
  color: #fff;
  background: var(--danger);
  border-color: transparent;
  box-shadow: 0 6px 14px -6px rgba(229, 72, 77, .6);
}
.btn-danger:hover { background: var(--danger-strong); border-color: transparent; }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; border-radius: 11px; }
.btn-icon {
  width: 44px; height: 44px; min-height: 44px; padding: 0;
  border-radius: 12px; font-size: 1.15rem;
}
.btn-icon.btn-sm { width: 36px; height: 36px; min-height: 36px; }
/* keep small buttons tappable on touch devices */
@media (pointer: coarse) {
  .btn-sm, .btn-icon.btn-sm { min-height: 44px; }
  .btn-icon.btn-sm { width: 44px; height: 44px; }
}
.btn-block { display: flex; width: 100%; }

/* ==========================================================================
   5. App layout
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "header" "main";
  min-height: 100vh;
  min-height: 100dvh;
}
.app > * { min-width: 0; }

/* Header */
.app-header {
  grid-area: header;
  position: sticky; top: 0; z-index: 40;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  min-height: var(--header-h);
  padding: 8px var(--gutter);
  padding-top: max(8px, env(safe-area-inset-top, 0px));
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.app-header .segmented { order: 3; flex: 1 1 100%; }
.app-header .btn { flex: 0 0 auto; }
.app-header .brand { margin-right: auto; }

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 900; font-size: 1.15rem; letter-spacing: -.01em;
  color: var(--text);
  min-width: 0;
  white-space: nowrap;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .brand-icon, .brand > span:first-child:not(:only-child) {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 11px;
  background: var(--primary-gradient); color: #fff;
  box-shadow: var(--shadow-primary);
  font-size: 1.1rem;
}

/* Segmented control */
.segmented {
  display: flex; gap: 4px;
  padding: 4px;
  background: var(--surface-3);
  border-radius: 14px;
  min-width: 0;
}
.segmented button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 6px 8px;
  font-size: .8rem; font-weight: 800;
  color: var(--text-2);
  background: transparent;
  border: 0; border-radius: 10px;
  cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s, box-shadow .15s;
}
.segmented button:hover { color: var(--primary-strong); }
.segmented button.active {
  color: var(--primary-strong);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
@media (min-width: 640px) {
  .app-header { flex-wrap: nowrap; }
  .app-header .segmented { order: 0; flex: 0 1 auto; margin-left: auto; }
  .app-header .brand { margin-right: 0; }
  .segmented button { font-size: .88rem; padding: 6px 14px; flex: 0 0 auto; }
}

/* Sidebar (desktop only) */
.sidebar { display: none; }

/* Main */
.main {
  grid-area: main;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 20px var(--gutter) calc(var(--bottom-nav-h) + var(--safe-bottom) + 32px);
  min-width: 0;
}

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: flex; justify-content: space-around; align-items: stretch;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 20px -12px rgba(40, 30, 110, .25);
}
.bottom-nav .nav-link {
  flex: 1 1 0;
  flex-direction: column; justify-content: center; gap: 2px;
  min-height: 52px;
  padding: 4px 2px;
  font-size: .72rem;
  border-radius: 14px;
  text-align: center;
}
.bottom-nav .nav-icon { font-size: 1.35rem; line-height: 1; transition: transform .2s var(--ease); }
.bottom-nav .nav-link.active { background: var(--primary-soft); }
.bottom-nav .nav-link.active .nav-icon { transform: translateY(-1px) scale(1.12); }

/* Nav link (shared) */
.nav-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px;
  padding: 10px 14px;
  font-weight: 800;
  color: var(--muted);
  border-radius: 14px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s;
  min-width: 0;
}
.nav-link:hover { color: var(--primary-strong); background: var(--primary-soft); text-decoration: none; }
.nav-link.active { color: var(--primary-strong); }
.nav-icon { flex: 0 0 auto; font-size: 1.25rem; line-height: 1; }
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Desktop layout */
@media (min-width: 900px) {
  .app-header .brand { display: none; }
  .app-header .segmented { margin-right: auto; }
  .app {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "sidebar header" "sidebar main";
  }
  .sidebar {
    grid-area: sidebar;
    display: flex; flex-direction: column; gap: 6px;
    position: sticky; top: 0;
    height: 100vh; height: 100dvh;
    padding: 20px 14px;
    background: var(--surface-glass);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  .sidebar .brand { padding: 4px 10px 18px; font-size: 1.2rem; }
  .sidebar .nav-link.active {
    color: #fff;
    background: var(--primary-gradient);
    box-shadow: var(--shadow-primary);
  }
  .bottom-nav, .fab { display: none !important; }
  .app-header { padding-left: 28px; padding-right: 28px; }
  .main { padding: 28px 28px 48px; }
}

/* ==========================================================================
   6. Page scaffolding & grids
   ========================================================================== */
.page { display: flex; flex-direction: column; gap: 18px; min-width: 0; animation: page-in .3s var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px 16px;
}
.page-title { margin: 0; font-size: 1.55rem; font-weight: 900; letter-spacing: -.015em; min-width: 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (min-width: 900px) { .page-title { font-size: 1.9rem; } }

.grid, .grid-2, .grid-3, .grid-4 {
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1fr);
}
.grid > *, .grid-2 > *, .grid-3 > *, .grid-4 > * { min-width: 0; }
.grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 700px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1000px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
}

/* ==========================================================================
   7. Utilities
   ========================================================================== */
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-width: 0; }
.spacer { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { display: block; font-size: .82rem; color: var(--muted); font-weight: 600; }
.btn-block { width: 100%; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px;
  min-height: 28px;
  font-size: .82rem; font-weight: 800;
  color: var(--primary-strong);
  background: var(--primary-soft);
  border-radius: var(--radius-pill);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis;
}
button.chip { border: 0; cursor: pointer; min-height: 36px; }
.chip.active { background: var(--primary-gradient); color: #fff; }

.subject-dot {
  display: inline-block; flex: 0 0 auto;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--border);
  vertical-align: middle;
}

/* ==========================================================================
   8. Card
   ========================================================================== */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}
.card-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin-bottom: 12px;
}
.card-title { margin: 0; font-size: 1.08rem; font-weight: 800; min-width: 0; flex: 1 1 auto; }
.card-body { min-width: 0; }
@media (min-width: 900px) { .card { padding: 22px; } }

/* ==========================================================================
   9. Stat tile
   ========================================================================== */
.stat {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  min-width: 0;
  position: relative;
  overflow: hidden;
}
.stat-icon {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px;
  font-size: 1.3rem;
  border-radius: 12px;
  background: var(--primary-soft);
  margin-bottom: 4px;
}
.stat-value {
  font-size: 1.6rem; font-weight: 900; line-height: 1.1;
  letter-spacing: -.02em; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-label { font-size: .82rem; font-weight: 700; color: var(--muted); }
.grid-4 > .stat:nth-child(4n+2) .stat-icon { background: var(--accent-soft); }
.grid-4 > .stat:nth-child(4n+3) .stat-icon { background: var(--g5-bg); }
.grid-4 > .stat:nth-child(4n+4) .stat-icon { background: var(--info-soft); }

/* ==========================================================================
   10. Grades
   ========================================================================== */
.grade {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px;
  padding: 0 8px;
  font-weight: 900; font-size: 1rem; line-height: 1;
  color: var(--g0-fg);
  background: var(--g0-bg);
  border: 1.5px solid transparent;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.grade.g0 { color: var(--g0-fg); background: var(--g0-bg); border-color: color-mix(in srgb, var(--g0) 30%, transparent); }
.grade.g1 { color: var(--g1-fg); background: var(--g1-bg); border-color: color-mix(in srgb, var(--g1) 30%, transparent); }
.grade.g2 { color: var(--g2-fg); background: var(--g2-bg); border-color: color-mix(in srgb, var(--g2) 30%, transparent); }
.grade.g3 { color: var(--g3-fg); background: var(--g3-bg); border-color: color-mix(in srgb, var(--g3) 30%, transparent); }
.grade.g4 { color: var(--g4-fg); background: var(--g4-bg); border-color: color-mix(in srgb, var(--g4) 30%, transparent); }
.grade.g5 { color: var(--g5-fg); background: var(--g5-bg); border-color: color-mix(in srgb, var(--g5) 30%, transparent); }
button.grade { cursor: pointer; font-family: inherit; }

.grade-picker {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}
.grade-picker .grade,
.grade-picker button {
  width: 100%; height: auto;
  aspect-ratio: 1 / 1;
  min-height: 48px; max-height: 72px;
  font-size: 1.5rem;
  border-radius: 16px;
  border-width: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s var(--ease), box-shadow .15s, background .15s;
}
.grade-picker .grade:hover { transform: translateY(-2px); }
.grade-picker .grade.selected {
  transform: scale(1.08);
  color: #fff;
  border-color: var(--surface);
  box-shadow: 0 0 0 3px var(--ring-sel, var(--primary)), 0 8px 18px -6px var(--ring-sel, var(--primary));
}
.grade-picker .grade.g1.selected { background: var(--g1); --ring-sel: var(--g1); }
.grade-picker .grade.g2.selected { background: var(--g2); --ring-sel: var(--g2); }
.grade-picker .grade.g3.selected { background: var(--g3); --ring-sel: var(--g3); }
.grade-picker .grade.g4.selected { background: var(--g4); --ring-sel: var(--g4); }
.grade-picker .grade.g5.selected { background: var(--g5); --ring-sel: var(--g5); }
@media (prefers-color-scheme: dark) {
  .grade-picker .grade.selected { color: #12111f; }
}

/* ==========================================================================
   11. Average ring
   ========================================================================== */
.avg-ring {
  --p: 0;
  --size: 96px;
  --thick: 12px;
  position: relative;
  display: inline-grid; place-items: center;
  width: var(--size); height: var(--size);
  flex: 0 0 auto;
  border-radius: 50%;
  background: conic-gradient(var(--ring-color) calc(var(--p) * 1%), var(--ring-track) 0);
  transition: --p .6s var(--ease);
}
.avg-ring::before {
  content: "";
  position: absolute;
  inset: var(--thick);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 2px 6px rgba(40, 30, 110, .08);
}
.avg-ring-value {
  position: relative; z-index: 1;
  font-weight: 900;
  font-size: calc(var(--size) * 0.24);
  letter-spacing: -.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.avg-ring.lg { --size: 140px; --thick: 14px; }
.avg-ring.sm { --size: 56px; --thick: 6px; }
.avg-ring.sm .avg-ring-value { font-size: .9rem; }
.avg-ring.g0 { --ring-color: var(--g0); }
.avg-ring.g1 { --ring-color: var(--g1); }
.avg-ring.g2 { --ring-color: var(--g2); }
.avg-ring.g3 { --ring-color: var(--g3); }
.avg-ring.g4 { --ring-color: var(--g4); }
.avg-ring.g5 { --ring-color: var(--g5); }

@property --p { syntax: '<number>'; inherits: true; initial-value: 0; }

/* ==========================================================================
   12. Progress
   ========================================================================== */
.progress {
  position: relative;
  width: 100%; height: 12px;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0;
  max-width: 100%;
  background: var(--primary-gradient);
  border-radius: inherit;
  transition: width .7s var(--ease);
  position: relative;
}
.progress-bar::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  background-size: 200% 100%;
  animation: shimmer 2.4s linear infinite;
}
.progress.achieved .progress-bar { background: linear-gradient(90deg, var(--g5) 0%, var(--gold) 100%); }
.progress.failed .progress-bar { background: linear-gradient(90deg, var(--danger) 0%, var(--accent-2) 100%); }
.progress.failed .progress-bar::after { display: none; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ==========================================================================
   13. Lists
   ========================================================================== */
.list { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; min-width: 0; }
.list-item {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  min-height: 52px;
  padding: 10px 12px;
  border-radius: 14px;
  background: transparent;
  transition: background .15s;
  min-width: 0;
}
.list-item > * { min-width: 0; }
.list-item:hover { background: var(--surface-2); }
.list > .list-item + .list-item { border-top: 1px solid var(--border); border-radius: 0; }
.list > .list-item:hover { border-radius: 14px; }
.list-item .btn-icon { flex: 0 0 auto; }

/* ==========================================================================
   14. Status pills & goals
   ========================================================================== */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  font-size: .78rem; font-weight: 800;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  color: var(--g0-fg); background: var(--g0-bg);
}
.status-pill.achieved { color: var(--g5-fg); background: var(--g5-bg); }
.status-pill.on-track { color: var(--info); background: var(--info-soft); }
.status-pill.behind   { color: var(--g2-fg); background: var(--g2-bg); }
.status-pill.failed   { color: var(--g1-fg); background: var(--g1-bg); }
.status-pill.no-data  { color: var(--g0-fg); background: var(--g0-bg); }

.reward-card {
  position: relative;
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  min-width: 0;
}
.reward-card.achieved {
  border: 2px solid transparent;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    var(--gold-gradient) border-box;
  animation: gold-glow 2.8s ease-in-out infinite;
}
.reward-card.achieved::after {
  content: "🎁";
  position: absolute; top: -12px; right: 14px;
  font-size: 1.6rem;
  filter: drop-shadow(0 4px 6px rgba(245, 179, 1, .4));
}
@keyframes gold-glow {
  0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(245, 179, 1, 0); }
  50%      { box-shadow: var(--shadow), 0 0 24px 2px rgba(245, 179, 1, .35); }
}

/* ==========================================================================
   15. Badges
   ========================================================================== */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (min-width: 420px) {
  .badge-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
.badge-tile {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  padding: 16px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0;
  transition: transform .2s var(--ease), box-shadow .2s;
}
.badge-tile h3, .badge-tile h4, .badge-tile strong { margin: 0; font-size: .95rem; font-weight: 800; }
.badge-tile p, .badge-tile small { margin: 0; font-size: .8rem; color: var(--muted); }
.badge-icon { font-size: 2.6rem; line-height: 1; display: block; }
.badge-tile.earned {
  background:
    radial-gradient(120% 80% at 50% 0%, var(--accent-soft) 0%, transparent 70%),
    var(--surface);
  border-color: color-mix(in srgb, var(--gold) 45%, var(--border));
  box-shadow: var(--shadow);
}
.badge-tile.earned:hover { transform: translateY(-3px) rotate(-1deg); box-shadow: var(--shadow-lg); }
.badge-tile.earned .badge-icon { filter: drop-shadow(0 4px 8px rgba(255, 159, 67, .35)); }
.badge-tile.locked { opacity: .55; filter: grayscale(1); background: var(--surface-2); box-shadow: none; }

/* ==========================================================================
   16. Bar chart
   ========================================================================== */
.bar-chart {
  display: flex; align-items: flex-end; justify-content: space-around;
  gap: 10px;
  height: 180px;
  padding: 8px 4px 0;
  min-width: 0;
}
.bar {
  flex: 1 1 0;
  min-width: 0;
  max-width: 64px;
  height: 100%;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  gap: 4px;
}
/* simple variant: .bar itself has inline height and no children */
.bar:empty {
  min-height: 4px;
  background: var(--primary-gradient);
  border-radius: 10px 10px 4px 4px;
}
.bar.g1:empty { background: var(--g1); } .bar.g2:empty { background: var(--g2); }
.bar.g3:empty { background: var(--g3); } .bar.g4:empty { background: var(--g4); }
.bar.g5:empty { background: var(--g5); }

.bar-fill {
  width: 100%;
  min-height: 4px;
  max-height: calc(100% - 44px);
  background: var(--primary-gradient);
  border-radius: 10px 10px 4px 4px;
  transition: height .6s var(--ease);
}
.bar.g1 .bar-fill { background: linear-gradient(180deg, color-mix(in srgb, var(--g1) 75%, #fff), var(--g1)); }
.bar.g2 .bar-fill { background: linear-gradient(180deg, color-mix(in srgb, var(--g2) 75%, #fff), var(--g2)); }
.bar.g3 .bar-fill { background: linear-gradient(180deg, color-mix(in srgb, var(--g3) 75%, #fff), var(--g3)); }
.bar.g4 .bar-fill { background: linear-gradient(180deg, color-mix(in srgb, var(--g4) 75%, #fff), var(--g4)); }
.bar.g5 .bar-fill { background: linear-gradient(180deg, color-mix(in srgb, var(--g5) 75%, #fff), var(--g5)); }
.bar-value { font-size: .8rem; font-weight: 800; color: var(--text-2); line-height: 1; font-variant-numeric: tabular-nums; }
.bar-label {
  font-size: .78rem; font-weight: 800; color: var(--muted); line-height: 1.1;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ==========================================================================
   17. Empty state
   ========================================================================== */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  padding: 36px 16px;
  color: var(--muted);
}
.empty > :first-child:not(:only-child) { font-size: 3rem; line-height: 1; margin-bottom: 6px; }
.empty .empty-icon { font-size: 3rem; line-height: 1; margin-bottom: 6px; }
.empty h3, .empty h2, .empty strong { color: var(--text); margin: 0; font-size: 1.1rem; }
.empty p { margin: 0; max-width: 36ch; }
.empty .btn { margin-top: 10px; }

/* ==========================================================================
   18. FAB
   ========================================================================== */
.fab {
  position: fixed; z-index: 44;
  right: var(--gutter);
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px;
  display: grid; place-items: center;
  font-size: 1.8rem; font-weight: 800; line-height: 1;
  color: #fff;
  background: var(--primary-gradient);
  border: 0; border-radius: 50%;
  box-shadow: var(--shadow-primary), var(--shadow-lg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s var(--ease), filter .15s;
}
.fab:hover { filter: brightness(1.08); }
.fab:active { transform: scale(.92); }

/* ==========================================================================
   19. Modal
   ========================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in .2s ease-out;
}
.modal {
  width: 100%;
  max-height: 90vh; max-height: 90dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-lg);
  padding-bottom: var(--safe-bottom);
  overflow: hidden;
  animation: sheet-up .3s var(--ease);
}
.modal::before {
  content: ""; display: block; flex: 0 0 auto;
  width: 40px; height: 5px; margin: 10px auto 0;
  border-radius: 3px; background: var(--border-strong);
}
.modal-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px 8px;
}
.modal-header h2, .modal-header h3 { margin: 0; font-size: 1.2rem; flex: 1 1 auto; min-width: 0; }
.modal-body {
  padding: 8px 20px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  min-height: 0;
}
.modal-actions {
  display: flex; flex-wrap: wrap-reverse; gap: 10px; justify-content: flex-end;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-actions .btn { flex: 1 1 auto; }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal {
    max-width: 520px;
    border-radius: var(--radius-lg);
    padding-bottom: 0;
    animation: pop-in .25s var(--ease);
  }
  .modal::before { display: none; }
  .modal-header { padding-top: 20px; }
  .modal-actions .btn { flex: 0 0 auto; }
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   20. Toasts
   ========================================================================== */
.toast-container {
  position: fixed; z-index: 120;
  left: var(--gutter); right: var(--gutter);
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
  display: flex; flex-direction: column-reverse; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  width: 100%; max-width: 420px;
  padding: 12px 16px;
  font-weight: 700; font-size: .95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--info);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  animation: toast-in-up .3s var(--ease);
}
.toast.success { border-left-color: var(--success); }
.toast.success::before { content: "✅"; }
.toast.error   { border-left-color: var(--danger); }
.toast.error::before { content: "⚠️"; }
.toast.info    { border-left-color: var(--info); }
.toast.info::before { content: "💡"; }
.toast.hide, .toast.leaving { opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }

@media (min-width: 900px) {
  .toast-container {
    top: calc(var(--header-h) + 16px); bottom: auto;
    left: 50%; right: auto; transform: translateX(-50%);
    width: min(420px, calc(100vw - 32px));
    flex-direction: column;
  }
  .toast { animation-name: toast-in-down; }
}
@keyframes toast-in-up { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toast-in-down { from { opacity: 0; transform: translateY(-16px) scale(.97); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   21. Login
   ========================================================================== */
.login-page {
  position: relative;
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px var(--gutter);
  overflow: hidden;
  background:
    radial-gradient(800px 500px at 0% 0%, #c7c3ff 0%, transparent 60%),
    radial-gradient(700px 500px at 100% 100%, #ffd2b3 0%, transparent 60%),
    linear-gradient(135deg, #eef0ff 0%, #f6ecff 50%, #fff3e8 100%);
}
.login-page::before,
.login-page::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .7;
  pointer-events: none;
  animation: blob 14s ease-in-out infinite alternate;
}
.login-page::before {
  width: 340px; height: 340px;
  top: -80px; left: -60px;
  background: radial-gradient(circle, #7c5cff 0%, #5b5bd6 70%);
}
.login-page::after {
  width: 300px; height: 300px;
  bottom: -70px; right: -50px;
  background: radial-gradient(circle, #ffb547 0%, #ff7a59 70%);
  animation-delay: -7s;
}
@keyframes blob {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(40px, 30px) scale(1.15); }
}
@media (prefers-color-scheme: dark) {
  .login-page {
    background:
      radial-gradient(800px 500px at 0% 0%, rgba(124, 92, 255, .35) 0%, transparent 60%),
      radial-gradient(700px 500px at 100% 100%, rgba(255, 122, 89, .22) 0%, transparent 60%),
      linear-gradient(135deg, #14132a 0%, #1a1530 50%, #1d1424 100%);
  }
  .login-page::before, .login-page::after { opacity: .45; }
}

.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px;
  padding: 32px 24px;
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid color-mix(in srgb, #fff 55%, transparent);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
}
@media (prefers-color-scheme: dark) {
  .login-card { border-color: rgba(255, 255, 255, .08); }
}
@media (min-width: 480px) { .login-card { padding: 40px 36px; } }
.login-card form { display: flex; flex-direction: column; gap: 4px; }
.login-card .btn-primary { margin-top: 8px; min-height: 50px; font-size: 1.05rem; }

.login-logo {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  margin-bottom: 24px;
  font-size: 3.4rem; line-height: 1;
}
.login-logo > * { font-size: initial; }
.login-logo h1, .login-logo .title {
  margin: 8px 0 0;
  font-size: 1.6rem; font-weight: 900; letter-spacing: -.02em;
  background: var(--primary-gradient);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.login-logo p { margin: 0; font-size: .95rem; color: var(--muted); }

.error-text {
  color: var(--danger);
  font-weight: 700; font-size: .9rem;
  min-height: 1.3em;
  margin: 4px 0;
}
.login-card.shake { animation: shake .45s cubic-bezier(.36, .07, .19, .97) both; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* ==========================================================================
   22. Confetti
   ========================================================================== */
.confetti-canvas {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  pointer-events: none;
  z-index: 9999;
}

/* ==========================================================================
   23. Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .progress-bar::after, .login-page::before, .login-page::after { animation: none !important; }
  .reward-card.achieved { animation: none; box-shadow: var(--shadow), 0 0 18px 1px rgba(245, 179, 1, .3); }
}
