:root {
  color-scheme: dark;
  --flashcard-bg-deep: #050b18;
  --flashcard-fg: #f3f7ff;
  --flashcard-muted: #a9b7cc;
  --flashcard-line: rgba(148, 197, 221, .28);
  --flashcard-line-soft: rgba(148, 197, 221, .18);
  --flashcard-cyan: #42e8e0;
  --flashcard-mint: #7cffb2;
  --flashcard-gold: #ffe47a;
  --flashcard-radius: 22px;
  --flashcard-shadow: 0 22px 60px rgba(0, 0, 0, .48);
}

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

html {
  min-height: 100%;
  background: var(--flashcard-bg-deep);
}

body[data-flashcard-app] {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--flashcard-fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto,
    "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  line-height: 1.7;
  text-shadow: 0 2px 5px rgba(0, 0, 0, .9), 0 0 12px rgba(0, 0, 0, .55);
  background-color: var(--flashcard-bg-deep);
  background-image: var(--flashcard-background);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

body[data-app="fc-tex"] {
  --flashcard-background: url("../../img/bg/フィールド_草原_夜.png");
}

body[data-app="fc-en"] {
  --flashcard-background: url("../../img/bg/ダンジョン_洞窟.png");
}

body[data-flashcard-app]::before,
body[data-flashcard-app]::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

body[data-flashcard-app]::before {
  background:
    linear-gradient(180deg, rgba(1, 7, 19, .3), transparent 28%, transparent 68%, rgba(1, 7, 19, .24)),
    radial-gradient(circle at 50% 45%, transparent 32%, rgba(1, 7, 19, .16) 100%);
}

body[data-flashcard-app]::after {
  opacity: .35;
  background:
    radial-gradient(circle at 14% 21%, rgba(255, 244, 168, .8) 0 1px, transparent 2px),
    radial-gradient(circle at 73% 17%, rgba(113, 238, 255, .75) 0 1px, transparent 2px),
    radial-gradient(circle at 88% 38%, rgba(255, 255, 255, .68) 0 1px, transparent 2px),
    radial-gradient(circle at 35% 8%, rgba(255, 255, 255, .65) 0 1px, transparent 2px);
  background-size: 260px 220px, 310px 270px, 380px 320px, 440px 390px;
}

body[data-flashcard-app] button,
body[data-flashcard-app] a {
  font: inherit;
}

.flashcard-topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  display: flex;
  justify-content: center;
  min-height: 60px;
  padding: 7px 18px;
  border: 0;
  background: linear-gradient(180deg, rgba(3, 12, 28, .5), rgba(5, 17, 36, .2));
  box-shadow: 0 6px 22px rgba(0, 0, 0, .14);
  backdrop-filter: blur(8px) saturate(112%);
  -webkit-backdrop-filter: blur(8px) saturate(112%);
}

.flashcard-topbar::after {
  display: none;
}

.flashcard-topbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  width: min(1100px, 100%);
}

.flashcard-topbar-inner .spacer {
  flex: 1;
}

.flashcard-title {
  min-width: 0;
  color: var(--flashcard-fg);
  font-size: clamp(18px, 3.2vw, 22px);
  font-weight: 900;
  letter-spacing: .03em;
  line-height: 1.2;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .9), 0 0 18px rgba(97, 181, 255, .18);
}

.flashcard-title-accent {
  color: #dffcff;
}

.flashcard-back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 2px;
  border: 0;
  color: var(--flashcard-fg);
  background: none;
  box-shadow: none;
  font-size: .9rem;
  font-weight: 800;
  text-decoration: none;
  transition: color .2s ease, transform .2s ease;
}

.flashcard-back:hover {
  color: var(--flashcard-cyan);
  transform: translateX(-2px);
}

.flashcard-back:focus-visible {
  border-radius: 4px;
  outline: 2px solid rgba(66, 232, 224, .7);
  outline-offset: 4px;
}

.flashcard-page {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 70px 16px 12px;
}

