/* 古道•熱腸 — 復古紙本風
   靈感：老地圖、火車硬票、郵戳、鉛字印刷 */

:root {
  --paper: #f2e8d2;
  --paper-2: #e9dcbd;
  --card: #fbf5e6;
  --ink: #2b2620;
  --ink-soft: #5c5244;
  --line: #c9b78f;
  --seal: #b23a2b;      /* 印章朱紅 */
  --seal-soft: #e7c4b5;
  --moss: #4b5e3c;      /* 苔綠 */
  --moss-soft: #d5dcc2;
  --amber: #b07a2a;     /* 琥珀黃 */
  --amber-soft: #ecd8a8;
  --shadow: 3px 3px 0 rgba(43, 38, 32, 0.85);
  --grain-opacity: 0.35;

  --font-serif: 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
  --font-hand: 'LXGW WenKai TC', 'Kaiti TC', 'DFKai-SB', serif;
  --font-mono: 'Courier Prime', 'Courier New', monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #221d17;
    --paper-2: #2c261e;
    --card: #2a241c;
    --ink: #ede2c8;
    --ink-soft: #b9ab8e;
    --line: #5a4e3b;
    --seal: #e0644f;
    --seal-soft: #4a2a22;
    --moss: #9db582;
    --moss-soft: #2f3a26;
    --amber: #ddb160;
    --amber-soft: #43361d;
    --shadow: 3px 3px 0 rgba(0, 0, 0, 0.6);
    --grain-opacity: 0.18;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --paper: #221d17;
  --paper-2: #2c261e;
  --card: #2a241c;
  --ink: #ede2c8;
  --ink-soft: #b9ab8e;
  --line: #5a4e3b;
  --seal: #e0644f;
  --seal-soft: #4a2a22;
  --moss: #9db582;
  --moss-soft: #2f3a26;
  --amber: #ddb160;
  --amber-soft: #43361d;
  --shadow: 3px 3px 0 rgba(0, 0, 0, 0.6);
  --grain-opacity: 0.18;
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.8;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 紙張顆粒 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: var(--grain-opacity);
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .28 0 0 0 0 .18 0 0 0 .5 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a { color: var(--seal); text-underline-offset: 3px; }
a:hover { color: var(--ink); }
img { max-width: 100%; display: block; }

h1, h2, h3 { line-height: 1.35; font-weight: 900; letter-spacing: 0.04em; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); }
h2 { font-size: clamp(1.35rem, 3.2vw, 1.75rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
main { flex: 1; padding: 28px 0 64px; }

.hand { font-family: var(--font-hand); }
.mono { font-family: var(--font-mono); letter-spacing: 0.02em; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.875rem; }

/* 標題下的雙線（老報紙） */
.rule {
  border: 0;
  height: 6px;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  margin: 0.6rem 0 1.6rem;
}

.section-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.section-title .en { font-family: var(--font-mono); font-size: 0.8rem; letter-spacing: 0.2em; color: var(--ink-soft); text-transform: uppercase; }

/* ─────────── 按鈕 ─────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 20px;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { color: var(--ink); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--seal); color: #fbf5e6; border-color: var(--ink); }
.btn.primary:hover { color: #fff; }
.btn.small { padding: 4px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ─────────── 表單 ─────────── */
label { display: block; font-weight: 700; margin-bottom: 4px; }
.field { margin-bottom: 18px; }
.hint { font-weight: 400; font-size: 0.85rem; color: var(--ink-soft); }
input[type='text'], input[type='email'], input[type='number'], input[type='date'], input[type='search'], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 0;
  padding: 8px 10px;
}
textarea { resize: vertical; min-height: 110px; line-height: 1.7; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}
.grid-2 { display: grid; gap: 0 18px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ─────────── 卡片：火車硬票 ─────────── */
.ticket {
  position: relative;
  background: var(--card);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow);
}

/* 印章 */
.seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2.5px solid var(--seal);
  color: var(--seal);
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 4px;
  transform: rotate(-6deg);
  letter-spacing: 0.1em;
  line-height: 1.4;
  box-shadow: inset 0 0 0 1.5px var(--card), inset 0 0 0 3px var(--seal);
  background: transparent;
}

.chip {
  display: inline-block;
  font-size: 0.8rem;
  padding: 0 8px;
  border: 1px solid var(--ink-soft);
  color: var(--ink-soft);
  border-radius: 999px;
  line-height: 1.7;
  white-space: nowrap;
}

