/* ═══════════════════════════════════════════
   班級電子佈告欄 — MUJI-inspired
   米白・自然・極簡・留白
   ═══════════════════════════════════════════ */

:root {
  --ink: #2c2c2c;
  --ink-soft: #555555;
  --ink-muted: #8a8a8a;
  --paper: #f5f2eb;
  --paper-2: #faf8f4;
  --cream: #ebe6dc;
  --line: #ddd6c8;
  --line-strong: #b8b0a2;
  --shadow: 0 8px 28px rgba(44, 44, 44, 0.06);
  --shadow-sm: 0 2px 10px rgba(44, 44, 44, 0.04);

  /* 分類：低彩度自然色 */
  --school: #5c5346;
  --admin: #6b6358;
  --teacher: #7a6a55;
  --homework: #6b7a63;
  --exam: #6b7a63;
  --officer: #5c5346;
  --helper: #6b7a63;
  --viewer: #5c5346;

  --accent: #4a4a4a;
  --accent-hover: #2c2c2c;
  --accent-soft: #7a7a7a;
  --blush: #ebe6dc;
  --blush-deep: #ddd6c8;
  --mint-block: #e8ebe4;
  --lilac-block: #ebe8e3;
  --success: #6b7a63;
  --danger: #9a5b55;
  --radius: 6px;
  --radius-sm: 4px;
  --font-sans: "Noto Sans TC", "PingFang TC", "Hiragino Sans", "Microsoft JhengHei", sans-serif;
  --font-serif: "Noto Sans TC", "PingFang TC", "Hiragino Sans", sans-serif;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --tracking-wide: 0.14em;
  --tracking-label: 0.08em;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  font-family: var(--font-sans);
  font-size: clamp(0.9rem, 0.86rem + 0.2vw, 1rem);
  font-weight: 400;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.7;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
  padding: 0;
  overflow-x: hidden;
  position: relative;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

/* 米白淨底 */
.bg-pattern {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--paper);
}








.hidden {
  display: none !important;
}

/* ── 模式提示／即時狀態／Toast ── */

.mode-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0.65rem 1.25rem;
  background: var(--cream);
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  line-height: 1.6;
  text-align: center;
}

.mode-banner code {
  font-size: 0.76rem;
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  background: var(--paper-2);
  color: var(--ink);
}

.mode-banner strong {
  color: var(--ink);
  font-weight: 700;
}

.status-live {
  margin: 0.85rem 0 0;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--ink-muted);
  font-weight: 500;
}

.status-live::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: var(--homework);
  box-shadow: none;
  vertical-align: 0.05em;
}

.status-live.off {
  color: var(--ink-muted);
}

.status-live.off::before {
  background: var(--ink-muted);
  box-shadow: none;
}

.status-live-bar {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--ink-muted);
}

.stats-mode {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 100;
  padding: 0.75rem 1.35rem;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: min(90vw, 360px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--danger);
}

/* ── 角色選擇 ── */

.role-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.25rem 1.25rem 3rem;
  animation: fadeUp 0.7s var(--ease) both;
}

.role-header {
  text-align: center;
  max-width: 36rem;
  width: 100%;
  margin-bottom: 2.5rem;
  position: relative;
  padding: 0 0.5rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}

.role-header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
  position: relative;
  min-height: 2rem;
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 500;
}

/* 今日日期 */
.today-date {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  margin: 0;
  padding: 0.25rem 0.15rem;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  box-shadow: none;
  font-family: var(--font-sans);
  font-size: clamp(1.1rem, 2.8vw, 1.3rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  color: var(--ink);
  line-height: 1;
  white-space: nowrap;
}

.role-header h1 {
  margin: 0 0 0.75rem;
  font-family: var(--font-sans);
  font-size: clamp(1.7rem, 4vw, 2.2rem);
  font-weight: 500;
  letter-spacing: 0.12em;
  line-height: 1.35;
  color: var(--ink);
}

.subtitle {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.role-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  width: min(100%, 960px);
  background: transparent;
  border: none;
}

.role-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 1.6rem 1.35rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  box-shadow: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.2s ease, background 0.2s ease;
  overflow: hidden;
}

.role-card::before {
  content: none;
}

.role-card:hover,
.role-card:focus-visible {
  transform: none;
  box-shadow: none;
  background: #fff;
  border-color: var(--ink-muted);
  outline: none;
}

.role-card:hover .role-icon,
.role-card:focus-visible .role-icon {
  width: 2.2rem;
  height: 2.2rem;
  margin-bottom: 1rem;
  color: var(--ink-soft);
  opacity: 0.85;
}


.role-card:hover .role-tag,
.role-card:focus-visible .role-tag {
  margin: 0 0 0.85rem;
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 2px;
  border: none;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  background: var(--cream);
  color: var(--ink-soft);
}

.role-card:hover .role-cta,
.role-card:focus-visible .role-cta {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
  text-transform: none;
}

