.mg-wrap {
  --mg-ink: #49372f;
  --mg-muted: #6c5148;
  --mg-paper: #fffaf4;
  --mg-sand: #e8dac7;
  --mg-blue: #39c2eb;
  --mg-shadow: 0 5px 0 #e3d2bd;
  max-width: 1120px;
  margin: auto;
  padding: 14px clamp(12px, 3vw, 30px) 36px;
  color: var(--mg-ink);
}
body.mg-page { margin: 0; background: #f9f0e2; }
body.mg-page[data-guide-fonts] {
  --guide-font: "Microsoft JhengHei", "PingFang TC", "Noto Sans CJK TC", system-ui, sans-serif;
}
.mg-wrap *, .mg-wrap *::before, .mg-wrap *::after { box-sizing: border-box; }
.mg-wrap [hidden] { display: none !important; }
.mg-wrap :focus-visible { outline: 3px solid #137a9b; outline-offset: 3px; }
.mg-wrap a { color: #125c76; }
.mg-wrap h1, .mg-wrap h2, .mg-wrap p { margin: 0; }
.mg-wrap h1 { font-size: clamp(1.9rem, 5vw, 3.1rem); line-height: 1.14; }
.mg-wrap h2 { font-size: clamp(1.18rem, 3vw, 1.5rem); }
.mg-breadcrumb { display: flex; gap: .55rem; padding: 10px 0 16px; color: var(--mg-muted); font-size: .9rem; }
.mg-intro, .mg-section {
  padding: clamp(14px, 3vw, 24px);
  margin: 0 0 18px;
  border: 2px solid var(--mg-sand);
  border-radius: 21px;
  background: var(--mg-paper);
  box-shadow: var(--mg-shadow);
}
.mg-intro {
  display: grid;
  gap: 12px;
  justify-items: start;
  background: radial-gradient(ellipse at 93% 3%, #ddf5f6, transparent 62%), var(--mg-paper);
}
.mg-kicker, .mg-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 5px 11px;
  background: #d4f2fb;
  color: #204c60;
  font-size: .86rem;
  font-weight: 700;
}
.mg-section { display: grid; gap: 12px; min-width: 0; }
.mg-heading, .mg-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.mg-heading { justify-content: space-between; }
.mg-wrap label { display: grid; gap: 5px; font-weight: 700; font-size: .94rem; min-width: 0; }
.mg-wrap button, .mg-wrap .mg-button, .mg-wrap input[type="search"], .mg-wrap select {
  min-width: 0;
  min-height: 44px;
  border: 1px solid #c5ac95;
  border-radius: 12px;
  padding: 8px 12px;
  font: inherit;
  color: inherit;
  background: #fff;
}
.mg-wrap button, .mg-wrap .mg-button { cursor: pointer; font-weight: 700; }
.mg-wrap .mg-button, .mg-wrap #mg-play { background: #cbf0fb; border-color: #79bace; color: #154859; text-decoration: none; }
.mg-wrap button[aria-pressed="true"], .mg-wrap button:hover { background: #e6f7f7; }
.mg-wrap button:disabled { cursor: default; opacity: .55; }
.mg-wrap input[type="search"], .mg-wrap select { width: 100%; }
.mg-wrap input[type="range"], .mg-wrap input[type="checkbox"] { accent-color: #147d9e; }
.mg-wrap input[type="checkbox"] { inline-size: 18px; block-size: 18px; margin: 0; }
.mg-wrap .mg-check, .mg-wrap .mg-speed, .mg-wrap .mg-opacity { display: flex; gap: 8px; align-items: center; min-height: 44px; }
.mg-speed select { width: auto; }
.mg-filters { display: grid; grid-template-columns: 1fr 1.45fr 1fr; gap: 12px; }
#mg-field-title { scroll-margin-top: 100px; }
.mg-map-frame button[data-zoom] { min-width: 44px; }
@media (min-width: 840px) {
  .mg-control-deck { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
}
.mg-grid, .mg-results { display: grid; padding: 0; margin: 0; list-style: none; gap: 13px; }
.mg-grid { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }
.mg-map-card {
  display: grid;
  gap: 10px;
  padding: 9px;
  background: #fff;
  border: 1px solid var(--mg-sand);
  border-radius: 15px;
  color: var(--mg-ink);
  text-decoration: none;
  text-align: center;
  transition: transform .18s;
}
.mg-map-card:hover { transform: translateY(-3px); }
.mg-map-card img { width: 100%; height: auto; aspect-ratio: 4/3; object-fit: contain; background: #e2f3f1; border-radius: 9px; }
.mg-wrap .mg-map-caption { margin: 6px 4px 0; font-size: .9rem; }
.mg-footer, .mg-source { font-size: .9rem; color: #6c5148; }
.mg-footer { text-align: center; padding: 18px; border-top: 1px solid #e8dac7; }
.mg-footer a { color: #23576b; }
.mg-footer p { margin: 8px 0 0; }
.mg-notice { background: #f6ecdf; border: 1px dashed #bfa88f; border-radius: 12px; padding: 12px 15px; }
@media (scripting: enabled) {
  /* Keep the reference section below the first viewport until the explorer has mounted. */
  .mg-wrap #mg-load[data-initial] { margin-bottom: 100svh; }
}
.mg-dialog {
  width: min(970px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: clamp(12px, 3vw, 20px);
  border: 2px solid var(--mg-sand);
  border-radius: 20px;
  background: var(--mg-paper);
  color: var(--mg-ink);
  box-shadow: 0 15px 60px #2a211840;
}
.mg-dialog::backdrop { background: #26221ccb; }
.mg-dialog .mg-heading { margin-bottom: 10px; }
.mg-gallery-nav { justify-content: space-between; margin-top: 10px; }
.mg-map-frame { background: #e7f5f3; border: 1px solid #9abbb9; border-radius: 16px; overflow: hidden; }
.mg-map-frame .mg-toolbar { padding: 8px; background: #fffaf4; }
.mg-viewport {
  position: relative;
  min-width: 0;
  height: clamp(265px, 57vw, 600px);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  overscroll-behavior: contain;
  user-select: none;
}
.mg-viewport:active { cursor: grabbing; }
.mg-gallery .mg-viewport { height: min(57dvh, 600px); }
.mg-map-frame:fullscreen, .mg-map-frame.is-fullscreen { display: flex; flex-direction: column; border: 0; border-radius: 0; }
.mg-map-frame.is-fullscreen { position: fixed; z-index: 10001; inset: 0; }
body:has(.mg-map-frame.is-fullscreen) { overflow: hidden; }
.mg-map-frame:fullscreen .mg-viewport, .mg-map-frame.is-fullscreen .mg-viewport { flex: 1; height: auto; }
.mg-plane { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.mg-plane > img, .mg-plane > svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.mg-plane polygon { fill: #008dd9; fill-opacity: var(--mg-opacity, .36); stroke: #075478; stroke-width: 1.7px; vector-effect: non-scaling-stroke; }
.mg-plane polygon.is-highlight { fill: #ffe254; fill-opacity: .56; stroke: #5b3700; stroke-width: 3px; }
.mg-plane polygon.mg-reference-zone { fill: #ffd25b; fill-opacity: .24; stroke: #855500; stroke-width: 2px; stroke-dasharray: 6px 4px; }
.mg-reference-swatch { display: inline-block; width: 24px; height: 13px; vertical-align: -.1em; background: #ffe8a6; border: 2px dashed #855500; border-radius: 4px; }
.mg-region-label { fill: #19374b; stroke: #fffaf4; stroke-width: 3px; paint-order: stroke; stroke-linejoin: round; font-family: var(--guide-font); font-weight: 700; dominant-baseline: central; text-anchor: middle; }
.mg-plane .mg-point { fill: #9355a6; stroke: #fff; stroke-width: 2px; vector-effect: non-scaling-stroke; }
.mg-plane .mg-point.is-highlight { fill: #a04613; stroke: #ffed8a; }
.mg-plane .mg-point-label { fill: white; font-family: var(--guide-font); font-weight: 700; dominant-baseline: central; text-anchor: middle; }
.mg-image-error { position: absolute; z-index: 1; inset: 12px 12px auto; padding: 12px; background: #fffaf4; border-radius: 12px; }
.mg-clock { --mg-night: #535c8e; }
.mg-time-badge { justify-self: start; border-radius: 12px; background: #fff0be; color: #634609; padding: 7px 10px; font-size: clamp(.82rem, 3.8vw, 1rem); font-variant-numeric: tabular-nums; }
.mg-clock[data-night] .mg-time-badge { background: var(--mg-night); color: #fff; }
#mg-time { font-weight: 900; }
.mg-track { position: relative; background: var(--mg-night); border-radius: 12px; isolation: isolate; }
.mg-day-band { position: absolute; z-index: -1; inset: 0 auto 0 var(--mg-day-left, 29.17%); width: var(--mg-day-width, 50%); background: #ffd879; }
.mg-track input { display: block; width: calc(100% - 10px); min-height: 44px; margin: 0 5px; }
.mg-ticks { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 2px; }
.mg-ticks button { font-size: .82rem; padding: 4px; background: transparent; border-color: transparent; }
.mg-strip { display: flex; gap: 10px; overflow-x: auto; padding: 4px 4px 10px; scroll-snap-type: x proximity; min-width: 0; }
.mg-strip:empty { display: none; }
.mg-wrap .mg-chip {
  flex: 0 0 126px;
  min-height: 112px;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 5px;
  scroll-snap-align: start;
  overflow-wrap: anywhere;
  text-align: center;
}
.mg-portrait { width: 46px; height: 46px; display: grid; place-items: center; overflow: hidden; border-radius: 12px; background: var(--mg-grade, #ede7df); }
.mg-portrait img { width: 42px; height: 42px; object-fit: contain; }
.mg-portrait span { font-size: .82rem; }
.mg-grade-1 { --mg-grade: #e4e0c5; }
.mg-grade-2 { --mg-grade: #a3e467; }
.mg-grade-3 { --mg-grade: #59c6d9; }
.mg-grade-4 { --mg-grade: #e793e8; }
.mg-grade-5 { --mg-grade: linear-gradient(135deg, #88f5ff, #f492ff); }
.mg-chip small, .mg-result small { color: var(--mg-muted); font-weight: 500; }
.mg-results { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.mg-result { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; border: 1px solid var(--mg-sand); background: #fff; border-radius: 12px; padding: 9px; }
.mg-result > span:nth-child(2) { flex: 1 1 120px; min-width: 0; overflow-wrap: anywhere; }
.mg-result small { display: block; }
.mg-result a { display: inline-flex; align-items: center; min-height: 44px; padding-inline: 5px; }
.mg-result[data-selected] { border-color: #39798d; box-shadow: inset 0 0 0 1px #39798d; }
.mg-sheet { width: min(680px, calc(100% - 24px)); }
#mg-inspector-body { display: grid; gap: 9px; }
.mg-area-picker { text-align: left; }
.mg-reference a { margin-inline: .15em; }
.mg-reference h3 { margin: 12px 0 4px; }
.mg-reference [id^="map-"], #habitat-reference, #habitat-source, #mg-catalog > li { scroll-margin-top: 6rem; }
.mg-habitat summary { cursor: pointer; font-weight: 700; padding-block: 8px; }
.mg-habitat ul { padding-inline-start: 1.5em; margin-block: 4px 12px; }
.mg-habitat li + li { margin-top: 6px; }
.mg-sr { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 600px) {
  .mg-filters { grid-template-columns: 1fr; }
  .mg-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .mg-sheet { position: fixed; inset: auto 0 0; width: 100%; max-width: none; max-height: 80dvh; margin: 0; border-radius: 20px 20px 0 0; }
}
@media (prefers-reduced-motion: reduce) { .mg-wrap *, .mg-wrap *::before, .mg-wrap *::after { transition: none !important; animation: none !important; } }
.motion-off .mg-wrap * { transition: none !important; animation: none !important; }