.cond { display: inline-flex; align-items: center; gap: 4px; font-size: 0.8rem; font-weight: 700; padding: 0 8px; border: 1.5px solid; line-height: 1.7; }
.cond[data-c='良好'] { color: var(--moss); background: var(--moss-soft); }
.cond[data-c='注意'] { color: var(--amber); background: var(--amber-soft); }
.cond[data-c='封閉'] { color: var(--seal); background: var(--seal-soft); }

.flash {
  border: 2px dashed var(--ink);
  background: var(--amber-soft);
  padding: 10px 14px;
  margin-bottom: 20px;
}

.notice-demo {
  background: var(--ink);
  color: var(--paper);
  font-size: 0.85rem;
  text-align: center;
  padding: 6px 16px;
}
.notice-demo a { color: var(--amber-soft); }

/* Leaflet 圖磚復古濾鏡 */
.leaflet-container { font-family: var(--font-serif); background: var(--paper-2); }
.retro-tiles { filter: sepia(0.45) saturate(0.8) contrast(0.95) brightness(1.02); }
:root[data-theme='dark'] .retro-tiles { filter: sepia(0.5) brightness(0.7) contrast(1.1); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .retro-tiles { filter: sepia(0.5) brightness(0.7) contrast(1.1); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

[hidden] { display: none !important; }

input[type='file'] { font: inherit; font-size: 0.9rem; max-width: 100%; }
input[type='file']::file-selector-button {
  font: inherit;
  font-weight: 700;
  margin-right: 10px;
  padding: 4px 12px;
  color: var(--ink);
  background: var(--paper-2);
  border: 1.5px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
}
input[type='checkbox'], input[type='radio'] { accent-color: var(--seal); width: 1.05em; height: 1.05em; }

/* ═══════════════════ 版面：頁首／頁尾 ═══════════════════ */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.site-header { border-bottom: 2px solid var(--ink); background: var(--paper); position: relative; }
.site-header::after { content: ''; position: absolute; left: 0; right: 0; bottom: -6px; border-bottom: 1px solid var(--ink); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; padding-top: 14px; padding-bottom: 14px; flex-wrap: wrap; }
.logo { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.logo:hover { color: var(--ink); }
.logo-mark { color: var(--seal); display: flex; transform: rotate(-4deg); }
.logo-name { font-size: 1.55rem; font-weight: 900; letter-spacing: 0.18em; white-space: nowrap; }
.logo-dot { color: var(--seal); margin: 0 0.05em; }
.site-nav { display: flex; gap: 4px 18px; flex-wrap: wrap; }
.site-nav a { color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: 0.1em; padding: 2px 0; border-bottom: 2px solid transparent; }
.site-nav a:hover, .site-nav a[aria-current='page'] { border-bottom-color: var(--seal); color: var(--ink); }
.site-nav .who { color: var(--seal); }
.site-footer { border-top: 2px solid var(--ink); padding: 28px 0 20px; background: var(--paper-2); }
.foot { display: flex; justify-content: space-between; gap: 16px 40px; flex-wrap: wrap; }
.foot .brand { font-size: 1.2rem; letter-spacing: 0.15em; }
.foot p { margin: 4px 0 0; }

.pad { padding: 16px 18px; }
.lead { font-size: 1.12rem; color: var(--ink-soft); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 24px; }
.report-list { list-style: none; margin: 0 0 20px; padding: 0; }
.report-list li { padding: 10px 0 8px; border-bottom: 1px dashed var(--line); }
.report-list p { margin: 2px 0; }
.report-list a { color: var(--ink); }
.rh { display: flex; justify-content: space-between; align-items: center; }

/* ═══════════════════ 元件：難度、等高線、海拔剖面 ═══════════════════ */
.diff { display: inline-flex; align-items: center; gap: 1px; }
.diff svg path { fill: none; stroke: var(--ink-soft); stroke-width: 1.2; }
.diff svg.on path { fill: var(--moss); stroke: var(--moss); }
.diff-lbl { margin-left: 6px; font-size: 0.85rem; font-weight: 700; }

.contour { width: 100%; height: 100%; display: block; }
.contour-bg { fill: var(--paper-2); }
.contour polygon { fill: none; stroke: var(--amber); stroke-linejoin: round; }
.contour .minor { stroke-width: 0.6; opacity: 0.6; }
.contour .major { stroke-width: 1.3; }
.contour-trail { fill: none; stroke: var(--seal); stroke-width: 2.2; stroke-dasharray: 6 4; }

.ele { margin: 0; }
.ele svg { width: 100%; height: auto; display: block; }
.ele-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.ele text { font-family: var(--font-mono); font-size: 11px; fill: var(--ink-soft); }
.ele-area { fill: var(--amber-soft); }
.ele-line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }

/* ═══════════════════ 元件：火車票卡片 ═══════════════════ */
.tc { display: flex; flex-direction: column; overflow: hidden; }
.tc-cover { position: relative; display: block; aspect-ratio: 2 / 1; border-bottom: 2px solid var(--ink); overflow: hidden; background: var(--paper-2); }
.tc-cover img { width: 100%; height: 100%; object-fit: cover; filter: sepia(0.25) contrast(1.05); }
.tc-region { position: absolute; top: 10px; right: 12px; background: var(--card); font-size: 0.85rem; }
.tc-body { padding: 14px 16px 10px; flex: 1; }
.tc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 1.6em; }
.tc-title { margin: 4px 0 6px; font-size: 1.25rem; }
.tc-title a { color: var(--ink); text-decoration: none; }
.tc-title a:hover { color: var(--seal); }
.tc-title a::after { content: ''; position: absolute; inset: 0; } /* 整張卡可點 */
.tc-summary { font-size: 0.92rem; color: var(--ink-soft); line-height: 1.7; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 8px; }
.tc-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.chip.need { border-color: var(--seal); color: var(--seal); }
.tc-stub { margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 2px dashed var(--ink); position: relative; background: var(--paper-2); }
.tc-stub::before, .tc-stub::after { content: ''; position: absolute; top: -9px; width: 16px; height: 16px; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink); }
.tc-stub::before { left: -10px; }
.tc-stub::after { right: -10px; }
.tc-stub div { padding: 8px 4px; text-align: center; }
.tc-stub div + div { border-left: 1px solid var(--line); }
.tc-stub dt, .spec dt { font-size: 0.72rem; letter-spacing: 0.2em; color: var(--ink-soft); }
.tc-stub dd, .spec dd { margin: 0; font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.tc-stub .diff-lbl { display: none; }
.tc-stub small { font-size: 0.7em; }

/* ═══════════════════ 首頁 ═══════════════════ */
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 12px; padding: clamp(20px, 4vw, 44px); margin-bottom: 28px; overflow: hidden; }
.kicker { letter-spacing: 0.25em; color: var(--ink-soft); font-size: 0.8rem; margin-bottom: 0.4em; }
.hot { color: var(--seal); }
.hero-search { display: flex; gap: 10px; max-width: 460px; margin-top: 18px; }
.hero-search input { flex: 1; min-width: 0; }
.hero-art svg { width: 100%; height: 100%; max-height: 300px; }
.hero-art .sun { fill: var(--seal); opacity: 0.85; }
.hero-art .m3 { fill: var(--amber-soft); stroke: var(--ink); stroke-width: 2; }
.hero-art .m2 { fill: var(--moss-soft); stroke: var(--ink); stroke-width: 2; }
.hero-art .path { fill: none; stroke: var(--seal); stroke-width: 3; stroke-dasharray: 7 5; }
.hero-art .stamp rect { fill: none; stroke: var(--seal); stroke-width: 3; }
.hero-art .stamp text { fill: var(--seal); font-weight: 900; font-size: 15px; letter-spacing: 2px; font-family: var(--font-serif); }
.hero-art .stamp .s { font-size: 13px; letter-spacing: 6px; }

