* {
  font-family: TWHEI, "台灣黑體";
}
:root {
  --brand: #3fbf9f;
  --brand-dark: #2e9f85;
  --card: #ffffff;
  --ink: #10231f;
  --header-glass: #ffffffcc;
  --star: #fbbf24;
  --overlay: #0f172acc;
  --btn-bg: #f3fcf9;
  --btn-bd: #c9e9de;
  --btn-tx: #10231f;
  --btn-bg-hover: #ebfaf6;
  --btn-bd-strong: #7dd3c5;
  --bg-grad-a: #e9fbf6;
  --bg-grad-b: #ffffff;
  --accent: #33b39a;
  --accent-dark: #289b84;
  --accent-warm: #f59e0b;

  --pick-blue: #dbeafe;
  --pick-blue-bd: #93c5fd;
  --pick-blue-tx: #1e3a8a;
  --wrong-red: #ef4444;
  --unanswered-dark: #111827;
}
html,
body {
  background: linear-gradient(160deg, var(--bg-grad-a) 0%, var(--bg-grad-b) 60%);
  color: var(--ink);
}
.container-safe {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0px;
}
@media (min-width: 640px) {
  .container-safe {
    padding: 20px;
  }
}
@media (min-width: 1024px) {
  .container-safe {
    padding: 24px;
  }
}

