/* ════════════════════════════════════════
   BASE
════════════════════════════════════════ */

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

:root {
  --bg:        #111827;
  --surface:   #1f2937;
  --surface2:  #374151;
  --text:      #f9fafb;
  --muted:     #9ca3af;
  --radius:    14px;
  --bonus-bg:  #f5f0ff;
  --bonus-bar: #aa73c2;
  --bonus-txt: #4c1d95;
  --bonus-lbl: #7c3aed;
}

html, body {
  height: 100%;
  font-family: 'Nunito', 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ════════════════════════════════════════
   SCREENS
════════════════════════════════════════ */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ════════════════════════════════════════
   MENU SCREEN
════════════════════════════════════════ */

.menu-brand {
  flex-shrink: 0;
  height: clamp(150px, 30vh, 210px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  text-align: center;
  padding: 0 24px;
}

.brand-emoji {
  font-size: 3rem;
  line-height: 1;
  display: block;
  margin-bottom: 8px;
  animation: emoji-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.brand-line1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
  opacity: 0;
  animation: fade-slide-up 0.45s 0.3s ease forwards;
}

.brand-line2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: #fcd34d;
  opacity: 0;
  animation: fade-slide-up 0.45s 0.5s ease forwards;
}

.app-header {
  background: var(--surface);
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--surface2);
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 1.4rem;
  font-weight: 800;
}

.menu-hint {
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 12px 20px 18px;
  line-height: 1.45;
  text-align: center;
}

#menu-nav {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 0 20px;
}

/* ── Row base ── */
.menu-row {
  display: flex;
  align-items: stretch;
  border-radius: 10px;
  overflow: hidden;
}

.row-subject { margin: 6px 12px;       background: var(--surface2); }
.row-group   { margin: 3px 12px 3px 28px; background: var(--surface);  }
.row-deck    { margin: 2px 12px 2px 44px; background: var(--bg);
               border-left: 4px solid var(--deck-color, #555); }

/* Name (link) side */
.row-link {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  padding: 13px 14px;
  min-height: 50px;
  display: flex;
  align-items: center;
}

.row-subject .row-link { font-size: clamp(1rem, 6.5vw, 1.6rem); font-weight: 800; }
.row-group   .row-link { font-size: clamp(1rem, 6.5vw, 1.6rem); font-weight: 700; }
.row-deck    .row-link { font-size: clamp(1rem, 6.5vw, 1.6rem); font-weight: 500; color: #e5e7eb; }

.row-link:active { opacity: 0.7; }

/* Chevron (expand) side — visually separated */
.row-chevron {
  flex-shrink: 0;
  width: 50px;
  background: rgba(255,255,255,0.08);
  border: none;
  border-left: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.chevron-icon {
  display: inline-block;
  transition: transform 0.25s;
}

.row-chevron.open .chevron-icon { transform: rotate(90deg); }

.row-chevron.open {
  background: rgba(255,255,255,0.15);
  color: var(--text);
}

/* Arrow on deck rows (decorative) */
.row-arrow {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 1rem;
  padding: 0 14px;
  display: flex;
  align-items: center;
}

/* Accordion body */
.accordion-body        { display: none; }
.accordion-body.open   { display: block; }

/* ════════════════════════════════════════
   STUDY SCREEN
════════════════════════════════════════ */

.study-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  min-height: 54px;
  flex-shrink: 0;
  background: var(--deck-hdr, var(--surface));
  transition: background 0.3s;
}

.hdr-btn {
  flex-shrink: 0;
  background: rgba(255,255,255,0.18);
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 7px 13px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 36px;
}

.hdr-btn:active { opacity: 0.7; }

.study-title {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shuffle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px 5px 10px;
  border-radius: 20px;
}

.shuffle-icon {
  font-size: 1rem;
  line-height: 1;
}

.toggle-track {
  width: 30px;
  height: 17px;
  border-radius: 9px;
  background: rgba(255,255,255,0.25);
  position: relative;
  transition: background 0.25s;
  flex-shrink: 0;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.25s, background 0.25s;
}

.shuffle-btn.on .toggle-track { background: rgba(255,255,255,0.9); }
.shuffle-btn.on .toggle-thumb { transform: translateX(13px); background: #111827; }

/* Progress strip */
#progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: var(--surface);
  flex-shrink: 0;
}

#progress-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  background: rgba(255,255,255,0.1);
}

.progress-seg {
  flex: 1;
  height: 100%;
  min-width: 1px;
  transition: opacity 0.3s;
}

#progress-text {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

/* Card arena */
#card-arena {
  flex: 1;
  position: relative;
  overflow: hidden;
  overscroll-behavior-y: none;
  cursor: grab;
  user-select: none;
}

#card-arena:active { cursor: grabbing; }

/* Track holds all 3 slots; left:-100% means default translateX(0) shows middle slot */
#card-track {
  position: absolute;
  top: 14px;
  left: -100%;
  bottom: 8px;
  width: 300%;
  display: flex;
}

