/* 依 Apple Human Interface Guidelines：iOS 系統色、字級、分組列表、導覽列與工具列 */

:root {
  color-scheme: light dark;

  /* iOS 系統色（淺色） */
  --bg: #f2f2f7;                         /* systemGroupedBackground */
  --card: #ffffff;                       /* secondarySystemGroupedBackground */
  --label: #000000;
  --secondary: rgba(60, 60, 67, 0.6);    /* secondaryLabel */
  --tertiary: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.29);
  --fill: rgba(118, 118, 128, 0.12);     /* tertiarySystemFill */
  --highlight: #d1d1d6;                  /* 列被按下時 */
  --tint: #248a3d;                       /* systemGreen（高對比版，白字可讀） */
  --tint-soft: rgba(52, 199, 89, 0.16);
  --on-tint: #ffffff;
  --orange: #c93400;
  --orange-soft: rgba(255, 149, 0, 0.16);
  --bar: rgba(249, 249, 249, 0.82);      /* 毛玻璃導覽列 */
  --tile-bg: #f3f7ee;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --gutter: max(16px, var(--safe-left), var(--safe-right));
  --ease-push: cubic-bezier(0.32, 0.72, 0, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --label: #ffffff;
    --secondary: rgba(235, 235, 245, 0.6);
    --tertiary: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.65);
    --fill: rgba(118, 118, 128, 0.24);
    --highlight: #3a3a3c;
    --tint: #30d158;
    --tint-soft: rgba(48, 209, 88, 0.2);
    --on-tint: #000000;
    --orange: #ff9f0a;
    --orange-soft: rgba(255, 159, 10, 0.2);
    --bar: rgba(22, 22, 23, 0.82);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--label);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  letter-spacing: -0.01em;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button, label, a, summary { touch-action: manipulation; }
button { font: inherit; color: inherit; }
a { color: var(--tint); text-decoration: none; }
[hidden] { display: none !important; }

/* ---------- 導覽列 ---------- */

