@custom-variant dark (&:is(.dark *));

:root {
  --font-size: 16px;
  --background: #FAFAF9;
  --foreground: #1F2937;
  --card: #ffffff;
  --card-foreground: #1F2937;
  --popover: #ffffff;
  --popover-foreground: #1F2937;
  --primary: #5B7FFF;
  --primary-foreground: #ffffff;
  --secondary: #F3F4F6;
  --secondary-foreground: #1F2937;
  --muted: #F3F4F6;
  --muted-foreground: #6B7280;
  --accent: #FF7B54;
  --accent-foreground: #ffffff;
  --destructive: #EF4444;
  --destructive-foreground: #ffffff;
  --success: #10B981;
  --success-foreground: #ffffff;
  --border: #E5E7EB;
  --input: #E5E7EB;
  --input-background: #ffffff;
  --switch-background: #D1D5DB;
  --font-weight-medium: 500;
  --font-weight-normal: 400;
  --ring: #5B7FFF;
  --chart-1: #5B7FFF;
  --chart-2: #FF7B54;
  --chart-3: #10B981;
  --chart-4: #F59E0B;
  --chart-5: #8B5CF6;
  --radius: 0.75rem;
  --app-shell-width: 1120px;
  --app-narrow-width: 760px;
  --sidebar: #ffffff;
  --sidebar-foreground: #1F2937;
  --sidebar-primary: #5B7FFF;
  --sidebar-primary-foreground: #ffffff;
  --sidebar-accent: #F3F4F6;
  --sidebar-accent-foreground: #1F2937;
  --sidebar-border: #E5E7EB;
  --sidebar-ring: #5B7FFF;
}

.dark {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.145 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.145 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.985 0 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.269 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.396 0.141 25.723);
  --destructive-foreground: oklch(0.637 0.237 25.331);
  --border: oklch(0.269 0 0);
  --input: oklch(0.269 0 0);
  --ring: oklch(0.439 0 0);
  --font-weight-medium: 500;
  --font-weight-normal: 400;
  --chart-1: oklch(0.488 0.243 264.376);
  --chart-2: oklch(0.696 0.17 162.48);
  --chart-3: oklch(0.769 0.188 70.08);
  --chart-4: oklch(0.627 0.265 303.9);
  --chart-5: oklch(0.645 0.246 16.439);
  --sidebar: oklch(0.205 0 0);
  --sidebar-foreground: oklch(0.985 0 0);
  --sidebar-primary: oklch(0.488 0.243 264.376);
  --sidebar-primary-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.269 0 0);
  --sidebar-accent-foreground: oklch(0.985 0 0);
  --sidebar-border: oklch(0.269 0 0);
  --sidebar-ring: oklch(0.439 0 0);
}

@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-success: var(--success);
  --color-success-foreground: var(--success-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-input-background: var(--input-background);
  --color-switch-background: var(--switch-background);
  --color-ring: var(--ring);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);
}

@layer base {
  * {
    @apply border-border outline-ring/50;
  }

  body {
    @apply bg-background text-foreground;
  }

  /**
  * Default typography styles for HTML elements (h1-h4, p, label, button, input).
  * These are in @layer base, so Tailwind utility classes (like text-sm, text-lg) automatically override them.
  */

  html {
    font-size: var(--font-size);
  }

  h1 {
    font-size: var(--text-2xl);
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
  }

  h2 {
    font-size: var(--text-xl);
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
  }

  h3 {
    font-size: var(--text-lg);
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
  }

  h4 {
    font-size: var(--text-base);
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
  }

  label {
    font-size: var(--text-base);
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
  }

  button {
    font-size: var(--text-base);
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
  }

  input {
    font-size: var(--text-base);
    font-weight: var(--font-weight-normal);
    line-height: 1.5;
  }
}

/* Flashcard flip animation helpers */
#card-container {
  perspective: 1000px;
}
#card-inner {
  transition: transform 0.6s cubic-bezier(.17,.67,.32,1.02);
  transform-style: preserve-3d;
}
#card-container.is-flipped #card-inner {
  transform: rotateY(180deg);
}
#card-front, #card-back {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
#card-back {
  transform: rotateY(180deg);
}