.role-viewer { --card-accent: var(--viewer); }
.role-officer { --card-accent: var(--officer); }
.role-helper { --card-accent: var(--helper); }
.role-tutor { --card-accent: var(--teacher); }

.role-icon {
  width: 2.6rem;
  height: 2.6rem;
  margin-bottom: 1.1rem;
  color: var(--card-accent);
  opacity: 1;
}

.role-icon svg {
  width: 100%;
  height: 100%;
}

.role-card h2 {
  margin: 0 0 0.4rem;
  font-family: var(--font-sans);
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.role-tag {
  margin: 0 0 0.9rem;
  display: inline-block;
  padding: 0.22rem 0.7rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: none;
  background: color-mix(in srgb, var(--card-accent) 12%, transparent);
  color: var(--card-accent);
}

.role-desc {
  margin: 0 0 1.25rem;
  flex: 1;
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--ink-soft);
  line-height: 1.7;
}

.role-cta {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--card-accent);
  letter-spacing: 0.02em;
  text-transform: none;
}

.tutor-hint {
  margin-top: 2.25rem;
  max-width: 28rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

/* ── 主應用 ── */

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  animation: fadeUp 0.45s var(--ease) both;
}

/* 頂欄：App 導覽列式佈局
   [返回 | 標題＋同步] ………… [身份標籤] [次要操作] [主要 CTA] */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
  box-sizing: border-box;
  background: rgba(245, 242, 235, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(100%, 1200px);
  max-width: 100%;
  margin: 0 auto;
  padding: 0.7rem 1.35rem;
  min-height: 3.5rem;
  box-sizing: border-box;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 0 0 auto;
}

.topbar-divider {
  width: 1px;
  height: 1.5rem;
  background: var(--line);
  flex-shrink: 0;
}

/* 返回 */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.35rem 0.55rem 0.35rem 0.3rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  flex-shrink: 0;
}

.btn-back:hover {
  background: var(--cream);
  color: var(--ink);
}

.btn-back:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 2px;
}

.btn-back svg {
  flex-shrink: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.1rem;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 0.98rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-live-bar {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--ink-muted);
  line-height: 1.2;
}

.status-live-bar::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 0.35rem;
  border-radius: 50%;
  background: var(--homework);
  box-shadow: none;
  vertical-align: 0.05em;
}

.status-live-bar.off {
  color: var(--ink-muted);
}

.status-live-bar.off::before {
  background: var(--ink-muted);
  box-shadow: none;
}

.topbar-meta {
  display: flex;
  align-items: center;
}

/* 身份標籤 */
.role-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.7rem;
  border-radius: 2px;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  white-space: nowrap;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink-soft);
}

.role-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}

.role-chip[data-role="viewer"],
.role-chip[data-role="officer"],
.role-chip[data-role="helper"],






.role-chip[data-role="tutor"] {
  background: var(--lilac-block);
  color: var(--teacher);
  border-color: color-mix(in srgb, var(--teacher) 18%, transparent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

/* 次要操作 */
.btn-soft {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-2);
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  white-space: nowrap;
}

.btn-soft:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #fff;
}

.btn-soft.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.btn-soft svg {
  flex-shrink: 0;
  opacity: 0.85;
}

.btn-new {
  border-radius: var(--radius-sm) !important;
  padding: 0.5rem 1rem !important;
  gap: 0.35rem;
  white-space: nowrap;
  letter-spacing: 0.06em;
  text-transform: none;
  font-size: 0.84rem !important;
  font-weight: 500 !important;
}

.btn-new svg {
  flex-shrink: 0;
}

.main {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  flex: 1;
  width: min(100%, 1200px);
  margin: 0 auto;
}

/* ── 側欄 ── */

.sidebar {
  padding: 1.75rem 1.25rem 2.25rem;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--cream) 40%, transparent);
}

.sidebar-title {
  margin: 0 0 0.9rem;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 500;
}

.filter-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.filter-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.filter-btn:hover {
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
}

.filter-btn.active {
  background: var(--paper-2);
  color: var(--ink);
  font-weight: 500;
  box-shadow: none;
  border-color: var(--line);
  letter-spacing: 0.03em;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.school { background: var(--school); }
.dot.admin { background: var(--admin); }
.dot.teacher { background: var(--teacher); }
.dot.homework { background: var(--homework); }
.dot.exam { background: var(--exam); }
.dot.officer { background: var(--officer); }

/* ── 跑馬燈（角色卡上方）── */

.marquee {
  display: flex;
  align-items: stretch;
  width: min(100%, 960px);
  max-width: 100%;
  margin: 0 auto 1.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  box-shadow: none;
  overflow: hidden;
  min-height: 2.55rem;
}

.marquee-label {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.95rem;
  background: var(--cream);
  border-right: 1px solid var(--line);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
  text-transform: none;
  white-space: nowrap;
  z-index: 1;
}

.marquee-label-icon {
  display: inline;
  font-size: 0.85rem;
}

.marquee-viewport {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  mask-image: linear-gradient(
    90deg,
    transparent 0,
    #000 1.5rem,
    #000 calc(100% - 1.5rem),
    transparent 100%
  );
}

.marquee-track {
  display: flex;
  width: max-content;
  animation: marquee-scroll var(--marquee-duration, 28s) linear infinite;
}

.marquee:hover .marquee-track {
  animation-play-state: paused;
}

.marquee-group {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding-right: 2.5rem;
  gap: 0;
}

.marquee-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.35rem;
  white-space: nowrap;
  font-size: 0.88rem;
  color: var(--ink);
}

