:root {
  --bg: #f5f1ff;
  --surface: #ffffff;
  --ink: #4b4468;
  --ink-soft: #6a638c;
  --muted: #948dae;
  --border: #e7e0ff;

  --violet: #b9a3ff;
  --violet-deep: #8f72e8;
  --violet-text: #5d4bb0;

  --mint: #8fe0b3;
  --mint-deep: #4fae7c;
  --mint-text: #2f7d58;

  --coral: #ffb1a0;
  --coral-deep: #e9836e;
  --coral-text: #b8543f;

  --gold: #ffd97d;
  --gold-deep: #eab449;

  --sky: #a9dfff;
  --sky-deep: #6bb8e8;

  --blush: #ffc2e2;
  --blush-deep: #ea8fbb;

  --font-display: "Baloo 2", ui-rounded, sans-serif;
  --font-body: "Nunito", ui-rounded, sans-serif;

  --shadow-card: 0 10px 0 var(--border), 0 14px 24px rgba(139, 120, 221, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221f36;
    --surface: #2c2947;
    --ink: #f1edff;
    --ink-soft: #cdc5f2;
    --muted: #a79fd1;
    --border: #3c3760;

    --violet: #a891f5;
    --violet-deep: #7d63d6;
    --violet-text: #d8cdff;

    --mint: #7fd1a4;
    --mint-deep: #4a9c6f;
    --mint-text: #bdf0d3;

    --coral: #f2a08e;
    --coral-deep: #d97862;
    --coral-text: #ffd3c6;

    --gold: #f0c665;
    --gold-deep: #d1a13a;

    --sky: #8fc9ec;
    --sky-deep: #5a9dc4;

    --blush: #ec9fc4;
    --blush-deep: #cf74a3;

    --shadow-card: 0 10px 0 var(--border), 0 14px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 22px 18px 48px;
}

[hidden] { display: none !important; }

/* Header */
header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  font-size: 1.7rem;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: var(--surface);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 0 var(--border);
  flex-shrink: 0;
}

header.top h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  margin: 0;
  color: var(--ink);
}

header.top .sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

a.repo-link {
  color: var(--violet-text);
  text-decoration: none;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.82rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  background: var(--surface);
  white-space: nowrap;
}

.screen-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  margin: 4px 0 16px;
  color: var(--ink);
}

/* Tile list: certification / world picker */
.tile-list, .deck-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tile {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  text-align: left;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: var(--font-body);
}

.tile:hover {
  transform: translateY(-2px);
}

.tile:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 var(--border), 0 6px 14px rgba(139, 120, 221, 0.18);
}

.tile-badge {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-family: var(--font-display);
  font-weight: 700;
}

.tile-body { flex: 1; min-width: 0; }

.tile h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0 0 4px;
  color: var(--ink);
}

.tile p {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.4;
}

.stat-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-body);
}

.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 20px 4px;
}

/* Level map: domain picker within a certification */
.level-map {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0 12px;
}

.level-map::before {
  content: "";
  position: absolute;
  top: 30px;
  bottom: 30px;
  left: 50%;
  width: 0;
  border-left: 4px dashed var(--border);
  transform: translateX(-2px);
  z-index: 0;
}

.level-node {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 10px 0;
  text-align: left;
  font-family: var(--font-body);
  opacity: 0;
  animation: pop-in 0.4s ease forwards;
}

.level-node.align-right { flex-direction: row-reverse; }

.level-node .level-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
  border: 3px solid var(--surface);
  transition: transform 0.15s ease;
}

.level-node:active .level-circle {
  transform: scale(0.92);
}

.level-card {
  flex: 1;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 10px 14px;
  min-width: 0;
}

.level-node.align-right .level-card { text-align: right; }

.level-card h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.98rem;
  margin: 0 0 3px;
  color: var(--ink);
}

.level-card .meta {
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 700;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(10px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .level-node { animation: none; opacity: 1; }
}

/* Topic filter chips */
.topic-filter { margin: 4px 0 18px; }

.topic-filter-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 10px;
  color: var(--ink);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.topic-chip {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 9px 14px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: transform 0.1s ease;
}

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

.topic-chip.active {
  color: #ffffff;
  border-color: transparent;
}

.start-btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 16px;
  background: var(--violet);
  color: #2f2560;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--violet-deep);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.start-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--violet-deep);
}

.back-btn {
  background: none;
  border: none;
  color: var(--violet-text);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 6px 0 16px;
}

/* Study view */
.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.progress-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink);
}

.exit-btn {
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.xp-bar {
  height: 14px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 20px;
  padding: 2px;
}

.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--coral));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.card-stage {
  perspective: 1400px;
  min-height: 300px;
}

.card-stage.celebrate {
  animation: celebrate-bounce 0.4s ease;
}

@keyframes celebrate-bounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .card-stage.celebrate { animation: none; }
}

.flashcard {
  position: relative;
  min-height: 300px;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0.2, 0.2, 1);
  cursor: pointer;
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow-card);
  padding: 68px 22px 28px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  text-align: center;
  gap: 10px;
  overflow-y: auto;
}

.face-chip {
  position: absolute;
  top: 16px;
  left: 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.72rem;
  padding: 4px 12px;
  border-radius: 999px;
}

.face-chip-q { background: var(--sky); color: #1c5478; }
.face-chip-a { background: var(--mint); color: var(--mint-text); }

.face .tag-stack {
  position: absolute;
  top: 16px;
  right: 16px;
  max-width: 55%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.face .domain-tag {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
  font-family: var(--font-body);
}

.face .skill-tag {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--muted);
  opacity: 0.75;
  text-align: right;
  font-family: var(--font-body);
  padding: 2px 8px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
}

.face .body-text {
  width: 100%;
  margin-top: auto;
  margin-bottom: auto;
  font-size: 1.12rem;
  line-height: 1.55;
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--ink);
  text-align: left;
}

.face .body-text p {
  margin: 0 0 10px;
}

.face .body-text p:last-child {
  margin-bottom: 0;
}

.face .body-text ul {
  margin: 0 0 10px;
  padding-left: 1.3em;
}

.face .body-text ul:last-child {
  margin-bottom: 0;
}

.face .body-text li {
  margin-bottom: 6px;
}

.face .body-text li:last-child {
  margin-bottom: 0;
}

.face.back {
  transform: rotateY(180deg);
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  margin-top: 12px;
}

.answer-controls {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.answer-controls button {
  flex: 1;
  padding: 15px;
  border-radius: 16px;
  border: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.98rem;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn-again {
  background: var(--coral);
  color: #5c2416;
  box-shadow: 0 6px 0 var(--coral-deep);
}

.btn-again:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--coral-deep);
}

.btn-good {
  background: var(--mint);
  color: #1e4a33;
  box-shadow: 0 6px 0 var(--mint-deep);
}

.btn-good:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--mint-deep);
}

.done-screen {
  text-align: center;
  padding: 40px 10px 10px;
}

.done-badge {
  font-size: 3rem;
  margin-bottom: 6px;
}

.done-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.6rem;
  margin: 0 0 8px;
  color: var(--ink);
}

.done-screen p {
  color: var(--ink-soft);
  font-size: 0.95rem;
  margin-bottom: 26px;
}
