/* ============================================================
   components.css — CardQuiz Design System · Reusable Components
   ------------------------------------------------------------
   Owns: buttons, nav-tabs, header elements, chips, segmented
   control, toggle switch, search box, flag flip card, text card,
   modal, toast, empty state.
   Does NOT redefine: #app, #app-header (layout), #app-content,
   #bottom-nav (container), .screen, or any keyframes.
   Tokens only — no hardcoded colors/sizes where a token exists.
   ============================================================ */

/* ────────────────────────────────────────────────────────────
   1. BUTTONS
   ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 10px var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn .material-symbols-rounded {
  font-size: 1.1em;
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Primary */
.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  border-color: transparent;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--sh-primary);
}

/* Secondary */
.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface-sunken);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-alt);
}

/* Danger */
.btn-danger {
  background: var(--danger);
  color: #ffffff;
  border-color: transparent;
}

.btn-danger:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  filter: brightness(1.06);
}

/* Icon button — square pill, ghost by default */
.btn-icon {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-2);
  border-color: transparent;
}

.btn-icon .material-symbols-rounded {
  font-size: 1.25rem;
}

.btn-icon:hover {
  background: var(--surface-alt);
}

/* Full width */
.btn-full {
  width: 100%;
}

/* Large */
.btn-lg {
  padding: 14px var(--sp-5);
  font-size: var(--fs-md);
}

/* Small */
.btn-sm {
  padding: 7px var(--sp-3);
  font-size: var(--fs-sm);
}

/* ────────────────────────────────────────────────────────────
   2. BOTTOM-NAV TABS
   ──────────────────────────────────────────────────────────── */
.nav-tab {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-h);
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out);
}

.nav-tab:active {
  transform: scale(0.93);
}

.nav-tab__icon {
  font-size: 1.4rem;
  line-height: 1;
  transition: font-variation-settings var(--dur-fast) var(--ease-out);
}

.nav-tab__label {
  font-size: 0.62rem;
  font-weight: var(--fw-medium);
  line-height: 1;
}

.nav-tab--active {
  color: var(--primary);
}

.nav-tab--active .nav-tab__icon {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* Desktop sidebar rows */
@media (min-width: 1024px) {
  .nav-tab {
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-md);
    min-height: 48px;
    flex: none;
  }

  .nav-tab__label {
    font-size: var(--fs-sm);
  }

  .nav-tab--active {
    background: var(--primary-soft);
    color: var(--primary);
  }
}

/* ────────────────────────────────────────────────────────────
   3. HEADER ELEMENTS
   ──────────────────────────────────────────────────────────── */
#header-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--r-md);
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-fast) var(--ease-out);
  flex-shrink: 0;
}

#header-back:hover {
  background: var(--surface-alt);
}

#header-title {
  flex: 1;
  text-align: center;
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: var(--lh-tight);
}

#header-action {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 44px;
  flex-shrink: 0;
}

/* ────────────────────────────────────────────────────────────
   4. CHIPS
   ──────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.chip:active {
  transform: scale(0.96);
}

.chip.active {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary);
}

.chip:hover:not(.active) {
  border-color: var(--primary-border);
}

/* ────────────────────────────────────────────────────────────
   5. SEGMENTED CONTROL
   ──────────────────────────────────────────────────────────── */
.segmented {
  display: inline-flex;
  background: var(--surface-sunken);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  padding: 7px var(--sp-3);
  border: none;
  background: none;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  border-radius: calc(var(--r-md) - 3px);
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    font-weight var(--dur-fast) var(--ease-out);
}

.seg-btn.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: var(--fw-bold);
  box-shadow: var(--sh-sm);
}

/* ────────────────────────────────────────────────────────────
   6. TOGGLE SWITCH
   ──────────────────────────────────────────────────────────── */
.toggle-label {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: background var(--dur-base) var(--ease-out);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 2px;
  top: 2px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform var(--dur-base) var(--ease-out);
  box-shadow: var(--sh-sm);
}

