:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2430;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-2: #7c3aed;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 16px 32px -12px rgba(16, 24, 40, 0.18), 0 4px 10px -4px rgba(16, 24, 40, 0.08);
  /* 天空效果的顏色也要跟著淺色/深色模式調整，不然裝置是深色模式時，
     白天的淺藍色天空會跟全站的暗色背景衝突撞色，變成突兀的色塊。 */
  --sky-day-tint: #cfe9fb;
  --sky-night-tint: #141a30;
  --sky-star: rgba(255, 255, 255, 0.75);
}

/* 深色樣式定義兩次：一次跟著系統設定（除非使用者自己選了「亮色」強制蓋掉），
   一次是使用者在會員選單裡自己選「暗色系」時，不管系統設定直接套用。 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --surface: #171a23;
    --border: #2a2e3a;
    --text: #eceef2;
    --text-muted: #9aa1af;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 32px -12px rgba(0, 0, 0, 0.55), 0 4px 10px -4px rgba(0, 0, 0, 0.3);
    --sky-day-tint: #1c2b45;
    --sky-night-tint: #090c16;
    --sky-star: rgba(255, 255, 255, 0.55);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #171a23;
  --border: #2a2e3a;
  --text: #eceef2;
  --text-muted: #9aa1af;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 32px -12px rgba(0, 0, 0, 0.55), 0 4px 10px -4px rgba(0, 0, 0, 0.3);
  --sky-day-tint: #1c2b45;
  --sky-night-tint: #090c16;
  --sky-star: rgba(255, 255, 255, 0.55);
}

/* 動態背景（日夜漸層＋太陽/月亮＋下雨動畫）關掉時，整個天空圖層跟溫度卡片的雨滴都不顯示。 */
body.bg-static #sky-layer,
body.bg-static .temp-card-rain {
  display: none !important;
}

/* 字體大小：小/中/大都是整個頁面等比例縮放（zoom 會連版面間距一起放大，
   比單純改 font-size 更接近「放大鏡」的效果，但只有 Chromium/Safari 支援，沒支援的瀏覽器就維持預設大小）。 */
body[data-font-size="small"] { zoom: 0.9; }
body[data-font-size="large"] { zoom: 1.15; }

* { box-sizing: border-box; }

html { height: 100%; overflow-x: hidden; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

.app-header {
  padding: 20px 24px 0;
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  flex-shrink: 0;
  width: 100%;
}

.app-title-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.app-title-link:hover h1 { color: var(--accent); }

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(155deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.5px;
  box-shadow: var(--shadow);
}

.brand-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.brand-en {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.app-header h1 {
  font-size: 22px;
  margin: 0;
  transition: color 0.12s ease;
}

.app-header .subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin: 3px 0 16px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-top: 4px;
}

.header-actions a, .header-actions button {
  font-size: 13px;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
}

.header-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 0 4px;
}

.live-clock { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

.online-count {
  display: flex;
  align-items: center;
  gap: 5px;
}

.online-count .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.report-issue-btn { color: var(--danger) !important; }

.header-member-btn {
  background: linear-gradient(155deg, var(--accent), var(--accent-2)) !important;
  color: #fff !important;
  border: none !important;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

.tab-btn {
  border: none;
  background: none;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(37, 99, 235, 0.06);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat-card .num {
  font-size: 26px;
  font-weight: 700;
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 4px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
}

.breadcrumb button {
  border: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
}

.breadcrumb button:hover { background: rgba(37,99,235,0.08); }

.breadcrumb .sep { color: var(--text-muted); }
.breadcrumb .current { color: var(--text-muted); }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}

.category-card {
  --tile-color: var(--accent);
  background: linear-gradient(135deg, var(--tile-color), color-mix(in srgb, var(--tile-color) 55%, black));
  border: none;
  border-radius: 22px;
  padding: 24px 20px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  text-align: left;
  color: #fff;
  position: relative;
  overflow: hidden;
  min-height: 148px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.category-card::before {
  content: "";
  position: absolute;
  top: -30%;
  right: -20%;
  width: 70%;
  height: 70%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.2), transparent 70%);
  pointer-events: none;
}

.category-card:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 20px 40px -14px rgba(0, 0, 0, 0.35);
}

.category-card .icon {
  font-size: 34px;
  margin-bottom: 12px;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}

.category-card .label {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.01em;
}

