/* 2026 南庄山水悠遊行 — 電子獎狀 v2（重排版）
   ------------------------------------------------------------
   主辦原稿的所有品牌資產都留著（字標、NANZHUANG 直排、印章、月桂、Cittaslow、
   四個機關 logo、縣長簽名、山稜插圖），差別在版面重排：

   - 紙張改成 A4 直式 794×1123px @96dpi —— 剛好 1:1 對上 A4，列印不必縮放，
     原稿那個 450×675pt（2:3）印在 A4 上會上下留一大塊白。
   - 資訊層級收成三段：你是誰 → 你跑了多久 → 這條路長什麼樣。
     原稿把六個欄位平均攤成兩欄，每一欄的視覺重量一樣，成績反而沒有被凸顯。
   - 成績下方補了一條真實的賽道剖面（資料來自 broadcast/assets/course-profile.json，
     跟轉播字卡同一份），以及從成績換算的均速與 VAM。

   版面單位一律 px，1px = 1/96 in。 */

@font-face {
  font-family: "Barlow Condensed";
  src: url("../cg/fonts/BarlowCondensed-Medium.woff2") format("woff2");
  font-weight: 500;
  font-display: block;
}
@font-face {
  font-family: "Barlow Condensed";
  src: url("../cg/fonts/BarlowCondensed-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-display: block;
}
@font-face {
  font-family: "Barlow Condensed";
  src: url("../cg/fonts/BarlowCondensed-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: block;
}
@font-face {
  font-family: "Barlow";
  src: url("../cg/fonts/Barlow-Medium.woff2") format("woff2");
  font-weight: 500;
  font-display: block;
}
@font-face {
  font-family: "Noto Sans TC";
  src: url("../cg/fonts/NotoSansTC-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: block;
}

:root {
  --ink: #1a3a30;
  --ink-2: #2c4a40;
  --paper: #f7f3ea;
  --paper-2: #efe8da;
  --gold: #b08d4f;
  --gold-lt: #e3cd97;
  --coral: #c9806f;
  --sage: #5a9b8a;
  --muted: #8c8375;

  --W: 794px;
  --H: 1123px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* .ridge 與 .course 都自帶 display，會把 [hidden] 壓過去 —— 元素照樣畫出來，
   而且不會有任何錯誤，只是版面上多一塊不該出現的東西。 */
[hidden] { display: none !important; }

html, body {
  background: #16211d;
  font-family: "Noto Sans TC", "Barlow", sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

.stage { display: flex; justify-content: center; padding: 24px 16px 72px; }
.bar + .stage { padding-top: 92px; }

.sheet {
  position: relative;
  width: var(--W);
  height: var(--H);
  flex: none;
  background: var(--paper);
  box-shadow: 0 20px 70px rgba(0, 0, 0, .5);
  overflow: hidden;
  transform-origin: top center;
  display: flex;
  flex-direction: column;
}

/* 紙面：極淡的等高線紋理。深色帶下方才看得出來，正面看只覺得紙有厚度。 */
.sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 70% at 50% 6%, rgba(90, 155, 138, .10), transparent 62%),
    radial-gradient(90% 50% at 50% 100%, rgba(176, 141, 79, .10), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* 內側金框：距離紙邊 14px，比原稿的雙框細，只留一條 */
.sheet::after {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(176, 141, 79, .38);
  pointer-events: none;
  z-index: 4;
}

/* ══ 頁首 ══ */
.crest {
  position: relative;
  z-index: 2;
  height: 132px;
  flex: none;
  background: linear-gradient(102deg, #16352c 0%, var(--ink) 48%, #24493d 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 44px 0 52px;
  border-bottom: 2px solid var(--gold);
}
.crest .wm { width: 302px; display: block; }
.crest .kicker { text-align: right; color: var(--gold-lt); }
.crest .kicker b {
  display: block;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: .42em;
  text-indent: .42em;
}
.crest .kicker span {
  display: block;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .46em;
  text-indent: .46em;
  text-transform: uppercase;
  opacity: .72;
  margin-bottom: 5px;
}

/* ══ 主體 ══ */
.body {
  position: relative;
  z-index: 2;
  flex: 1;
  padding: 26px 62px 0 62px;
  display: flex;
  flex-direction: column;
}

.event {
  text-align: center;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .38em;
  text-indent: .38em;
  text-transform: uppercase;
  color: var(--gold);
}
.event-zh {
  margin-top: 4px;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .3em;
  text-indent: .3em;
  color: var(--ink-2);
}

.rule {
  width: 86px;
  height: 1px;
  margin: 14px auto 0;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.name {
  margin-top: 18px;
  text-align: center;
  font-size: 72px;
  font-weight: 500;
  line-height: 1.14;
  letter-spacing: .12em;
  text-indent: .12em;
  color: var(--ink);
}

/* 號碼與組別：一條細細的中繼資訊，不跟姓名搶 */
.meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: .08em;
}
.meta .bib {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--ink);
  border: 1px solid rgba(26, 58, 48, .28);
  border-radius: 3px;
  padding: 1px 9px 0;
}
.meta i { width: 3px; height: 3px; border-radius: 50%; background: var(--gold); }
.meta .x { display: none; }

/* ══ 成績 ══ */
.result {
  position: relative;
  margin-top: 26px;
  padding: 6px 0 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.result .lau {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 170px;
  opacity: .92;
}
/* 左支用右支鏡像 —— 原稿的左右兩支本來就不是同一個形狀（寬度差快 100px），
   各放各的會看出一邊胖一邊瘦，鏡像才對稱。 */
.result .lau.l { left: 74px; transform: translateY(-50%) scaleX(-1); }
.result .lau.r { right: 74px; }
/* 4K 版月桂環抱的是標誌＋三行賀詞，區塊高很多，月桂要跟著放大 */
.sheet[data-race="fun"] .result .lau { height: 250px; }
.sheet[data-race="fun"] .result .lau.l { left: 40px; }
.sheet[data-race="fun"] .result .lau.r { right: 40px; }

.time {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 100px;
  font-weight: 700;
  line-height: .92;
  font-variant-numeric: tabular-nums;
  letter-spacing: .005em;
  color: var(--ink);
}
/* 百分之一秒弱一階：它是計時系統的精度，不是成績的重點 */
.time .frac { font-size: .52em; color: var(--ink-2); margin-left: .04em; }

.cap {
  margin-top: 8px;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .44em;
  text-indent: .44em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ══ 賽道剖面 ══ */
.course {
  margin-top: 24px;
  padding: 0 8px;
}
.course svg { display: block; width: 100%; height: 118px; }
.course .axis {
  display: flex;
  justify-content: space-between;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .2em;
  color: var(--muted);
  margin-top: 2px;
}

/* 山稜插圖（路跑與 4K 用，取代剖面） */
.ridge {
  margin-top: 26px;
  width: 100%;
  opacity: .13;
  display: block;
}

/* ══ 數據列 ══ */
.stats {
  margin-top: 24px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border-top: 1px solid rgba(176, 141, 79, .42);
  border-bottom: 1px solid rgba(176, 141, 79, .42);
}
.stats div {
  padding: 15px 4px 14px;
  text-align: center;
  border-left: 1px solid rgba(176, 141, 79, .22);
}
.stats div:first-child { border-left: 0; }
.stats b {
  display: block;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 29px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.stats b em {
  font-style: normal;
  font-size: .46em;
  font-weight: 600;
  color: var(--muted);
  margin-left: .22em;
}
.stats span {
  display: block;
  margin-top: 5px;
  font-size: 10px;
  letter-spacing: .22em;
  text-indent: .22em;
  color: var(--muted);
}
.stats .hi b { color: var(--coral); }

/* ══ 名次與分組 ══ */
.grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px 18px;
}
.cell {
  border-left: 2px solid var(--gold);
  padding: 2px 0 2px 11px;
}
.cell span {
  display: block;
  font-size: 10px;
  letter-spacing: .2em;
  color: var(--muted);
}
.cell span i {
  font-style: normal;
  font-family: "Barlow Condensed", sans-serif;
  letter-spacing: .16em;
  text-transform: uppercase;
  opacity: .8;
}
.cell b {
  display: block;
  margin-top: 3px;
  font-size: 22px;
  font-weight: 500;
  line-height: 1.15;
  color: var(--ink);
}
.cell b.num {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cell b em {
  font-style: normal;
  font-size: .62em;
  font-weight: 500;
  color: var(--muted);
  margin-left: .16em;
}
.cell.empty { display: none; }

/* 4K 休閒組：沒有成績，改用中央的慢城標誌與一段祝賀語，
   月桂維持環抱 —— 那張獎狀少了成績，中間空掉會像沒印完。 */
.emblem { display: block; height: 104px; margin: 4px auto 0; }
.salute {
  margin-top: 22px;
  text-align: center;
  font-size: 26px;
  font-weight: 500;
  line-height: 2.0;
  letter-spacing: .26em;
  text-indent: .26em;
  color: var(--gold);
}

.date {
  margin-top: auto;
  margin-bottom: 12px;
  text-align: center;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .34em;
  text-indent: .34em;
  color: var(--ink-2);
}
.date span { color: var(--muted); margin-right: .5em; letter-spacing: .3em; }

/* ══ 頁尾 ══ */
.foot {
  position: relative;
  z-index: 2;
  flex: none;
  height: 168px;
  padding: 0 34px 22px 34px;
  border-top: 1px solid rgba(176, 141, 79, .42);
  display: flex;
  align-items: center;
  gap: 16px;
}
/* 三組各佔三分之一、各自置中：靠 space-between 會讓兩端貼邊、中間那組偏移，
   組內元素數量不一樣時看起來更歪。 */
.foot > .org, .foot > .marks { flex: 1 1 0; min-width: 0; }
/* 主辦那組橫向最寬（縣府鎖定 ＋ 簽名），分到的寬度不夠就會把簽名擠到第二行 */
.foot > .org:has(.lab-top) { flex: 1.9 1 0; }
.org { display: flex; align-items: center; justify-content: center; gap: 10px; }
.org:has(.lab-top) { flex-wrap: wrap; justify-content: center; row-gap: 3px; }
.org .lab-top { width: 100%; text-align: center; }
.org .lab {
  font-size: 10px;
  line-height: 1.5;
  letter-spacing: .1em;
  color: var(--muted);
  white-space: nowrap;
}
.org .lab b { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); letter-spacing: .06em; }
/* 尺寸按「符號本體」的視覺重量配，不是按整張圖的高度 ——
   每顆 logo 底下附的字數不一樣（運動署兩行英文、農會一行中文、慢城一個字標），
   照整張圖等高排會變成字多的那顆符號特別小。 */
.foot .sfa { height: 46px; }        /* 符號 + 中文 + 兩行英文 */
.foot .miaoli { height: 30px; }     /* 橫式鎖定，符號約等於整張高 */
.foot .sign { height: 38px; }
.foot .nongfu { height: 40px; }     /* 符號 + 一行中文 */
.foot .cittaslow { height: 40px; }  /* 符號 + 字標 */
.foot .marks { display: flex; align-items: center; justify-content: center; gap: 22px; }
.note {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 7px;
  text-align: center;
  font-size: 8.5px;
  letter-spacing: .12em;
  color: #a79c8c;
}

/* ══ 控制列（列印時消失）══ */
.bar {
  position: fixed;
  left: 0; right: 0; top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  padding: 10px 14px;
  background: rgba(22, 33, 29, .96);
  border-bottom: 1px solid rgba(227, 205, 151, .3);
  color: #ede5d8;
  font-size: 13px;
}
.bar label { display: flex; align-items: center; gap: 5px; }
.bar input, .bar select {
  font: inherit;
  color: #23201c;
  background: #f5f0ea;
  border: 1px solid rgba(0, 0, 0, .2);
  border-radius: 6px;
  padding: 4px 7px;
  width: 104px;
}
.bar input.wide { width: 130px; }
.bar button {
  font: inherit;
  font-weight: 600;
  color: #1a3a30;
  background: var(--gold-lt);
  border: 0;
  border-radius: 999px;
  padding: 6px 16px;
  cursor: pointer;
}
.bar .sp { flex: 1; }
.bar .msg { color: var(--gold-lt); }
.bar .msg.err { color: #f0a090; }
.bar a { color: var(--gold-lt); }

/* ══ ibon 列印說明 ══ */
.ibon {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 18, 15, .6);
}
.ibon-box {
  width: 100%;
  max-width: 460px;
  padding: 22px 22px 18px;
  border-radius: 14px;
  background: #f5f0ea;
  color: #23201c;
  font-size: 14px;
  line-height: 1.65;
}
.ibon-box h2 { margin: 0 0 6px; font-size: 19px; color: #1a3a30; }
.ibon-box ol { margin: 10px 0 16px; padding-left: 20px; }
.ibon-box li { margin-bottom: 6px; }
.ibon-box a { color: #1a5a4a; }
.ibon-state { margin: 0; color: #5a9b8a; }
.ibon-pin {
  display: flex;
  gap: 16px;
  align-items: center;
  margin: 12px 0 4px;
  padding: 12px;
  border-radius: 10px;
  background: #fff;
}
.ibon-pin img { flex: none; image-rendering: pixelated; }
.ibon-pin span { display: block; font-size: 12px; color: #6b6358; letter-spacing: .08em; }
.ibon-pin b {
  display: block;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 34px;
  letter-spacing: .06em;
  color: #1a3a30;
  user-select: all;
}
.ibon-pin em { display: block; font-style: normal; font-size: 12px; color: #b4533f; }
.ibon-state.err { color: #b4533f; }
.img-preview {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 55vh;
  margin: 12px auto;
  border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .18);
}
.ibon-act { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.ibon-act button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  text-decoration: none;
}
.ibon-act button { background: #e3d9c9; color: #1a3a30; }

/* ══ 列印 ══
   紙張本身就是 A4 @96dpi，所以列印是 1:1，不縮放也不分頁。 */
/* 選手專區的縮圖（?thumb=1）：只留紙面，其餘交給外層 iframe */
.thumb, .thumb body { background: transparent; overflow: hidden; }
.thumb .bar, .thumb .ibon { display: none !important; }
.thumb .stage { display: block; padding: 0 !important; }
.thumb .sheet { box-shadow: none; transform-origin: top left; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff; }
  .bar, .ibon { display: none !important; }
  .stage, .bar + .stage { padding: 0 !important; display: block; height: auto !important; }
  .sheet { box-shadow: none; margin: 0; }
}