/* 處室名稱 */
.marquee-office {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 2px;
  border: none;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  background: var(--cream);
  color: var(--ink-soft);
  flex-shrink: 0;
}

.marquee-item.is-admin .marquee-office {
  background: var(--cream);
  color: var(--ink-soft);
}

.marquee-type {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.marquee-type::after {
  content: "·";
  margin-left: 0.35rem;
  color: var(--line-strong, var(--line));
}

/* 實際公告內容（標題＋摘要） */
.marquee-text {
  max-width: min(78vw, 560px);
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.marquee-sep {
  display: inline-flex;
  align-items: center;
  padding: 0 0.85rem;
  color: var(--line);
  font-size: 0.55rem;
  user-select: none;
}

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

@media (prefers-reduced-motion: reduce) {
  .marquee-track {
    animation: none;
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-start;
    padding: 0.45rem 0.75rem;
    gap: 0.35rem 0.75rem;
  }

  .marquee-group:last-child {
    display: none;
  }

  .marquee-group {
    flex-wrap: wrap;
    padding-right: 0;
    gap: 0.35rem 0.5rem;
  }

  .marquee-text {
    max-width: none;
    white-space: normal;
  }
}

.sidebar-stats {
  margin-top: 1.5rem;
  padding: 0.95rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--paper-2);
  border: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  line-height: 1.65;
  box-shadow: none;
}

.sidebar-stats strong {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

/* ── 幹部／小老師登錄模式：隱藏列表，只保留編輯 ── */

.app--composer .sidebar {
  display: none;
}

.app--composer .main {
  grid-template-columns: 1fr;
  width: min(100%, 720px);
}

.app--composer .board-toolbar,
.app--composer #dashboard-box,
.app--composer #calendar-view,
.app--composer #post-list,
.app--composer #empty-state,
.app--composer #board-extras {
  display: none !important;
}

/* ── 周課表（可摺疊）── */
.timetable-card {
  width: min(100%, 720px);
  margin: 1.75rem auto 0;
  padding: 1.1rem 1.15rem 1rem;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.timetable-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.timetable-title {
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--ink);
}

.timetable-today {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

.btn-sm {
  padding: 0.35rem 0.75rem !important;
  font-size: 0.78rem !important;
  min-height: 0 !important;
}

.weekly-timetable-wrap {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px dashed var(--line);
}

.weekly-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.weekly-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 0.8rem;
  text-align: center;
  color: var(--ink);
}

.weekly-table th,
.weekly-table td {
  padding: 0.55rem 0.35rem;
  border-bottom: 1px solid var(--line);
  font-weight: 400;
}

.weekly-table th {
  font-weight: 500;
  color: var(--ink-muted);
  letter-spacing: 0.06em;
  background: color-mix(in srgb, var(--cream) 55%, transparent);
}

.weekly-table th.is-today,
.weekly-table td.is-today {
  background: color-mix(in srgb, var(--cream) 80%, #fff);
  color: var(--ink);
  font-weight: 600;
}

.weekly-table td.period-num {
  font-weight: 500;
  color: var(--ink-muted);
  width: 2.2rem;
}

/* ── 常用資源 ── */
.resources-card {
  width: min(100%, 720px);
  margin: 1rem auto 0;
  padding: 1.1rem 1.15rem 1.15rem;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.resources-title {
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--ink);
  margin-bottom: 0.85rem;
}

.resources-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
}

.resource-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  padding: 0.7rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--cream) 45%, #fff);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
  min-height: 2.75rem;
  word-break: break-word;
}

.resource-btn:hover {
  border-color: var(--line-strong);
  background: #fff;
  color: var(--ink);
}

.resources-empty {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-muted);
  padding: 0.5rem 0;
}

.board-extras {
  margin-top: 1.75rem;
  padding-top: 0.25rem;
}

.board-extras .timetable-card,
.board-extras .resources-card {
  width: 100%;
  max-width: none;
}

.role-screen .timetable-card {
  animation: fadeUp 0.5s var(--ease) both;
  animation-delay: 0.05s;
}

.role-screen .resources-card {
  animation: fadeUp 0.5s var(--ease) both;
  animation-delay: 0.1s;
  margin-bottom: 0.5rem;
}

