/* ================================================================
   TRTOI 網站樣式 — 學術機構風 (參考 UPenn TRIDENT)
   置中白框 · 深灰 masthead · 左側直式選單 · 暗酒紅點綴
   刻意採用實色、細線、留白，避免漸層與過度設計。
   ================================================================ */
:root {
  --paper: #ffffff;       /* 內容白框 */
  --canvas: #e8e7e3;      /* 外層淺灰畫布 */
  --bar: #565b60;         /* 深灰 masthead / hero */
  --bar-dark: #454a4e;
  --accent: #8a1f2b;      /* 暗酒紅：標題、選單、連結 */
  --accent-dark: #6d1822;
  --ink: #333a3f;         /* 內文 */
  --muted: #6c727a;
  --line: #d9d8d3;
  --line-soft: #ececea;
  --soft: #f6f5f2;        /* 淺色區塊底 */
  --max: 1120px;
  --side: 250px;          /* 左側選單寬 */
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC",
               -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  line-height: 1.8;
  background-color: var(--canvas);
  background-image:
    repeating-linear-gradient(45deg, rgba(0,0,0,.012) 0 2px, transparent 2px 5px);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); text-decoration: underline; }

/* ---------- 置中白框 ---------- */
.page-frame {
  max-width: var(--max);
  margin: 22px auto;
  background: var(--paper);
  box-shadow: 0 2px 18px rgba(0,0,0,.10);
  /* 捲動/拖曳時不要反白選取整頁文字 */
  -webkit-user-select: none;
  user-select: none;
}
/* 但編輯欄位、輸入框仍可正常選取與打字 */
.page-frame [contenteditable],
.page-frame input,
.page-frame textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* ---------- 頂部 masthead ---------- */
.masthead {
  position: relative; z-index: 3;
  background: var(--bar);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: 22px 34px; min-height: 92px;
}
.masthead .brand-txt {
  color: #fff; text-decoration: none; font-weight: 700;
  font-size: 36px; letter-spacing: 2px; text-align: center;
}
.masthead .brand-txt:hover { color: #fff; }
/* 標誌絕對定位於右側，放大並向下凸出，幾乎頂到 hero 灰色帶底部 */
.masthead .brand-logo {
  position: absolute; right: 30px; top: 16px; z-index: 4;
  display: block; line-height: 0;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,.45));
}
.masthead .logo-img { height: 290px; width: auto; display: block; }