.flashcard-face {
  padding: 2rem;
  font-size: 48px;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.flashcard-review {
  overflow-wrap: anywhere;
}

html {
  scroll-behavior: smooth;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
}

a {
  text-decoration: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.bg-background { background-color: var(--background); }
.text-primary-foreground { color: var(--primary-foreground); }

.app-container {
  width: 100%;
  max-width: var(--app-shell-width);
  margin-inline: auto;
  padding-inline: 1rem;
}

.app-main {
  padding-block: 1.25rem 2.25rem;
}

.app-page {
  display: grid;
  gap: 1.25rem;
  min-width: 0;
}

.app-page-narrow {
  max-width: var(--app-narrow-width);
  margin-inline: auto;
}

.app-page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.app-page-title {
  color: var(--foreground);
  font-size: clamp(1.5rem, 2vw, 2rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0;
}

.app-page-subtitle {
  margin-top: 0.35rem;
  color: var(--muted-foreground);
  font-size: 0.92rem;
  line-height: 1.55;
}

.app-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 1px 2px rgba(31, 41, 55, 0.04);
}

.app-card-pad {
  padding: 1.25rem;
}

.app-button,
.app-button-secondary,
.app-button-danger {
  display: inline-flex;
  min-height: 2.6rem;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border-radius: 0.65rem;
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.app-button {
  background: var(--primary);
  color: var(--primary-foreground);
}

.app-button:hover {
  background: color-mix(in srgb, var(--primary) 90%, black);
}

.app-button-secondary {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
}

.app-button-secondary:hover {
  background: var(--secondary);
}

.app-button-danger {
  border: 1px solid color-mix(in srgb, var(--destructive) 25%, white);
  background: color-mix(in srgb, var(--destructive) 8%, white);
  color: #b91c1c;
}

.app-button-danger:hover {
  background: color-mix(in srgb, var(--destructive) 14%, white);
}

.app-kicker {
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
}

.app-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 0.55rem;
  background: var(--secondary);
  color: var(--muted-foreground);
  padding: 0.35rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1;
}

.app-field {
  display: grid;
  gap: 0.45rem;
}

.app-field label {
  color: var(--foreground);
  font-size: 0.88rem;
  font-weight: 650;
}

.starter-option {
  display: flex;
  min-height: 2.6rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: var(--card);
  color: var(--foreground);
  font-size: 0.9rem;
  font-weight: 650;
}

.starter-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.starter-option:has(input:checked) {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, white);
  color: var(--primary);
}

.starter-check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--foreground);
  font-size: 0.9rem;
  font-weight: 650;
}

.starter-check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
}

.form-control,
.app-input {
  width: 100%;
  min-height: 2.85rem;
  border: 1px solid var(--input);
  border-radius: 0.65rem;
  background: var(--input-background);
  color: var(--foreground);
  padding: 0.75rem 0.9rem;
  font-size: 0.95rem;
  line-height: 1.4;
  outline: none;
}

.form-control:focus,
.app-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 127, 255, 0.16);
}

.app-meta-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.app-stat {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 1rem;
}