.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.06);
}
.cat-header {
  background: linear-gradient(90deg, var(--brand) 0%, color-mix(in oklab, var(--brand) 35%, #fff) 100%);
}
.q-card {
  background: #fff;
  border: 2px solid color-mix(in oklab, var(--brand) 20%, #fff 80%);
  border-radius: 14px;
  transition: transform .15s, box-shadow .15s, border-color .2s;
}
.q-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.06);
}

.opt-btn {
  border-radius: 12px;
  border: 2px solid transparent;
  transition: transform .05s, box-shadow .15s, background-color .2s, color .2s;
}
.opt-btn:active {
  transform: translateY(1px);
}
.opt-neutral {
  background: #f8fafc;
  color: var(--ink);
}
.opt-right {
  background: #dcfce7;
  color: #065f46;
  border-color: #86efac;
}
.opt-wrong {
  background: #fee2e2;
  color: #7f1d1d;
  border-color: #fca5a5;
}
.opt-picked {
  background: var(--pick-blue);
  color: var(--pick-blue-tx);
  border-color: var(--pick-blue-bd);
}

.audio-btn {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 10px color-mix(in oklab, var(--accent) 35%, #0000);
  transition: background .2s, transform .05s, box-shadow .15s;
  white-space: nowrap;
  font-size: .9rem;
}
.audio-btn:hover {
  background: var(--accent-dark);
}
.audio-btn:active {
  transform: translateY(1px);
}
.audio-btn.playing {
  background: var(--accent-warm);
  box-shadow: 0 4px 10px color-mix(in oklab, var(--accent-warm) 30%, #0000);
}
.audio-badge {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  text-align: center;
  font-size: .9rem;
}
.audio-btn.unanswered {
  background: var(--unanswered-dark);
  color: #fff;
}
.audio-badge.unanswered {
  background: #1f2937;
  color: #fff;
}
.audio-btn.wrong {
  background: var(--wrong-red);
  color: #fff;
}
.audio-badge.wrong {
  background: #fff;
  color: var(--wrong-red);
}

.divider {
  height: 1px;
  background: #e2e8f0;
}
.accordion-body {
  overflow: hidden;
}
.accordion-body.closed {
  max-height: 0;
}

.topbar-btn {
  background: var(--btn-bg);
  color: var(--btn-tx);
  border: 1px solid var(--btn-bd);
  border-radius: 12px;
  padding: 6px 10px;
  transition: background .2s, border-color .2s, box-shadow .2s, color .2s, opacity .2s;
  font-size: .9rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.topbar-btn:hover {
  background: var(--btn-bg-hover);
}
.topbar-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.topbar-btn.emphasis {
  border-color: var(--btn-bd-strong);
}

.material-symbols-outlined {
  font-variation-settings: "FILL" 0, "wght" 600, "GRAD" 0, "opsz" 24;
}

.star-btn {
  color: #cbd5e1;
  transition: color .2s, transform .05s;
}
.star-btn.active {
  color: var(--star);
}

.menu {
  position: relative;
}
.menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
  padding: 6px;
  display: none;
  min-width: 200px;
  z-index: 30;
}
.menu.open .menu-list {
  display: block;
}
.menu-item {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  color: #0f172a;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}
.menu-item:hover {
  background: #f1f5f9;
}
.menu-item .check {
  width: 20px;
  text-align: center;
  color: #16a34a;
  visibility: hidden;
}
.menu-item.active .check {
  visibility: visible;
}
.menu-item .icon {
  width: 22px;
  display: inline-flex;
  justify-content: center;
  opacity: 0.9;
}
.menu-item .count {
  margin-left: auto;
  color: #475569;
}
.menu-item[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

.learn-title mark {
  color: var(--ink);
  background: color-mix(in oklab, var(--brand) 15%, #ffffff);
  padding: 0 6px 1px 6px;
  border-radius: 8px;
  box-shadow: inset 0 -2px 0 color-mix(in oklab, var(--brand) 35%, #ffffff);
  font-weight: 500;
}
.learn-note {
  color: #475569;
  font-size: .95rem;
}

/* 頂部列：小視窗時自動換行，避免擠在同一行 */
.topbar-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 240px;
}
.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  flex: 1 1 240px;
}
@media (min-width: 768px) {
  .topbar-wrap {
    flex-wrap: nowrap;
  }
}

/* 手機版緊湊設計：重新排列題目卡片內的元素佈局 */
@media (max-width: 640px) {
  .q-card {
    background: transparent;
    border: none;
    border-radius: 0;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: none;
    padding: 16px 0;
    margin: 0;
    position: relative;
  }

  /* 移除hover效果，因為緊湊設計不需要 */
  .q-card:hover {
    transform: none;
    box-shadow: none;
  }

  /* 最後一個題目卡片不顯示底線 */
  .accordion-inner .q-card:last-child {
    border-bottom: none;
  }

  /* 題目卡片在手機版採用垂直堆疊佈局 */
  .q-card .flex.items-start {
    flex-direction: column;
    gap: 12px;
  }

  /* 音訊按鈕與星號按鈕的容器 */
  .q-card .flex.items-start > :first-child,
  .q-card .flex.items-start > :last-child {
    align-self: flex-start;
  }

  /* 題目文字容器在手機版佔滿寬度 */
  .q-card .flex-1 {
    flex: none;
    width: 100%;
    order: 2;
  }

  /* 音訊按鈕在手機版置於左上角 */
  .audio-btn {
    order: 1;
    align-self: flex-start;
  }

  /* 星號按鈕在手機版置於右上角 */
  .star-btn {
    order: 3;
    align-self: flex-end;
    position: absolute;
    top: 24px;
    right: 24px;
  }


  .accordion-inner {
    padding: 16px 0px; 
    gap: 0;
  }

  /* 隨機測驗模式的手機版佈局調整 */
  .rand-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .rand-head .flex-1 {
    flex: none;
    width: 100%;
    order: 2;
  }

  .rand-head .audio-btn {
    order: 1;
    align-self: flex-start;
  }
}

.random-wrap {
  background: #fff;
  border-radius: 16px;
}
.random-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.score-badge {
  background: #f1f5f9;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 800;
}
.submit-wrap {
  display: flex;
  justify-content: center;
}
.submit-btn {
  background: var(--brand);
  color: #073d33;
  font-weight: 800;
  border-radius: 12px;
  padding: 10px 16px;
  border: 1px solid color-mix(in oklab, var(--brand) 30%, #0000);
}
.submit-btn:hover {
  background: color-mix(in oklab, var(--brand) 90%, #fff);
}
.rand-item {
  padding: 14px 6px;
  border-bottom: 1px solid #e2e8f0;
}
.rand-item:last-child {
  border-bottom: 0;
}
.rand-head {
  display: flex;
  align-items: start;
  gap: 10px;
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-mask.show {
  display: flex;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  width: min(92vw, 460px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

/* 模糊效果 */
.blurred-text {
  color: transparent !important;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.2);
  transition: text-shadow 0.2s ease-in-out, color 0.2s ease-in-out;
}


/* 確保 emoji 是相對於 q-card 定位 */
.q-card {
  position: relative;
}

.celebrate-emoji {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px; /* 加大 emoji 尺寸 */
  pointer-events: none; /* 避免 emoji 擋住滑鼠點擊 */
  animation: celebrate-float 1.2s ease-out forwards;
  z-index: 10;
}

@keyframes celebrate-float {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.5);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -250%) scale(1.2);
  }
}

/* ---- KA 圖示的浮現特效 ---- */
.sparkle-effect {
  position: absolute;
  font-size: 1.5rem; /* 控制 ✨ 的大小 */
  color: gold;
  pointer-events: none; /* 避免擋住滑鼠點擊 */
  animation: sparkle-float 0.8s ease-out forwards;
  z-index: 20;
}

@keyframes sparkle-float {
  0% {
    opacity: 1;
    transform: scale(0.5);
  }
  100% {
    opacity: 0;
    transform: translateY(-30px) scale(1.2); /* 向上飄移並放大 */
  }
}