.flashcard-shell {
  position: relative;
  display: block;
  width: min(980px, 96vw);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(181, 224, 241, .4);
  border-radius: var(--flashcard-radius);
  color: var(--flashcard-fg);
  background: linear-gradient(160deg, rgba(5, 20, 39, .9), rgba(2, 10, 24, .95));
  box-shadow: var(--flashcard-shadow), inset 0 1px 0 rgba(255, 255, 255, .07);
  backdrop-filter: blur(14px) saturate(108%);
  -webkit-backdrop-filter: blur(14px) saturate(108%);
  cursor: default;
  caret-color: transparent;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.flashcard-shell:focus {
  outline: none;
}

.flashcard-shell:focus-visible {
  outline: 2px solid rgba(66, 232, 224, .72);
  outline-offset: 4px;
}

.flashcard-shell[aria-busy="true"] {
  cursor: default;
}

.flashcard-category-row {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid rgba(148, 197, 221, .2);
  border-radius: 0;
  background: rgba(7, 20, 39, .2);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.flashcard-category-main,
.flashcard-category-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.flashcard-category-main {
  overflow: hidden;
  white-space: nowrap;
  container-type: inline-size;
}

.flashcard-category-actions {
  flex: 0 0 auto;
  justify-content: flex-end;
  white-space: nowrap;
}

.flashcard-category-label,
.flashcard-category-count {
  flex: 0 0 auto;
}

.flashcard-category-label {
  color: #b8d7e5;
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.flashcard-category-count {
  color: var(--flashcard-muted);
  font-size: .78rem;
  font-weight: 750;
}

.flashcard-category-name {
  min-width: 0;
  overflow: hidden;
  color: var(--flashcard-fg);
  font-size: clamp(15px, 2.6vw, 19px);
  font-weight: 850;
  letter-spacing: .01em;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 2px 7px rgba(0, 0, 0, .88);
}

.flashcard-meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 4px 9px;
  border: 1px solid rgba(148, 197, 221, .18);
  border-radius: 999px;
  color: #d8e8f2;
  background: rgba(5, 15, 30, .36);
  font-size: .76rem;
  font-weight: 750;
  white-space: nowrap;
}

.flashcard-meta-label {
  color: #6fd8df;
  font-size: .57rem;
  font-weight: 800;
  letter-spacing: .09em;
}

.flashcard-progress-track {
  position: relative;
  width: 76px;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(116, 154, 180, .2);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .38);
}

.flashcard-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #27c8d0, var(--flashcard-mint), var(--flashcard-gold));
  box-shadow: 0 0 9px rgba(76, 229, 196, .62);
  transition: width .24s ease;
}

.flashcard-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 31px;
  padding: 4px 9px;
  border: 1px solid rgba(91, 219, 215, .3);
  border-radius: 10px;
  color: var(--flashcard-fg);
  background: rgba(9, 31, 47, .46);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
  font-weight: 850;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.flashcard-switch:hover {
  border-color: rgba(66, 232, 224, .68);
  box-shadow: 0 0 14px rgba(66, 232, 224, .1);
}

.flashcard-switch:focus {
  outline: none;
}

.flashcard-switch:focus-visible {
  outline: 2px solid rgba(66, 232, 224, .72);
  outline-offset: 2px;
}

.flashcard-switch:disabled {
  opacity: .56;
  cursor: default;
}

.flashcard-switch-icon {
  font-size: 1.05em;
  line-height: 1;
}

/* TeX: one question and one answer. */
.tex-card-body {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: clamp(280px, 44vh, 460px);
  color: var(--flashcard-fg);
  background: linear-gradient(180deg, rgba(3, 14, 30, .7), rgba(3, 11, 24, .8));
  font-size: clamp(18px, 3.4vw, 24px);
  text-align: center;
}

.tex-card-section {
  position: relative;
  display: flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  padding: 18px clamp(18px, 4vw, 44px);
}

.tex-card-section + .tex-card-section {
  border-top: 1px solid rgba(124, 255, 178, .24);
}

.tex-card-section::before {
  content: attr(data-label);
  position: absolute;
  z-index: 0;
  top: 10px;
  left: 14px;
  color: rgba(111, 216, 223, .16);
  font-size: clamp(18px, 2.8vw, 30px);
  font-weight: 900;
  letter-spacing: .14em;
  line-height: 1;
  pointer-events: none;
  text-shadow: none;
}

.tex-card-content {
  position: relative;
  z-index: 1;
  width: 100%;
  overflow-wrap: anywhere;
  white-space: pre-line;
  text-shadow: 0 2px 7px rgba(0, 0, 0, .95), 0 0 18px rgba(18, 76, 116, .24);
}

