/* Modern minimal academic layout — geometry flashcards SPA */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #5c6370;
  --border: #d8dce3;
  --accent: #1e5a8a;
  --accent-soft: #e8f0f7;
  --pill-bg: #eef1f5;
  --shadow: 0 4px 24px rgba(26, 29, 35, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
}

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

.app {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.header {
  text-align: center;
  margin-bottom: 1rem;
}

.title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.header-toast {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0.4rem 0 0;
  text-align: center;
  transition: opacity 0.35s ease;
  opacity: 0;
  min-height: 0;
  pointer-events: none;
}

.header-toast.header-toast--show {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .header-toast {
    transition: opacity 0.15s ease;
  }
}

.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

.toolbar-row + .toolbar-row {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.mode-row {
  align-items: center;
}

.toolbar-row--view-score {
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.toolbar-view {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.toolbar-session {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
  margin-left: auto;
}

.toolbar-session .field-label {
  width: 100%;
  margin-bottom: 0.1rem;
}

@media (min-width: 481px) {
  .toolbar-session {
    flex-direction: row;
    align-items: center;
    margin-left: auto;
  }

  .toolbar-session .field-label {
    width: auto;
    margin-bottom: 0;
  }
}

.score-inline {
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

.score-inline strong {
  font-weight: 650;
}

.score-inline__sep {
  color: var(--muted);
  margin: 0 0.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.field-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.select {
  font: inherit;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-width: 11rem;
  max-width: 100%;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.checkbox-field input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.segment {
  font: inherit;
  padding: 0.45rem 0.9rem;
  border: none;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.segment + .segment {
  border-left: 1px solid var(--border);
}

.segment:hover {
  background: var(--accent-soft);
}

.segment.active {
  background: var(--accent);
  color: #fff;
}

.main {
  margin-bottom: 2rem;
}

.progress {
  text-align: center;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.score-panel__meta {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--muted);
}

.btn-reset {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  flex-shrink: 0;
}

.btn-reset:hover {
  background: var(--pill-bg);
  color: var(--text);
}

.deck-progress-wrap {
  height: 4px;
  background: var(--pill-bg);
  border-radius: 999px;
  margin-bottom: 0.65rem;
  overflow: hidden;
}

.deck-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.study-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.study-panel.hidden {
  display: none;
}

.card-flip {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  perspective: 1000px;
}

.card-inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto;
  min-height: 12rem;
  min-width: 0;
  /* Do not use overflow: hidden here — it flattens 3D and mirrors the back face. */
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
  border-radius: var(--radius);
  /* Both faces share one grid cell; row height = max(front, back) so the box grows with content. */
}

.card-flip.is-flipped .card-inner {
  transform: rotateY(180deg);
}

.card-flip.is-advancing .card-inner {
  opacity: 0.55;
  transition: transform 0.35s ease, opacity 0.18s ease;
}

.card-face {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  padding: 1.1rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-front {
  position: relative;
  transform: translateZ(1px);
}

.card-back {
  position: relative;
  transform: rotateY(180deg) translateZ(1px);
  background: linear-gradient(180deg, #fafbfd 0%, var(--surface) 100%);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.topic-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--muted);
}

.type-pill {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 600;
}

.answer-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.card-text {
  font-size: 1.05rem;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  overflow-x: hidden;
}

.card-text .math {
  font-family: var(--mono);
  font-size: 0.98em;
}

.card-hint {
  margin-top: auto;
  padding-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  flex-shrink: 0;
}

.rating-row {
  margin-top: 0.85rem;
  padding: 0.65rem 0;
  text-align: center;
  transition: opacity 0.15s ease;
}

.rating-row[hidden] {
  display: none;
}

.rating-hint {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.rating-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.btn-score {
  font: inherit;
  font-size: 0.92rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: filter 0.12s ease, opacity 0.12s ease;
}

.btn-score:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-score--ok {
  background: #e8f4ec;
  border-color: #a8cbb4;
  color: #1a4d2e;
}

.btn-score--ok:hover:not(:disabled) {
  filter: brightness(0.97);
}

.btn-score--review {
  background: #fdf6e8;
  border-color: #e0c9a0;
  color: #5c4518;
}

.btn-score--review:hover:not(:disabled) {
  filter: brightness(0.97);
}

.nav-buttons {
  display: flex;
  gap: 0.65rem;
  margin-top: 1rem;
  justify-content: center;
}

.btn {
  font: inherit;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: filter 0.12s ease, opacity 0.12s ease;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.secondary {
  background: var(--surface);
  color: var(--accent);
}

.browse-panel {
  margin-top: 0.25rem;
}

.browse-panel.hidden {
  display: none;
}

.browse-count {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.card-list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.card-list-item summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.card-list-item summary::-webkit-details-marker {
  display: none;
}

.card-list-item summary::after {
  content: " ▼";
  font-size: 0.65em;
  color: var(--muted);
}

.card-list-item[open] summary::after {
  content: " ▲";
}

.card-list-front {
  display: block;
  margin: 0.4rem 0 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.card-list-back {
  margin: 0.65rem 0 0;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  font-size: 0.92rem;
  color: var(--text);
  white-space: pre-wrap;
}

.footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.footer code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--pill-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

@media (max-width: 480px) {
  .title {
    font-size: 1.3rem;
  }

  .toolbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-row--view-score {
    align-items: stretch;
  }

  .toolbar-session {
    margin-left: 0;
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-session .field-label {
    width: 100%;
  }

  .score-inline {
    white-space: normal;
  }

  .select {
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .segment {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner {
    transition: none;
  }

  .card-flip.is-flipped .card-inner {
    transform: none;
  }

  .card-flip:not(.is-flipped) .card-back {
    display: none;
  }

  .card-flip.is-flipped .card-back {
    display: flex;
  }

  .card-flip.is-flipped .card-front {
    display: none;
  }
}
