@font-face {
  font-family: "CartiCJK";   /* Noto Serif TC Black, sous-ensemble (SIL OFL 1.1) */
  src: url("vendor/fonts/carti-cjk.woff2") format("woff2");
  font-weight: 900;
  font-display: block;
}
:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e2ddd2;
  --accent: #2448a8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --panel: #1d2024;
    --ink: #e8e6e1;
    --muted: #9aa1ab;
    --line: #2e3238;
    --accent: #7ea2ff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 14px/1.4 -apple-system, "Helvetica Neue", "Segoe UI", sans-serif; }
main { display: grid; grid-template-columns: 1fr 300px; height: 100vh; }
#stage { position: relative; display: flex; align-items: center; justify-content: center; padding: 12px; min-width: 0; }
#map { max-width: 100%; max-height: 100%; aspect-ratio: 16 / 9; width: 100%; height: auto;
  background: #fff; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
#panel { background: var(--panel); border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; }
h1 { margin: 0; font-size: 22px; letter-spacing: .02em; }
.sub { margin: 2px 0 14px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.play input { flex: 1; }
#play { width: 40px; height: 32px; font-size: 16px; }
#yearLabel { font-size: 20px; font-variant-numeric: tabular-nums; }
fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 10px 0; padding: 8px 10px; }
legend { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
label { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 4px 0; }
label:has(input[type=checkbox]) { justify-content: flex-start; }
input[type=number] { width: 84px; }
label input[type=range] { width: 110px; min-width: 0; }
select, input, button { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
  border-radius: 4px; padding: 2px 6px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
progress { width: 100%; }
#info { font-size: 12px; color: var(--muted); min-height: 3em; }
.credit { font-size: 11px; color: var(--muted); margin-top: 16px; }
.credit a, .hint a { color: var(--accent); }
@media (max-width: 800px) {
  main { grid-template-columns: 1fr; height: auto; }
  #panel { border-left: 0; border-top: 1px solid var(--line); }
}

#map { cursor: crosshair; }
#tip { position: absolute; pointer-events: none; max-width: 300px; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.18); padding: 8px 10px; font-size: 13px; z-index: 5; }
.it { display: flex; gap: 8px; align-items: flex-start; }
.it + .it { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.emb { width: 28px; height: 28px; flex: none; }
.sw { width: 18px; height: 18px; border-radius: 4px; flex: none; margin: 4px 5px; border: 1px solid rgba(0,0,0,.15); }
.muted { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
#info .it { margin-top: 6px; }
#info a { color: var(--accent); }

/* ------------------------------------------------ téléphone et petits écrans */
#mbar, #rotate, #menuClose { display: none; }
#menuClose { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; font-size: 18px; }
/* téléphone à l'horizontale : carte plein écran, réglages en tiroir */
body.compact main { display: block; height: 100vh; height: 100dvh; }
body.compact #stage { position: fixed; inset: 0; padding: 0; }
body.compact #map { aspect-ratio: auto; width: 100%; height: 100%; max-width: none; max-height: none;
  border-radius: 0; box-shadow: none; }
body.compact #mbar { display: flex; position: fixed; z-index: 10; top: 6px; right: max(8px, env(safe-area-inset-right));
  width: min(56vw, 520px); gap: 6px; align-items: center; padding: 4px 6px; border-radius: 24px;
  background: color-mix(in srgb, var(--panel) 88%, transparent); box-shadow: 0 1px 6px rgba(0,0,0,.2); }
body.compact #mbar button { min-width: 40px; height: 36px; font-size: 17px; border-radius: 18px; }
body.compact #mbar input { flex: 1; min-width: 0; }
body.compact #panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 86vw); z-index: 20;
  transform: translateX(105%); transition: transform .2s ease; box-shadow: -4px 0 18px rgba(0,0,0,.25);
  padding-top: 52px; padding-right: max(16px, env(safe-area-inset-right)); }
body.compact.menu-open #panel { transform: none; }
body.compact #menuClose { display: block; }
body.compact #tip { max-width: 260px; font-size: 12px; }
/* téléphone à la verticale : invitation à tourner l'écran */
#rotate { position: fixed; inset: 0; z-index: 30; background: var(--panel); flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 12px; }
.rot-icon { font-size: 48px; }
#rotate button { padding: 8px 14px; }
body.portrait-phone #rotate:not(.dismissed) { display: flex; }
@media (hover: none) { #map { cursor: default; } }

/* ------------------------------------------------ choix de la langue */
.head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
body.compact .head { padding-right: 44px; }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.lang button { border: 0; border-radius: 0; padding: 4px 10px; font-size: 13px; font-weight: 600; background: var(--panel); color: var(--muted); }
.lang button + button { border-left: 1px solid var(--line); }
.lang button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ------------------------------------------------ zoom, lien, thème */
#map { touch-action: none; }
#mapctl { position: absolute; right: 22px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column;
  gap: 6px; z-index: 6; }
#mapctl button { width: 34px; height: 34px; font-size: 18px; line-height: 1; padding: 0; border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 90%, transparent); box-shadow: 0 1px 4px rgba(0,0,0,.18); }
body.compact #mapctl { right: max(8px, env(safe-area-inset-right)); }
#toast { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 8; background: var(--ink);
  color: var(--panel); padding: 8px 14px; border-radius: 18px; font-size: 13px; max-width: 90%; word-break: break-all; }
.theme-row { margin: 6px 0 2px; }
.theme-row select { flex: 1; }

#exportBox button { margin: 4px 6px 2px 0; }
#map { cursor: grab; }
#map:active { cursor: grabbing; }
#tip .tt, #info .tt { margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
#tip .tt + .tt, #info .tt + .tt { margin-top: -2px; }
#tip .today, #info .today { font-size: 12px; margin: -2px 0 6px; }
