/* =============================================================
   設計系統：治癒溫暖沙盤學院風格（以 #f9e9da, #ef5a56, #f4d474 為核心）
   ============================================================= */
:root {
  --bg-0: #f9e9da;                      /* 柔和暖杏底色（用戶色票） */
  --bg-1: #ffffff;                      /* 典雅純白卡片底 */
  --bg-2: #fcf4eb;                      /* 暖杏淡米色（次級卡片/輸入框） */
  --bg-3: #f3decb;                      /* 暖杏加深（按鈕/邊框底） */
  --line: rgba(180, 130, 100, 0.20);    /* 溫潤暖褐邊框線 */
  --text: #2c201b;                      /* 深暖褐黑，高對比清晰耐看 */
  --text-dim: #685247;                  /* 次級暖褐 */
  --text-mute: #998074;                 /* 柔和灰褐 */
  --accent: #ef5a56;                    /* 主行動活力珊瑚朱紅（用戶色票） */
  --accent-2: #dc4844;                  /* 漸層深朱紅 */
  --gold: #f4d474;                      /* 溫暖麥黃金（用戶色票） */
  --gold-2: #dfbc55;                    /* 漸層小麥金 */
  --gold-dark: #a87915;                 /* 高對比小麥金文字用 */
  --mint: #10b981;                      /* 翡翠綠（成功/達標） */
  --rose: #ef5a56;                      /* 警示朱紅 */
  --amber: #f4d474;                     /* 暖黃 */
  --sky: #0284c7;                       /* 霽藍 */
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px -4px rgba(120, 70, 50, 0.08), 0 2px 6px -1px rgba(120, 70, 50, 0.04);
  --shadow-glow: 0 0 0 1px rgba(239, 90, 86, 0.25), 0 10px 25px -5px rgba(239, 90, 86, 0.35);
  --font: 'Inter', 'Noto Sans TC', system-ui, -apple-system, 'Microsoft JhengHei', sans-serif;
}

