* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, Arial, sans-serif;
  background: #f6f3ed;
  color: #1e2420;
}

.app {
  min-height: 100vh;
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.site-header {
  margin-bottom: 28px;
}

h1 {
  margin: 0 0 8px;
  font-size: 2rem;
}

h2 {
  margin: 0;
  font-size: 1.65rem;
}

p {
  margin: 0;
  color: #667064;
}

.header-top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.chapter-picker {
  display: none;
  gap: 6px;
  min-width: 220px;
  color: #4b564d;
  font-size: 0.9rem;
  font-weight: 700;
}

.chapter-picker[hidden] {
  display: none;
}

select {
  width: 100%;
  border: 1px solid #c8d2c7;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: #1e2420;
  font: inherit;
}

.subject-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  overflow: visible;
  padding-bottom: 4px;
}

.subject-menu {
  position: relative;
  flex: 0 0 auto;
}

.subject-tab {
  border: 1px solid #c9d2c7;
  border-radius: 8px;
  padding: 10px 14px;
  background: #fff;
  color: #29302b;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.subject-tab::after {
  content: "▾";
  margin-left: 8px;
  color: currentColor;
  font-size: 0.78rem;
}

.subject-tab[aria-pressed="true"] {
  border-color: #27362c;
  background: #27362c;
  color: #fff;
}

.chapter-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  display: grid;
  min-width: 240px;
  padding: 6px;
  border: 1px solid #c9d2c7;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 32px rgba(31, 36, 32, 0.14);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.subject-menu:hover .chapter-menu,
.subject-menu:focus-within .chapter-menu {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.chapter-menu-item {
  justify-self: stretch;
  border: 0;
  border-radius: 6px;
  padding: 10px 12px;
  background: transparent;
  color: #29302b;
  text-align: left;
}

.chapter-menu-item:hover,
.chapter-menu-item:focus {
  background: #eef2ec;
  filter: none;
}

.chapter-menu-item[aria-current="true"] {
  background: #27362c;
  color: #fff;
}

.chapter-menu-empty {
  padding: 10px 12px;
  color: #667064;
  font-size: 0.92rem;
}

.landing-page {
  display: grid;
  gap: 18px;
  margin-bottom: 28px;
}

.landing-page[hidden] {
  display: none;
}

.eyebrow {
  margin-bottom: 6px;
  color: #8a5a2f;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.chapter-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.chapter-button {
  min-height: 92px;
  border: 1px solid #d7d0c4;
  border-radius: 8px;
  padding: 16px;
  background: #fff;
  color: #1e2420;
  cursor: pointer;
  text-align: left;
}

.chapter-button span,
.chapter-button strong {
  display: block;
}

.chapter-button span {
  margin-bottom: 10px;
  font-size: 1rem;
  font-weight: 800;
}

.chapter-button strong {
  color: #667064;
  font-size: 0.86rem;
}

.study-area {
  display: grid;
  gap: 24px;
}

.card {
  height: 260px;
  perspective: 1000px;
  cursor: pointer;
}

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

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

.card-side {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  border-radius: 8px;
  background: white;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.1);
  backface-visibility: hidden;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 650;
}

.card-front {
  border: 2px solid #d9e4ff;
}

.card-back {
  border: 2px solid #c8f7d0;
  transform: rotateY(180deg);
}

.card:focus {
  outline: none;
}

.card:focus .card-side {
  box-shadow: 0 0 0 4px #aac7ff;
}

button {
  justify-self: center;
  border: none;
  border-radius: 8px;
  padding: 12px 22px;
  font: inherit;
  font-weight: 650;
  background: #27362c;
  color: white;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button:active {
  transform: scale(0.98);
}

.error {
  color: #b00020;
  text-align: center;
}

@media (max-width: 680px) {
  .app {
    padding: 20px 14px;
  }

  .header-top {
    align-items: stretch;
    flex-direction: column;
  }

  .subject-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: visible;
  }

  .subject-menu {
    position: static;
  }

  .chapter-menu {
    display: none;
  }

  .card {
    height: 300px;
  }

  .card-side {
    font-size: 1.25rem;
  }
}