@media (max-width: 640px) {
  .resources-grid {
    grid-template-columns: 1fr 1fr;
  }

  .timetable-card,
  .resources-card {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
  }

  .timetable-head {
    align-items: flex-start;
  }

  .weekly-table {
    font-size: 0.74rem;
    min-width: 380px;
  }
}

.composer-panel {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0.5rem 0 1rem;
  min-height: min(60vh, 480px);
}

.composer-card {
  width: min(100%, 440px);
  margin: 1.5rem auto 0;
  padding: 2rem 1.6rem 1.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  box-shadow: none;
  text-align: center;
}

.composer-eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  text-transform: uppercase;
}

.composer-card h2 {
  margin: 0 0 0.6rem;
  font-family: var(--font-sans);
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: 0.1em;
}

.composer-desc {
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--ink-soft);
  line-height: 1.7;
}

.btn-composer-cta {
  width: 100%;
  justify-content: center;
  min-height: 2.75rem;
  border-radius: var(--radius-sm) !important;
  gap: 0.4rem;
}

.composer-hint {
  margin: 1.15rem 0 0;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
  line-height: 1.6;
}

.composer-select-field {
  text-align: left;
  margin-bottom: 0.85rem;
}

.composer-select-field select {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 400;
  color: var(--ink);
  min-height: 2.65rem;
  cursor: pointer;
}

.composer-select-field select:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: none;
}

.composer-card .form-error {
  text-align: left;
  margin: 0 0 0.65rem;
}

#post-author-select,
#post-subject-select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  min-height: 2.6rem;
}

#post-author[readonly] {
  opacity: 0.85;
  background: color-mix(in srgb, var(--cream) 50%, var(--paper));
}

/* ── 佈告區 ── */

.board {
  padding: 1.5rem 1.5rem 3rem;
  min-width: 0;
}

.board-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding: 0;
  border-bottom: none;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.search-wrap {
  flex: 1;
  min-width: 180px;
}

.search-wrap input {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-2);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--ink);
  transition: border-color 0.2s ease;
}

.search-wrap input:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: none;
}

.search-wrap input::placeholder {
  color: var(--ink-muted);
  letter-spacing: 0.02em;
  font-weight: 400;
}

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink-soft);
}

.sort-wrap select {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-2);
  font: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  cursor: pointer;
}

.board-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ── 今日儀表板 ── */
.dashboard-box {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin-bottom: 1.15rem;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.dashboard-item {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  justify-content: center;
  padding: 0.95rem 0.5rem;
  border-right: 1px solid var(--line);
}

.dashboard-item:last-child {
  border-right: none;
}

.dashboard-label {
  font-size: 0.72rem;
  color: var(--ink-muted);
  font-weight: 500;
  letter-spacing: 0.06em;
}

.dashboard-value {
  font-size: 1.45rem;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.dashboard-value.is-hot {
  color: #8a5a3a;
}

/* ── 列表／月曆切換 ── */
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--paper-2);
}

.view-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.view-btn + .view-btn {
  border-left: 1px solid var(--line);
}

.view-btn.active {
  background: var(--ink);
  color: #fff;
}

.view-btn:hover:not(.active) {
  background: var(--cream);
  color: var(--ink);
}

/* ── 月曆 ── */
.calendar-container {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1rem 0.85rem;
  margin-bottom: 1rem;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  gap: 0.5rem;
}

.calendar-month-title {
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.btn-cal-nav {
  min-width: 2.4rem;
  padding: 0.35rem 0.55rem !important;
  font-size: 1.15rem !important;
  line-height: 1;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-day-header {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-muted);
  padding: 0.4rem 0;
  letter-spacing: 0.04em;
}

.calendar-day {
  min-height: 4.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  background: var(--paper-2);
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: default;
}

.calendar-day.has-events {
  cursor: pointer;
}

.calendar-day.has-events:hover {
  border-color: var(--line-strong);
  background: #fff;
}

.calendar-day.other-month {
  background: color-mix(in srgb, var(--cream) 50%, var(--paper));
  opacity: 0.55;
  cursor: default;
}

.calendar-day.today {
  border-color: var(--ink);
  background: color-mix(in srgb, var(--cream) 65%, #fff);
}

.calendar-day.today .calendar-day-num {
  font-weight: 700;
  color: var(--ink);
}

.calendar-day-num {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink-muted);
}

.calendar-day-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.calendar-event-tag {
  font-size: 0.62rem;
  padding: 1px 3px;
  border-radius: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.cal-tag-school {
  background: color-mix(in srgb, var(--school) 14%, transparent);
  color: var(--school);
}

.cal-tag-homework {
  background: color-mix(in srgb, var(--homework) 16%, transparent);
  color: var(--homework);
}

.cal-tag-teacher {
  background: color-mix(in srgb, var(--teacher) 14%, transparent);
  color: var(--teacher);
}

.calendar-more-badge {
  font-size: 0.6rem;
  color: var(--ink-muted);
  text-align: right;
  font-weight: 500;
}

.calendar-dot-bar {
  display: none;
  gap: 3px;
  flex-wrap: wrap;
  justify-content: flex-start;
  margin-top: auto;
}

.calendar-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.dot-school { background: var(--school); }
.dot-homework { background: var(--homework); }
.dot-teacher { background: var(--teacher); }

.calendar-hint {
  margin: 0.75rem 0 0;
  font-size: 0.74rem;
  color: var(--ink-muted);
  letter-spacing: 0.03em;
  text-align: center;
}

.cal-day-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.cal-day-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: min(55vh, 420px);
  overflow-y: auto;
  margin: 0.75rem 0 0.25rem;
}

.cal-day-item {
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  background: #fff;
}

.cal-day-item .cal-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.65rem;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.cal-day-item .cal-item-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 0.3rem;
  letter-spacing: 0.02em;
}