html[data-theme="dark"] {
  --bg-0: #0f1422;
  --bg-1: #161e31;
  --bg-2: #1e2842;
  --bg-3: #283556;
  --line: rgba(180, 195, 220, 0.16);
  --text: #f5f0eb;
  --text-dim: #abb8cf;
  --text-mute: #7c8ba3;
  --accent: #ff6b67;
  --accent-2: #ef5a56;
  --gold: #f5d880;
  --gold-2: #f4d474;
  --gold-dark: #f4d474;
  --mint: #34d399;
  --rose: #ff6b67;
  --amber: #fcd34d;
  --sky: #38bdf8;
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 0 1px rgba(239, 90, 86, 0.35), 0 10px 30px -10px rgba(239, 90, 86, 0.45);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  margin: 0; padding: 0;
  overflow-x: hidden;
  max-width: 100vw;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
}
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(239, 90, 86, 0.08), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(244, 212, 116, 0.15), transparent 60%),
    var(--bg-0);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  touch-action: pan-x pan-y;
  -webkit-user-select: none;
  user-select: none;
}
html[data-theme="dark"] body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(124, 140, 255, 0.16), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(167, 139, 250, 0.12), transparent 60%),
    var(--bg-0);
}
button, input, select, textarea {
  font-family: inherit; font-size: inherit; color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button { user-select: none; }
a { color: var(--accent); -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; }
.hidden { display: none !important; }
.dim { color: var(--text-dim); }
.mute { color: var(--text-mute); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 20px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg-3); color: var(--text);
  font-weight: 600; cursor: pointer; user-select: none;
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease, opacity .2s;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow); background: var(--bg-2); }
html[data-theme="dark"] .btn:hover:not(:disabled) { background: #26345a; }
.btn:active:not(:disabled) { transform: translateY(0) scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, #f86a66, #e04541); box-shadow: var(--shadow-glow); }
.btn-gold { background: linear-gradient(135deg, #f4d474, #dfbc55); color: #3d2600; border-color: transparent; font-weight: 800; }
.btn-gold:hover:not(:disabled) { background: linear-gradient(135deg, #fae08f, #cfab45); box-shadow: 0 8px 24px -4px rgba(244, 212, 116, 0.45); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-3); border-color: var(--line); }
.btn-danger { background: rgba(239, 90, 86, .12); border-color: rgba(239, 90, 86, .35); color: var(--rose); }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: 13px; position: relative; }
/* iPad 觸控熱區擴增，確保有效點擊半徑 >= 48px */
@media (pointer: coarse) {
  .btn-sm::after {
    content: ''; position: absolute; inset: -4px -4px; min-height: 48px; pointer-events: none;
  }
}
.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 表單 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.input, select.input, textarea.input {
  min-height: 44px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--bg-1); border: 1px solid var(--line); outline: none; color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(239, 90, 86, .2); }
textarea.input { min-height: 120px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--bg-1);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
html[data-theme="dark"] .card {
  background: linear-gradient(180deg, rgba(31, 42, 68, .92), rgba(23, 32, 54, .92));
}
.card h2, .card h3 { margin: 0 0 10px; color: var(--text); }
.card h2 { font-size: 18px; }
.card h3 { font-size: 15px; color: var(--text-dim); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: rgba(100, 116, 139, .12); color: var(--text-dim);
}
.badge-mint { background: rgba(16, 185, 129, .14); color: var(--mint); }
.badge-gold { background: rgba(244, 212, 116, .26); color: var(--gold-dark); }
.badge-rose { background: rgba(239, 90, 86, .14); color: var(--rose); }
.badge-accent { background: rgba(239, 90, 86, .15); color: var(--accent); }
.badge-sky { background: rgba(2, 132, 199, .14); color: var(--sky); }

.progress { height: 8px; border-radius: 99px; background: rgba(180, 130, 100, .15); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s ease; }
.progress.gold > i { background: linear-gradient(90deg, #f4d474, #dfbc55); }
.progress.mint > i { background: linear-gradient(90deg, #10b981, var(--mint)); }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; width: min(92vw, 420px); }
.toast {
  padding: 12px 16px; border-radius: 12px; background: var(--bg-1); border: 1px solid var(--line);
  box-shadow: 0 10px 25px -5px rgba(0,0,0,0.15); font-weight: 600; opacity: 0; transform: translateY(-8px); transition: all .25s ease; color: var(--text);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: rgba(5, 150, 105, .4); background: #ecfdf5; color: #065f46; }
.toast-error { border-color: rgba(225, 29, 72, .4); background: #fff1f2; color: #9f1239; }
.toast-gold { border-color: rgba(217, 119, 6, .4); background: #fef3c7; color: #92400e; }
html[data-theme="dark"] .toast-success { border-color: rgba(52, 211, 153, .5); background: linear-gradient(135deg, #0f2f28, #13332c); color: #e6ebf5; }
html[data-theme="dark"] .toast-error { border-color: rgba(251, 113, 133, .5); background: linear-gradient(135deg, #3a1520, #2e1119); color: #e6ebf5; }
html[data-theme="dark"] .toast-gold { border-color: rgba(245, 196, 81, .5); background: linear-gradient(135deg, #3a2a08, #2b1f06); color: #e6ebf5; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, .6); opacity: 0; transition: opacity .2s; padding: 16px;
}
html[data-theme="dark"] .modal-back { background: rgba(5, 8, 15, .86); }
.modal-back.show { opacity: 1; }

/* Modal（測驗）開啟時，暫停背景所有無限循環動畫，降低 GPU 負擔 */
body.modal-open #viewApp *,
body.modal-open #viewApp *::before,
body.modal-open #viewApp *::after { animation-play-state: paused !important; }

/* 使用者系統設定「減少動態效果」時，關閉循環動畫 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
.modal {
  position: relative; width: min(560px, 100%); max-height: 92vh; overflow: auto;
  -webkit-overflow-scrolling: touch; touch-action: pan-y;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1)); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.8); padding: 24px;
  transform: translateY(10px) scale(.98); transition: transform .2s ease;
}
.modal-wide { width: min(860px, 100%); }
.modal-back.show .modal { transform: none; }
.modal-x { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 20px; display: flex; align-items: center; justify-content: center; touch-action: manipulation; }
.modal-x:hover { background: var(--bg-3); color: var(--text); }
.modal h2 { margin-top: 0; }

/* ---------- 表格 ---------- */
.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; border-radius: var(--radius-sm); border: 1px solid var(--line); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { position: sticky; top: 0; background: var(--bg-2); font-size: 12px; color: var(--text-dim); font-weight: 700; z-index: 1; }
.tbl tbody tr { transition: background .15s; }
.tbl tbody tr:hover { background: rgba(124, 140, 255, .06); }

/* ---------- 題目（題庫可能含圖） ---------- */
.q-html img { vertical-align: middle; background: #fff; border-radius: 4px; padding: 2px; max-height: 140px; }

@media (max-width: 640px) {
  body { font-size: 15px; }
  .card { padding: 14px; }
  .modal { padding: 18px; border-radius: 14px; }
  .title-badge-md {
    font-size: 11px;
    padding: 2px 7px;
    margin-left: 4px;
  }
}

/* ===================== 全站共用稱號徽章與流光動畫 ===================== */
.title-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border-radius: 9999px;
  white-space: nowrap;
  vertical-align: middle;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, filter 0.2s ease;
  user-select: none;
  box-sizing: border-box;
}
.title-badge:hover {
  transform: translateY(-1.5px) scale(1.04);
  filter: brightness(1.08);
}
.title-badge-sm {
  font-size: 11px;
  padding: 1.5px 7px;
  margin-left: 6px;
  line-height: 1.35;
}
.title-badge-md {
  font-size: 12px;
  padding: 2.5px 10px;
  margin-left: 8px;
  line-height: 1.4;
  cursor: pointer;
}
.title-badge-lg {
  font-size: 14px;
  padding: 5px 14px;
  line-height: 1.5;
}
.title-badge .title-icon {
  display: inline-block;
  font-style: normal;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3));
}
.title-badge .title-text {
  display: inline-block;
  letter-spacing: 0.3px;
}

.title-glow-celestial {
  background-size: 200% 200% !important;
  animation: titleCelestialShimmer 4s ease infinite;
}
@keyframes titleCelestialShimmer {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.title-glow-red { animation: titlePulseRed 2.8s ease-in-out infinite alternate; }
@keyframes titlePulseRed {
  0% { box-shadow: 0 0 6px rgba(239, 68, 68, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  100% { box-shadow: 0 0 14px rgba(239, 68, 68, 0.85), 0 0 4px rgba(254, 202, 202, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
}

.title-glow-purple { animation: titlePulsePurple 2.8s ease-in-out infinite alternate; }
@keyframes titlePulsePurple {
  0% { box-shadow: 0 0 6px rgba(168, 85, 247, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  100% { box-shadow: 0 0 14px rgba(168, 85, 247, 0.85), 0 0 4px rgba(233, 213, 255, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
}

.title-glow-orange { animation: titlePulseOrange 2.8s ease-in-out infinite alternate; }
@keyframes titlePulseOrange {
  0% { box-shadow: 0 0 6px rgba(249, 115, 22, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  100% { box-shadow: 0 0 14px rgba(249, 115, 22, 0.85), 0 0 4px rgba(254, 215, 170, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
}

.title-glow-blue { animation: titlePulseBlue 2.8s ease-in-out infinite alternate; }
@keyframes titlePulseBlue {
  0% { box-shadow: 0 0 6px rgba(2, 132, 199, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  100% { box-shadow: 0 0 12px rgba(2, 132, 199, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
}

.title-glow-gold {
  background-size: 200% 200% !important;
  animation: titlePulseGold 2.6s ease-in-out infinite alternate;
}
@keyframes titlePulseGold {
  0% { background-position: 0% 50%; box-shadow: 0 0 8px rgba(245, 158, 11, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
  100% { background-position: 100% 50%; box-shadow: 0 0 16px rgba(251, 191, 36, 0.9), 0 0 5px rgba(254, 240, 138, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.55); }
}

.title-glow-emerald { animation: titlePulseEmerald 2.8s ease-in-out infinite alternate; }
@keyframes titlePulseEmerald {
  0% { box-shadow: 0 0 6px rgba(16, 185, 129, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  100% { box-shadow: 0 0 13px rgba(16, 185, 129, 0.85), 0 0 4px rgba(110, 231, 183, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
}

.title-glow-green { animation: titlePulseGreen 2.8s ease-in-out infinite alternate; }
@keyframes titlePulseGreen {
  0% { box-shadow: 0 0 6px rgba(5, 150, 105, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  100% { box-shadow: 0 0 13px rgba(16, 185, 129, 0.85), 0 0 4px rgba(167, 243, 208, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
}

.title-glow-indigo { animation: titlePulseIndigo 2.8s ease-in-out infinite alternate; }
@keyframes titlePulseIndigo {
  0% { box-shadow: 0 0 6px rgba(79, 70, 229, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  100% { box-shadow: 0 0 14px rgba(99, 102, 241, 0.85), 0 0 4px rgba(199, 210, 254, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
}

.title-glow-amber { animation: titlePulseAmber 2.8s ease-in-out infinite alternate; }
@keyframes titlePulseAmber {
  0% { box-shadow: 0 0 6px rgba(217, 119, 6, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  100% { box-shadow: 0 0 13px rgba(245, 158, 11, 0.85), 0 0 4px rgba(253, 230, 138, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
}

.title-glow-cyan { animation: titlePulseCyan 2.8s ease-in-out infinite alternate; }
@keyframes titlePulseCyan {
  0% { box-shadow: 0 0 6px rgba(8, 145, 178, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
  100% { box-shadow: 0 0 13px rgba(6, 182, 212, 0.85), 0 0 4px rgba(165, 243, 252, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
}
