:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-soft: #eeebe4;
  --ink: #161616;
  --muted: #6b675f;
  --line: #ded9ce;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --good: #15803d;
  --hard: #b45309;
  --again: #b91c1c;
  --easy: #0f766e;
  --shadow: 0 22px 70px rgba(34, 31, 24, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(15, 118, 110, 0.07), transparent 32%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.shell {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-button,
.secondary-button,
.primary-button,
.rating {
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.ghost-button {
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  border: 1px solid var(--line);
}

.app-stack {
  display: grid;
  gap: 14px;
}

.command-bar,
.study-panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.command-bar {
  display: grid;
  grid-template-columns: auto minmax(220px, 300px) minmax(240px, 1fr) auto;
  align-items: end;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.face-label,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input,
.field select {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.search-control {
  position: relative;
  display: block;
}

.search-control input {
  padding-right: 72px;
}

.clear-search {
  position: absolute;
  right: 6px;
  top: 6px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.study-panel {
  min-width: 0;
  padding: 24px;
  border-radius: 8px;
}

.stats-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  margin-top: 6px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
  letter-spacing: 0;
}

.mode-tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.mode-tab {
  min-height: 34px;
  padding: 0 14px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.mode-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(34, 31, 24, 0.08);
}

.stat-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stat-pills span,
#resultCount {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.flashcard {
  min-height: 340px;
  display: grid;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.card-face {
  display: grid;
  align-content: start;
  gap: 12px;
}

.answer-face {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.card-content {
  font-size: clamp(21px, 2.4vw, 32px);
  line-height: 1.32;
}

.card-content div {
  margin: 0.15em 0;
}

.card-content img {
  display: block;
  max-width: min(360px, 100%);
  max-height: 260px;
  margin: 16px auto 0;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f8f8f8;
}

.controls,
.rating-row {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

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

.primary-button {
  background: var(--accent);
  color: var(--accent-ink);
}

.secondary-button {
  background: var(--surface-soft);
  color: var(--ink);
}

.rating-row {
  grid-template-columns: repeat(4, 1fr);
}

.rating {
  display: grid;
  align-content: center;
  gap: 3px;
  min-height: 58px;
  color: white;
}

.rating span,
.rating small {
  display: block;
}

.rating small {
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 800;
}

.again {
  background: var(--again);
}

.hard {
  background: var(--hard);
}

.good {
  background: var(--good);
}

.easy {
  background: var(--easy);
}

.filter-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
}

.results-panel {
  margin-top: 0;
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.results-head h2 {
  font-size: 18px;
}

.result-list {
  display: grid;
  gap: 8px;
  max-height: 70vh;
  overflow: auto;
  padding-right: 2px;
}

.result-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  text-align: left;
  cursor: pointer;
}

.result-item:hover,
.result-item.active {
  border-color: rgba(37, 99, 235, 0.4);
  background: rgba(37, 99, 235, 0.07);
}

.result-question {
  color: var(--ink);
  font-weight: 700;
}

.result-meta {
  color: var(--muted);
  font-size: 13px;
}

.empty {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 860px) {
  .shell {
    width: min(100% - 20px, 680px);
    padding-top: 12px;
  }

  .topbar,
  .stats-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 14px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: auto 1fr;
  }

  .top-actions .ghost-button {
    min-height: 40px;
  }

  .command-bar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .mode-tabs {
    width: 100%;
  }

  .study-panel {
    padding: 14px;
  }

  .stats-row {
    margin-bottom: 14px;
  }

  h1 {
    font-size: 32px;
  }

  .flashcard {
    min-height: 220px;
    padding: 18px;
  }

  .card-content {
    font-size: 22px;
  }

  .controls,
  .rating-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .controls .primary-button {
    grid-column: 1 / -1;
    order: -1;
  }

  .rating {
    min-height: 50px;
  }
}
