/* =========================================================
   ロケット団？中文牌張查詢 — 樣式
   以手機為主；寬螢幕時網格會多放幾欄。
   顏色跟著系統的淺色／深色模式切換。
   ========================================================= */

:root {
  --bg: #f4f3f0;
  --surface: #ffffff;
  --text: #1d1f24;
  --muted: #6b6f78;
  --border: #dddad3;
  --accent: #c0392b;
  --accent-text: #ffffff;
  --header-bg: #1d1f24;
  --header-text: #f4f3f0;
  --card-ratio: 63 / 88;   /* 卡片長寬比；拿到實體牌後可依實際尺寸調整 */
  --radius: 10px;
  --font-zh: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-ja: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --surface: #22242a;
    --text: #e9e7e2;
    --muted: #9a9ea8;
    --border: #353841;
    --accent: #e0574a;
    --header-bg: #0f1013;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-zh);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[lang="ja"] { font-family: var(--font-ja); }

main {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 12px 32px;
}

a { color: inherit; }

h1, h2, h3 { line-height: 1.3; }

.muted { color: var(--muted); }

.box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.notice {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--muted);
}

/* ---------- 頁首 ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--header-bg);
  color: var(--header-text);
}

.brand {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  text-decoration: none;
  font-size: 15px;
  white-space: nowrap;
}

.header-search { flex: 1; min-width: 0; }

.header-search input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--header-text);
  font: inherit;
  font-size: 16px; /* 16px 以上，iOS 點擊時才不會自動放大畫面 */
}
.header-search input::placeholder { color: rgba(244, 243, 240, 0.55); }
.header-search input:focus { outline: 2px solid var(--accent); background: rgba(255, 255, 255, 0.18); }

.header-link {
  flex: none;
  color: var(--header-text);
  text-decoration: none;
  font-size: 15px;
  padding: 6px 4px;
}

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 16px;
}
.site-footer p { margin: 0; }

/* ---------- 首頁 ---------- */

.hero {
  text-align: center;
  padding: 40px 4px 12px;
}
.hero-ja {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  font-size: 15px;
}
.hero h1 {
  margin: 4px 0 20px;
  font-size: 28px;
}

.home-search {
  display: flex;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
}
.home-search input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 16px;
  border: 2px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 17px;
}
.home-search input:focus { outline: none; border-color: var(--accent); }
.home-search button {
  flex: none;
  height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 24px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.home-section { margin-top: 28px; }
.home-section h2 {
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 10px;
}

.cat-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 720px) {
  .cat-buttons { grid-template-columns: repeat(4, 1fr); }
}

.cat-button {
  --cat-color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 14px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 5px solid var(--cat-color);
  border-radius: var(--radius);
  text-decoration: none;
}
.cat-button:active { transform: scale(0.98); }
.cat-zh { font-weight: 700; font-size: 17px; }
.cat-ja { color: var(--muted); font-size: 12px; }
.cat-count { margin-top: 6px; color: var(--muted); font-size: 13px; }

.rules-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--header-bg);
  color: var(--header-text);
  text-decoration: none;
}
.rules-link strong { font-size: 18px; }
.rules-link span { font-size: 14px; opacity: 0.8; }

/* ---------- 總覽網格 ---------- */

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 12px;
}
.list-head h1 { margin: 0; font-size: 22px; }
.list-head h1 small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.count { margin: 0; color: var(--muted); font-size: 14px; flex: none; }
.cat-note { margin: -4px 0 14px; color: var(--muted); font-size: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);   /* 手機：固定一排 2 張 */
  gap: 12px 10px;
}
@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(4, 1fr); gap: 16px 14px; }
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tile[hidden] { display: none; }
.tile:active { transform: scale(0.98); }

