:root {
  color-scheme: light;
  --brand: #394398;
  --brand-dark: #252d78;
  --brand-soft: #eef0ff;
  --accent: #f4b33f;
  --accent-soft: #fff7df;
  --ink: #182034;
  --muted: #6d7a91;
  --line: #dde3f0;
  --surface: #ffffff;
  --shadow: 0 22px 60px rgba(40, 50, 125, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #f3f5fc;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 0 0, rgba(96, 109, 220, 0.15), transparent 30%),
    radial-gradient(circle at 100% 28%, rgba(244, 179, 63, 0.14), transparent 28%),
    #f5f6fc;
}

button,
select,
a {
  -webkit-tap-highlight-color: transparent;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  background: rgba(249, 250, 255, 0.86);
}

.mobile-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid rgba(221, 227, 240, 0.82);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--brand);
  background: #fff;
  font-size: 24px;
  font-weight: 800;
  text-decoration: none;
}

#random-button {
  font-size: 27px;
  transform: rotate(18deg);
}

.mini-brand {
  display: flex;
  align-items: center;
  justify-self: center;
  gap: 9px;
  color: var(--ink);
  text-decoration: none;
}

.mini-brand img {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  object-fit: cover;
}

.mini-brand span {
  display: grid;
  gap: 1px;
}

.mini-brand strong {
  font-size: 14px;
}

.mini-brand small {
  color: var(--muted);
  font-size: 11px;
}

.study-main {
  padding: 22px 16px calc(34px + env(safe-area-inset-bottom));
}

.study-heading {
  padding: 0 4px 16px;
}

.breadcrumb {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 750;
}

.breadcrumb span {
  margin: 0 5px;
  color: #a1aac0;
}

.study-heading h1 {
  margin: 0 0 18px;
  font-size: clamp(25px, 7vw, 34px);
  line-height: 1.16;
  letter-spacing: -0.025em;
}

.heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.heading-row h1 {
  margin-bottom: 0;
}

.letter-picker {
  display: grid;
  flex: 0 0 auto;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
}

.letter-picker select {
  min-width: 74px;
  height: 38px;
  padding: 0 28px 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--brand);
  background: #fff;
  font-size: 15px;
  font-weight: 850;
}

.source-note {
  margin: 18px 4px 0;
  color: #8a94a8;
  font-size: 10px;
  line-height: 1.6;
  text-align: center;
}

.source-note a {
  color: var(--brand);
}

.progress-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 99px;
  background: #e4e7f3;
}

.progress-track span {
  display: block;
  width: 1%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), #7b83e7);
  transition: width 220ms ease;
}

.card-frame {
  position: relative;
  padding: 9px;
  overflow: hidden;
  border-radius: 30px;
  background:
    radial-gradient(circle at 12px 12px, rgba(255, 255, 255, 0.75) 0 2px, transparent 3px),
    linear-gradient(145deg, #ffd78a, #f2a63b 52%, #ffd98d);
  background-size: 48px 48px, auto;
  box-shadow: var(--shadow);
  touch-action: pan-y;
}

.flashcard {
  display: flex;
  min-height: min(490px, 60dvh);
  flex-direction: column;
  padding: clamp(22px, 6vw, 34px);
  border-radius: 23px;
  outline: none;
  background: rgba(255, 255, 255, 0.97);
  transition: opacity 150ms ease, transform 150ms ease;
}

.flashcard.is-changing {
  opacity: 0;
  transform: translateX(var(--shift, 12px));
}

.flashcard:focus-visible {
  box-shadow: inset 0 0 0 3px rgba(57, 67, 152, 0.24);
}

.card-topline,
.phrase-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.type-badge,
.part-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.type-badge {
  color: #8a5600;
  background: var(--accent-soft);
}

.part-badge {
  color: var(--brand);
  background: var(--brand-soft);
}

.phrase-row {
  margin: 30px 0 22px;
}

.phrase-row h2 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(32px, 8.6vw, 46px);
  font-style: italic;
  font-weight: 700;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.speak-small {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(57, 67, 152, 0.25);
  border-radius: 50%;
  color: var(--brand);
  background: #fff;
  font-size: 21px;
}

.phonetic {
  min-height: 25px;
  margin: -12px 0 20px;
  color: var(--brand);
  font-family: "Segoe UI", "Lucida Sans Unicode", sans-serif;
  font-size: clamp(16px, 4.4vw, 20px);
  font-weight: 650;
  letter-spacing: 0.015em;
}

.phonetic[hidden] {
  display: none;
}

.definition-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.definition-list div {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: baseline;
  gap: 10px;
}

.definition-list dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.definition-list dd {
  margin: 0;
  font-size: clamp(18px, 5vw, 22px);
  line-height: 1.45;
}

.definition-list div:nth-child(2) dd {
  color: #3e4961;
  font-size: 17px;
  font-style: italic;
}

.example-block {
  margin-top: 24px;
  padding: 15px 16px;
  border-left: 4px solid var(--brand);
  border-radius: 4px 15px 15px 4px;
  background: #f4f5fb;
}

.example-block span,
.exam-point span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.06em;
}

