:root {
  --bg: #faf9f6;
  --panel: #ffffff;
  --panel-border: rgba(15, 23, 42, 0.06);
  --ink: #15192c;
  --ink-soft: #2d3656;
  --muted: #6b7280;
  --muted-soft: #9ca3af;
  --accent: #1e3a5f;
  --accent-hover: #2b4d7a;
  --accent-ink: #ffffff;
  --again: #b03a3a;
  --hard:  #c47a2c;
  --good:  #3f7a4a;
  --easy:  #2b4d7a;
  --border: #ebe9e4;
  --border-strong: #d6d3cb;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 4px 12px rgba(15, 23, 42, 0.08), 0 20px 48px rgba(15, 23, 42, 0.05);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "ss01", "cv01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

body { display: flex; flex-direction: column; }

h1, h2, h3 {
  letter-spacing: -0.015em;
  line-height: 1.2;
  margin: 0;
}
h1 { font-size: 32px; font-weight: 700; }
h2 { font-size: 24px; font-weight: 700; }
h3 { font-size: 18px; font-weight: 600; }

p { margin: 0; }

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

#topbar .brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}

#topbar nav {
  display: flex;
  gap: 4px;
  align-items: center;
}

#topbar nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: color 120ms var(--ease), background 120ms var(--ease);
}

#topbar nav a:hover { color: var(--ink); }
#topbar nav a.active { color: var(--ink); background: rgba(15, 23, 42, 0.05); }

#app {
  flex: 1;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.005em;
  min-height: 44px;
  transition: background 120ms var(--ease), transform 80ms var(--ease);
}
button:hover { background: var(--accent-hover); }
button:active { transform: translateY(1px); }

button.secondary {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--border-strong);
}
button.secondary:hover { background: rgba(15, 23, 42, 0.03); }

a.link, a.link:visited { color: var(--accent); }

.panel {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 24px;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.muted { color: var(--muted); }
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.small { font-size: 14px; }

/* Login */
.login-card {
  margin-top: 64px;
  text-align: center;
  padding: 48px 32px;
}
.login-card h1 { margin-bottom: 12px; }
.login-card .tagline {
  color: var(--muted);
  margin-bottom: 32px;
  font-size: 16px;
  max-width: 32ch;
  margin-left: auto;
  margin-right: auto;
}

/* Home tiles */
.welcome {
  margin-bottom: 28px;
}
.welcome .greeting {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}
.welcome h1 { margin-top: 4px; }

.tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 540px) {
  .tiles { grid-template-columns: 1fr 1fr; }
}

.tile {
  display: block;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  text-decoration: none;
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease), border-color 140ms var(--ease);
}
.tile:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}
.tile h3 { margin-bottom: 6px; }
.tile p { color: var(--muted); font-size: 14px; }

/* Flashcard */
.session-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}
.session-header strong { color: var(--ink); font-weight: 600; }

.flashcard {
  perspective: 1400px;
  margin: 8px 0 20px;
}
.flashcard .inner {
  position: relative;
  width: 100%;
  min-height: 300px;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}
.flashcard.flipped .inner { transform: rotateY(180deg); }
.flashcard .face {
  position: absolute;
  inset: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  text-align: center;
}
.flashcard .face.back {
  transform: rotateY(180deg);
  justify-content: flex-start;
  align-items: stretch;
  text-align: left;
}
.flashcard .word {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.flashcard .hint {
  color: var(--muted-soft);
  margin-top: 16px;
  font-size: 13px;
  font-weight: 500;
}
.flashcard .definition {
  font-size: 19px;
  line-height: 1.5;
  margin-top: 4px;
  color: var(--ink-soft);
}
.flashcard .example {
  font-style: italic;
  color: var(--muted);
  margin-top: 16px;
  font-size: 15px;
  line-height: 1.5;
  padding-left: 12px;
  border-left: 2px solid var(--border-strong);
}
.flashcard .pos {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.rate-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 20px;
}
.rate-row button {
  padding: 12px 8px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}
.rate-row .key {
  display: inline-block;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
}
.rate-row .again { background: var(--again); }
.rate-row .hard  { background: var(--hard); }
.rate-row .good  { background: var(--good); }
.rate-row .easy  { background: var(--easy); }
.rate-row button:hover { filter: brightness(1.05); }

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
}
.progress-bar > div {
  height: 100%;
  background: var(--accent);
  transition: width 0.35s var(--ease);
}

/* Dashboard / Progress */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
@media (min-width: 540px) {
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
}
.metric {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.metric .label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.metric .value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-top: 6px;
  color: var(--ink);
}

.minutes-chart {
  display: grid;
  grid-template-columns: repeat(30, 1fr);
  gap: 3px;
  align-items: end;
  height: 64px;
  margin: 12px 0 4px;
}
.minutes-chart .bar {
  background: var(--accent);
  min-height: 2px;
  border-radius: 2px;
  opacity: 0.9;
}
.minutes-chart .bar.empty {
  background: var(--border);
  height: 3px !important;
  opacity: 1;
}

.struggling {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.struggling .pill {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
}

/* Session summary */
.session-summary {
  text-align: center;
  padding: 40px 24px;
}
.session-summary h2 {
  margin-bottom: 8px;
}
.session-summary .big {
  font-size: 56px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 16px 0 8px;
  color: var(--ink);
}
/* Alerts (auth errors etc) */
.alert {
  background: #fff4e6;
  border: 1px solid #f3c97a;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  color: #6e4c14;
}
.alert h3 { margin: 0 0 4px 0; font-size: 16px; color: #5a3a0c; }
.alert p { margin: 0; font-size: 14px; line-height: 1.5; }
.alert strong { color: #5a3a0c; }

.session-summary .actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

/* Family dashboard */
.family-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.family-card { display: block; padding: 22px 24px; }
.family-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.family-head h3 { margin: 0; font-size: 20px; }
.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.role-badge.student { background: #eef3fa; color: var(--accent); }
.role-badge.parent { background: var(--bg); color: var(--muted); }
.family-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  text-align: center;
}
.fm-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.fm-sub { font-size: 13px; color: var(--muted); font-weight: 500; }
.fm-label {
  margin-top: 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