.app-stat-value {
  color: var(--foreground);
  font-size: 1.55rem;
  font-weight: 750;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.app-stat-label {
  margin-top: 0.35rem;
  color: var(--muted-foreground);
  font-size: 0.78rem;
}

.brand-mark {
  display: grid;
  width: 1.45rem;
  height: 1.45rem;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.13rem;
}

.brand-mark span {
  border-radius: 0.18rem;
}

.brand-mark span:nth-child(1) { background: #4fa86f; }
.brand-mark span:nth-child(2) { background: #8754a0; }
.brand-mark span:nth-child(3) { background: #f48b45; }
.brand-mark span:nth-child(4) { background: #f05263; }

.article-word,
.article-pill,
#card-front.article-der,
#card-front.article-die,
#card-front.article-das,
#card-front.article-plural {
  border-color: currentColor;
}

.article-der {
  color: #4fa86f;
}

.article-das {
  color: #8754a0;
}

.article-die {
  color: #f48b45;
}

.article-plural {
  color: #f05263;
}

.article-pill {
  border: 1px solid color-mix(in srgb, currentColor 45%, transparent);
  background: color-mix(in srgb, currentColor 10%, white);
}

.article-pill.is-selected {
  color: white;
}

.article-pill.article-der.is-selected {
  background: #4fa86f;
}

.article-pill.article-das.is-selected {
  background: #8754a0;
}

.article-pill.article-die.is-selected {
  background: #f48b45;
}

.article-pill.article-plural.is-selected {
  background: #f05263;
}

#card-front.article-der,
#card-front.article-die,
#card-front.article-das,
#card-front.article-plural {
  background: color-mix(in srgb, currentColor 8%, white);
}

.article-display {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.16em;
}

.article-token {
  display: inline-flex;
  gap: 0;
}

.article-prefix {
  color: var(--foreground);
}

.article-colored {
  color: currentColor;
}

.article-colored.article-der {
  color: #4fa86f;
}

.article-colored.article-das {
  color: #8754a0;
}

.article-colored.article-die {
  color: #f48b45;
}

.article-colored.article-plural {
  color: #f05263;
}

#card-front .article-prefix {
  color: var(--foreground);
}

#card-front .article-colored.article-der {
  color: #4fa86f;
}

#card-front .article-colored.article-das {
  color: #8754a0;
}

#card-front .article-colored.article-die {
  color: #f48b45;
}

#card-front .article-colored.article-plural {
  color: #f05263;
}

.article-plural-badge {
  border: 1px solid #f05263;
  background: rgba(240, 82, 99, 0.1);
  color: #f05263;
}

.noun-example-line {
  display: grid;
  gap: 0.25rem;
}

.example-muted {
  color: #b8bec6;
}

.example-translation {
  color: var(--muted-foreground);
  font-size: 0.86rem;
  font-style: italic;
}

.mobile-bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 60;
  display: grid;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.25rem;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  padding: 0.45rem 0.55rem calc(0.45rem + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px rgba(31, 41, 55, 0.08);
  backdrop-filter: blur(12px);
}

.mobile-bottom-link {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  border-radius: 0.65rem;
  color: var(--muted-foreground);
  font-size: 0.72rem;
  line-height: 1.1;
  padding: 0.35rem 0.25rem;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-bottom-link.is-active {
  background: var(--primary);
  color: var(--primary-foreground);
}

.mobile-bottom-icon {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.review-controls {
  position: sticky;
  bottom: 4.75rem;
  z-index: 20;
  border-radius: 0.9rem;
  background: rgba(250, 250, 249, 0.92);
  padding: 0.5rem;
  backdrop-filter: blur(10px);
}

.coach-submit {
  width: 100%;
}

details.review-panel > summary {
  cursor: pointer;
  list-style: none;
}

details.review-panel > summary::-webkit-details-marker {
  display: none;
}

details.review-filter-panel > summary {
  list-style: none;
}

details.review-filter-panel > summary::-webkit-details-marker {
  display: none;
}

.review-filter-panel select,
.review-filter-panel button {
  min-height: 2.5rem;
}

@media (max-width: 640px) {
  .app-container {
    padding-inline: 0.9rem;
  }

  .app-main {
    padding-block: 1rem 1.5rem;
  }

  .app-page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .app-page-title {
    font-size: 1.55rem;
  }

  .app-card-pad {
    padding: 1rem;
  }

  .app-shell {
    padding-bottom: 5.25rem;
  }

  footer {
    display: none;
  }

  .flashcard-review h2 {
    margin-bottom: 0.75rem;
    font-size: 1.35rem;
  }

  #card-container {
    height: min(26rem, calc(100vh - 22rem));
    min-height: 20rem;
    margin-bottom: 0;
  }

  .flashcard-review {
    gap: 0.85rem;
  }

  .flashcard-review .app-page-header {
    display: none;
  }

  .review-filter-panel.app-card-pad {
    padding: 0.85rem 1rem;
  }

  #card-level-badge {
    top: 0.75rem;
    left: 0.75rem;
  }

  .flashcard-face {
    padding: 1rem;
    font-size: 42px;
  }

  .coach-submit {
    position: sticky;
    bottom: 4.85rem;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(31, 41, 55, 0.14);
  }
}