.toggle-input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-input:focus-visible + .toggle-slider {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* ────────────────────────────────────────────────────────────
   7. SEARCH BOX
   ──────────────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-ico {
  position: absolute;
  left: 12px;
  color: var(--text-3);
  font-size: 1.1rem;
  pointer-events: none;
  line-height: 1;
  z-index: 1;
}

.search-input {
  width: 100%;
  padding: 10px 40px 10px 40px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-base);
  outline: none;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.search-input::placeholder {
  color: var(--text-3);
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-clear {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-3);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.search-clear:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.search-clear .material-symbols-rounded {
  font-size: 1.1rem;
}

/* ────────────────────────────────────────────────────────────
   8. FLAG FLIP CARD
   ──────────────────────────────────────────────────────────── */
.flag-flip-card {
  position: relative;
  cursor: pointer;
  border-radius: var(--r-md);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow var(--dur-fast) var(--ease-out);
}

.flag-flip-card.studied {
  box-shadow: 0 0 0 2px var(--success);
}

.flag-flip-inner {
  position: relative;
  width: 100%;
  /* Square so the back face has room for all text without scrolling */
  aspect-ratio: 1 / 1;
  transform-style: preserve-3d;
  transition: transform var(--dur-flip) var(--ease-out);
}

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

.flag-flip-front,
.flag-flip-back {
  position: absolute;
  inset: 0;
  border-radius: var(--r-md);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--sh-sm);
}

/* Front face */
.flag-flip-front {
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
}

.flag-full-img {
  width: 100%;
  height: 100%;
  /* contain keeps the WHOLE flag visible (important for learning) */
  object-fit: contain;
  padding: var(--sp-2);
  display: block;
}

/* Back face */
.flag-flip-back {
  transform: rotateY(180deg);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2);
  gap: var(--sp-1);
  text-align: center;
  overflow: hidden;
}

.flag-thumb {
  width: 64px;
  height: 43px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  box-shadow: var(--sh-sm);
  display: block;
  flex-shrink: 0;
}

.flag-back-name {
  font-size: clamp(0.85rem, 3.2vw, 1rem);
  font-weight: var(--fw-bold);
  color: var(--text);
  line-height: var(--lh-snug);
}

.flag-back-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: clamp(0.72rem, 2.6vw, 0.82rem);
  color: var(--text-2);
  line-height: var(--lh-snug);
}

.flag-back-row .material-symbols-rounded {
  font-size: 0.95rem;
}

.flag-back-cont {
  color: var(--text-3);
}

.flag-back-diff {
  font-size: 0.72rem;
  margin-top: 2px;
  line-height: 1;
}

/* Studied dot (front face, top-left) */
.studied-dot {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--surface);
  z-index: 1;
  flex-shrink: 0;
}

/* Star button (flag card) */
.flag-flip-card .star-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  background: rgba(0, 0, 0, 0.4);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  color: #ffffff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.flag-flip-card .star-btn:active {
  transform: scale(1.2);
}

.flag-flip-card .star-btn.active {
  background: var(--accent);
}

.flag-flip-card .star-btn .material-symbols-rounded {
  font-size: 0.95rem;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* ────────────────────────────────────────────────────────────
   9. TEXT CARD (proverbs / idioms / quotes)
   ──────────────────────────────────────────────────────────── */
.text-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--sh-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    box-shadow var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.text-card:hover {
  box-shadow: var(--sh-md);
}

.text-card:active {
  transform: scale(0.99);
}

.text-card.studied {
  border-color: var(--success-soft);
}

/* Star button (text card) */
.text-card .star-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  color: var(--text-3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.text-card .star-btn:active {
  transform: scale(1.2);
}

.text-card .star-btn.active {
  color: var(--accent);
}

.text-card .star-btn .material-symbols-rounded {
  font-size: 1rem;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* Front section */
.text-card-front {
  padding: 14px 46px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

/* Category label */
.text-card-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--primary);
  opacity: 0.85;
  line-height: var(--lh-tight);
}

/* Front content elements */
.text-main {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--text);
  line-height: var(--lh-base);
}

.text-hanja {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--primary);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-wide);
}

.text-quote {
  font-size: var(--fs-md);
  font-style: italic;
  color: var(--text);
  line-height: var(--lh-relaxed);
}

.text-author {
  font-size: var(--fs-sm);
  color: var(--text-3);
  font-weight: var(--fw-medium);
  line-height: var(--lh-snug);
}

