.subject-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  width: min(100%, 30rem);
  margin: 0 auto 0.5rem;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 1.15rem;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 10px 24px rgba(48, 102, 147, 0.1);
}

.subject-switch-button {
  min-height: 3rem;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.85rem;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.subject-switch-button.is-active {
  color: #fff;
  background: linear-gradient(180deg, #4da6ed, var(--primary));
  box-shadow: 0 8px 18px rgba(35, 130, 217, 0.2);
}

#subject-history[hidden],
#subject-english[hidden],
#subject-history .history-is-hidden {
  display: none;
}

#subject-history .history-hero {
  padding: 1.25rem 0 1rem;
  text-align: center;
}

#subject-history .history-hero-kicker {
  margin: 0 0 0.5rem;
  color: #875812;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.2em;
}

#subject-history .history-hero h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.15;
}

#subject-history .history-hero-copy {
  width: min(100%, 42rem);
  margin: 0.9rem auto 0;
  color: var(--ink-muted);
  line-height: 1.7;
}

#subject-history .history-app-frame,
#subject-history .history-section-head,
#subject-history .history-card-topbar,
#subject-history .history-control-row,
#subject-history .history-card-stage,
#subject-history .history-nav-row {
  display: grid;
  gap: 1rem;
}

#subject-history .history-status-banner,
#subject-history .history-panel {
  border: 1px solid rgba(135, 88, 18, 0.2);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

#subject-history .history-status-banner {
  padding: 0.9rem 1.1rem;
  font-weight: 700;
}

#subject-history .history-panel {
  padding: clamp(1rem, 3vw, 1.5rem);
}

#subject-history .history-panel h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
}

#subject-history .history-section-copy,
#subject-history .history-message,
#subject-history .history-card-hint {
  color: var(--ink-muted);
  line-height: 1.7;
}

#subject-history .history-section-head {
  margin-bottom: 1rem;
}

#subject-history .history-summary-pill {
  justify-self: start;
  margin: 0;
  padding: 0.65rem 0.95rem;
  border: 1px solid rgba(135, 88, 18, 0.18);
  border-radius: 999px;
  background: #fff9e9;
  color: #875812;
  font-weight: 800;
}

#subject-history .history-empty-message {
  margin: 0 0 1.25rem;
  padding: 1rem;
  border: 1px solid #e3bf71;
  border-radius: var(--radius-md);
  background: #fff8df;
  color: #694407;
  font-weight: 700;
}

#subject-history .history-range-group + .history-range-group {
  margin-top: 1.5rem;
}

#subject-history .history-range-group h3 {
  margin: 0 0 0.8rem;
}

#subject-history .history-range-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.8rem;
}

#subject-history .history-range-card {
  display: grid;
  gap: 0.6rem;
  min-height: 7.2rem;
  padding: 1rem;
  border: 1px solid rgba(135, 88, 18, 0.18);
  border-radius: 1.15rem;
  background: linear-gradient(180deg, #fff, #fffbef);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

#subject-history .history-range-card:hover:enabled,
#subject-history .history-range-card:focus-visible {
  border-color: rgba(135, 88, 18, 0.45);
  transform: translateY(-2px);
}

#subject-history .history-range-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#subject-history .history-range-label {
  font-size: 1.05rem;
  font-weight: 800;
}

#subject-history .history-range-count {
  align-self: end;
  justify-self: start;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: var(--accent-soft);
  font-weight: 700;
}

#subject-history .history-button {
  min-height: 3.25rem;
  padding: 0.85rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 800;
}

#subject-history .history-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#subject-history .history-button-primary {
  color: #fff;
  background: linear-gradient(180deg, #a56d18, #7c4c08);
  box-shadow: 0 14px 24px rgba(124, 76, 8, 0.2);
}

#subject-history .history-button-secondary,
#subject-history .history-direction-button {
  border-color: rgba(24, 50, 74, 0.1);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
}

#subject-history .history-direction-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

#subject-history .history-direction-button.is-active {
  color: #fff;
  background: linear-gradient(180deg, #b77c22, #875812);
}

#subject-history .history-course-meta {
  display: grid;
  gap: 0.35rem;
}

#subject-history .history-card-stage {
  justify-items: center;
}

#subject-history .history-card-counter {
  width: min(100%, 38rem);
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

#subject-history .history-flashcard {
  width: min(100%, 38rem);
  height: clamp(22rem, 60vh, 31rem);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  perspective: 1500px;
  touch-action: manipulation;
}

#subject-history .history-flashcard-core {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transition: transform 0.44s cubic-bezier(0.22, 0.7, 0.2, 1);
  transform-style: preserve-3d;
}

#subject-history .history-flashcard.is-flipped .history-flashcard-core {
  transform: rotateY(180deg);
}

#subject-history .history-flashcard-face {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 1rem;
  padding: clamp(1.2rem, 4vw, 2rem);
  overflow: hidden;
  border: 1px solid rgba(135, 88, 18, 0.22);
  border-radius: 1.7rem;
  background: linear-gradient(145deg, #fffef9, #fff6da);
  box-shadow: 0 20px 42px rgba(97, 72, 30, 0.14);
  backface-visibility: hidden;
}

#subject-history .history-flashcard-back {
  background: linear-gradient(145deg, #fff, #eef8ff);
  transform: rotateY(180deg);
}

#subject-history .history-flashcard-label {
  color: #875812;
  font-size: 0.85rem;
  font-weight: 800;
}

#subject-history .history-flashcard-body {
  display: grid;
  place-items: center;
  overflow: auto;
}

#subject-history .history-flashcard-value {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: clamp(1.45rem, 4vw, 2.4rem);
  font-weight: 800;
  line-height: 1.6;
  text-align: center;
}

#subject-history .history-card-hint {
  margin: 0;
  text-align: center;
}

#subject-history .history-nav-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
}

@media (min-width: 48rem) {
  #subject-history .history-section-head,
  #subject-history .history-card-topbar,
  #subject-history .history-control-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }
}

@media (max-width: 34rem) {
  .subject-switch {
    width: 100%;
  }

  #subject-history .history-direction-toggle,
  #subject-history .history-nav-row {
    grid-template-columns: 1fr;
  }

  #subject-history .history-flashcard {
    height: clamp(20rem, 58vh, 27rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  #subject-history .history-flashcard-core,
  #subject-history .history-range-card {
    transition: none;
  }
}