.tex-card-content mjx-container {
  max-width: 100%;
  margin: .15em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

.tex-card-answer {
  color: var(--flashcard-mint);
  opacity: 1;
  text-shadow: 0 0 18px rgba(51, 255, 163, .2), 0 2px 7px rgba(0, 0, 0, .9);
}

.tex-card-answer.is-hidden {
  opacity: 0;
  pointer-events: none;
}

/* English: a word pair followed by progressive example pairs. */
.english-term-meaning {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 0;
  padding: 12px clamp(16px, 3vw, 28px);
  border-bottom: 1px solid rgba(148, 197, 221, .18);
  text-align: left;
}

.english-phrases {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.english-phrase-line {
  display: grid;
  grid-template-rows: minmax(1.4em, auto) minmax(1.4em, auto);
  gap: 2px;
  min-height: 0;
  padding: 8px clamp(16px, 3vw, 28px);
}

.english-phrase-line + .english-phrase-line {
  border-top: 1px solid rgba(148, 197, 221, .14);
}

.english-question,
.english-answer {
  width: 100%;
  min-height: 1.4em;
  font-size: clamp(18px, 3.6vw, 24px);
  font-weight: 700;
  line-height: 1.4;
}

.english-question {
  color: var(--flashcard-muted);
}

.english-question.is-active {
  color: var(--flashcard-fg);
}

.english-answer {
  color: var(--flashcard-mint);
}

.english-answer.is-hidden {
  visibility: hidden;
}

/* Shared reward/message glass. The more specific selector wins over injected defaults. */
body[data-flashcard-app] #rewardSlot .study-reward-window {
  border-color: rgba(181, 224, 241, .24);
  background: linear-gradient(135deg, rgba(7, 18, 36, .26), rgba(20, 37, 61, .16));
  box-shadow: 0 10px 28px rgba(0, 0, 0, .22), inset 0 1px 0 rgba(255, 255, 255, .08);
  backdrop-filter: blur(8px) saturate(108%);
  -webkit-backdrop-filter: blur(8px) saturate(108%);
  text-shadow: 0 2px 4px rgba(0, 0, 0, .98), 0 0 10px rgba(0, 0, 0, .9);
}

body[data-flashcard-app] #rewardSlot :is(.study-reward-title, .study-reward-detail, .study-reward-gain) {
  text-shadow: 0 2px 4px rgba(0, 0, 0, 1), 0 0 9px rgba(0, 0, 0, .95);
}

body[data-flashcard-app] #rewardSlot .study-reward-detail {
  color: #d7e3ef;
}

@container (max-width: 420px) {
  .flashcard-category-label {
    display: none;
  }
}

@container (max-width: 310px) {
  .flashcard-category-count {
    display: none;
  }
}

@media (max-width: 760px) {
  .flashcard-topbar {
    min-height: 56px;
    padding: 6px 12px;
  }

  .flashcard-page {
    padding: 64px 8px 8px;
  }

  .flashcard-shell {
    width: 100%;
    border-radius: 17px;
  }

  .flashcard-category-row {
    gap: 8px;
    padding: 9px 11px;
  }

  .tex-card-body {
    min-height: clamp(270px, 50vh, 420px);
  }

  .tex-card-section {
    min-height: 135px;
  }

  .english-term-meaning {
    padding: 10px 12px;
  }

  .english-phrase-line {
    padding: 7px 12px;
  }

  .flashcard-progress-track {
    width: 58px;
  }
}

@media (max-width: 480px) {
  .flashcard-topbar-inner {
    gap: 8px;
  }

  .flashcard-title {
    font-size: 15px;
    letter-spacing: .015em;
  }

  .flashcard-back {
    padding: 4px 0;
    font-size: .8rem;
  }

  .flashcard-page {
    padding-inline: 7px;
  }

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

  .flashcard-category-actions {
    gap: 5px;
  }

  .flashcard-category-name {
    font-size: 14px;
  }

  .flashcard-category-count {
    font-size: .7rem;
  }

  .flashcard-meta-pill {
    min-height: 29px;
    padding: 3px 7px;
    font-size: .68rem;
  }

  .flashcard-category-actions .flashcard-meta-label,
  .flashcard-switch-label {
    display: none;
  }

  .flashcard-switch {
    min-width: 36px;
    min-height: 29px;
    padding: 3px 8px;
    font-size: .72rem;
  }

  .flashcard-progress-track {
    width: 44px;
  }

  .tex-card-body {
    min-height: clamp(250px, 50vh, 380px);
    font-size: 17px;
  }

  .tex-card-section {
    min-height: 125px;
    padding: 14px 12px;
  }

  .tex-card-section::before {
    top: 9px;
    left: 11px;
    font-size: 20px;
  }
}

@media (max-width: 360px) {
  .flashcard-progress-track {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}


