/* Mandarin Stack — Flashcards app. */

.flashcards-page { overscroll-behavior-y: contain; }

.flashcards-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  height: calc(100dvh - var(--header-h, 60px));
}

.flashcards-sidebar {
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.flashcards-sidebar .label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
}
.flashcards-deck-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.flashcards-deck-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
}
.flashcards-deck-item:hover {
  background: var(--color-surface-2);
  border-color: var(--color-border);
}
.flashcards-deck-item input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}
.flashcards-deck-item .deck-title {
  flex: 1;
  font-size: 0.92rem;
  color: var(--color-ink);
}
.flashcards-deck-item .deck-count {
  font-size: 0.78rem;
  color: var(--color-muted);
  flex-shrink: 0;
}
.flashcards-deck-empty {
  font-size: 0.85rem;
  color: var(--color-muted);
  padding: 0.5rem;
}

.flashcards-main {
  overflow-y: auto;
  padding: 1.75rem 2rem 3rem;
  background: var(--color-surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.flashcards-screen {
  width: 100%;
  max-width: 720px;
}

/* ----- Setup screen ----- */
.setup-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow-sm);
}
.setup-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0 0 0.25rem;
}
.setup-card p.lead { font-size: 1rem; color: var(--color-ink-2); margin: 0 0 1.25rem; }

.setup-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  margin: 1rem 0;
}
.setup-row .row-label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  flex-shrink: 0;
  min-width: 110px;
}

.face-pills {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 99px;
  background: var(--color-surface-2);
  padding: 3px;
  gap: 2px;
}
.face-pills input { position: absolute; opacity: 0; pointer-events: none; }
.face-pills label {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.9rem;
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--color-muted);
  transition: background-color .12s ease, color .12s ease;
}
.face-pills input:checked + label {
  background: var(--color-primary);
  color: #fff;
}

/* ----- Card-fields grid (front / back / off per field) ----- */
.setup-row-fields { align-items: flex-start; flex-direction: column; }
.setup-row-fields .row-label { margin-bottom: 0.35rem; }
.field-grid {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 0.35rem 0.75rem;
  align-items: center;
  width: 100%;
}
.field-row {
  display: contents;
}
.field-row .field-label {
  font-size: 0.92rem;
  color: var(--color-ink);
}
.field-pills {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 99px;
  background: var(--color-surface-2);
  padding: 2px;
  gap: 2px;
}
.field-pills input { position: absolute; opacity: 0; pointer-events: none; }
.field-pills label {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.7rem;
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--color-muted);
  transition: background-color .12s ease, color .12s ease;
}
.field-pills input:checked + label {
  background: var(--color-primary);
  color: #fff;
}

/* ----- Multi-field card faces ----- */
.card-face-multi {
  font-family: var(--font-cn);
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.3;
}
.card-back-fields {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  align-items: center;
  text-align: center;
}
.cf-line {
  max-width: 36rem;
  word-break: break-word;
}
.cf-line.cf-hanzi {
  font-family: var(--font-cn);
  font-weight: 700;
  font-size: clamp(2.4rem, 7vw, 4.6rem);
  line-height: 1.05;
  color: var(--color-ink);
}
.cf-line.cf-pinyin {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: clamp(1.2rem, 3.5vw, 1.7rem);
  color: var(--color-primary);
  letter-spacing: 0.03em;
}
.cf-line.cf-english {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 1rem;
  color: var(--color-ink-2);
  line-height: 1.5;
}
.cf-line.cf-zh-sent,
.cf-line.cf-zh-dlg {
  font-family: var(--font-cn);
  font-weight: 500;
  font-size: 1.15rem;
  line-height: 1.5;
  color: var(--color-ink);
  white-space: pre-wrap;
}
.cf-line.cf-zh-sent strong,
.cf-line.cf-zh-dlg strong {
  color: var(--color-primary);
  font-weight: 700;
}
.cf-line.cf-empty .cf-val { font-style: italic; }
.cf-muted { color: var(--color-muted); }
.cf-key {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  margin-right: 0.4rem;
}