/* ---------- hero-strip (灰階組織影像佔位) ---------- */
.hero-strip {
  height: 240px; position: relative; z-index: 1; display: flex;
  background: #7a7f83;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,.16) 0 6%, transparent 7%),
    radial-gradient(circle at 62% 68%, rgba(0,0,0,.20) 0 5%, transparent 6%),
    radial-gradient(circle at 85% 25%, rgba(255,255,255,.10) 0 8%, transparent 9%),
    radial-gradient(circle at 40% 80%, rgba(0,0,0,.16) 0 4%, transparent 5%),
    linear-gradient(100deg, #6f7377, #8b9094 55%, #63676b);
  border-bottom: 4px solid var(--accent);
}
.hero-strip::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(115deg, rgba(255,255,255,.05) 0 3px, transparent 3px 9px);
}
.hero-strip .cap {
  position: relative; z-index: 1; align-self: flex-end;
  padding: 16px 26px; color: #fff;
  font-size: 12.5px; letter-spacing: .5px;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.hero-strip .cap em { font-style: normal; color: #f0d9dc; }

/* ---------- 主佈局：左選單 + 右內容 ---------- */
.layout { display: grid; grid-template-columns: var(--side) 1fr; }

/* 左側直式選單 */
.sidebar {
  border-right: 1px solid var(--line);
  padding: 30px 0;
  background: var(--paper);
}
.sidebar nav { display: flex; flex-direction: column; }
.sidebar nav a {
  color: var(--accent);
  font-size: 15.5px; font-weight: 500;
  padding: 11px 26px; line-height: 1.4;
  border-left: 4px solid transparent;
}
.sidebar nav a:hover { background: var(--soft); text-decoration: none; color: var(--accent-dark); }
.sidebar nav a.active {
  color: #fff; background: var(--accent);
  border-left-color: var(--accent-dark); font-weight: 700;
}
.sidebar .side-note {
  margin: 22px 26px 0; padding-top: 18px; border-top: 1px solid var(--line-soft);
  font-size: 12.5px; color: var(--muted); line-height: 1.7;
}

/* 右側內容 */
.main { padding: 40px 48px 56px; min-width: 0; }

/* ---------- 內容通用排版 ---------- */
.main h1.title { color: var(--accent); font-size: 30px; margin: 0 0 6px; font-weight: 700; }
.main .subtitle { color: var(--muted); font-size: 16px; margin: 0 0 8px; }
.rule { height: 1px; background: var(--line); border: 0; margin: 20px 0 26px; }

.prose { max-width: 760px; }
.prose h2 { color: var(--accent); font-size: 23px; margin: 34px 0 12px; font-weight: 700; }
.prose h3 { color: var(--bar-dark); font-size: 18px; margin: 24px 0 8px; }
.prose p { margin: 0 0 15px; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 22px; }
.prose li { margin-bottom: 7px; }
.prose .callout {
  background: var(--soft); border-left: 4px solid var(--accent);
  padding: 16px 20px; margin: 20px 0; color: var(--ink);
}
.tag {
  display: inline-block; border: 1px solid var(--line); background: var(--soft);
  color: var(--ink); padding: 6px 15px; border-radius: 20px;
  font-size: 14.5px; font-weight: 500; letter-spacing: .3px; margin: 4px 6px 4px 0;
}

/* 由 JSON 區塊渲染的獨立文字元素（限制易讀寬度） */
.blk-h2 { color: var(--accent); font-size: 23px; margin: 32px 0 12px; font-weight: 700; max-width: 780px; }
.blk-h3 { color: var(--bar-dark); font-size: 18px; margin: 24px 0 8px; max-width: 780px; }
.blk-p { margin: 0 0 15px; max-width: 780px; }
.blk-w { max-width: 780px; }
.blk-list { margin: 0 0 16px; padding-left: 22px; max-width: 780px; }
.blk-list li { margin-bottom: 7px; }
.pub-list { margin: 6px 0; }
.pub-desc { margin: 6px 0 0; color: var(--ink); font-size: 14.5px; }
.pub [contenteditable] { outline: none; border-radius: 3px; }
.pub [contenteditable]:focus { background: #fffef8; box-shadow: inset 0 0 0 2px var(--accent); }
.pub [contenteditable]:empty:before { content: attr(data-ph); color: var(--muted); font-weight: 400; }
.pub-del {
  position: absolute; top: 16px; right: 0; z-index: 2;
  border: 0; background: rgba(138, 31, 43, .9); color: #fff;
  width: 24px; height: 24px; border-radius: 50%; font-size: 12px; cursor: pointer;
}
.pub-del:hover { background: var(--accent-dark); }
.pub { position: relative; }

/* 內頁標題區 (取代舊 page-banner) */
.page-banner { margin-bottom: 26px; padding-bottom: 20px; border-bottom: 2px solid var(--line); }
.page-banner .crumb { font-size: 12.5px; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }
.page-banner h1 { color: var(--accent); font-size: 30px; margin: 6px 0 6px; font-weight: 700; }
.page-banner p { margin: 0; color: var(--muted); font-size: 15.5px; }

/* section 區塊（內頁沿用 .block / .soft） */
section.block { padding: 8px 0 26px; }
section.block.soft { background: transparent; }
.section-head { margin: 6px 0 22px; }
.section-head .kicker { color: var(--accent); font-weight: 700; letter-spacing: 1.5px; font-size: 12px; text-transform: uppercase; }
.section-head h2 { font-size: 24px; margin: 6px 0 8px; color: var(--bar-dark); font-weight: 700; }
.section-head p { color: var(--muted); font-size: 15.5px; margin: 0; }

/* ---------- 卡片（實色、細框、無漸層） ---------- */
.cards { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.card {
  background: var(--paper); border: 1px solid var(--line); border-top: 3px solid var(--accent);
  padding: 22px; transition: box-shadow .15s;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.card .icon {
  width: 42px; height: 42px; display: grid; place-items: center;
  background: var(--soft); border: 1px solid var(--line); color: var(--accent);
  font-size: 20px; margin-bottom: 14px;
}
.card h3 { margin: 0 0 8px; color: var(--accent); font-size: 17px; font-weight: 700; }
.card p { margin: 0; color: var(--ink); font-size: 14.5px; }

/* ---------- 首頁統計條 ---------- */
.stats { margin: 6px 0 30px; }
.stats .grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  border: 1px solid var(--line);
}
.stats .cell { padding: 20px 16px; text-align: center; border-right: 1px solid var(--line-soft); }
.stats .cell:last-child { border-right: 0; }
.stats .num { font-size: 30px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.stats .num small { font-size: 15px; color: var(--muted); font-weight: 700; }
.stats .lbl { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* 首頁大標區（取代舊深藍 hero，改白底暗紅） */
.intro { margin-bottom: 8px; }
.intro .eyebrow { display: block; color: var(--muted); font-size: 12.5px; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 10px; }
.intro h1 { color: var(--accent); font-size: 30px; line-height: 1.3; margin: 0 0 14px; font-weight: 700; }
.intro p.lead { font-size: 17px; color: var(--ink); margin: 0 0 20px; max-width: 720px; }
.intro .cta { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }

/* 按鈕（實色，無漸層） */
.btn {
  display: inline-block; padding: 11px 22px; font-weight: 700; font-size: 14.5px;
  cursor: pointer; border: 2px solid var(--accent); transition: background .15s, color .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent); color: #fff; }

/* CTA 帶狀（改實色深灰，非漸層） */
.cta-band { background: var(--bar); color: #fff; text-align: center; padding: 34px 20px; margin: 30px 0 6px; }
.cta-band h2 { font-size: 22px; margin: 0 0 8px; color: #fff; }
.cta-band p { margin: 0 0 18px; color: #dcdedf; font-size: 15.5px; }
.cta-band .btn-ghost { color: #fff; border-color: #fff; }
.cta-band .btn-ghost:hover { background: #fff; color: var(--bar); }

/* ---------- 時間軸 ---------- */
.timeline { position: relative; padding-left: 30px; margin: 8px 0; max-width: 760px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; margin-bottom: 24px; }
.tl-item::before {
  content: ""; position: absolute; left: -30px; top: 6px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--accent);
}
.tl-item h3 { margin: 0 0 4px; color: var(--accent); font-size: 17px; }
.tl-item p { margin: 0; color: var(--ink); }

/* ---------- 發表列表 ---------- */
.pub { border-bottom: 1px solid var(--line-soft); padding: 18px 0; display: flex; gap: 18px; }
.pub:last-child { border-bottom: 0; }
.pub .year { flex: 0 0 70px; font-weight: 800; color: var(--accent); font-size: 15px; }
.pub .body h3 { margin: 0 0 5px; font-size: 16px; color: var(--ink); }
.pub .body .journal { color: var(--muted); font-size: 13.5px; }
.pub .body .badge {
  display: inline-block; background: #f2e6c9; color: #7a5a12;
  font-size: 11.5px; font-weight: 700; padding: 1px 8px; margin-left: 6px;
}

/* ---------- 團隊 ---------- */
.team-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.member { text-align: center; border: 1px solid var(--line); border-top: 3px solid var(--accent); padding: 22px; background: var(--paper); }
.member .avatar {
  width: 66px; height: 66px; border-radius: 50%; margin: 0 auto 12px;
  background: var(--soft); border: 1px solid var(--line); color: var(--accent);
  display: grid; place-items: center; font-size: 22px; font-weight: 700;
}
.member h3 { margin: 0 0 3px; color: var(--accent); font-size: 16px; }
.member .role { color: var(--muted); font-size: 13px; }

/* ---------- 表單 ---------- */
.form-card { max-width: 420px; border: 1px solid var(--line); border-top: 3px solid var(--accent); padding: 28px; background: var(--paper); }
.form-card label { display: block; font-weight: 600; margin: 12px 0 5px; font-size: 14px; }
.form-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); font-size: 15px; }
.form-card input:focus { outline: none; border-color: var(--accent); }
.form-card .btn { width: 100%; margin-top: 18px; }
.notice { background: var(--soft); border: 1px solid var(--line); color: var(--ink); padding: 11px 14px; font-size: 13.5px; }

/* ---------- 頁尾 ---------- */
footer.site { background: var(--bar-dark); color: #cfd1d3; padding: 34px 48px 24px; font-size: 13.5px; }
footer.site .f-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 34px; }
footer.site h4 { color: #fff; font-size: 14px; margin: 0 0 12px; }
footer.site ul { list-style: none; padding: 0; margin: 0; }
footer.site li { margin-bottom: 7px; }
footer.site a { color: #cfd1d3; }
footer.site a:hover { color: #fff; }
footer.site .copyright { border-top: 1px solid rgba(255,255,255,.14); margin-top: 26px; padding-top: 16px; color: #9a9ea1; font-size: 12.5px; }

/* ---------- 研究團隊（直列式成員卡）---------- */
.team-list { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.team-member {
  position: relative; background: #fff;
  border: 1px solid var(--line); border-top: 3px solid var(--accent);
  box-shadow: var(--shadow); overflow: hidden;
}
.team-member.dragging { opacity: .4; }
.tm-handle {
  background: var(--soft); color: var(--muted); font-size: 13px; font-weight: 600;
  padding: 6px 14px; cursor: grab; border-bottom: 1px solid var(--line-soft); user-select: none;
}
.tm-handle:active { cursor: grabbing; }
.tm-title {
  padding: 12px 22px; font-size: 19px; font-weight: 800; color: var(--accent);
  border-bottom: 1px solid var(--line-soft); letter-spacing: .5px;
}
.tm-title[contenteditable] { outline: none; }
.tm-title[contenteditable]:focus { background: #fffef8; box-shadow: inset 0 0 0 2px var(--accent); }
.tm-title[contenteditable]:empty:before { content: attr(data-ph); color: var(--muted); font-weight: 500; font-size: 15px; }
.tm-photo {
  width: 240px; height: 290px; margin: 20px auto 4px;
  background-size: contain; background-repeat: no-repeat;
  background-position: center; background-color: var(--soft);
  border: 1px solid var(--line);
  display: grid; place-items: center;
}
.tm-photo.empty {
  width: 240px; height: 200px; margin: 20px auto 4px;
  background: var(--soft); border: 1px dashed var(--line);
}
.tm-upload {
  background: rgba(138, 31, 43, .92); color: #fff; font-weight: 700; font-size: 14px;
  padding: 10px 20px; border-radius: 6px; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}
.tm-upload:hover { background: var(--accent-dark); }
.tm-bio { padding: 18px 22px; color: var(--ink); line-height: 1.8; min-height: 60px; }
.tm-bio[contenteditable] { outline: none; }
.tm-bio[contenteditable]:focus { background: #fffef8; box-shadow: inset 0 0 0 2px var(--accent); }
.tm-bio[contenteditable]:empty:before { content: attr(data-ph); color: var(--muted); }
.tm-del {
  position: absolute; top: 8px; right: 10px; z-index: 2;
  border: 0; background: rgba(138, 31, 43, .9); color: #fff;
  font-size: 12.5px; font-weight: 700; padding: 5px 12px; border-radius: 5px; cursor: pointer;
}
.tm-del:hover { background: var(--accent-dark); }
.tm-add { margin: 22px auto 0; display: block; }

/* ---------- 頂部輪播圖片 ---------- */
.hero-strip.has-images { background: #2b2f33; }
.hero-slide {
  position: absolute; inset: 0; z-index: 1;
  background-size: cover; background-position: center;
  opacity: 0; transition: opacity .8s ease;
}
.hero-slide.active { opacity: 1; }

/* 編輯：縮圖管理列（登入後才出現） */
.hero-manage {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: rgba(0, 0, 0, .5);
}
.hero-thumbs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.hero-thumb {
  position: relative; flex: 0 0 auto; width: 66px; height: 46px;
  background-size: cover; background-position: center; border-radius: 4px;
  border: 2px solid rgba(255, 255, 255, .5); cursor: grab;
}
.hero-thumb:active { cursor: grabbing; }
.hero-thumb.dragging { opacity: .4; }
.hero-thumb .hero-del {
  position: absolute; top: -8px; right: -8px; width: 22px; height: 22px;
  border: 0; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 12px; line-height: 1; cursor: pointer; box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.hero-thumb .hero-del:hover { background: var(--accent-dark); }
.hero-btn {
  flex: 0 0 auto; display: inline-block; background: var(--accent); color: #fff;
  font-weight: 700; font-size: 14px; padding: 9px 16px; border-radius: 6px;
  cursor: pointer; white-space: nowrap; box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}
.hero-btn:hover { background: var(--accent-dark); }

/* ---------- 首頁即時圓餅圖 ---------- */
.chart-row { display: flex; gap: 20px; flex-wrap: wrap; margin: 8px 0 6px; }
.chart-card {
  flex: 1 1 210px; min-width: 190px; max-width: 280px;
  border: 1px solid var(--line); border-top: 3px solid var(--accent);
  background: #fff; padding: 18px 16px 14px; text-align: center;
}
.chart-card canvas { max-height: 210px; }
.chart-title { margin-top: 10px; font-weight: 700; color: var(--accent); font-size: 15.5px; }
.chart-bar-card {
  margin-top: 18px; border: 1px solid var(--line); border-top: 3px solid var(--accent);
  background: #fff; padding: 18px 20px 16px;
}
.chart-bar-title { font-weight: 700; color: var(--accent); font-size: 15.5px; margin-bottom: 10px; }
.chart-bar-wrap { position: relative; height: 240px; width: 100%; }
.worldmap-card {
  border: 1px solid var(--line); border-top: 3px solid var(--accent);
  background: #fff; padding: 14px;
}
.worldmap-box { width: 100%; height: 480px; }
.range-tabs { display: flex; gap: 6px; margin: 0 0 12px; }
.range-btn {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 5px 18px; font-size: 14px; font-weight: 600; cursor: pointer; border-radius: 4px;
}
.range-btn:hover { border-color: var(--accent); color: var(--accent); }
.range-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- 就地編輯 UI ---------- */
.edit-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  background: var(--accent); color: #fff; border: 0; cursor: pointer;
  padding: 12px 20px; font-size: 15px; font-weight: 700; border-radius: 30px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); font-family: inherit;
}
.edit-fab:hover { background: var(--accent-dark); }
.editbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  background: var(--bar-dark); color: #fff; display: none;
  align-items: center; justify-content: center; gap: 14px; padding: 12px 20px;
  box-shadow: 0 -3px 14px rgba(0,0,0,.25);
}
.editbar.show { display: flex; }
.editbar .editbar-label { font-size: 14px; color: #e6e8ea; margin-right: 8px; }
.editbar .btn { padding: 9px 22px; }
.edit-mode [data-e] {
  outline: 1px dashed rgba(138,31,43,.5); outline-offset: 2px;
  cursor: text; transition: background .12s;
}
.edit-mode [data-e]:hover { background: rgba(138,31,43,.06); }
.edit-mode [data-e]:focus { outline: 2px solid var(--accent); background: #fff; }

/* ---------- 響應式 ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 0; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; padding: 0 14px; }
  .sidebar nav a { border-left: 0; border-bottom: 3px solid transparent; padding: 8px 12px; }
  .sidebar nav a.active { border-left: 0; border-bottom-color: var(--accent-dark); }
  .sidebar .side-note { display: none; }
  .main { padding: 28px 22px 40px; }
  .masthead { flex-direction: column; gap: 10px; text-align: center; padding: 16px; }
  .masthead .brand-logo { position: static; margin: 0 auto; filter: none; }
  .masthead .logo-img { height: 96px; }
  .masthead .brand-txt { font-size: 21px; }
  footer.site { padding: 30px 22px 20px; }
  footer.site .f-grid { grid-template-columns: 1fr; gap: 22px; }
}