.category-card .count {
  color: rgba(255, 255, 255, 0.85);
  font-size: 12.5px;
  margin-top: 3px;
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.search-input, .text-input, select.text-input, textarea.text-input {
  flex: 1;
  min-width: 160px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.filter-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.card-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.item-card {
  background: var(--surface);
  border: none;
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.item-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.item-card .badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  margin-bottom: 8px;
}

.card-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.tag-row.top {
  justify-content: flex-end;
  margin-top: 0;
  max-width: 65%;
}

.item-card h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.item-card .meta {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 2px 0;
  display: flex;
  gap: 6px;
}

.item-card .desc {
  font-size: 13px;
  margin-top: 8px;
  color: var(--text);
  line-height: 1.5;
}

.tag-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.tag {
  font-size: 11px;
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 999px;
}

/* 活動卡片改版（羽球測試）：日期放大＋星期、人數用小圖示、右下報名狀態、即將開始凸顯 */
.event-card .event-date-big {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.event-card .event-date-big .badge {
  font-size: 14px;
  padding: 4px 10px;
  margin-bottom: 0;
}
.event-card .event-weekday {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.event-card.imminent {
  border: 2px solid #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15), var(--shadow);
}
.imminent-flag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #ef4444;
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.capacity-icons-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  flex-wrap: wrap;
}
.capacity-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-width: 220px;
}
.capacity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.capacity-dot.red { background: #ef4444; }
.capacity-dot.green { background: #22c55e; }

.card-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.reg-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.reg-badge.joined { background: rgba(34, 197, 94, 0.15); color: #16a34a; }
.reg-badge.waitlist { background: rgba(249, 115, 22, 0.15); color: #ea580c; }
.reg-badge.not-joined { background: rgba(148, 163, 184, 0.2); color: var(--text-muted); }

/* 卡片正中間、大一點的報名／已報名按鈕 */
.event-card-action-row {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
.card-join-btn {
  width: 100%;
  max-width: 260px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 999px;
  border: none;
  background: linear-gradient(155deg, var(--accent), var(--accent-2));
  color: #fff;
  cursor: pointer;
}
.card-join-btn.joined {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
}

.expired-flag {
  text-align: center;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

/* 我自己開的／已報名的活動，快開始時讓原本「即將開始」的紅框本身發光脈動，比靜態紅框更搶眼，
   但不另外疊加裝飾性外框，維持原本卡片形狀簡潔。 */
.event-card.my-imminent {
  animation: event-card-glow 1.8s ease-in-out infinite;
}
@keyframes event-card-glow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15), var(--shadow); }
  50% { box-shadow: 0 0 16px 4px rgba(239, 68, 68, 0.55), var(--shadow); }
}
@media (prefers-reduced-motion: reduce) {
  .event-card.my-imminent { animation: none; }
}

.empty-state {
  text-align: center;
  padding: 40px 0;
  color: var(--text-muted);
  font-size: 14px;
}

.note {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(37, 99, 235, 0.06);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
}

/* map */
#map {
  height: 560px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.mini-map {
  height: 220px;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: 8px;
}

/* ---------- admin ---------- */

.login-wrap {
  max-width: 360px;
  margin: 80px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-wrap h2 { margin-top: 0; }

.form-row {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.btn {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { opacity: 0.92; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-text { color: var(--danger); font-size: 13px; margin-top: 6px; }
.success-text { color: #16a34a; font-size: 13px; margin-top: 6px; }

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13.5px;
}

table.admin-table th, table.admin-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.admin-table th {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

table.admin-table tr:last-child td { border-bottom: none; }

.row-actions { display: flex; gap: 6px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 22px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
}

.modal h3 { margin-top: 0; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.admin-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.admin-tabs button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}

.admin-tabs button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.crawler-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
}

.crawler-panel h3 { margin-top: 0; font-size: 15px; }

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0;
}

.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.candidate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.candidate-card .top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.candidate-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.candidate-fields .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.candidate-fields .field label {
  font-size: 11px;
  color: var(--text-muted);
}

.spinner-text {
  color: var(--text-muted);
  font-size: 13px;
  padding: 10px 0;
}

/* ================== 前台 portal 版面 ================== */

.portal-layout {
  display: flex;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  gap: 16px;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 24px 20px;
  box-sizing: border-box;
}

/* ---- 上方：文字導覽列（改版：原本左側圖示直排移到頂部橫排，登入靠最右） ---- */

/* .side-nav 本身有 overflow-x:auto（讓按鈕列在窄螢幕能橫向捲動），會把底色一起裁掉，
   所以底色改放在這層不捲動的外層——這層本身沒有 max-width，天生就是滿版寬度，
   不需要額外暈開，只要給實色背景即可。 */
.side-nav-outer {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 1;
}

.side-nav {
  flex-shrink: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 24px;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
  background: transparent;
}

.side-nav-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 4px;
  position: relative;
  border: none;
  background: none;
  color: var(--text-muted);
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13.5px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.side-nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.side-nav-item.active {
  background: linear-gradient(155deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 6px 16px -6px rgba(37, 99, 235, 0.55);
}

.nav-badge {
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #f59e0b;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- 中間：布告欄 / 跑馬燈 / 新聞 / 一般內容 ---- */

.portal-center {
  flex: 1 1 auto;
  min-width: 240px;
  overflow-y: auto;
  padding-right: 6px;
}

.bulletin-board {
  position: relative;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  margin-bottom: 24px;
}

.bulletin-board::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 88% -10%, rgba(255, 255, 255, 0.28), transparent 55%);
  pointer-events: none;
}

.marquee-wrap {
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.16);
  color: #fff;
  padding: 10px 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.marquee-track {
  display: inline-block;
  padding-left: 100%;
  animation: marquee-scroll 22s linear infinite;
}

.marquee-track span { margin-right: 60px; }

@keyframes marquee-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

/* 全站最上方的跑馬燈（header 上面），右邊可以按 ✕ 隱藏這次 session。 */
.site-marquee {
  border-radius: 0;
  margin-bottom: 0;
  box-shadow: none;
}
.site-marquee .marquee-wrap { padding-right: 40px; }

.marquee-hide-btn {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.2);
  border: none;
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}
.marquee-hide-btn:hover { background: rgba(0, 0, 0, 0.35); }

/* 側邊欄的問答互助小卡：跟其他 weather-card 一樣的外觀，點了彈出瀏覽視窗。 */
.qa-side-teaser:hover { box-shadow: var(--shadow-lg); }

/* 首頁行事曆：周末去哪／運動專區的活動簡單標示在月曆上，點某一天展開當天活動清單。 */
.home-calendar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.home-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.home-cal-title { font-weight: 700; font-size: 15px; }

.home-cal-legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.home-cal-legend span { display: flex; align-items: center; gap: 5px; }

.home-cal-weekdays, .home-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.home-cal-weekdays {
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 4px;
}

.home-cal-weekdays span {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
}

/* 淡淡的格線：每一格自己畫右邊/下邊的線，整個格子區外層再補左邊的線，
   這樣相鄰格子共用同一條線，不會變成到處都是雙倍粗的線。 */
.home-cal-grid {
  border-left: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.home-cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  background: none;
  border: 0 solid var(--border);
  border-right-width: 1px;
  border-bottom-width: 1px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  padding: 4px 3px;
  overflow: hidden;
}
.home-cal-cell.empty { cursor: default; }
.home-cal-cell:not(.empty):hover { background: var(--bg); }
.home-cal-cell.today .home-cal-daynum { color: var(--accent); font-weight: 800; }
.home-cal-cell.selected { background: var(--bg); box-shadow: inset 0 0 0 2px var(--accent); }
.home-cal-cell.has-events .home-cal-daynum { font-weight: 700; }

/* 日期數字放左上角，字放大一點；活動點數獨立一排貼在格子最下面，上下分兩層。 */
.home-cal-daynum { font-size: 16px; line-height: 1.2; }

.home-cal-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: auto;
  padding-top: 2px;
}
.home-cal-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.home-cal-dot.general { background: var(--accent); }
.home-cal-dot.sports { background: #f97316; }


.bulletin-list {
  position: relative;
  padding: 26px 28px 30px;
}

.bulletin-item {
  padding: 11px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.bulletin-item:last-child { border-bottom: none; }

.bulletin-item .title {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.01em;
  margin-bottom: 4px;
}

.bulletin-item .content {
  font-size: 13.5px;
  color: rgba(255, 255, 255, 0.88);
  line-height: 1.6;
}

.news-section {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 22px 26px 24px;
}

.news-section h2 {
  font-size: 17px;
  font-weight: 800;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.news-updated {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 400;
}

.news-list { margin-top: 10px; }

.news-item {
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.news-item:last-child { border-bottom: none; }

.news-item a {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.4;
}

.news-item a:hover { color: var(--accent); }

.news-item .meta {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---- 右側：空氣品質 / 氣溫小工具 ---- */

.side-widget {
  flex: 0 0 300px;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.weather-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.weather-card h3 {
  font-size: 14px;
  margin: 0 0 10px;
}

.bulletin-list-side { display: flex; flex-direction: column; gap: 10px; }

.bulletin-item-side {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.bulletin-item-side:last-child { padding-bottom: 0; border-bottom: none; }

.bulletin-item-side .title {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text);
  margin-bottom: 3px;
}

.bulletin-item-side .content {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.55;
}

.range-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.range-toggle button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 0;
  border-radius: 8px;
  cursor: pointer;
}

.range-toggle button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.aqi-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 26px;
  font-weight: 800;
}

.aqi-badge .status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.aqi-status-label {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.weather-period {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.weather-period:last-child { border-bottom: none; }

.weather-period .day-label { color: var(--text-muted); min-width: 64px; }
.weather-period .temp-range { font-weight: 700; }

.aqi-trend-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 4px;
  height: 70px;
  margin-top: 8px;
}

.aqi-trend-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.aqi-trend-bar .bar {
  width: 100%;
  border-radius: 3px 3px 0 0;
  min-height: 3px;
}

.aqi-trend-bar .label {
  font-size: 9.5px;
  color: var(--text-muted);
}

.widget-error {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px;
  line-height: 1.5;
}

/* ---- 我的最愛（cookie）星星按鈕 ---- */

.fav-star {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px;
  color: #d1d5db;
}

.fav-star.active { color: #f59e0b; }

.item-card .card-header-row .fav-star { margin-left: 6px; }

.popular-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.popular-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.popular-row:hover { transform: translateY(-1px); box-shadow: 0 6px 16px -8px rgba(0, 0, 0, 0.25); }

.popular-row .rank {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  background: var(--accent);
  color: #fff;
}

.popular-row .rank-name { flex: 1 1 auto; font-weight: 600; font-size: 13.5px; }
.popular-row .rank-hearts { flex: 0 0 auto; font-size: 12.5px; color: var(--text-muted); font-weight: 700; }

.time-range-slider { margin: 14px 0 22px; }

.trs-track {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  margin: 26px 10px 0;
  cursor: pointer;
  touch-action: none;
}

.trs-range-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 3px;
  pointer-events: none;
}

.trs-handle {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  transform: translateY(-50%);
  background: #fff;
  border: 3px solid var(--accent);
  border-radius: 50%;
  cursor: grab;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  touch-action: none;
  z-index: 2;
}

.trs-handle:active { cursor: grabbing; }

.trs-handle .trs-label {
  position: absolute;
  top: -27px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  white-space: nowrap;
  pointer-events: none;
}

.trs-scale {
  display: flex;
  justify-content: space-between;
  margin: 8px 10px 0;
  font-size: 10.5px;
  color: var(--text-muted);
}

.date-calendar-popup {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  padding: 10px;
  z-index: 50;
}

.date-calendar-popup .cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 8px;
}

.date-calendar-popup .cal-header button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
}
.date-calendar-popup .cal-header button:hover { background: var(--border); }

.date-calendar-popup .cal-weekdays,
.date-calendar-popup .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.date-calendar-popup .cal-weekdays span {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
  padding-bottom: 4px;
}

.date-calendar-popup .cal-day {
  background: none;
  border: none;
  color: var(--text);
  font-size: 12.5px;
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
}
.date-calendar-popup .cal-day:hover { background: var(--border); }
.date-calendar-popup .cal-day.today { font-weight: 800; color: var(--accent); }
.date-calendar-popup .cal-day.selected { background: var(--accent); color: #fff; }

#toast-root {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(340px, calc(100vw - 32px));
}

.toast-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast-item.show { opacity: 1; transform: translateX(0); }
.toast-item.toast-warning { border-left-color: #f59e0b; }
.toast-item.toast-success { border-left-color: #22c55e; }
.toast-item.toast-error { border-left-color: var(--danger); }

/* ================== RWD：窄螢幕（手機/平板）版面覆寫 ==================
   放在檔案最後，確保這裡的規則在同層級選擇器的 cascade 順序上一定贏過前面的桌面版基本樣式。 */

@media (max-width: 1100px) {
  body { height: auto; }
  .app-header { position: static; }

  .side-nav { padding: 8px 16px; }

  .portal-layout {
    display: block;
    flex: none;
    min-height: 0;
    padding: 16px;
  }

  .portal-center { order: 1; min-width: 0; overflow-y: visible; margin-bottom: 16px; }
  .side-widget { order: 2; flex: none; width: auto; overflow-y: visible; }
}

@media (max-width: 640px) {
  /* 手機寬度放不下 8 個導覽項目，原本用橫向捲動，但使用者常常沒發現要滑，
     導致「店家」這種排比較後面的項目看起來像消失了。改成自動換行，全部項目一次顯示完，
     不用捲動也不會被裁掉。 */
  .side-nav {
    flex-wrap: wrap;
    overflow-x: visible;
  }
}

/* ---------------------------------------------------------------
   天空效果：跟著現在真實時間判斷日出日落，換成白天/夜晚的漸層，
   一顆太陽或月亮沿弧線慢慢移動；樹林目前如果在下雨，畫面也跟著下雨。
   純裝飾用（aria-hidden、pointer-events:none），不影響任何操作。
--------------------------------------------------------------- */

/* 天空漸層是獨立的 fixed 圖層（蓋滿整個視窗，蓋在 body 最底下），
   不能直接放在 body 的 background 上——body 底下有好幾個區塊各自有自己的 max-width
   （頁首 1120px、導覽列 1500px...），background 只會在那些區塊「以外」的留白處露出來，
   會變成一格一格奇怪的色塊，而不是統一的背景。 */
#sky-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  transition: background 3s ease;
}
/* 上面 260px 先維持跟頁首/導覽列一樣的純色（不管頁首在哪個斷點是 sticky 或 static，
   兩者背景本來就都是 var(--bg)，顏色完全一樣，不會有接縫），漸層的顏色從 260px 之後才開始，
   這樣就不需要再讓頁首/導覽列本身去做「滿版底色」的特殊處理，避免額外的跨瀏覽器風險。 */
body.time-day #sky-layer {
  background: linear-gradient(180deg, var(--bg) 0px, var(--bg) 260px, var(--sky-day-tint) 340px, var(--bg) 780px);
}
body.time-night #sky-layer {
  background:
    radial-gradient(1.5px 1.5px at 12% 34%, var(--sky-star), transparent),
    radial-gradient(1.5px 1.5px at 28% 40%, var(--sky-star), transparent),
    radial-gradient(1px 1px at 45% 30%, var(--sky-star), transparent),
    radial-gradient(1.5px 1.5px at 65% 38%, var(--sky-star), transparent),
    radial-gradient(1px 1px at 82% 28%, var(--sky-star), transparent),
    radial-gradient(1.5px 1.5px at 92% 42%, var(--sky-star), transparent),
    linear-gradient(180deg, var(--bg) 0px, var(--bg) 260px, var(--sky-night-tint) 340px, var(--bg) 780px);
}

/* 太陽/月亮圖示釘在頁首的時間資訊列裡（不是 position:fixed 飄在畫面上）：
   之前用 fixed + 依時間移動的弧線動畫，在手機（尤其 iOS Safari 網址列滑動變化視窗高度時）
   會看起來像跟著頁面亂飄、擋住畫面，所以改成跟時鐘同一排的固定小圖示，不會再移動或飄浮。 */
.clock-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
#sky-body {
  font-size: 18px;
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(255, 210, 120, 0.5));
}
body.time-night #sky-body {
  filter: drop-shadow(0 0 5px rgba(200, 210, 255, 0.5));
}

/* 下雨效果縮到「樹林氣溫」卡片裡面，只在那個框框裡下，不會蓋住整頁內容。
   flex-shrink:0 是必要的：這張卡片是 .side-widget（flex-direction:column）裡的一個 flex item，
   一旦設了 overflow:hidden，瀏覽器會把它的「自動最小高度」視為 0（不是內容高度），
   在側欄內容變多（例如切到「1 週」有 7 天資料）超出可用空間時，就會整張被壓縮到幾乎看不見、
   內容被 overflow:hidden 裁光，而不是把這張卡片維持原本高度、改由側欄自己捲動。 */
#weather-temp-card {
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.temp-card-rain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  display: none;
  z-index: 0;
}
.temp-card-rain.active { display: block; }
.temp-card-rain .drop {
  position: absolute;
  top: -20px;
  width: 1.5px;
  height: 16px;
  background: linear-gradient(180deg, transparent, rgba(90, 140, 220, 0.6));
  animation-name: rain-fall-card;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
@keyframes rain-fall-card {
  to { transform: translateY(220px); }
}
#weather-temp-card > *:not(.temp-card-rain) {
  position: relative;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  .temp-card-rain .drop { animation: none; opacity: 0; }
}