.example-block p {
  margin: 7px 0 0;
  color: #2f374d;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(17px, 4.6vw, 21px);
  font-style: italic;
  line-height: 1.5;
}

.exam-point {
  margin-top: auto;
  padding-top: 20px;
}

.exam-point span {
  color: #996100;
}

.exam-point p {
  margin: 7px 0 0;
  font-size: 15px;
  line-height: 1.65;
}

.playback-controls {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.playback-controls button {
  min-height: 52px;
  border-radius: 16px;
  font-weight: 800;
}

.control-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  color: var(--brand);
  background: #fff;
}

.control-button:disabled {
  opacity: 0.38;
  cursor: default;
}

.play-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  color: #fff;
  background: linear-gradient(145deg, var(--brand), #626bd2);
  box-shadow: 0 10px 24px rgba(57, 67, 152, 0.24);
}

.play-button.is-playing .play-icon::before {
  content: "■";
}

.play-button.is-playing .play-icon {
  font-size: 0;
}

.play-button.is-playing .play-icon::before {
  font-size: 14px;
}

.play-button:disabled,
.speak-small:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.speech-note {
  margin: 10px 2px 0;
  padding: 10px 12px;
  border-radius: 12px;
  color: #7c560f;
  background: #fff5d9;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.study-settings {
  display: grid;
  grid-template-columns: 0.85fr 1.35fr;
  gap: 12px;
  margin-top: 14px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.88);
}

.study-settings label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.study-settings select {
  width: 100%;
  min-height: 42px;
  padding: 0 32px 0 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
  font-size: 13px;
}

.auto-setting {
  grid-column: 1 / -1;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 18px !important;
  padding-top: 2px;
}

.auto-setting span {
  display: grid;
  gap: 2px;
}

.auto-setting strong {
  color: var(--ink);
  font-size: 13px;
}

.auto-setting small {
  font-size: 11px;
  font-weight: 500;
}

.auto-setting input {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  margin: 0;
  appearance: none;
  border-radius: 99px;
  background: #d9deeb;
  transition: background 160ms ease;
}

.auto-setting input::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(24, 32, 52, 0.18);
  content: "";
  transition: transform 160ms ease;
}

.auto-setting input:checked {
  background: var(--brand);
}

.auto-setting input:checked::after {
  transform: translateX(20px);
}

.mastered-button {
  display: flex;
  width: 100%;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  border: 1px solid rgba(57, 67, 152, 0.22);
  border-radius: 16px;
  color: var(--brand);
  background: var(--brand-soft);
  font-weight: 800;
}

.mastered-button[aria-pressed="true"] {
  color: #276b48;
  border-color: #a7d6bf;
  background: #eaf8f0;
}

.swipe-tip {
  margin: 16px 0 0;
  color: #8993a8;
  font-size: 11px;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(57, 67, 152, 0.25);
  outline-offset: 3px;
}

@media (min-width: 561px) {
  body {
    padding: 24px 0;
  }

  .app-shell {
    overflow: hidden;
    border: 1px solid rgba(221, 227, 240, 0.9);
    border-radius: 32px;
    box-shadow: 0 28px 90px rgba(39, 49, 120, 0.15);
  }
}

@media (max-width: 380px) {
  .study-main {
    padding-right: 12px;
    padding-left: 12px;
  }

  .flashcard {
    min-height: 455px;
    padding: 21px;
  }

  .phrase-row {
    margin-top: 24px;
  }

  .playback-controls {
    gap: 7px;
  }

  .control-button {
    font-size: 12px;
  }
}

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