.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: var(--safe-top);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 0.5px 0 var(--separator);
}
/* 大標題首頁：導覽列透明（iOS Large Title 的捲動前狀態） */
.navbar.flat {
  background: transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.navbar-inner {
  max-width: 680px;
  margin: 0 auto;
  height: 44px;
  padding: 0 var(--gutter);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.nav-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-back {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 44px;
  margin-left: -8px;
  padding: 0 8px;
  border: 0;
  background: none;
  color: var(--tint);
  cursor: pointer;
}
.nav-back svg { width: 12px; height: 20px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.nav-back:active { opacity: 0.4; }
.nav-step { justify-self: end; font-size: 15px; color: var(--secondary); font-variant-numeric: tabular-nums; }

.progress { height: 2px; background: transparent; }
.progress span { display: block; height: 100%; width: 0; background: var(--tint); transition: width 0.35s var(--ease-push); }

/* ---------- 內容區 ---------- */

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 var(--gutter) calc(110px + var(--safe-bottom));
}

.large-title { padding: 12px 4px 4px; }
.large-title h2 {
  margin: 0;
  font-size: 34px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.large-title p { margin: 6px 0 0; color: var(--secondary); font-size: 15px; }
.eyebrow { margin: 0 0 2px !important; color: var(--tint) !important; font-size: 13px !important; font-weight: 600; }

/* 推入／返回的轉場 */
.push-in { animation: push-in 0.38s var(--ease-push); }
.pop-in { animation: pop-in 0.38s var(--ease-push); }
@keyframes push-in { from { opacity: 0; transform: translateX(24%); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: translateX(-16%); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .push-in, .pop-in { animation: none; } }

/* ---------- 分組列表（Inset Grouped） ---------- */

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 28px 16px 7px;
  font-size: 13px;
  font-weight: 400;
  color: var(--secondary);
  text-transform: uppercase;
}
.group-header .text-btn { font-size: 15px; text-transform: none; }
.group-footer { margin: 7px 16px 0; font-size: 13px; color: var(--secondary); line-height: 1.45; }
.group-footer + .group-footer { margin-top: 10px; }

.group {
  background: var(--card);
  border-radius: 10px;
  overflow: hidden;
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 11px 16px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.2s;
}
button.row:active, label.row:active, a.row:active { background: var(--highlight); transition: none; }
.row.static { cursor: default; }

/* 列與列之間的細分隔線，從文字起點開始（iOS 的內縮分隔線） */
.group > .row:not(:first-child)::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 16px;
  height: 0.5px;
  background: var(--separator);
}
.group.with-icons > .row:not(:first-child)::before { left: 60px; }

.row-icon {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: var(--tint-soft);
}
.row-thumb { flex: none; width: 32px; height: 32px; border-radius: 6px; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { color: var(--label); }
.row-sub { font-size: 15px; color: var(--secondary); }
.row-value { color: var(--secondary); }
.row-link .row-title { color: var(--tint); }

.chevron { flex: none; width: 8px; height: 14px; fill: none; stroke: var(--tertiary); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* 選取用：隱藏原生核取方塊，改以右側打勾表示（iOS 風格） */
.row input, .tile input { position: absolute; opacity: 0; pointer-events: none; }
.check { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--tint); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; visibility: hidden; }
.row:has(input:checked) .check, .row.selected .check { visibility: visible; }
.row:has(input:focus-visible), .tile:has(input:focus-visible) { outline: 2px solid var(--tint); outline-offset: -2px; }

/* ---------- 圖片選項（相簿風格的選取） ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.tile:active { transform: scale(0.97); }
.tile img { display: block; width: 100%; height: auto; background: var(--tile-bg); }
.tile-caption { padding: 8px 10px 10px; font-size: 15px; line-height: 1.35; }
.tile-caption small { display: block; margin-top: 2px; font-size: 13px; color: var(--secondary); }
.tile::after { /* 選取時的外框 */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 12px;
  box-shadow: inset 0 0 0 3px var(--tint);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.tile:has(input:checked)::after { opacity: 1; }
.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid rgba(60, 60, 67, 0.35);
  background: rgba(255, 255, 255, 0.75);
  display: grid;
  place-items: center;
}
.badge svg { width: 14px; height: 14px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.tile:has(input:checked) .badge { background: var(--tint); border-color: var(--tint); }
.tile:has(input:checked) .badge svg { opacity: 1; stroke: var(--on-tint); }
.tiles + .group { margin-top: 12px; }

/* ---------- 摘要 ---------- */

.pick-row .row-title { font-size: 16px; }
.empty .row-title { color: var(--secondary); }

/* ---------- 結果 ---------- */

.candidate { margin-top: 20px; }
.candidate-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 14px 16px 12px;
}
.candidate-head h3 { margin: 0 4px 0 0; font-size: 22px; font-weight: 700; }
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--fill);
  color: var(--secondary);
}
.pill.high { background: var(--tint); color: var(--on-tint); }
.pill.medium { background: var(--orange-soft); color: var(--orange); }
.block { padding: 11px 16px; position: relative; }
.block::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 0.5px; background: var(--separator); }
.block h4 { margin: 0 0 4px; font-size: 13px; font-weight: 400; color: var(--secondary); text-transform: uppercase; }
.block p { margin: 0; }
.block ul { margin: 0; padding-left: 1.1em; }
.block li + li { margin-top: 2px; }
.block details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 22px;
  list-style: none;
  color: var(--tint);
  cursor: pointer;
}
.block details summary::-webkit-details-marker { display: none; }
.block details summary .chevron { stroke: var(--tint); transform: rotate(90deg); transition: transform 0.2s; }
.block details[open] summary .chevron { transform: rotate(-90deg); }
.block details ul { margin-top: 8px; }
.block details .note { margin-top: 6px; font-size: 15px; color: var(--secondary); }

.notice { margin-top: 20px; }
.notice .row { align-items: flex-start; }
.notice .row-icon { background: var(--orange-soft); }

/* ---------- 搜尋 ---------- */

.search { display: flex; gap: 8px; padding: 10px 12px; }
.search-field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 8px;
  border-radius: 10px;
  background: var(--fill);
  color: var(--secondary);
}
.search-field svg { flex: none; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.search-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: none;
  color: var(--label);
  font: inherit;
  font-size: 17px; /* ≥16px，避免 iPhone 自動放大 */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search-field input::placeholder { color: var(--secondary); }

/* ---------- 按鈕 ---------- */

.text-btn { border: 0; background: none; padding: 0; color: var(--tint); cursor: pointer; }
.text-btn:active { opacity: 0.4; }
.text-btn:disabled { color: var(--tertiary); }

.btn-filled {
  display: block;
  width: 100%;
  height: 50px;
  border: 0;
  border-radius: 12px;
  background: var(--tint);
  color: var(--on-tint);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.btn-filled:active:not(:disabled) { opacity: 0.75; }
.btn-filled:disabled { background: var(--fill); color: var(--tertiary); cursor: default; }
.btn-filled.gray { background: var(--fill); color: var(--tint); }

/* ---------- 底部工具列 ---------- */

.toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 10px var(--gutter) calc(10px + var(--safe-bottom));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 -0.5px 0 var(--separator);
}
.toolbar .btn-filled { max-width: 648px; margin: 0 auto; }

/* 滑鼠裝置才顯示 hover */
@media (hover: hover) {
  button.row:hover, label.row:hover, a.row:hover { background: var(--fill); }
  .tile:hover { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08); }
}