.regions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 40px; }
.stamp-link {
  display: flex; flex-direction: column; align-items: center; padding: 14px 6px 10px; text-align: center;
  text-decoration: none; color: var(--ink); background: var(--card);
  border: 2px dotted var(--ink); outline: 6px solid var(--card); outline-offset: -10px; box-shadow: var(--shadow);
}
.stamp-link:hover { color: var(--seal); transform: rotate(-2deg); }
.stamp-link .r { font-size: 1.4rem; font-weight: 900; letter-spacing: 0.2em; }
.stamp-link .n { color: var(--ink-soft); line-height: 1.4; }

.home-cols { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; }
.more { margin-top: 28px; }
.cta { padding: 16px; text-align: center; }
.cta .hand { font-size: 1.4rem; margin: 0; }

/* ═══════════════════ 古道索引 ═══════════════════ */
.filters { display: grid; grid-template-columns: 2fr repeat(3, 1fr) auto; gap: 12px; padding: 16px; margin-bottom: 20px; align-items: end; }
.filters label { font-size: 0.85rem; }
.empty { font-size: 1.2rem; text-align: center; padding: 40px 0; }

/* ═══════════════════ 古道頁 ═══════════════════ */
.crumb { color: var(--ink-soft); margin-bottom: 8px; }
.crumb a { color: var(--ink-soft); }
.td-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; border-bottom: 2px solid var(--ink); padding-bottom: 14px; margin-bottom: 20px; }
.td-head h1 { margin-bottom: 0.2em; }
.td-head .lead { margin-bottom: 0.4em; }
.td-meta { display: flex; gap: 16px; flex-wrap: wrap; }
.td-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.permit { display: flex; align-items: center; gap: 12px; background: var(--seal-soft); border: 1.5px solid var(--seal); padding: 10px 14px; }
.td-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 36px; align-items: start; }
.td-main > * + * { margin-top: 28px; }
.td-cover { margin: 0; aspect-ratio: 2 / 1; overflow: hidden; }
.td-cover img { width: 100%; height: 100%; object-fit: cover; filter: sepia(0.2) contrast(1.05); }
.spec { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0; }
.spec div { padding: 10px; text-align: center; }
.spec div + div { border-left: 1px dashed var(--ink); }
.profile { margin-top: 14px; padding: 12px 12px 6px; }
.prose { white-space: pre-line; }
.story .prose::first-letter { font-size: 2.6em; float: left; line-height: 1; margin: 0.08em 0.12em 0 0; color: var(--seal); font-weight: 900; }
.tips { padding: 16px 20px; background: var(--amber-soft); }
.td-tags { display: flex; gap: 8px; flex-wrap: wrap; }
.td-tags .chip { text-decoration: none; }
.comments { list-style: none; padding: 0; margin: 0 0 20px; }
.comments li { border-bottom: 1px dashed var(--line); padding: 12px 0; }
.comments .prose { font-size: 1.08rem; margin: 0; }
.comments .small { margin: 2px 0 0; }
.inline { display: inline; margin-left: 8px; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--seal); text-decoration: underline; cursor: pointer; }
.td-side { position: sticky; top: 16px; }
.td-side h2 { margin-bottom: 0; }
.td-side .report-list { margin: 10px 0 16px; }
.report-form fieldset { border: 0; padding: 0; margin: 0 0 8px; }
.radios { display: flex; gap: 10px; flex-wrap: wrap; }
.radio { display: inline-flex; align-items: center; gap: 4px; font-weight: 400; cursor: pointer; }
.report-form p { margin: 10px 0 0; }