.cal-day-item .cal-item-content {
  font-size: 0.86rem;
  color: var(--ink-soft);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.cal-day-empty {
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.88rem;
  padding: 1.5rem 0.5rem;
}

.post-list {
  display: grid;
  gap: 0.85rem;
  border-top: none;
}

.post-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem 1rem;
  padding: 1.2rem 1.2rem 1.2rem 1.3rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  box-shadow: none;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  animation: fadeUp 0.4s var(--ease) both;
  overflow: hidden;
}

.post-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--cat-color, var(--line-strong));
  transition: none;
}

.post-card:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--line-strong);
  background: #fff;
}

.post-card:hover::before {
  width: 3px;
}

.post-card.pinned {
  background: color-mix(in srgb, var(--cream) 55%, var(--paper-2));
}

.post-card.pinned .post-card-main h3 {
  font-weight: 700;
}

.post-card-main {
  min-width: 0;
}

.post-cat {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.12rem 0.5rem;
  border-radius: 2px;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  background: var(--cream);
  color: var(--ink-soft);
}

.post-card h3 {
  margin: 0.45rem 0 0.35rem;
  font-family: var(--font-sans);
  font-size: clamp(1.02rem, 1.5vw, 1.15rem);
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: 0.04em;
}

.post-excerpt {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.7;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.8rem;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
}

.post-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}

.post-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.85rem;
}

.post-card-actions .btn-soft,
.post-card-actions .btn-danger {
  padding: 0.5rem 1rem;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line));
  background: transparent;
  color: var(--danger);
  font-weight: 500;
  font-size: 0.84rem;
}

.post-card-actions .btn-danger {
  border-radius: var(--radius-sm);
}

.post-card--manageable {
  cursor: default;
}

.post-card--manageable .post-card-main h3 {
  cursor: pointer;
}

.pin-badge {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--ink-soft);
  background: var(--cream);
  border: none;
  padding: 0.15rem 0.5rem;
  border-radius: 2px;
}

.due-badge {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--teacher);
  white-space: nowrap;
}

.due-badge.overdue {
  color: var(--danger);
}

.subject-chip {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  padding: 0.12rem 0.5rem;
  border-radius: 2px;
  border: none;
  background: var(--mint-block);
  color: var(--homework);
}

.empty-state {
  text-align: center;
  padding: 4.5rem 1rem;
  color: var(--ink-muted);
}

.empty-state p {
  margin: 0 0 0.4rem;
  font-family: var(--font-sans);
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

/* ── 按鈕 ── */

.btn-primary,
.btn-ghost,
.btn-danger,
.btn-text {
  padding: 0.25rem 0;
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 1.15rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  font-weight: 500;
  font-size: 0.86rem;
  letter-spacing: 0.06em;
  text-transform: none;
  box-shadow: none;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: none;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.84rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
}

.btn-ghost:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--paper-2);
}

.btn-danger {
  padding: 0.5rem 1rem;
  border: 1.5px solid color-mix(in srgb, var(--danger) 35%, var(--line));
  background: color-mix(in srgb, var(--danger) 8%, var(--paper-2));
  color: var(--danger);
  font-weight: 700;
  font-size: 0.84rem;
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-text {
  padding: 0.25rem 0;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-text:hover {
  color: var(--ink);
}

.btn-icon {
  font-size: 1rem;
  line-height: 1;
}

.btn-icon-only {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1rem;
  cursor: pointer;
}

.btn-icon-only:hover {
  background: var(--cream);
  color: var(--ink);
}

/* ── Modal ── */

.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 2rem);
}

.modal::backdrop {
  background: rgba(44, 44, 44, 0.28);
  backdrop-filter: blur(2px);
}

.modal-card {
  width: min(100vw - 2rem, 400px);
  margin: auto;
  padding: 1.6rem 1.5rem 1.3rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  box-shadow: var(--shadow);
  animation: modalIn 0.3s var(--ease) both;
}

.modal-wide {
  width: min(100vw - 2rem, 520px);
}

