:root {
  --bg:        #f6f2ea;
  --card:      #fffdf8;
  --ink:       #1e2430;
  --ink-soft:  #3d4657;
  --muted:     #78716a;
  --line:      #e0d8c8;
  --accent:    #c1452e;
  --accent-dk: #97331f;
  --accent-bg: #fbeae6;

  --ocean:     #e4ecf1;
  --land:      #d7cfbe;
  --land-dim:  #e6e0d4;
  --land-hi:   #bfae8f;
  --fam:       #3d7f8c;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(30,36,48,.05), 0 6px 20px rgba(30,36,48,.07);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 4.2rem;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system,
               BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.85;
  letter-spacing: .01em;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 1.25rem; }

/* ── Hero ──────────────────────────────── */
.hero {
  background: linear-gradient(160deg, #232b3a 0%, #17324a 55%, #1e4a52 100%);
  color: #f4f1e9;
  padding: 4rem 0 3.5rem;
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 18% 30%, rgba(255,255,255,.07) 0 1.5px, transparent 1.6px),
    radial-gradient(circle at 72% 62%, rgba(255,255,255,.05) 0 1.5px, transparent 1.6px);
  background-size: 46px 46px, 61px 61px;
  pointer-events: none;
}

.hero .wrap { position: relative; z-index: 1; }

.hero .kicker {
  margin: 0 0 .7rem;
  font-size: .82rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: #e9b8a8;
  font-weight: 600;
}

.hero h1 {
  margin: 0 0 1.15rem;
  font-size: clamp(1.85rem, 5.2vw, 3rem);
  line-height: 1.32;
  letter-spacing: .01em;
  font-weight: 700;
}

.hero .lede {
  margin: 0;
  max-width: 46rem;
  color: #cfd6dd;
  font-size: clamp(.98rem, 2.1vw, 1.08rem);
  line-height: 1.85;
}