/* ═══════════════════ 分享頁 ═══════════════════ */
.share-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; }
.share-layout fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.share-layout legend { font-size: 1.25rem; font-weight: 900; margin-bottom: 12px; letter-spacing: 0.1em; }
.share-layout .no { display: inline-block; background: var(--ink); color: var(--paper); padding: 0 8px; margin-right: 6px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.share-side { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 16px; }
.share-side .h { font-size: 1.1rem; }
#cover-preview { margin-top: 10px; border: 2px solid var(--ink); }
.btn.big { width: 100%; font-size: 1.15rem; padding: 12px; }

/* ═══════════════════ 其他頁 ═══════════════════ */
.login-box { max-width: 440px; margin: 20px auto; padding: 28px; text-align: center; }
.login-box form { text-align: left; }
.login-box .big { font-size: 1.1rem; margin-bottom: 14px; }
.login-box .wide { width: 100%; }
.login-box .or { margin: 16px 0; }
.login-box .sent { font-size: 1.2rem; }
.me-top { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 24px; margin-bottom: 36px; }
.me-stat { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 14px; text-align: center; }
.me-stat div { display: flex; flex-direction: column; }
.me-stat .n { font-size: 2rem; font-weight: 700; color: var(--seal); line-height: 1.1; }
.about { max-width: 720px; margin: 0 auto; }
.about-lead { font-size: 1.3rem; color: var(--seal); }
.rules li { margin-bottom: 8px; }
.lost { text-align: center; padding: 60px 0; }
.lost .seal { font-size: 2.4rem; margin-bottom: 20px; }

/* ═══════════════════ 響應式 ═══════════════════ */
@media (max-width: 900px) {
  .td-layout { grid-template-columns: 1fr; }
  .td-side { position: static; }
}
@media (max-width: 880px) {
  .share-layout { grid-template-columns: 1fr; }
  .share-side { position: static; }
}
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .hero-art { max-width: 320px; justify-self: center; }
  .home-cols { grid-template-columns: 1fr; }
  .regions { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .q, .filters .act { grid-column: 1 / -1; }
  .filters .act .btn { width: 100%; }
}
@media (max-width: 700px) { .me-top { grid-template-columns: 1fr; } }
@media (max-width: 520px) {
  .spec { grid-template-columns: repeat(2, 1fr); }
  .spec div:nth-child(3) { border-left: 0; }
  .spec div:nth-child(n + 3) { border-top: 1px dashed var(--ink); }
}
@media (max-width: 420px) { .regions { grid-template-columns: repeat(2, 1fr); } }