.session-summary {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--color-primary-100);
  border-radius: 10px;
  color: var(--color-primary);
  font-weight: 600;
}
.session-summary.empty {
  background: var(--color-surface-2);
  color: var(--color-muted);
  font-weight: 500;
}

/* ----- Session screen ----- */
.session-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.session-progress {
  height: 4px;
  background: var(--color-border);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 1.25rem;
}
.session-progress-fill {
  display: block;
  height: 100%;
  background: var(--color-primary);
  transition: width .25s ease;
}

.card-stage {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 2rem 2rem;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.card-face {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: var(--font-cn);
  font-weight: 600;
  line-height: 1.2;
  word-break: break-word;
}
.card-face.is-hanzi { font-size: clamp(3rem, 8vw, 5.5rem); }
.card-face.is-pinyin { font-size: clamp(2.2rem, 5vw, 3.6rem); color: var(--color-primary); font-family: var(--font-sans); font-weight: 500; letter-spacing: 0.03em; }
.card-face.is-english { font-size: clamp(1.2rem, 3vw, 1.8rem); color: var(--color-ink); font-family: var(--font-sans); font-weight: 500; }

.card-back {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  align-items: center;
  text-align: center;
}
.card-back .b-hanzi { font-family: var(--font-cn); font-size: clamp(2.4rem, 6vw, 4rem); font-weight: 700; }
.card-back .b-pinyin { font-size: 1.25rem; font-weight: 500; color: var(--color-primary); }
.card-back .b-english {
  font-size: 1rem;
  color: var(--color-ink-2);
  max-width: 36rem;
  line-height: 1.5;
}
.card-back .b-translate-action {
  min-height: 1rem;
  margin-top: -0.4rem;
}
.card-back .b-translate-action .btn-link {
  text-decoration: none;
}
.card-back .b-translate-status {
  margin-top: 0.1rem;
}
.card-back .b-stroke {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
}
.card-back .b-stroke-cell {
  width: 110px;
  height: 110px;
  border: 1px dashed var(--color-border-strong);
  border-radius: 10px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-actions {
  display: flex;
  justify-content: center;
  gap: 0.7rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
.card-actions .btn { min-width: 120px; }

/* ----- Summary screen ----- */
.summary-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  padding: 2rem;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.summary-card h2 { font-size: 1.8rem; font-weight: 800; margin: 0 0 0.5rem; }
.summary-stats {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}
.summary-stats .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.summary-stats .stat .value { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.summary-stats .stat .label { font-size: 0.8rem; color: var(--color-muted); margin-top: 0.35rem; text-transform: uppercase; letter-spacing: 0.04em; }
.summary-stats .stat.correct .value { color: #198754; }
.summary-stats .stat.wrong .value { color: #b54708; }

.summary-hardest {
  margin: 1rem 0;
  text-align: left;
}
.summary-hardest h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--color-ink);
}
.summary-hardest ul { list-style: none; padding: 0; margin: 0; }
.summary-hardest li {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--color-border);
  font-family: var(--font-cn);
}
.summary-hardest li:last-child { border-bottom: none; }
.summary-hardest .hard-word { font-weight: 600; }
.summary-hardest .hard-misses { color: var(--color-muted); font-family: var(--font-sans); }

@media (max-width: 820px) {
  .flashcards-layout { grid-template-columns: 1fr; }
  .flashcards-sidebar {
    position: fixed;
    z-index: 1040;
    top: 0; left: 0; bottom: 0;
    width: 300px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 20px rgba(0,0,0,.15);
  }
  .flashcards-sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1039;
    display: none;
  }
  .sidebar-backdrop.show { display: block; }
  .flashcards-main { padding: 1.25rem 1rem 2.5rem; }
}