/* ── 導覽 ──────────────────────────────── */
.toc {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(246,242,234,.93);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.toc .wrap {
  display: flex;
  gap: .3rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-top: .45rem;
  padding-bottom: .45rem;
}
.toc .wrap::-webkit-scrollbar { display: none; }

.toc a {
  flex: 0 0 auto;
  padding: .35rem .8rem;
  border-radius: 999px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: .93rem;
  font-weight: 600;
  white-space: nowrap;
}
.toc a:hover { background: var(--accent-bg); color: var(--accent-dk); }

/* ── 通用區塊 ──────────────────────────── */
main { padding-bottom: 2rem; }

section { padding: 3rem 0; border-bottom: 1px solid var(--line); }
section:last-of-type { border-bottom: 0; }

h2 {
  margin: 0 0 1.2rem;
  font-size: clamp(1.35rem, 3.4vw, 1.7rem);
  line-height: 1.45;
  position: relative;
  padding-left: .85rem;
  letter-spacing: .02em;
}
h2::before {
  content: "";
  position: absolute;
  left: 0; top: .34em;
  width: 4px; height: 1.05em;
  border-radius: 2px;
  background: var(--accent);
}

h3 { font-size: 1.08rem; line-height: 1.6; margin: 0 0 .55rem; }
p  { margin: 0 0 1rem; }
strong { font-weight: 700; }
b { font-weight: 700; color: var(--accent-dk); }

.intro { color: var(--ink-soft); }

.note {
  font-size: .92rem;
  color: var(--muted);
  border-left: 3px solid var(--line);
  padding-left: .85rem;
}

.highlight {
  background: var(--accent-bg);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.15rem;
  margin: 1.5rem 0;
}
.highlight p:last-child { margin-bottom: 0; }

/* ── 地圖區 ────────────────────────────── */
.mapsec { padding-top: 2.25rem; border-bottom: 1px solid var(--line); }

.toolbar {
  display: flex;
  gap: .7rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 1.1rem 0 .9rem;
}

.searchbox { position: relative; flex: 1 1 240px; min-width: 0; }

.searchbox > svg {
  position: absolute;
  left: .72rem; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.searchbox input {
  width: 100%;
  padding: .58rem .8rem .58rem 2.2rem;
  font: inherit;
  font-size: .95rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
}
.searchbox input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

.results {
  position: absolute;
  z-index: 30;
  top: calc(100% + .35rem);
  left: 0; right: 0;
  max-height: 17rem;
  overflow-y: auto;
  margin: 0; padding: .3rem;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.results li {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .38rem .5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: .93rem;
}
.results li:hover, .results li[aria-selected="true"] { background: var(--accent-bg); }
.results img { width: 26px; height: 18px; object-fit: cover; border: 1px solid var(--line); border-radius: 2px; flex: 0 0 auto; }
.results .en { color: var(--muted); font-size: .82rem; }

.zoombtns { display: flex; gap: .35rem; }
.zoombtns button {
  font: inherit;
  font-size: .88rem;
  padding: .5rem .8rem;
  min-width: 2.5rem;
  background: var(--card);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  line-height: 1;
}
.zoombtns button:hover { background: var(--accent-bg); color: var(--accent-dk); border-color: var(--accent); }

.famhint { margin: .3rem 0 .5rem; font-size: .92rem; color: var(--muted); }

.fambar { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.fambar button {
  font: inherit;
  font-size: .87rem;
  padding: .32rem .78rem;
  background: var(--card);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.fambar button:hover { border-color: var(--fam); color: var(--fam); }
.fambar button[aria-pressed="true"] {
  background: var(--fam);
  border-color: var(--fam);
  color: #fff;
  font-weight: 600;
}

.maplayout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.1rem;
  align-items: start;
}

.mapbox {
  position: relative;
  background: var(--ocean);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
}

#map { display: block; width: 100%; height: auto; cursor: grab; }
#map.dragging { cursor: grabbing; }

.land {
  fill: var(--land);
  stroke: var(--ocean);
  stroke-width: .8;
  vector-effect: non-scaling-stroke;
  transition: fill .12s;
}
.land.no { fill: var(--land-dim); }
.land.has { cursor: pointer; }
.land.has:hover { fill: var(--land-hi); }
.land.fam { fill: var(--fam); }
.land.sel { fill: var(--accent); }

/* 看不見的加大點擊區，讓手指也點得到小島國 */
.hit {
  fill: none;
  pointer-events: all;
  cursor: pointer;
}

.dot {
  fill: var(--accent-dk);
  stroke: #fff;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}
.dot:hover { fill: var(--accent); }
.dot.fam { fill: var(--fam); }
.dot.sel { fill: var(--accent); stroke-width: 2.5; }

/* 國名標籤：白色描邊當底，深色地形上也讀得到 */
.labels { pointer-events: none; }

.lbl {
  fill: #4a4335;
  stroke: rgba(255, 255, 255, .9);
  stroke-width: 3px;
  paint-order: stroke fill;
  vector-effect: non-scaling-stroke;   /* 描邊粗細不隨縮放變化 */
  text-anchor: middle;
  dominant-baseline: middle;
  font-weight: 600;
  letter-spacing: .02em;
  user-select: none;
}

.tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: rgba(30,36,48,.93);
  color: #fff;
  font-size: .82rem;
  line-height: 1.4;
  padding: .28rem .6rem;
  border-radius: 6px;
  white-space: nowrap;
  transform: translate(-50%, -140%);
}

/* ── 詳情面板 ──────────────────────────── */
.panel {
  position: sticky;
  top: 3.6rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.panel .empty {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem .5rem;
}
.panel .empty svg { width: 48px; height: 32px; opacity: .5; margin-bottom: .6rem; }
.panel .empty p { margin: 0; }
.panel .empty .hint { font-size: .87rem; margin-top: .3rem; }

.pflag {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: .9rem;
}

.pname { margin: 0 0 .1rem; font-size: 1.28rem; line-height: 1.4; font-weight: 700; }
.pen   { margin: 0 0 .8rem; font-size: .88rem; color: var(--muted); letter-spacing: .02em; }

.pmeta {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin: 0 0 .95rem;
  padding: 0;
  list-style: none;
}
.pmeta li {
  font-size: .8rem;
  padding: .16rem .58rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
}
.pmeta li span { color: var(--muted); }

.pstory { font-size: .95rem; line-height: 1.85; margin: 0; }
.pstory b { color: var(--accent-dk); }

.pfam {
  margin: .95rem 0 0;
  padding-top: .8rem;
  border-top: 1px solid var(--line);
  font-size: .87rem;
  color: var(--muted);
}
.pfam button {
  font: inherit;
  font-size: .84rem;
  padding: .18rem .6rem;
  margin: .2rem .25rem 0 0;
  background: transparent;
  color: var(--fam);
  border: 1px solid var(--fam);
  border-radius: 999px;
  cursor: pointer;
}
.pfam button:hover { background: var(--fam); color: #fff; }

/* ── 旗幟家族 ──────────────────────────── */
.fams {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 1rem;
}

.fam {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
}
.fam h3 { color: var(--accent-dk); margin-bottom: .3rem; }
.fam .from { font-size: .86rem; color: var(--muted); margin-bottom: .7rem; }
.fam p { font-size: .95rem; }
.fam .who {
  font-size: .86rem;
  color: var(--fam);
  line-height: 1.75;
  margin-bottom: 0;
}
.fam .note { margin-top: .8rem; margin-bottom: 0; }

/* ── 設計原則 ──────────────────────────── */
.rules { list-style: none; counter-reset: r; margin: 1.5rem 0; padding: 0; }
.rules > li {
  counter-increment: r;
  position: relative;
  padding-left: 3rem;
  margin-bottom: 1.5rem;
}
.rules > li::before {
  content: counter(r);
  position: absolute;
  left: 0; top: .1em;
  width: 2.1rem; height: 2.1rem;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: .95rem;
  font-weight: 700;
}
.rules h3 { color: var(--accent-dk); }
.rules p:last-child { margin-bottom: 0; }

.callout {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--fam);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.15rem;
}
.callout h3 { color: var(--fam); }
.callout p:last-child { margin-bottom: 0; }

/* ── 表格 ──────────────────────────────── */
.tablewrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  -webkit-overflow-scrolling: touch;
}

table { border-collapse: collapse; width: 100%; min-width: 30rem; font-size: .93rem; }
th, td { padding: .62rem .85rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--bg); font-size: .85rem; color: var(--muted); letter-spacing: .04em; white-space: nowrap; }
tbody th { font-weight: 600; color: var(--accent-dk); white-space: nowrap; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }

/* ── 全部國旗 ──────────────────────────── */
.allgrid { margin-top: 1.2rem; }

.contblock { margin-bottom: 1.8rem; }
.contblock h3 {
  font-size: .88rem;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: .7rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--line);
}

.flags {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: .7rem;
}

.fcard {
  display: block;
  width: 100%;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  text-align: center;
  font: inherit;
  transition: border-color .12s, transform .12s;
}
.fcard:hover { border-color: var(--accent); transform: translateY(-2px); }
/* contain 而非 cover：尼泊爾（非矩形）、瑞士／梵蒂岡（正方形）、
   卡達（11:28）不會被裁切 */
.fcard img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: contain;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.fcard span {
  display: block;
  padding: .32rem .3rem .42rem;
  font-size: .8rem;
  line-height: 1.35;
  color: var(--ink-soft);
}

/* ── 連結清單 ──────────────────────────── */
.links { list-style: none; padding: 0; margin: 0 0 1.2rem; }
.links li { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.links li:last-child { border-bottom: 0; }
.links a { color: var(--accent-dk); font-weight: 600; }
.links p { margin: .15rem 0 0; color: var(--muted); font-size: .9rem; }

/* ── 頁尾 ──────────────────────────────── */
footer {
  padding: 2rem 0 2.5rem;
  color: var(--muted);
  font-size: .9rem;
  text-align: center;
  border-top: 1px solid var(--line);
}
footer p { margin: 0 0 .4rem; }
footer a { color: var(--accent-dk); }
.counter strong { color: var(--accent-dk); font-size: 1.05rem; }

/* ── 響應式 ────────────────────────────── */
@media (max-width: 900px) {
  .maplayout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .hero { padding: 2.75rem 0 2.5rem; }
  section { padding: 2.25rem 0; }
  .flags { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: .55rem; }
  .zoombtns { width: 100%; justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
