:root {
  color-scheme: light;
  --bg: #f4f1eb;
  --bg-top: #fbf9f4;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-strong: #ffffff;
  --panel-border: rgba(92, 64, 148, 0.12);
  --text: #221d2d;
  --muted: #625c6d;
  --muted-soft: #847d92;
  --purple: #7c3aed;
  --purple-dark: #5b21b6;
  --purple-soft: #e2dff0;
  --gold: #f4b400;
  --gold-soft: #fff1c2;
  --stone: #f1ece4;
  --danger-soft: #f8eef2;
  --shadow-lg: 0 28px 50px rgba(36, 28, 52, 0.12);
  --shadow-md: 0 14px 28px rgba(36, 28, 52, 0.08);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg-top);
}

a,
button,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0.25rem 0 5rem;
}

.hero {
  margin-bottom: 1rem;
}

.hero-logo {
  display: block;
  max-width: min(720px, 100%);
  height: auto;
  mix-blend-mode: multiply;
  margin: 0 auto;
}

.eyebrow,
.section-label,
.label,
.history-count,
.status-message {
  letter-spacing: 0.04em;
}

.eyebrow,
.section-label,
.label {
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted-soft);
}

.hero h1 {
  max-width: 14ch;
  margin: 0 0 0.9rem;
  font-size: clamp(2.6rem, 6vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.intro,
.panel-copy,
.filter-copy p:last-child,
.talk-speaker,
.talk-reference,
.history-count,
.status-message {
  color: var(--muted);
}

.intro {
  max-width: 46rem;
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.7;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat,
.mini-stat {
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.stat {
  padding: 1.35rem;
  background: rgba(255, 255, 255, 0.78);
  border-color: rgba(92, 64, 148, 0.08);
  backdrop-filter: blur(14px);
}

.stat strong,
.mini-stat strong {
  display: block;
  margin-top: 0.35rem;
  font-size: clamp(1.7rem, 4vw, 2.3rem);
  line-height: 1;
}

.stat-primary {
  background: linear-gradient(180deg, #ffffff 0%, #e2dff0 100%);
  border-color: rgba(124, 58, 237, 0.10);
}

.stat-accent {
  background: linear-gradient(180deg, #fffdf6 0%, #ffedb6 100%);
  border-color: rgba(244, 180, 0, 0.28);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.progress-panel,
.mark-studied-panel,
.history-panel,
.favorites-panel {
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.mark-studied-panel {
  display: grid;
  gap: 1.35rem;
}

.mark-studied-button {
  background: linear-gradient(180deg, #f0fdf4 0%, #dcfce7 100%);
  border-color: rgba(22, 163, 74, 0.2);
  color: #15803d;
}

.star-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.1em;
  margin-right: 0.4em;
  flex-shrink: 0;
}

.favorite-button .star-icon,
.history-favorite-button .star-icon {
  transition: fill 160ms ease, stroke 160ms ease;
}

.btn-favorited {
  background: linear-gradient(180deg, #fffdf6 0%, var(--gold-soft) 100%);
  border-color: rgba(244, 180, 0, 0.35);
  color: #92600a;
}

.clear-filters-button {
  align-self: start;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--purple-dark);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 140ms ease, transform 0ms;
}

.clear-filters-button:hover {
  color: var(--purple);
  transform: none;
}

.secondary-button.reset-pending {
  background: linear-gradient(180deg, #fff8f0 0%, #ffe8cc 100%);
  border-color: rgba(180, 90, 0, 0.25);
  color: #92400e;
}

.actions-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.actions-panel button {
  flex: 1 1 240px;
}

.draw-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
  margin-bottom: 1rem;
  overflow: hidden;
}

.draw-panel-left {
  display: grid;
  gap: 1.35rem;
  align-content: start;
  padding: 1.5rem;
  border-right: 1px solid var(--panel-border);
}

.draw-panel-right {
  display: grid;
  gap: 1rem;
  align-content: start;
  padding: 1.5rem;
}

.progress-header,
.panel-heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.9rem;
  align-items: end;
}

.panel-title {
  margin: 0.25rem 0 0;
  font-size: 1.3rem;
  line-height: 1.15;
}

.progress-copy {
  color: var(--text);
  font-size: 0.95rem;
}

.progress-track {
  width: 100%;
  height: 14px;
  margin-top: 1rem;
  border-radius: 999px;
  overflow: hidden;
  background: #d3cfdf;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--purple-dark) 0%, var(--purple) 100%);
  transition: width 200ms ease;
}

.year-progress {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(109, 90, 157, 0.12);
}

.year-progress-fill {
  background: linear-gradient(90deg, #db9d00 0%, var(--gold) 100%);
}


.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: end;
}

.filter-field {
  display: grid;
  gap: 0.55rem;
}

select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

select {
  width: 100%;
  appearance: none;
  border: 1px solid rgba(92, 64, 148, 0.14);
  border-radius: 1rem;
  padding: 0.95rem 2.5rem 0.95rem 1rem;
  color: var(--text);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23625c6d' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 1rem center,
    linear-gradient(180deg, #ffffff 0%, #e8e6f2 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.mini-stat {
  padding: 1.05rem 1.15rem;
  background: linear-gradient(180deg, #f4f3f8 0%, #e2dff0 100%);
  border-color: rgba(124, 58, 237, 0.10);
}

button {
  border: none;
  border-radius: 999px;
  padding: 1rem 1.3rem;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
  box-shadow: none;
}

button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
  transition-duration: 60ms;
}

.draw-button-wrapper {
  width: 100%;
}

.draw-button-wrapper #draw-button {
  width: 100%;
}

.primary-button {
  background: linear-gradient(135deg, var(--purple-dark) 0%, var(--purple) 100%);
  color: #ffffff;
  box-shadow: 0 16px 28px rgba(91, 33, 182, 0.28);
}

.secondary-button {
  background: linear-gradient(180deg, #ffffff 0%, #f4efff 100%);
  color: var(--text);
  border: 1px solid rgba(92, 64, 148, 0.12);
}

.status-message {
  margin: 0;
  min-height: 1.3rem;
  font-size: 0.95rem;
}

.empty-state,
.talk-card {
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  background: linear-gradient(180deg, #ffffff 0%, #eceaf4 100%);
  border: 1px solid rgba(92, 64, 148, 0.08);
}

.empty-state {
  text-align: center;
  padding: 2.25rem 1.4rem;
}

.empty-state h3,
.talk-card h3 {
  margin: 0 0 0.55rem;
  font-size: clamp(1.5rem, 3vw, 2rem);
  line-height: 1.1;
}

.empty-state p {
  max-width: 38rem;
  margin: 0 auto;
  color: var(--muted);
  line-height: 1.6;
}

.talk-session {
  margin: 0 0 0.45rem;
  color: var(--purple-dark);
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.talk-speaker,
.talk-reference {
  margin: 0.3rem 0;
  font-size: 1rem;
}

.talk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  align-items: center;
  margin-top: 1.1rem;
}

.favorite-button {
  flex: 0 1 auto;
}

.talk-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  color: var(--purple-dark);
  font-weight: 700;
  text-decoration: none;
}

.talk-link:hover {
  text-decoration: underline;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.history-list {
  list-style: none;
  margin: 1.1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.8rem;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.history-list::-webkit-scrollbar {
  width: 6px;
}

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--purple-soft);
  border-radius: 999px;
}

.history-list::-webkit-scrollbar-thumb:hover {
  background: var(--purple);
}

.history-list li {
  padding: 1rem 1.05rem;
  border-radius: 1rem;
  background: var(--panel-strong);
  border: 1px solid rgba(92, 64, 148, 0.08);
  box-shadow: 0 10px 18px rgba(36, 28, 52, 0.04);
  line-height: 1.5;
}

.history-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: start;
}

.history-copy {
  flex: 1 1 0;
}

.history-favorite-button {
  flex: 0 0 auto;
  padding: 0.6rem 0.9rem;
  font-size: 0.88rem;
}

.history-talk-link {
  color: var(--text);
  text-decoration: none;
}

.history-talk-link:hover {
  color: var(--purple-dark);
  text-decoration: underline;
}

.favorite-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: start;
}

.favorite-copy {
  flex: 1 1 240px;
}

.favorite-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  flex-shrink: 0;
}

.favorite-open-link {
  font-size: 0.9rem;
  min-height: auto;
  padding: 0 0.25rem;
}

.favorite-remove-button {
  flex: 0 0 auto;
  padding: 0.75rem 1rem;
  background: var(--danger-soft);
}

.hidden {
  display: none;
}

/* ─── Auth modal ─────────────────────────────────────────────────────────────── */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(36, 28, 52, 0.65);
  backdrop-filter: blur(8px);
}

.auth-overlay.hidden {
  display: none;
}

.auth-card {
  width: min(440px, 100%);
  background: var(--panel-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  display: grid;
  gap: 1.25rem;
}

.auth-icon {
  width: 4rem;
  height: auto;
  margin: 0 auto;
  display: block;
  mix-blend-mode: multiply;
}

.auth-title {
  margin: 0;
  font-size: 1.5rem;
  text-align: center;
}

.auth-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
  text-align: center;
}

.auth-toggle {
  display: flex;
  background: var(--purple-soft);
  border-radius: 999px;
  padding: 0.25rem;
  gap: 0.25rem;
}

.auth-toggle-btn {
  flex: 1;
  padding: 0.5rem;
  border: none;
  border-radius: 999px;
  background: none;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.auth-toggle-btn:hover {
  transform: none;
  box-shadow: none;
}

.auth-toggle-btn.active {
  background: #ffffff;
  color: var(--purple-dark);
  box-shadow: 0 2px 8px rgba(91, 33, 182, 0.12);
}

.auth-form {
  display: grid;
  gap: 1rem;
}

.auth-field {
  display: grid;
  gap: 0.5rem;
}

.auth-field input {
  width: 100%;
  border: 1px solid rgba(92, 64, 148, 0.14);
  border-radius: 1rem;
  padding: 0.9rem 1rem;
  font: inherit;
  color: var(--text);
  background: linear-gradient(180deg, #ffffff 0%, #e8e6f2 100%);
  box-sizing: border-box;
}

.auth-field input:focus {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.auth-error {
  margin: 0;
  color: #dc2626;
  font-size: 0.875rem;
}

/* ─── User bar ───────────────────────────────────────────────────────────────── */

.user-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.user-email {
  font-size: 0.8rem;
  color: var(--muted);
}

.signout-button {
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: none;
  border: 1px solid rgba(92, 64, 148, 0.2);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}

.signout-button:hover {
  color: var(--text);
  border-color: rgba(92, 64, 148, 0.4);
  transform: none;
  box-shadow: none;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  overflow: visible;
  background: rgba(251, 249, 244, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--panel-border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.65rem 0.5rem;
  background: none;
  border: none;
  border-radius: 0;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted-soft);
  cursor: pointer;
  transition: color 140ms ease;
  letter-spacing: 0.02em;
}

.tab-btn:hover,
.tab-btn.active {
  color: var(--purple);
  transform: none;
  box-shadow: none;
}

.tab-icon {
  width: 1.5rem;
  height: 1.5rem;
  stroke-width: 1.8;
}

.tab-fab-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tab-fab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  background: linear-gradient(135deg, var(--purple-dark) 0%, var(--purple) 100%);
  color: #ffffff;
  border: none;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(91, 33, 182, 0.35);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.tab-fab:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(91, 33, 182, 0.45);
}

.tab-fab:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(91, 33, 182, 0.25);
  transition-duration: 60ms;
}

.tab-fab-icon {
  width: 1rem;
  height: 1rem;
  stroke-width: 2.2;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#talk-card:not(.hidden) {
  animation: card-in 220ms ease forwards;
}

#year-progress-panel:not(.hidden) {
  animation: card-in 200ms ease forwards;
}

:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 3px;
}

@media (max-width: 900px) {
  .stats-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .draw-panel {
    grid-template-columns: 1fr;
  }

  .draw-panel-left {
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
  }

  .controls-grid,
  .library-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 1rem, 1180px);
    padding-top: 1.1rem;
    padding-bottom: calc(5rem + env(safe-area-inset-bottom));
  }

  .hero-badge {
    gap: 0.75rem;
  }

  .hero-icon {
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 0.9rem;
  }

  .hero h1 {
    max-width: none;
  }

  .progress-panel,
  .mark-studied-panel,
  .history-panel,
  .favorites-panel {
    padding: 1.15rem;
  }

  .draw-panel-left,
  .draw-panel-right {
    padding: 1.15rem;
  }

  .stats-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .favorite-item {
    align-items: stretch;
  }

  .favorite-remove-button {
    width: 100%;
  }
}