.card-slot {
  flex: 0 0 33.333%;
  height: 100%;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-scene {
  width: 100%;
  max-width: 500px;
  height: 100%;
  perspective: 1200px;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
}

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

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* ── Card front ── */
.card-front {
  background: var(--surface);
  color: var(--text);
  border: 3px solid #45b574; /* overridden per card via JS */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 22px;
  text-align: center;
}

.topic-label {
  position: absolute;
  top: 10px;
  left: 14px;
  right: 14px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.65;
  pointer-events: none;
}

/* ── Card back ── */
.card-back {
  background: #fff;
  color: #111827;
  transform: rotateY(-180deg);
  padding: 18px 18px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Nav hint */
/* ════════════════════════════════════════
   CARD CONTENT — FRONT
════════════════════════════════════════ */

.bonus-badge {
  display: inline-block;
  background: rgba(255,255,255,0.25);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 1.48rem;
  font-weight: 800;
  margin-bottom: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.q-content {
  font-size: 1.6rem;
  font-weight: 400;
  line-height: 1.55;
}

.q-content p              { margin-bottom: 10px; }
.q-content p:last-child   { margin-bottom: 0; }
.q-content strong         { font-weight: 800; }
.q-content em             { font-style: italic; }
.q-content svg            { width: 100%; height: auto; margin-top: 10px; }

/* ════════════════════════════════════════
   CARD CONTENT — BACK
════════════════════════════════════════ */

.answer-content { display: flex; flex-direction: column; gap: 0; }

/* Answer table */
.answer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.1rem;
  line-height: 1.45;
}

.answer-table td {
  vertical-align: top;
  padding: 6px 6px;
  border-bottom: 1px solid #e5e7eb;
}

.answer-table tr:last-child td { border-bottom: none; }

.answer-table td:first-child {
  font-weight: 800;
  color: #374151;
  white-space: nowrap;
  padding-right: 10px;
  width: 34%;
}

/* Bonus section */
.bonus-part {
  margin-top: 14px;
  background: var(--bonus-bg);
  border-left: 3px solid var(--bonus-bar);
  border-radius: 8px;
  padding: 10px 12px 10px;
}

.bonus-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--bonus-lbl);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.bonus-part > div {
  font-size: 0.85rem;
  color: var(--bonus-txt);
  line-height: 1.5;
}

/* Loading state */
.card-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 1.05rem;
  font-weight: 700;
  opacity: 0.7;
}

/* ════════════════════════════════════════
   CONGRATS CARD
════════════════════════════════════════ */

@keyframes emoji-pop {
  0%   { transform: scale(0) rotate(-15deg); opacity: 0; }
  65%  { transform: scale(1.3) rotate(8deg);  opacity: 1; }
  82%  { transform: scale(0.9) rotate(-3deg); }
  100% { transform: scale(1)   rotate(0deg);  }
}

@keyframes fade-slide-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0);    }
}

.congrats-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.congrats-emoji {
  font-size: 4.5rem;
  line-height: 1;
  display: block;
  animation: emoji-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.congrats-heading {
  font-size: 2rem;
  font-weight: 800;
  opacity: 0;
  animation: fade-slide-up 0.45s 0.3s ease forwards;
}

.congrats-sub {
  font-size: 1.1rem;
  font-weight: 600;
  opacity: 0;
  animation: fade-slide-up 0.45s 0.48s ease forwards;
}