.tile-img {
  display: block;
  width: 100%;
  aspect-ratio: var(--card-ratio);
  object-fit: cover;
  border-radius: 4.5% / 3.2%;
  background: var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.tile-caption {
  font-size: 13px;
  text-align: center;
  line-height: 1.35;
}

/* 沒有卡圖時的文字卡 */
.placeholder {
  --cat-color: var(--muted);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  aspect-ratio: var(--card-ratio);
  padding: 14% 8% 10%;
  border-radius: 4.5% / 3.2%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 8px solid var(--cat-color);
  text-align: center;
  overflow: hidden;
}
.ph-cat {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  font-size: 11px;
  color: var(--muted);
}
.ph-zh { font-size: 17px; font-weight: 700; line-height: 1.3; word-break: break-word; }
.ph-ja { font-size: 13px; color: var(--muted); line-height: 1.3; word-break: break-word; }
.ph-num {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- 單卡頁 ---------- */

.crumbs { margin: 4px 0 10px; font-size: 14px; }
.crumbs a { color: var(--muted); text-decoration: none; }

.card-detail {
  display: grid;
  gap: 16px;
}
@media (min-width: 720px) {
  .card-detail { grid-template-columns: 320px 1fr; gap: 28px; align-items: start; }
  .card-image { position: sticky; top: 64px; }
}

.card-image { max-width: 340px; width: 78%; margin: 0 auto; }
.card-image.no-image { width: 52%; }   /* 沒圖時縮小，讓敘述更早出現在畫面上 */
@media (min-width: 720px) { .card-image, .card-image.no-image { width: 100%; } }
.card-image img {
  display: block;
  width: 100%;
  border-radius: 4.5% / 3.2%;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.placeholder.large .ph-zh { font-size: 20px; }
.placeholder.large .ph-ja { font-size: 14px; }
@media (min-width: 720px) {
  .placeholder.large .ph-zh { font-size: 24px; }
  .placeholder.large .ph-ja { font-size: 16px; }
}
.ph-noimg {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 1px 8px;
}

.card-info { display: grid; gap: 14px; min-width: 0; }

.card-title h1 { margin: 0; font-size: 24px; }
.name-ja { margin: 2px 0 0; color: var(--muted); font-size: 16px; }
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--muted);
}
.badge {
  --cat-color: var(--muted);
  color: #fff;
  background: var(--cat-color);
  border-radius: 4px;
  padding: 0 8px;
  font-size: 13px;
}

/* 中日文切換（純 CSS） */
.lang-radio { position: absolute; opacity: 0; pointer-events: none; }
.lang-tabs {
  display: inline-flex;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.lang-tabs label {
  padding: 4px 14px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}
#lang-zh:checked ~ .lang-tabs label[for="lang-zh"],
#lang-ja:checked ~ .lang-tabs label[for="lang-ja"] {
  background: var(--text);
  color: var(--bg);
}
#lang-zh:focus-visible ~ .lang-tabs label[for="lang-zh"],
#lang-ja:focus-visible ~ .lang-tabs label[for="lang-ja"] { outline: 2px solid var(--accent); }
#lang-zh:checked ~ .text-ja,
#lang-ja:checked ~ .text-zh { display: none; }

.text-body { font-size: 16px; }
.text-body > :first-child { margin-top: 0; }
.text-body > :last-child { margin-bottom: 0; }
.text-body ul, .text-body ol { padding-left: 1.3em; }

.fields {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
  font-size: 14px;
}
.fields th, .fields td {
  padding: 6px 4px;
  border-top: 1px solid var(--border);
  text-align: left;
}
.fields th { color: var(--muted); font-weight: 500; width: 40%; }

/* 規則說明 / FAQ */
.faq h2 { margin: 0 0 8px; font-size: 17px; }
.faq ol { margin: 0; padding-left: 1.4em; }
.faq li { padding: 8px 0; border-top: 1px solid var(--border); }
.faq li:first-child { border-top: 0; padding-top: 0; }
.faq li::marker { color: var(--muted); }
.faq-text { display: inline; }
.faq-text p { display: inline; margin: 0; }
.faq-text p + p { display: block; margin-top: 0.5em; }

.orig-btn {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-left: 6px;
  vertical-align: 1px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

/* 原文浮窗（HTML popover，點外面或按關閉即收起） */
.orig-pop {
  width: min(92vw, 480px);
  max-height: 70vh;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.orig-pop::backdrop { background: rgba(0, 0, 0, 0.4); }
.orig-head { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.orig-body > :first-child { margin-top: 0; }
.orig-src { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.orig-close {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}
.pager a {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  text-decoration: none;
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 規則頁 ---------- */

.prose { max-width: 720px; margin: 0 auto; }
.prose h1 { font-size: 24px; margin: 8px 0 14px; }
.prose h2 {
  font-size: 20px;
  margin: 32px 0 10px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent);
  scroll-margin-top: 64px;
}
.prose h3 { font-size: 17px; margin: 20px 0 6px; scroll-margin-top: 64px; }
.prose blockquote {
  margin: 0 0 16px;
  padding: 8px 12px;
  border-left: 4px solid var(--border);
  color: var(--muted);
  font-size: 14px;
}
.prose blockquote p { margin: 0; }
.prose table { border-collapse: collapse; width: 100%; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose th { background: var(--surface); }

.toc { margin-bottom: 8px; }
.toc-head { margin: 0 0 4px; font-weight: 700; font-size: 14px; color: var(--muted); }
.toc ol { margin: 0; padding-left: 1.4em; }
.toc a { text-decoration: none; }