.modal-card h3 {
  margin: 0 0 0.4rem;
  font-family: var(--font-sans);
  font-size: 1.2rem;
  letter-spacing: 0.08em;
  font-weight: 500;
  color: var(--ink);
}

.modal-desc {
  margin: 0 0 1.1rem;
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--ink-soft);
}

.field.full {
  grid-column: 1 / -1;
}

.field input,
.field select,
.field textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink);
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: none;
}

.check-field {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  padding-top: 1.5rem;
}

.check-field input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

.form-error {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--danger);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.pin-hint {
  margin: 1rem 0 0;
  font-size: 0.72rem;
  color: var(--ink-muted);
  text-align: center;
  line-height: 1.5;
}

.pin-hint code {
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--cream);
  font-size: 0.75rem;
}

/* 詳情 */

.detail-card {
  max-height: min(85vh, 640px);
  overflow-y: auto;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.detail-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
  line-height: 1.35;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.1rem;
  margin-bottom: 1.15rem;
  padding-bottom: 1rem;
  border-bottom: 1px dashed var(--line);
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.detail-content {
  font-size: 0.95rem;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.75;
}

.detail-actions {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  margin-top: 1.25rem;
}

/* ── 動畫 ── */

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ═══════════════════════════════════════════
   響應式：iPhone → iPad → MacBook → 大螢幕
   ═══════════════════════════════════════════ */

/* ── 大桌機／外接螢幕（≥1280）── */
@media (min-width: 1280px) {
  .main {
    width: min(100%, 1280px);
    grid-template-columns: 260px 1fr;
  }

  .board {
    padding: 1.75rem 2rem 3.5rem;
  }

  .role-cards {
    width: min(100%, 1040px);
    gap: 1.5rem;
  }
}

/* ── 筆電／MacBook 一般寬（1024–1279）── */
@media (min-width: 1024px) and (max-width: 1279px) {
  .main {
    width: min(100%, 1100px);
    grid-template-columns: 220px 1fr;
  }

  .board {
    padding: 1.35rem 1.5rem 3rem;
  }
}

/* ── 平板直向／小筆電（641–1023）：側欄改頂部橫列 ── */
@media (max-width: 1023px) {
  .role-screen {
    padding: 2.5rem 1.25rem 2rem;
    justify-content: flex-start;
    padding-top: max(2.5rem, env(safe-area-inset-top, 0px) + 1.5rem);
  }

  .role-header {
    margin-bottom: 1.25rem;
  }

  .marquee {
    width: min(100%, 420px);
    margin-bottom: 1.35rem;
  }

  .role-cards {
    grid-template-columns: 1fr;
    width: min(100%, 420px);
    gap: 1rem;
  }

  .main {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 1rem 1rem 0.95rem;
    background: color-mix(in srgb, var(--cream) 55%, transparent);
  }

  .sidebar-title {
    margin-bottom: 0.55rem;
  }

  /* 手機／平板：上下分區，避免橫向捲動被裁切 */
  .filter-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
    overflow: visible;
    padding-bottom: 0;
    margin: 0;
  }

  .filter-nav::-webkit-scrollbar {
    display: none;
  }

  /* 上區：全部訊息（整列） */
  .filter-btn[data-filter="all"] {
    grid-column: 1 / -1;
  }

  .filter-btn {
    width: 100%;
    min-width: 0;
    flex: none;
    justify-content: center;
    white-space: normal;
    text-align: center;
    line-height: 1.3;
    padding: 0.55rem 0.4rem;
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
    background: var(--paper-2);
    border: 1px solid var(--line);
  }

  .filter-btn .dot {
    display: none;
  }

  .filter-btn.active {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
    box-shadow: none;
  }

  .sidebar-stats {
    display: none;
  }

  /* 平板／手機：強制全寬直向堆疊（修正 iPhone 擠在左側） */
  .app {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .topbar {
    width: 100%;
    max-width: 100%;
    left: 0;
    right: 0;
  }

  .topbar-inner {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 0.65rem;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    box-sizing: border-box;
    padding: 0.7rem max(1rem, env(safe-area-inset-right, 0px))
      0.75rem max(1rem, env(safe-area-inset-left, 0px));
    min-height: 0;
  }

  .topbar-left {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.5rem;
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 auto !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }

  .topbar-divider {
    display: none;
  }

  .topbar-left .brand {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: auto !important;
  }

  .topbar-right {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 0.5rem;
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 auto !important;
    margin: 0 !important;
    padding-top: 0.6rem;
    border-top: 1px solid var(--line);
    box-sizing: border-box;
  }

  .topbar-meta {
    flex: 0 0 auto;
    min-width: 0;
  }

  .topbar-actions {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    justify-content: flex-end !important;
    align-items: stretch !important;
    gap: 0.45rem;
    width: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
  }

  .brand-title {
    font-size: 0.95rem;
    max-width: 100%;
  }

  .btn-soft,
  .btn-new {
    flex: 1 1 0 !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    justify-content: center !important;
    box-sizing: border-box;
  }

  .btn-soft {
    font-size: 0.8rem;
    padding: 0.5rem 0.55rem;
  }

  .btn-new {
    font-size: 0.82rem !important;
    padding: 0.5rem 0.55rem !important;
  }

  .main {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    box-sizing: border-box;
  }

  .board {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* 角色選擇頁也拉滿寬度，避免卡片像靠左半邊 */
  .role-screen {
    align-items: stretch;
    width: 100%;
    box-sizing: border-box;
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
  }

  .role-header {
    width: 100%;
    max-width: 36rem;
    margin-left: auto;
    margin-right: auto;
  }

  .marquee,
  .role-cards {
    width: 100% !important;
    max-width: 28rem;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
  }

  .board {
    padding: 1rem 1rem 2.5rem;
    padding-bottom: max(2.5rem, env(safe-area-inset-bottom, 0px) + 1.5rem);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .check-field {
    padding-top: 0.25rem;
  }

  .post-card {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .post-side {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    padding-left: 0;
    gap: 0.45rem;
  }

  .post-card-main {
    width: 100%;
  }
}

/* ── 手機（≤640，含 iPhone）── */
@media (max-width: 640px) {
  .mode-banner {
    font-size: 0.75rem;
    padding: 0.6rem 0.85rem;
    text-align: left;
  }

  .role-screen {
    padding: 1.5rem 1rem 2rem;
    padding-top: max(1.5rem, env(safe-area-inset-top, 0px) + 1rem);
    padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px) + 1rem);
  }

  .role-header h1 {
    font-size: clamp(1.45rem, 6.5vw, 1.85rem);
    letter-spacing: 0.03em;
  }

  .role-header-top {
    flex-direction: column;
    gap: 0.55rem;
    min-height: 0;
  }

  .today-date {
    font-size: clamp(1.55rem, 7vw, 1.9rem);
    padding: 0.4rem 1rem 0.45rem;
  }

  .marquee {
    width: 100%;
    margin-bottom: 1.15rem;
    min-height: 2.5rem;
    border-radius: var(--radius-sm);
  }

  .marquee-label {
    padding: 0 0.65rem;
    font-size: 0.72rem;
  }

  .marquee-item {
    font-size: 0.82rem;
  }

  .marquee-text {
    max-width: 55vw;
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  .subtitle {
    font-size: 0.9rem;
    padding: 0 0.25rem;
  }

  .role-cards {
    width: 100%;
    max-width: none;
    gap: 0.85rem;
  }

  .role-card {
    padding: 1.25rem 1.15rem 1.15rem;
    /* 觸控更舒適 */
    min-height: 0;
  }

  .role-card:hover,
  .role-card:focus-visible {
    transform: none;
  }

  .role-card:active {
    transform: scale(0.99);
  }

  .role-icon {
    width: 2.5rem;
    height: 2.5rem;
    margin-bottom: 0.85rem;
  }

  .role-card h2 {
    font-size: 1.15rem;
  }

  .role-desc {
    font-size: 0.86rem;
    margin-bottom: 1rem;
  }

  .topbar-inner {
    padding: 0.65rem max(0.9rem, env(safe-area-inset-right, 0px))
      0.75rem max(0.9rem, env(safe-area-inset-left, 0px)) !important;
    gap: 0.6rem !important;
  }

  .btn-back {
    padding: 0.4rem;
    min-width: 2.6rem;
    min-height: 2.6rem;
    justify-content: center;
    flex: 0 0 auto !important;
  }

  .btn-back-text {
    display: none;
  }

  .brand-title {
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .status-live-bar {
    font-size: 0.65rem;
  }

  /* 第二列：身份 + 按鈕整列拉滿 */
  .topbar-right {
    gap: 0.45rem !important;
    padding-top: 0.55rem !important;
  }

  .role-chip {
    font-size: 0.72rem;
    padding: 0.42rem 0.6rem;
    max-width: 7.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 0 1 auto;
  }

  .topbar-actions {
    flex: 1 1 auto !important;
    gap: 0.4rem !important;
  }

  .btn-soft,
  .btn-new {
    flex: 1 1 0% !important;
    min-height: 2.6rem !important;
    font-size: 0.78rem !important;
    padding: 0.45rem 0.4rem !important;
  }

  .btn-soft svg,
  .btn-new svg {
    flex-shrink: 0;
  }

  .marquee,
  .role-cards {
    max-width: none !important; /* iPhone 上吃滿可用寬度 */
    width: 100% !important;
  }

  .role-screen {
    padding-left: max(0.9rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.9rem, env(safe-area-inset-right, 0px));
  }

  .sidebar {
    padding: 0.9rem 0.85rem 0.85rem;
  }

  .sidebar-title {
    font-size: 0.7rem;
    margin-bottom: 0.5rem;
  }

  .filter-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
  }

  .filter-btn {
    padding: 0.6rem 0.3rem;
    font-size: 0.8rem;
    min-height: 2.55rem;
  }

  .filter-btn[data-filter="all"] {
    min-height: 2.4rem;
    font-size: 0.84rem;
  }

  .board {
    padding: 0.85rem 0.75rem 2rem;
    padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px) + 1.25rem);
  }

  .dashboard-box {
    grid-template-columns: 1fr 1fr;
  }

  .dashboard-item {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 0.8rem 0.4rem;
  }

  .dashboard-item:nth-child(odd) {
    border-right: 1px solid var(--line);
  }

  .dashboard-item:nth-child(3),
  .dashboard-item:nth-child(4) {
    border-bottom: none;
  }

  .dashboard-value {
    font-size: 1.3rem;
  }

  .board-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    margin-bottom: 1rem;
  }

  .board-toolbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .search-wrap input {
    font-size: 16px; /* 避免 iOS 自動放大 */
    min-height: 2.75rem;
    padding: 0.7rem 1rem;
  }

  .sort-wrap {
    justify-content: space-between;
    flex: 1;
  }

  .sort-wrap select {
    flex: 1;
    min-height: 2.5rem;
    font-size: 16px;
  }

  .calendar-container {
    padding: 0.75rem 0.65rem 0.7rem;
  }

  .calendar-day {
    min-height: 3.1rem;
    padding: 0.25rem;
  }

  .calendar-day-events {
    display: none;
  }

  .calendar-dot-bar {
    display: flex;
  }

  .calendar-more-badge {
    display: none;
  }

  .calendar-day-num {
    font-size: 0.7rem;
  }

  .calendar-hint {
    font-size: 0.7rem;
  }

  .post-card {
    padding: 1rem 0.95rem 1rem 1.1rem;
  }

  .post-card:hover {
    transform: none;
  }

  .post-card h3 {
    font-size: 1rem;
  }

  .post-excerpt {
    font-size: 0.86rem;
  }

  .post-meta {
    font-size: 0.72rem;
    gap: 0.35rem 0.75rem;
  }

  /* 彈窗：接近全螢幕，避開安全區 */
  .modal {
    max-width: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    height: 100%;
    max-height: 100%;
  }

  .modal-card,
  .modal-wide {
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    min-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: none;
    padding:
      max(1.25rem, env(safe-area-inset-top, 0px) + 0.75rem)
      max(1rem, env(safe-area-inset-right, 0px) + 0.75rem)
      max(1.25rem, env(safe-area-inset-bottom, 0px) + 0.75rem)
      max(1rem, env(safe-area-inset-left, 0px) + 0.75rem);
    box-shadow: none;
  }

  .detail-card {
    max-height: none;
  }

  .field input,
  .field select,
  .field textarea {
    font-size: 16px; /* 避免 iOS 聚焦放大 */
    min-height: 2.6rem;
  }

  .field textarea {
    min-height: 8rem;
  }

  .modal-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .modal-actions .btn-ghost,
  .modal-actions .btn-primary,
  .modal-actions .btn-danger {
    flex: 1 1 auto;
    min-height: 2.75rem;
    justify-content: center;
  }

  .toast {
    bottom: max(1rem, env(safe-area-inset-bottom, 0px) + 0.75rem);
    left: 1rem;
    right: 1rem;
    width: auto;
    max-width: none;
    transform: translateY(12px);
    border-radius: 12px;
  }

  .toast.show {
    transform: translateY(0);
  }
}