.text-sub-en {
  font-size: var(--fs-sm);
  color: var(--text-3);
  font-style: italic;
  line-height: var(--lh-snug);
}

/* Expand toggle row */
.text-card-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-sm);
  color: var(--primary);
  font-weight: var(--fw-semibold);
  margin-top: 2px;
}

.text-card-toggle .material-symbols-rounded {
  font-size: 1.1rem;
  transition: transform var(--dur-base) var(--ease-out);
}

.text-card.open .text-card-toggle .material-symbols-rounded {
  transform: rotate(180deg);
}

/* Back section */
.text-card-back {
  display: none;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  flex-direction: column;
  gap: 8px;
}

.text-card.open .text-card-back {
  display: flex;
  animation: slideDown var(--dur-base) var(--ease-out);
}

/* Back content elements */
.back-meaning {
  font-size: var(--fs-base);
  color: var(--text-2);
  line-height: var(--lh-relaxed);
}

.back-example {
  font-size: var(--fs-sm);
  color: var(--text-3);
  border-left: 2px solid var(--primary);
  padding-left: 10px;
  line-height: var(--lh-base);
}

.back-en {
  font-size: var(--fs-sm);
  color: var(--text-3);
  font-style: italic;
  line-height: var(--lh-snug);
}

.back-source {
  font-size: var(--fs-sm);
  color: var(--text-3);
  line-height: var(--lh-snug);
}

.back-badge {
  display: inline-block;
  font-size: var(--fs-xs);
  background: var(--primary-soft);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: var(--r-full);
  font-weight: var(--fw-semibold);
  align-self: flex-start;
  line-height: var(--lh-base);
}

/* Legacy alias */
.cat-badge {
  display: inline-block;
  font-size: var(--fs-xs);
  background: var(--primary-soft);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: var(--r-full);
  font-weight: var(--fw-semibold);
  align-self: flex-start;
  line-height: var(--lh-base);
}

/* Studied progress bar */
.studied-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--success);
  pointer-events: none;
}

/* ────────────────────────────────────────────────────────────
   10. MODAL
   ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn var(--dur-base) var(--ease-out) both;
}

.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  max-width: 340px;
  width: 100%;
  box-shadow: var(--sh-xl);
  animation: popIn var(--dur-slow) var(--ease-spring) both;
}

.modal-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--text);
  margin-bottom: var(--sp-2);
  line-height: var(--lh-snug);
}

.modal-message {
  font-size: var(--fs-base);
  color: var(--text-2);
  line-height: var(--lh-base);
  margin-bottom: var(--sp-5);
}

.modal-actions {
  display: flex;
  gap: var(--sp-2);
}

.modal-actions .btn {
  flex: 1;
}

/* ────────────────────────────────────────────────────────────
   11. TOAST
   ──────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  align-items: center;
  pointer-events: none;
  width: min(90vw, 380px);
}

.toast {
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 12px var(--sp-4);
  border-radius: var(--r-md);
  background: var(--surface-elevated);
  color: var(--text);
  box-shadow: var(--sh-lg);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  width: 100%;
  border: 1px solid var(--border);
  cursor: pointer;
  animation: fadeInUp var(--dur-base) var(--ease-out) both;
  transition:
    opacity 0.3s var(--ease-out),
    transform 0.3s var(--ease-out);
}

.toast .material-symbols-rounded {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.toast-success .material-symbols-rounded {
  color: var(--success);
}

.toast-error .material-symbols-rounded {
  color: var(--danger);
}

.toast-warning .material-symbols-rounded {
  color: var(--warning);
}

.toast-info .material-symbols-rounded {
  color: var(--primary);
}

.toast-msg {
  flex: 1;
  line-height: var(--lh-snug);
}

/* ────────────────────────────────────────────────────────────
   12. EMPTY STATE
   ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-12) var(--sp-5);
  color: var(--text-3);
  gap: var(--sp-3);
  font-size: var(--fs-base);
  text-align: center;
  line-height: var(--lh-relaxed);
}

.empty-state .material-symbols-rounded {
  font-size: 2.8rem;
  opacity: 0.7;
}
