:root {
  --bg: #f6f1fb;
  --surface: #ffffff;
  --border: #e2d6f0;
  --text: #241a35;
  --text-muted: #6c5d82;
  --accent: #cc1f7a;
  --accent2: #6d7fe0;
  --accent-gradient: linear-gradient(135deg, #cc1f7a 0%, #cc1f7a 60%, #6d7fe0 100%);
  --accent-soft: #fbe0ef;
  --accent2-soft: #eef0fc;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-tap-highlight-color: transparent;
}

button {
  touch-action: manipulation;
}

h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

/* ---------- App shell ---------- */

.app-header {
  padding: 24px 24px 0;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 20px;
}

.app-header h1 {
  display: inline-block;
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.header-title::after {
  content: "";
  display: block;
  width: 88px;
  height: 5px;
  margin-top: 10px;
  border-radius: 999px;
  background: var(--accent-gradient);
}

.quote-bar {
  margin: 6px 0 0;
  max-width: 280px;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--text-muted);
  text-align: right;
  transition: opacity 0.4s ease;
}

.quote-bar.quote-fade {
  opacity: 0;
}

.course-tabs,
.week-nav {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.course-tabs {
  margin-top: 20px;
}

.week-nav {
  margin-top: 14px;
}

.week-pill-btn {
  display: none;
  margin: 16px auto 0;
  max-width: 900px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn,
.week-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  cursor: pointer;
}

.tab-btn:hover,
.week-btn:hover {
  border-color: var(--accent);
}

.tab-btn.active,
.week-btn.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #fff;
}

.week-btn {
  font-size: 0.85rem;
  padding: 6px 12px;
}

.content {
  max-width: 900px;
  margin: 24px auto 60px;
  padding: 0 24px;
}

.empty-week {
  color: var(--text-muted);
  font-size: 0.95rem;
  padding: 40px 0;
  text-align: center;
}

/* ---------- Flashcards ---------- */

.flashcard-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.flashcard-main-wrap {
  width: 100%;
  max-width: 560px;
}

.flashcard {
  perspective: 1200px;
  height: 240px;
  width: 100%;
  overflow: hidden;
  border-radius: 16px;
}

.flashcard.flashcard-main {
  height: 520px;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

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

.flashcard-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  border-radius: 16px;
  backface-visibility: hidden;
  font-size: 1.15rem;
  line-height: 1.5;
  box-shadow: 0 4px 14px rgba(63, 20, 90, 0.08);
  overflow-y: auto;
}

.flashcard-front {
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 600;
  color: var(--text);
}

.flashcard-quiz-front {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 22px;
  padding: 32px;
}

.flashcard-question {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

.reveal-choices-btn {
  align-self: center;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1.5px dashed var(--accent2);
  background: transparent;
  color: var(--accent2);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.reveal-choices-btn:hover {
  background: var(--accent2-soft);
}

.reveal-choices-btn.revealed {
  border-style: solid;
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
  cursor: default;
  opacity: 1;
}

.reveal-choices-btn.revealed:hover {
  background: transparent;
}

.flashcard-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.flashcard-choices[hidden] {
  display: none;
}

.choice-btn {
  width: 100%;
  padding: 13px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.98rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--accent2);
}

.choice-btn:disabled {
  cursor: default;
}

.choice-btn.choice-correct {
  border-color: #2e9e5b;
  background: #e6f7ec;
  color: #1c6b3d;
  font-weight: 700;
}

.choice-btn.choice-wrong {
  border-color: #d1435a;
  background: #fbe6e9;
  color: #9c2436;
  font-weight: 700;
}

.flashcard-try-again {
  margin: 0;
  min-height: 1.2em;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: #9c2436;
  opacity: 0;
}

.flashcard-try-again.show {
  opacity: 1;
}

.flashcard-back {
  background: linear-gradient(135deg, var(--accent-soft) 0%, var(--accent2-soft) 100%);
  border: 1px solid #ecd9ea;
  transform: rotateY(180deg);
  color: var(--text);
  flex-direction: column;
  gap: 14px;
  padding: 36px;
  cursor: pointer;
}

.flashcard-result {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
}

.flashcard-result.result-correct {
  color: #2c3690;
}

.flashcard-result.result-wrong {
  color: #b3273f;
}

.flashcard-explanation {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.5;
}

/* ---------- Flashcard strip (horizontal scroll) ---------- */

.flashcard-strip-row {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.strip-arrow {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--accent-gradient);
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(204, 31, 122, 0.28);
}

.strip-arrow:hover {
  filter: brightness(1.08);
}

.strip-arrow:active {
  transform: scale(0.96);
}

.flashcard-strip {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 6px 6px 22px;
  scrollbar-width: auto;
  scrollbar-color: var(--accent2) var(--accent2-soft);
}

.flashcard-strip::-webkit-scrollbar {
  height: 18px;
}

.flashcard-strip::-webkit-scrollbar-track {
  background: var(--accent2-soft);
  border-radius: 999px;
}

.flashcard-strip::-webkit-scrollbar-thumb {
  background: var(--accent-gradient);
  border-radius: 999px;
  border: 4px solid var(--accent2-soft);
}

.flashcard-mini {
  flex: 0 0 170px;
  height: 110px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 12px;
  font-size: 0.85rem;
  line-height: 1.35;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: inherit;
}

.flashcard-mini-num {
  display: none;
}

.flashcard-mini-text {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.flashcard-mini:hover {
  border-color: var(--accent2);
}

.flashcard-mini.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent2) inset;
  font-weight: 600;
}

.flashcard-mini.status-correct {
  background: #5f8a68;
  border-color: #4a6f52;
  color: #fff;
}

.flashcard-mini.status-wrong {
  background: #a85c50;
  border-color: #8a483e;
  color: #fff;
}

/* ---------- Phone layout ---------- */

@media (max-width: 600px) {
  .app-header {
    padding: 16px 16px 0;
    gap: 8px 16px;
  }

  .app-header h1 {
    font-size: 1.8rem;
  }

  .header-title::after {
    width: 60px;
    height: 4px;
    margin-top: 8px;
  }

  .quote-bar {
    max-width: 100%;
    text-align: left;
    font-size: 0.8rem;
    flex-basis: 100%;
  }

  .course-tabs,
  .week-nav {
    padding: 0 16px;
  }

  .week-nav.collapsed {
    display: none;
  }

  .week-pill-btn:not([hidden]) {
    display: block;
    margin-left: 16px;
    margin-right: 16px;
    width: calc(100% - 32px);
  }

  .course-tabs {
    margin-top: 16px;
  }

  .tab-btn {
    font-size: 0.85rem;
    padding: 7px 12px;
  }

  .week-btn {
    font-size: 0.8rem;
    padding: 6px 10px;
  }

  .content {
    padding: 0 16px;
    margin-top: 18px;
  }

  body:not(.week-focused) .content {
    display: none;
  }

  .strip-arrow {
    display: none;
  }

  .flashcard.flashcard-main {
    height: 480px;
  }

  .flashcard-quiz-front {
    padding: 22px;
    gap: 16px;
  }

  .flashcard-question {
    font-size: 1.15rem;
  }

  .flashcard-back {
    padding: 24px;
  }

  .reveal-choices-btn {
    width: 100%;
    padding: 12px 16px;
  }

  .choice-btn {
    padding: 14px 16px;
    font-size: 1rem;
  }

  .flashcard-strip-row {
    gap: 6px;
  }

  .strip-arrow {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
  }

  .flashcard-mini {
    flex: 0 0 44px;
    height: 44px;
    border-radius: 50%;
    padding: 0;
  }

  .flashcard-mini-num {
    display: block;
    font-weight: 700;
    font-size: 0.95rem;
  }

  .flashcard-mini-text {
    display: none;
  }

  /* ---------- Focused week view: fixed top bar + fixed bottom strip ---------- */

  body.week-focused {
    overflow: hidden;
  }

  body.week-focused .app-header,
  body.week-focused .course-tabs,
  body.week-focused .week-nav {
    display: none;
  }

  body.week-focused .week-pill-btn:not([hidden]) {
    display: flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 30;
    margin: 0;
    width: 100%;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  }

  body.week-focused .week-pill-btn:not([hidden])::before {
    content: "‹";
    font-size: 1.4rem;
    line-height: 1;
  }

  body.week-focused .content {
    height: 100vh;
    height: 100dvh;
    margin-top: 0;
    padding-top: calc(56px + env(safe-area-inset-top));
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }

  body.week-focused .flashcard-stage {
    flex: 1;
    min-height: 0;
  }

  body.week-focused .flashcard-main-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
  }

  body.week-focused .flashcard.flashcard-main {
    flex: 1;
    height: auto;
    min-height: 0;
  }

  body.week-focused .flashcard-strip-row {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    max-width: none;
    margin: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  }
}

@media (max-width: 360px) {
  .strip-arrow {
    width: 34px;
    height: 34px;
    font-size: 1.3rem;
  }

  .flashcard-mini {
    flex: 0 0 38px;
    height: 38px;
  }
}