/* ── 極窄機型（≤380，如 SE）── */
@media (max-width: 380px) {
  .role-header h1 {
    font-size: 1.35rem;
  }

  .btn-primary,
  .btn-ghost {
    font-size: 0.78rem;
  }

  .filter-btn {
    padding: 0.55rem 0.25rem;
    font-size: 0.74rem;
    min-height: 2.45rem;
  }

  .filter-btn[data-filter="all"] {
    font-size: 0.8rem;
  }
}

/* ── 橫向手機：壓縮上下留白 ── */
@media (max-height: 500px) and (orientation: landscape) {
  .role-screen {
    justify-content: flex-start;
    padding-top: 1rem;
    padding-bottom: 1rem;
  }

  .role-header {
    margin-bottom: 1rem;
  }

  .role-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    max-width: none;
  }

  .role-desc {
    display: none;
  }

  .modal-card,
  .modal-wide {
    min-height: auto;
    max-height: 100dvh;
    overflow-y: auto;
  }
}

/* ── 觸控裝置：加大可點區域 ── */
@media (hover: none) and (pointer: coarse) {
  .filter-btn,
  .btn-ghost,
  .btn-primary,
  .btn-danger {
    min-height: 2.5rem;
  }

  .post-card {
    -webkit-tap-highlight-color: transparent;
  }

  .role-card:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
