/*
 * 學得快 UI Polish 1.0
 * 以原本的暖紙色、深藍墨色與珊瑚色為基礎，細修層次、互動、可讀性及手機安全區。
 * 不覆寫解題、登入或資料儲存流程。
 */
:root {
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --radius-sm: 9px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 160ms ease;
  --shadow-card-soft: 0 2px 12px rgba(23, 50, 77, 0.07);
  --shadow-card-elevated: 0 8px 24px rgba(23, 50, 77, 0.12);
}

/* 保留紙感網格，只降低長時間閱讀時的干擾 */
body {
  font-family: var(--font-sans);
  background-attachment: scroll;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body.theme-paper {
  --theme-bg: #f7f4ee;
  --theme-bg-glass: #f7f4eee8;
  --theme-card: #fffdf9;
  --theme-border: #20384c;
  --theme-accent: #df7b56;
  --theme-accent-hover: #cf6b48;
  --theme-accent-dark: #b95b3a;
  --theme-grid: #20384c08;
  --theme-shadow: #20384c26;
  --theme-shadow-light: #20384c0a;
  --theme-overlay: #20384cb3;
  --theme-accent-shadow: #df7b5638;
  --theme-accent-shadow-light: #df7b5630;
}
body.theme-matcha { --theme-grid: #12352408; }
body.theme-soda { --theme-grid: #0f1c2e08; }
body.theme-sakura { --theme-grid: #4a152508; }
body.theme-lavender { --theme-grid: #2d1b4e08; }
body.theme-lemon { --theme-grid: #4a3f0008; }
body.theme-oat { --theme-grid: #3d2b1f08; }
body.theme-glacier { --theme-grid: #11182708; }

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 84px; }
body { overflow-x: clip; }
img, video, canvas, svg { max-width: 100%; }
p, li, h1, h2, h3, h4, label, button, a { overflow-wrap: anywhere; }
button, input, select, textarea { font: inherit; }
button, a, [role="button"] { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
button:disabled { cursor: not-allowed; }

/* 主導覽列：原本 utility class 不會在此打包版中生效，補上實際定位與層次 */
header[class~="sticky"] {
  position: sticky !important;
  top: 0 !important;
  z-index: 80 !important;
  background: var(--theme-bg-glass, rgba(248, 243, 235, .94)) !important;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-paper, #e8ded0) !important;
  box-shadow: 0 2px 9px rgba(23, 50, 77, .045);
}
header[class~="sticky"] > div {
  max-width: 1440px;
  min-width: 0;
}
header img[alt="學得快官方標誌"] { flex-shrink: 0; }

/* 內容區更容易掃讀，桌面留白維持舒適，窄螢幕不浪費寬度 */
.main-content {
  width: min(100%, 1440px);
  min-width: 0;
  padding: 28px clamp(16px, 2.2vw, 28px) 96px;
}
.main-content > * { min-width: 0; }
.main-content h1, .main-content h2, .main-content h3 {
  text-wrap: pretty;
}
.main-content h1 { letter-spacing: -.025em !important; }
.main-content p { text-wrap: pretty; }

/* 卡片保留原本的深藍描邊與紙張層次，將厚重硬陰影收斂 */
.glass-panel {
  border-width: 1.5px !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 3px 3px 0 var(--theme-border, #17324d) !important;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
.glass-panel-glow {
  border-width: 1.5px !important;
  box-shadow: 4px 4px 0 #ead69b !important;
  border-radius: var(--radius-lg) !important;
}
@media (hover: hover) and (pointer: fine) {
  .glass-panel:hover {
    box-shadow: 4px 4px 0 var(--theme-border, #17324d) !important;
    transform: translate(-1px, -1px);
  }
}
.btn {
  border-width: 1.5px !important;
  border-radius: 11px !important;
  letter-spacing: 0;
  box-shadow: 2px 2px 0 var(--theme-border, #17324d);
}
.btn-primary {
  text-shadow: none !important;
  box-shadow: 0 3px 0 var(--theme-accent-dark, #d76740) !important;
}
.btn-primary:hover {
  box-shadow: 0 4px 0 var(--theme-accent-dark, #d76740) !important;
  transform: translateY(-1px);
}
.btn-secondary { box-shadow: 2px 2px 0 var(--theme-border, #17324d) !important; }
.btn-secondary:hover {
  box-shadow: 3px 3px 0 var(--theme-border, #17324d) !important;
}
.btn:active:not(:disabled) {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--theme-border, #17324d) !important;
}
.btn-ghost { box-shadow: none !important; }
.badge { letter-spacing: 0; }
.quiz-option { min-width: 0; line-height: 1.55; }
.quiz-option:hover { transform: translateY(-1px); }
.quiz-option-selected, .quiz-option-correct, .quiz-option-wrong {
  box-shadow: 2px 2px 0 var(--theme-accent, #ef8354) !important;
}
input, textarea, select {
  max-width: 100%;
  border-radius: 10px;
}
:focus-visible {
  outline-width: 2px !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 3px var(--theme-accent-shadow-light, #ef835438) !important;
}

/* 公告保留深色識別，但減少亮面與重陰影；不改跑馬燈內容或關閉功能 */
.marquee-bar {
  border-bottom-width: 1px;
  box-shadow: 0 1px 5px rgba(23, 50, 77, .14);
}
.marquee-badge-pill { box-shadow: none; }
.marquee-item { padding-left: 20px; padding-right: 20px; }

/* 彈窗：固定標頭與內容區分離，較長表單可在彈窗內捲動 */
.modal-overlay {
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.modal-card {
  border-width: 1.5px !important;
  border-radius: 16px !important;
  box-shadow: 4px 4px 0 var(--theme-border, #17324d) !important;
  overscroll-behavior: contain;
}
.modal-header {
  border-bottom-width: 1px !important;
  gap: 12px;
}
.modal-body { min-width: 0; }
.modal-footer { border-top-width: 1px !important; flex-wrap: wrap; }

/* 手機底部導覽：依安全區加高，六至七個項目可在窄機身內平均排版 */
nav[style*="position: fixed"][style*="bottom: 0"] {
  height: calc(66px + env(safe-area-inset-bottom, 0px)) !important;
  padding: 4px 5px calc(4px + env(safe-area-inset-bottom, 0px)) !important;
  gap: 1px;
  border-top-width: 1px !important;
  box-shadow: 0 -2px 10px rgba(23, 50, 77, .08) !important;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
nav[style*="position: fixed"][style*="bottom: 0"] > button {
  flex: 1 1 0 !important;
  min-width: 0 !important;
  max-width: none !important;
  min-height: 48px;
  padding: 4px 1px !important;
  border-radius: 9px !important;
  gap: 1px !important;
}
nav[style*="position: fixed"][style*="bottom: 0"] > button span {
  max-width: 100%;
  font-size: 11px !important;
  line-height: 1.15;
  white-space: nowrap;
  letter-spacing: -.02em;
}
nav[style*="position: fixed"][style*="bottom: 0"] > button svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
}
/* 兼顧原本在 React 內指定的底部留白 */
.main-content { padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)) !important; }

/* 載入與 SEO fallback 內容在手機上不應超出視窗 */
.seo-semantic-container {
  width: min(100% - 24px, 960px);
  margin-left: auto !important;
  margin-right: auto !important;
}
.seo-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
[data-app-boot-screen] { padding-top: max(24px, env(safe-area-inset-top)) !important; }

/* 無障礙：鍵盤跳至主內容時才顯示，不影響原本視覺 */
.skip-link {
  position: fixed;
  left: 12px;
  top: 10px;
  z-index: 20000;
  padding: 10px 14px;
  color: #fff;
  background: var(--theme-border, #17324d);
  border: 2px solid var(--theme-card, #fffdf9);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
  transform: translateY(-160%);
  transition: transform 140ms ease;
  text-decoration: none;
  font-weight: 700;
}
.skip-link:focus { transform: translateY(0); }

/* 螢幕閱讀器仍能感知主要導覽的目前位置 */
[aria-current="page"] { scroll-margin-top: 88px; }
nav[style*="position: fixed"][style*="bottom: 0"] > button[aria-current="page"] {
  background: var(--theme-accent-shadow-light, #ef835438) !important;
  color: var(--theme-accent, #ef8354) !important;
}

@media (max-width: 900px) {
  .main-content {
    padding: 20px 16px calc(88px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .modal-overlay { align-items: flex-start; overflow-y: auto; }
  .modal-card {
    max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto;
    margin: auto 0;
  }
  .modal-header { padding: 16px 18px !important; }
  .modal-body { padding: 18px !important; }
  .modal-footer { padding: 12px 16px !important; }
  header[class~="sticky"] > div {
    padding-left: 14px !important;
    padding-right: 14px !important;
    gap: 10px !important;
  }
}
@media (max-width: 640px) {
  html { scroll-padding-top: 70px; }
  header img[alt="學得快官方標誌"] + div > div:nth-child(2) { display: none; }
  body { background-size: 28px 28px; }
  .main-content {
    padding: 16px 12px calc(86px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .marquee-bar {
    min-height: 34px;
    height: 34px;
    font-size: .78rem;
  }
  .marquee-item { gap: 7px; padding: 0 12px; }
  .marquee-badge-pill { padding: 3px 7px; font-size: .68rem; }
  .modal-overlay {
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }
  .modal-card {
    width: 100%;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    border-radius: 14px !important;
  }
  .modal-body { padding: 14px !important; }
  input, textarea, select {
    font-size: 16px !important; /* 避免 iOS 聚焦輸入框時自動放大畫面 */
  }
  button, .btn, [role="button"] { touch-action: manipulation; }
  .seo-semantic-container { width: calc(100% - 20px); padding: 18px !important; }
  .seo-grid { gap: 10px; }
  .seo-card { min-width: 0; padding: 12px; }
}
@media (max-width: 360px) {
  .main-content { padding-left: 10px !important; padding-right: 10px !important; }
  nav[style*="position: fixed"][style*="bottom: 0"] > button span { font-size: 10px !important; }
  nav[style*="position: fixed"][style*="bottom: 0"] > button svg { width: 17px; height: 17px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .marquee-track { animation: none !important; }
}
