:root {
  --ink: #1c1510;
  --panel: rgba(246, 230, 194, 0.88);
  --panel-strong: rgba(238, 216, 176, 0.95);
  --line: rgba(116, 36, 28, 0.32);
  --gold: #b7823f;
  --paper: #f4e3bd;
  --muted: rgba(53, 40, 28, 0.72);
  --jade: #4f7f66;
  --vermillion: #9a2d23;
  --blood: #681b16;
  --indigo: #405c72;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #d4bb8e;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(244, 227, 188, 0.34), rgba(246, 231, 196, 0.58) 42%, rgba(96, 38, 29, 0.22)),
    url("assets/ink-wash-backdrop.png") center / cover no-repeat;
  transform: scale(1.02);
  z-index: -3;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 84% 18%, rgba(118, 26, 20, 0.22), transparent 24%),
    radial-gradient(circle at 14% 84%, rgba(32, 22, 15, 0.2), transparent 30%),
    linear-gradient(180deg, rgba(255, 246, 219, 0.18), transparent 46%, rgba(42, 22, 14, 0.28));
  z-index: -2;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  grid-template-rows: 1fr;
  gap: 14px;
  height: calc(100vh - 136px);
  padding: 14px 14px 12px;
}

.map-stage,
.intel-panel > section,
.timeline-dock {
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(62, 35, 20, 0.26);
}

.map-stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: rgba(64, 43, 28, 0.22);
}

.topbar {
  position: absolute;
  z-index: 500;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 12px;
  pointer-events: none;
}

.brand-lockup,
.year-badge {
  display: flex;
  align-items: center;
  border: 1px solid rgba(128, 42, 32, 0.42);
  background: rgba(27, 20, 14, 0.84);
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 32px rgba(55, 28, 16, 0.22);
}

.brand-lockup {
  gap: 12px;
  max-width: min(560px, calc(100vw - 180px));
  padding: 10px 14px 10px 10px;
  border-radius: var(--radius);
}

.seal {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  font-family: "Spectral", serif;
  font-size: 24px;
  font-weight: 700;
  background: radial-gradient(circle at 34% 28%, #b93a2e, #701d17 68%, #3e0f0c);
  border-radius: 50%;
  color: #f6dfad;
  box-shadow: inset 0 0 0 1px rgba(255, 229, 174, 0.28), 0 0 0 2px rgba(180, 127, 62, 0.14);
}

.brand-lockup p,
.brand-lockup h1 {
  margin: 0;
}

.brand-lockup p {
  color: rgba(244, 227, 188, 0.72);
  font-size: 0.76rem;
  font-weight: 600;
}

.brand-lockup h1 {
  color: #fff0c2;
  font-family: "Noto Sans Thai", sans-serif;
  font-size: clamp(0.85rem, 1.6vw, 1.15rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.host-avatar {
  flex: 0 0 auto;
  width: 140px;
  height: 140px;
  object-fit: contain;
  object-position: top;
  margin-top: -20px;
  pointer-events: auto;
  cursor: pointer;
  transition: opacity 0.15s;
}

.host-avatar:hover { opacity: 0.85; }

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  pointer-events: none;
}

.map-toggle-btn {
  flex: 0 0 auto;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 9px 13px;
  border: 1px solid rgba(128, 42, 32, 0.42);
  border-radius: 999px;
  background: rgba(27, 20, 14, 0.72);
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 32px rgba(55, 28, 16, 0.22);
  color: rgba(244, 227, 188, 0.78);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.map-toggle-btn:hover {
  background: rgba(27, 20, 14, 0.9);
  color: #f8e6bd;
}

.map-toggle-btn.is-active {
  background: rgba(72, 38, 12, 0.92);
  border-color: rgba(183, 130, 63, 0.72);
  color: #f8e6bd;
}

.map-toggle-btn svg {
  width: 15px;
  height: 15px;
  color: var(--gold);
}

.music-toggle-btn.is-active svg {
  animation: music-pulse 1.8s ease-in-out infinite;
}

.autoplay-control {
  position: absolute;
  bottom: 10px;
  left: 58px;
  z-index: 800;
  pointer-events: none;
}

.autoplay-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid rgba(128, 42, 32, 0.42);
  border-radius: var(--radius);
  background: rgba(27, 20, 14, 0.84);
  backdrop-filter: blur(14px);
  color: rgba(244, 227, 188, 0.88);
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  pointer-events: auto;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}

.autoplay-btn #autoplayIconPlay,
.autoplay-btn #autoplayIconStop {
  display: flex;
  align-items: center;
  line-height: 0;
}

.autoplay-btn svg {
  width: 15px;
  height: 15px;
  color: rgba(244, 227, 188, 0.72);
  flex: 0 0 auto;
}

.autoplay-btn:hover {
  background: rgba(50, 30, 18, 0.92);
  border-color: rgba(183, 130, 63, 0.55);
}

.autoplay-btn.is-active {
  background: rgba(108, 29, 23, 0.82);
  border-color: rgba(183, 130, 63, 0.7);
}

.autoplay-btn.is-active svg {
  color: #f8c96a;
  animation: music-pulse 2s ease-in-out infinite;
}

@keyframes music-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.88); }
}

.year-badge {
  flex: 0 0 auto;
  margin-left: auto;
  gap: 8px;
  height: 44px;
  padding: 0 13px;
  border-radius: 999px;
  color: #f8e6bd;
  background: rgba(108, 29, 23, 0.9);
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}

.city-marker {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.city-marker-inner {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
}

.city-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  margin-top: 3px;
  background: radial-gradient(circle at 35% 30%, #d04428, #8b1a14);
  border: 1px solid rgba(255, 210, 140, 0.8);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(180, 50, 20, 0.65);
}

.city-label-text {
  white-space: nowrap;
  line-height: 1.25;
  font-family: "Noto Sans Thai", system-ui, sans-serif;
}

.city-name-th {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #1e0e05;
  text-shadow:
    0 0 4px rgba(244, 220, 170, 1),
    1px 1px 0 rgba(244, 220, 170, 0.9),
    -1px -1px 0 rgba(244, 220, 170, 0.9);
}

.city-name-zh {
  display: block;
  font-size: 9px;
  font-weight: 600;
  color: rgba(42, 20, 8, 0.6);
  text-shadow: 0 0 3px rgba(244, 220, 170, 0.9);
}

.city-tooltip {
  background: rgba(246, 230, 194, 0.95);
  border: 1px solid rgba(116, 36, 28, 0.36);
  border-radius: 6px;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(62, 35, 20, 0.2);
  padding: 4px 8px;
}

/* ── Event battle icons ─────────────────────────────── */
.event-icon-marker {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.event-icon-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  pointer-events: none;
}

.event-icon-glyph {
  width: 30px;
  height: 30px;
  background: radial-gradient(circle at 40% 35%, rgba(200, 50, 30, 0.92), rgba(120, 20, 10, 0.9));
  border: 1.5px solid rgba(255, 195, 60, 0.72);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  box-shadow: 0 0 0 0 rgba(200, 50, 30, 0.5);
  animation: event-icon-pulse 2s ease-out infinite;
}

.event-icon-glyph.move-glyph {
  background: radial-gradient(circle at 40% 35%, rgba(90, 40, 130, 0.92), rgba(45, 15, 70, 0.9));
  border-color: rgba(200, 160, 255, 0.7);
}

.event-icon-glyph.emperor-glyph {
  background: radial-gradient(circle at 40% 35%, rgba(200, 155, 20, 0.95), rgba(130, 90, 5, 0.92));
  border-color: rgba(255, 220, 80, 0.85);
  box-shadow: 0 0 0 0 rgba(200, 155, 20, 0.5);
  animation: emperor-icon-pulse 2s ease-out infinite;
}

@keyframes emperor-icon-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(200, 155, 20, 0.6); }
  60%  { box-shadow: 0 0 0 10px rgba(200, 155, 20, 0); }
  100% { box-shadow: 0 0 0 0   rgba(200, 155, 20, 0); }
}

.event-icon-glyph.fire-glyph {
  background: radial-gradient(circle at 40% 35%, rgba(240, 110, 15, 0.95), rgba(170, 55, 5, 0.92));
  border-color: rgba(255, 175, 40, 0.85);
  box-shadow: 0 0 0 0 rgba(240, 110, 15, 0.5);
  animation: fire-icon-pulse 1.4s ease-out infinite;
}

@keyframes fire-icon-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(240, 110, 15, 0.7); }
  60%  { box-shadow: 0 0 0 13px rgba(240, 110, 15, 0); }
  100% { box-shadow: 0 0 0 0   rgba(240, 110, 15, 0); }
}

.event-icon-glyph.strategy-glyph {
  background: radial-gradient(circle at 40% 35%, rgba(55, 80, 185, 0.95), rgba(25, 40, 120, 0.92));
  border-color: rgba(120, 155, 255, 0.85);
  box-shadow: 0 0 0 0 rgba(55, 80, 185, 0.5);
  animation: strategy-icon-pulse 2.5s ease-out infinite;
}

@keyframes strategy-icon-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(55, 80, 185, 0.6); }
  60%  { box-shadow: 0 0 0 10px rgba(55, 80, 185, 0); }
  100% { box-shadow: 0 0 0 0   rgba(55, 80, 185, 0); }
}

.event-icon-label-text {
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 210, 80, 0.97);
  font-family: "Noto Sans Thai", system-ui, sans-serif;
  text-shadow: 0 1px 3px rgba(0,0,0,0.95), 0 0 6px rgba(0,0,0,0.8);
  white-space: nowrap;
}

@keyframes event-icon-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(200, 50, 30, 0.55); }
  60%  { box-shadow: 0 0 0 10px rgba(200, 50, 30, 0); }
  100% { box-shadow: 0 0 0 0   rgba(200, 50, 30, 0); }
}

.event-icon-glyph.warlord-glyph {
  background: radial-gradient(circle at 40% 35%, rgba(100, 20, 15, 0.95), rgba(55, 8, 5, 0.92));
  border-color: rgba(200, 80, 50, 0.75);
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 190, 140, 0.95);
  animation: event-icon-pulse 2s ease-out infinite;
}

@keyframes icon-shake {
  0%,100% { transform: translate(0,0) rotate(0deg); }
  12%     { transform: translate(-3px,-1px) rotate(-2deg); }
  25%     { transform: translate(3px,1px) rotate(2deg); }
  37%     { transform: translate(-2px,2px) rotate(-1deg); }
  50%     { transform: translate(3px,-1px) rotate(2deg); }
  62%     { transform: translate(-2px,0px) rotate(-1deg); }
  75%     { transform: translate(2px,1px) rotate(1deg); }
  87%     { transform: translate(-1px,-1px) rotate(-1deg); }
}

.event-icon-shake .event-icon-inner {
  animation: icon-shake 0.42s ease-in-out 4;
}

@keyframes icon-dissolve {
  0%   { opacity: 1; transform: scale(1); filter: brightness(1); }
  40%  { opacity: 0.6; transform: scale(1.2); filter: brightness(2) saturate(0); }
  100% { opacity: 0; transform: scale(0.2); filter: brightness(0); }
}

.event-icon-dissolve .event-icon-inner {
  animation: icon-dissolve 1.2s ease-out forwards;
}

.year-badge svg {
  width: 18px;
  height: 18px;
  color: var(--gold);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  min-height: 480px;
  background: #efe1bf;
}

.leaflet-container {
  font-family: "Noto Sans Thai", system-ui, sans-serif;
  background: #efe1bf;
}

.leaflet-control-zoom a {
  color: var(--ink);
  background: rgba(249, 234, 201, 0.92);
  border-color: rgba(116, 36, 28, 0.28);
}

.leaflet-control-attribution {
  max-width: min(70vw, 760px);
  color: rgba(42, 31, 21, 0.72);
  background: rgba(246, 230, 194, 0.78);
}

.province-label {
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.05;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  background: transparent;
  border: none;
  box-shadow: none;
  pointer-events: none;
}

.province-label::before {
  display: none;
}

.map-sheen {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(247, 229, 190, 0.08), transparent 26%),
    radial-gradient(circle at 50% 46%, transparent 0 48%, rgba(58, 29, 18, 0.16) 100%);
  mix-blend-mode: multiply;
  opacity: 0.75;
}

.map-loading,
.map-error {
  position: absolute;
  z-index: 510;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  padding: 10px 14px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(246, 230, 194, 0.9);
  backdrop-filter: blur(12px);
}

.map-error {
  bottom: 22px;
  color: var(--blood);
}

.intel-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.timeline-handle {
  display: none;
}

.intel-panel > section,
.timeline-dock {
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 8% 0%, rgba(150, 45, 35, 0.08), transparent 32%),
    linear-gradient(180deg, var(--panel), rgba(232, 206, 162, 0.9));
  backdrop-filter: blur(18px);
}

.event-card {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: auto;
  padding: 20px;
}

.event-kicker {
  width: fit-content;
  margin-bottom: 11px;
  padding: 5px 9px;
  color: #f7e6bd;
  font-size: 0.78rem;
  font-weight: 800;
  background: linear-gradient(135deg, #9e2f25, #661a15);
  border: 1px solid rgba(255, 223, 164, 0.24);
  border-radius: 999px;
}

.event-card h2 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: clamp(1.28rem, 2.4vw, 2.2rem);
  line-height: 1.15;
  letter-spacing: 0;
}

.event-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.97rem;
  line-height: 1.72;
}

.event-points {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.event-points li {
  position: relative;
  padding-left: 18px;
  color: rgba(37, 27, 19, 0.88);
  font-size: 0.9rem;
  line-height: 1.52;
}

.event-points li::before {
  content: "";
  position: absolute;
  top: 0.68em;
  left: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: none;
}

.legend-panel {
  padding: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.section-title svg {
  width: 18px;
  height: 18px;
  color: var(--gold);
}

.section-title h2 {
  margin: 0;
  color: var(--ink);
  font-size: 0.96rem;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 10px;
}

.legend-item {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  color: rgba(38, 28, 20, 0.84);
  font-size: 0.84rem;
  font-weight: 700;
}

.legend-item span {
  display: block;
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  border: 1px solid rgba(31, 21, 14, 0.34);
  border-radius: 3px;
  background: var(--swatch);
  box-shadow: 0 0 18px color-mix(in srgb, var(--swatch), transparent 28%);
}

.legend-swatch-pulse {
  background: transparent !important;
  border-color: #D01010 !important;
  box-shadow: none !important;
  animation: legend-jing-pulse 1.4s ease-in-out infinite;
}

@keyframes legend-jing-pulse {
  0%, 100% { border-color: rgba(208, 16, 16, 0.22) !important; border-width: 1px; }
  50% { border-color: #D01010 !important; border-width: 2.5px; box-shadow: 0 0 6px rgba(208,16,16,0.5) !important; }
}

.timeline-dock {
  position: fixed;
  right: 14px;
  bottom: 14px;
  left: 14px;
  z-index: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 14px;
  background:
    radial-gradient(circle at 88% 10%, rgba(116, 28, 22, 0.1), transparent 28%),
    linear-gradient(180deg, rgba(248, 235, 204, 0.96), var(--panel-strong));
}

.timeline-nav-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(116, 36, 28, 0.28);
  border-radius: var(--radius);
  background: rgba(255, 247, 222, 0.6);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.timeline-nav-btn:hover {
  background: rgba(255, 241, 207, 0.9);
  border-color: rgba(116, 36, 28, 0.44);
}

.timeline-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.scroll-fade-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
}

.scroll-fade-wrap::before,
.scroll-fade-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 52px;
  z-index: 10;
  pointer-events: none;
}

.scroll-fade-wrap::before {
  left: 0;
  background: linear-gradient(to right, rgba(248,235,204,1) 0%, transparent 100%);
  transition: opacity 200ms ease;
}

.scroll-fade-wrap::after {
  right: 0;
  background: linear-gradient(to left, rgba(238,216,176,1) 0%, transparent 100%);
  transition: opacity 200ms ease;
}

.scroll-fade-wrap.no-fade-left::before,
.scroll-fade-wrap.no-fade-right::after {
  opacity: 0;
}

.event-scroll-wrapper {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.event-scroll-wrapper::-webkit-scrollbar {
  display: none;
}

.event-button-grid {
  display: flex;
  gap: 8px;
  padding: 3px 2px;
}

.event-button {
  display: grid;
  align-content: center;
  gap: 2px;
  flex: 0 0 150px;
  min-height: 54px;
  padding: 9px;
  color: var(--ink);
  text-align: left;
  border: 1px solid rgba(116, 36, 28, 0.22);
  border-radius: var(--radius);
  background: rgba(255, 247, 222, 0.5);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.event-button:hover {
  transform: translateY(-1px);
  border-color: rgba(116, 36, 28, 0.44);
  background: rgba(255, 241, 207, 0.86);
}

.event-button:focus-visible {
  outline: 2px solid #8f251f;
  outline-offset: 2px;
}

.event-button.is-active {
  color: #f7e6bd;
  border-color: rgba(255, 226, 168, 0.58);
  background: linear-gradient(135deg, #9e2f25, #661a15 72%);
  box-shadow: 0 0 24px rgba(104, 27, 22, 0.26);
}

.event-button-year,
.event-button-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-button-year {
  color: var(--vermillion);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
}

.event-button.is-active .event-button-year {
  color: rgba(247, 230, 189, 0.78);
}

.event-button-name {
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.25;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 330px;
  }

  .legend-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Tablet ≤860px ── */
@media (max-width: 860px) {
  .leaflet-control-attribution {
    font-size: 9px;
    line-height: 1.2;
  }

  body {
    overflow: auto;
    padding-bottom: 28px;
  }

  .app-shell {
    display: block;
    height: auto;
    padding: 10px 10px 0;
  }

  .map-stage {
    height: 58vh;
    min-height: 380px;
  }

  #map {
    min-height: 0;
  }

  .topbar {
    align-items: stretch;
    left: 10px;
    right: 10px;
  }

  .brand-lockup {
    max-width: calc(100vw - 106px);
    padding-right: 10px;
  }

  .brand-lockup h1 {
    font-size: 1rem;
  }

  .brand-lockup p {
    font-size: 0.68rem;
  }

  .seal {
    width: 36px;
    height: 36px;
    font-size: 21px;
  }

  .year-badge {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 13px;
  }

  /* Intel panel: event card left, legend right */
  .intel-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    grid-template-rows: auto;
    gap: 10px;
    margin-top: 10px;
  }

  .event-card {
    padding: 16px;
    max-height: none;
    overflow: visible;
  }

  /* Timeline: bottom sheet */
  .timeline-dock {
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 12px 12px 0 0;
    padding: 0 8px 12px;
    gap: 4px;
    flex-direction: column;
    align-items: stretch;
    transform: translateY(calc(100% - 28px));
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }

  .timeline-dock.is-expanded {
    transform: translateY(0);
  }

  .timeline-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    flex-shrink: 0;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .timeline-handle::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(128, 42, 32, 0.35);
    transition: width 0.2s ease, background 0.2s ease;
  }

  .timeline-dock.is-expanded .timeline-handle::before {
    width: 44px;
    background: rgba(128, 42, 32, 0.6);
  }

  .event-scroll-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .event-button-grid {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .event-button {
    flex: 0 0 auto;
    min-height: 52px;
    min-width: 100px;
  }

  .timeline-nav-btn {
    display: none;
  }
}

/* ── Mobile ≤600px ── */
@media (max-width: 600px) {
  body {
    padding-bottom: 28px;
  }

  .app-shell {
    padding: 8px 8px 0;
  }

  .map-stage {
    height: 52vh;
    min-height: 300px;
  }

  .topbar {
    left: 8px;
    right: 8px;
    gap: 6px;
    align-items: flex-start;
  }

  .host-avatar,
  .topbar-controls,
  .year-badge {
    align-self: flex-start;
  }

  .brand-lockup {
    max-width: calc(100vw - 86px);
    min-width: 112px;
    gap: 6px;
    padding: 8px 10px 8px 8px;
  }

  .brand-lockup h1 {
    font-size: 0.8rem;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    max-width: 100%;
    overflow-wrap: normal;
    word-break: normal;
  }

  .brand-lockup p {
    display: none;
  }

  .host-avatar {
    width: 105px;
    height: 105px;
    margin-top: -14px;
  }

  .year-badge {
    font-size: 13px;
    padding: 0 9px;
    height: 44px;
  }

  .year-badge svg {
    display: none;
  }

  .topbar-controls {
    gap: 5px;
  }

  .map-toggle-btn span {
    display: none;
  }

  .map-toggle-btn {
    width: 40px;
    height: 40px;
    min-height: unset;
    padding: 0;
    justify-content: center;
  }

  /* Single column on phone */
  .intel-panel {
    grid-template-columns: 1fr;
  }

  .event-card {
    max-height: none;
    overflow: visible;
  }

  .event-card h2 {
    font-size: 1.1rem;
  }

  .event-card p,
  .event-points li {
    font-size: 0.85rem;
  }

  .legend-grid {
    grid-template-columns: 1fr 1fr;
  }

  .event-button {
    min-width: 84px;
    min-height: 48px;
  }
}

/* Great Wall tower markers */
.wall-tower-emoji {
  font-size: 13px;
  line-height: 1;
  pointer-events: none;
  background: none !important;
  border: none !important;
}

/* River callout chips (option 2: pill + leader line) */
.river-label {
  background: rgba(12, 8, 2, 0.76) !important;
  border: 1.5px solid;
  border-radius: 999px !important;
  box-shadow: none !important;
  padding: 2px 10px !important;
  font-family: "Noto Sans Thai", system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: 0.03em;
  backdrop-filter: blur(3px);
}
.river-label--yellow { border-color: rgba(200, 152, 26, 0.65); }
.river-label--blue   { border-color: rgba(58, 122, 184, 0.65); }

/* Leader line — replaces Leaflet's triangle tip */
.river-label::before {
  border: none !important;
  width: 1px !important;
  height: 18px !important;
  bottom: 0 !important;
  margin-bottom: -18px !important;
  left: 50% !important;
  margin-left: -0.5px !important;
  display: block !important;
}
.river-label--yellow::before { background: rgba(200, 152, 26, 0.6) !important; }
.river-label--blue::before   { background: rgba(58, 122, 184, 0.6) !important; }

/* Geographic feature tooltips */
.geo-tooltip {
  background: rgba(20, 14, 8, 0.82);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(183, 130, 63, 0.38);
  border-radius: 6px;
  color: rgba(244, 227, 188, 0.88);
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}
.geo-tooltip::before {
  display: none;
}

/* Ruler portrait markers */
.ruler-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 60px;
  pointer-events: none;
  overflow: visible;
}

.ruler-face {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2.5px solid var(--kc, #888888);
  background: rgba(20, 14, 8, 0.90);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 229, 170, 0.14);
  overflow: visible;
  pointer-events: auto;
  cursor: default;
  z-index: 1;
}

/* Portrait — base (no positioning, set per direction) */
.ruler-portrait {
  position: absolute;
  width: 90px;
  height: 112px;
  object-fit: cover;
  object-position: top center;
  border-radius: 8px;
  border: 2.5px solid var(--kc, #888);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.80), 0 0 0 1px rgba(255, 229, 170, 0.18);
  opacity: 0;
  pointer-events: none;
  z-index: 900;
  transition: opacity 0.18s ease, transform 0.24s cubic-bezier(0.34, 1.4, 0.64, 1);
}

/* North — portrait above, unfolds upward */
.ruler-face[data-dir="n"] .ruler-portrait {
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) scaleY(0);
  transform-origin: bottom center;
}
.ruler-face[data-dir="n"]:hover .ruler-portrait {
  opacity: 1;
  transform: translateX(-50%) scaleY(1);
}

/* South — portrait below, unfolds downward */
.ruler-face[data-dir="s"] .ruler-portrait {
  top: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) scaleY(0);
  transform-origin: top center;
}
.ruler-face[data-dir="s"]:hover .ruler-portrait {
  opacity: 1;
  transform: translateX(-50%) scaleY(1);
}

/* East — portrait right, unfolds rightward */
.ruler-face[data-dir="e"] .ruler-portrait {
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) scaleX(0);
  transform-origin: left center;
}
.ruler-face[data-dir="e"]:hover .ruler-portrait {
  opacity: 1;
  transform: translateY(-50%) scaleX(1);
}

/* West — portrait left, unfolds leftward */
.ruler-face[data-dir="w"] .ruler-portrait {
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) scaleX(0);
  transform-origin: right center;
}
.ruler-face[data-dir="w"]:hover .ruler-portrait {
  opacity: 1;
  transform: translateY(-50%) scaleX(1);
}

/* Connecting line (::after) — base */
.ruler-face::after {
  content: '';
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
  z-index: 899;
}
.ruler-face:hover::after {
  opacity: 1;
}

/* North line: vertical up */
.ruler-face[data-dir="n"]::after {
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 12px;
  background: linear-gradient(to top, rgba(255, 229, 170, 0.9), rgba(255, 229, 170, 0.2));
}

/* South line: vertical down */
.ruler-face[data-dir="s"]::after {
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 12px;
  background: linear-gradient(to bottom, rgba(255, 229, 170, 0.9), rgba(255, 229, 170, 0.2));
}

/* East line: horizontal right */
.ruler-face[data-dir="e"]::after {
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  width: 12px;
  height: 2px;
  background: linear-gradient(to right, rgba(255, 229, 170, 0.9), rgba(255, 229, 170, 0.2));
}

/* West line: horizontal left */
.ruler-face[data-dir="w"]::after {
  top: 50%;
  right: 100%;
  transform: translateY(-50%);
  width: 12px;
  height: 2px;
  background: linear-gradient(to left, rgba(255, 229, 170, 0.9), rgba(255, 229, 170, 0.2));
}

/* Touch devices: portrait-open class replaces :hover */
@media (hover: none) {
  .ruler-face.portrait-open .ruler-portrait { opacity: 1; }
  .ruler-face.portrait-open::after { opacity: 1; }

  .ruler-face[data-dir="n"].portrait-open .ruler-portrait { transform: translateX(-50%) scaleY(1); }
  .ruler-face[data-dir="s"].portrait-open .ruler-portrait { transform: translateX(-50%) scaleY(1); }
  .ruler-face[data-dir="e"].portrait-open .ruler-portrait { transform: translateY(-50%) scaleX(1); }
  .ruler-face[data-dir="w"].portrait-open .ruler-portrait { transform: translateY(-50%) scaleX(1); }
}

.ruler-zh {
  font-family: "Spectral", serif;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--kc, #cccccc);
  letter-spacing: -0.5px;
  line-height: 1;
}

.ruler-caption {
  margin-top: 3px;
  background: rgba(20, 14, 8, 0.82);
  border: 1px solid rgba(183, 130, 63, 0.28);
  border-radius: 4px;
  padding: 2px 6px;
  max-width: 76px;
  text-align: center;
}

.ruler-name-th {
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(244, 227, 188, 0.92);
  white-space: nowrap;
  display: block;
}

/* ─── Loading Screen ─── */

@keyframes ls-breathe {
  0%, 100% { text-shadow: 0 0 24px rgba(183,130,63,0.45), 0 0 64px rgba(183,130,63,0.15); }
  50%       { text-shadow: 0 0 40px rgba(183,130,63,0.80), 0 0 100px rgba(183,130,63,0.30); }
}

@keyframes ls-shimmer {
  0%   { left: -40%; }
  100% { left: 120%; }
}

@keyframes ls-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0c0906;
  transition: opacity 0.9s ease;
}

#loading-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("assets/ink-wash-backdrop.png") center / cover no-repeat;
  opacity: 0.12;
  pointer-events: none;
}

#loading-screen.ls-out {
  opacity: 0;
  pointer-events: none;
}

.ls-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: ls-fade-in 0.6s ease both;
}

.ls-panel {
  position: relative;
  padding: 52px 72px 44px;
  border: 1px solid rgba(183,130,63,0.38);
  background: rgba(14,10,6,0.90);
  backdrop-filter: blur(20px);
  text-align: center;
  min-width: 360px;
}

/* Corner brackets */
.ls-corner {
  position: absolute;
  width: 18px;
  height: 18px;
}
.ls-corner::before,
.ls-corner::after {
  content: "";
  position: absolute;
  background: var(--gold);
  opacity: 0.7;
}
.ls-corner::before { width: 100%; height: 1px; top: 0; left: 0; }
.ls-corner::after  { width: 1px; height: 100%; top: 0; left: 0; }
.ls-tl { top: 10px; left: 10px; }
.ls-tr { top: 10px; right: 10px; transform: scaleX(-1); }
.ls-bl { bottom: 10px; left: 10px; transform: scaleY(-1); }
.ls-br { bottom: 10px; right: 10px; transform: scale(-1); }

.ls-en {
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: rgba(244,227,188,0.92);
  letter-spacing: 0.01em;
  margin: 0 0 20px;
}

.ls-rule {
  width: 80px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--vermillion) 40%, var(--vermillion) 60%, transparent);
  margin: 0 auto 28px;
}

.ls-bar-wrap {
  width: 100%;
  height: 3px;
  background: rgba(255,255,255,0.07);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 12px;
  position: relative;
}

.ls-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6e1a15, var(--vermillion) 50%, var(--gold));
  border-radius: 2px;
  transition: width 0.25s ease;
  position: relative;
  overflow: hidden;
}

.ls-bar::after {
  content: "";
  position: absolute;
  top: 0;
  left: -40%;
  width: 35%;
  height: 100%;
  background: rgba(255,255,255,0.45);
  filter: blur(3px);
  animation: ls-shimmer 1.4s ease-in-out infinite;
}

.ls-pct {
  font-family: "Spectral", serif;
  font-size: 12px;
  color: rgba(183,130,63,0.55);
  letter-spacing: 0.06em;
}

/* ── Muze badge + contact card ── */
.muze-badge {
  flex: 0 0 auto;
  margin-left: auto;
  align-self: center;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  gap: 5px;
  padding: 6px 14px;
  background: rgba(248, 240, 218, 0.88);
  border: 1px solid rgba(128, 42, 32, 0.22);
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #3a1a0a;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1200;
  transition: background 0.2s, box-shadow 0.2s, transform 0.15s;
  user-select: none;
}
.muze-badge:hover {
  background: rgba(248, 240, 218, 1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}
.muze-badge:focus-visible {
  outline: 2px solid rgba(128, 42, 32, 0.5);
  outline-offset: 3px;
}
.muze-badge-icon { font-size: 0.8rem; line-height: 1; }
.muze-badge-text { text-align: center; line-height: 1.35; white-space: nowrap; }
.muze-badge-text br { display: none; }

.muze-card {
  position: fixed;
  top: 100px;
  right: auto;
  width: auto;
  white-space: nowrap;
  background: rgba(248, 240, 218, 0.97);
  border: 1px solid rgba(128, 42, 32, 0.18);
  border-radius: 14px;
  padding: 18px 18px 16px;
  box-shadow: 0 8px 36px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 1201;
  font-size: 0.8rem;
  color: #3a1a0a;
  line-height: 1.6;
  animation: muzeCardIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.muze-card[hidden] { display: none; }
.muze-card br { display: none; }
@keyframes muzeCardIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.muze-card h3 {
  margin: 0 0 8px;
  font-size: 0.88rem;
  font-weight: 700;
  color: #5a1a0a;
}
.muze-card p {
  margin: 16px 0 8px;
  opacity: 0.82;
}
.muze-card p:last-of-type { margin-bottom: 12px; }
.muze-card-cta {
  display: inline-block;
  padding: 7px 16px;
  background: rgba(128, 42, 32, 0.85);
  color: #f5ead0;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s;
}
.muze-card-cta:hover { background: rgba(128, 42, 32, 1); }
.muze-card-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 0.8rem;
  color: rgba(58, 26, 10, 0.4);
  cursor: pointer;
  padding: 2px 5px;
  line-height: 1;
  transition: color 0.15s;
}
.muze-card-close:hover { color: rgba(58, 26, 10, 0.85); }


@media (max-width: 860px) {
  .muze-badge {
    min-height: 38px;
    align-self: stretch;
    font-size: 13px;
  }
  .muze-badge-text { white-space: normal; }
  .muze-badge-text br { display: inline; }
  .muze-card {
    top: 62px;
    left: 20px;
    right: auto;
    width: 250px;
    white-space: normal;
  }
  .muze-card br { display: block; }
}

/* ─── CTA Button ─── */
.map-cta-btn {
  position: absolute;
  bottom: 26px;
  right: 18px;
  z-index: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid rgba(183, 130, 63, 0.65);
  background: linear-gradient(135deg, var(--vermillion), var(--blood));
  color: #f8e6bd;
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
  box-shadow: 0 4px 20px rgba(104, 27, 22, 0.5), inset 0 1px 0 rgba(255, 220, 140, 0.12);
  backdrop-filter: blur(8px);
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 200ms cubic-bezier(0.4, 0, 0.2, 1),
              border-color 200ms;
  opacity: 0.92;
}
.map-cta-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(183, 130, 63, 0.9);
  box-shadow: 0 8px 28px rgba(104, 27, 22, 0.6), 0 0 0 4px rgba(183, 130, 63, 0.15), inset 0 1px 0 rgba(255, 220, 140, 0.18);
  opacity: 1;
}
.map-cta-btn:active {
  transform: translateY(0);
}
@media (max-width: 640px) {
  .map-cta-btn {
    bottom: 12px;
    right: 12px;
    font-size: 12px;
    padding: 8px 14px;
  }
}

/* ── Welcome modal ── */
#welcome-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10,7,4,0.72);
  backdrop-filter: blur(6px);
  animation: wm-fade-in 0.45s ease both;
}
#welcome-modal[hidden] { display: none; }
#welcome-modal.wm-out { animation: wm-fade-out 0.35s ease forwards; }

@keyframes wm-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes wm-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.wm-panel {
  position: relative;
  padding: 48px 56px 40px;
  border: 1px solid rgba(183,130,63,0.38);
  background: rgba(14,10,6,0.93);
  backdrop-filter: blur(20px);
  text-align: center;
  max-width: 480px;
  width: 100%;
  animation: wm-slide-up 0.45s cubic-bezier(0.2,0.8,0.2,1) both;
}
@keyframes wm-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Corner brackets — same as loading screen */
.wm-corner {
  position: absolute;
  width: 18px;
  height: 18px;
}
.wm-corner::before,
.wm-corner::after {
  content: "";
  position: absolute;
  background: var(--gold);
  opacity: 0.7;
}
.wm-corner::before { width: 100%; height: 1px; top: 0; left: 0; }
.wm-corner::after  { width: 1px; height: 100%; top: 0; left: 0; }
.wm-corner.wm-tl { top: 10px; left: 10px; }
.wm-corner.wm-tr { top: 10px; right: 10px; transform: scaleX(-1); }
.wm-corner.wm-bl { bottom: 10px; left: 10px; transform: scaleY(-1); }
.wm-corner.wm-br { bottom: 10px; right: 10px; transform: scale(-1); }

.wm-title {
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: rgba(244,227,188,0.92);
  margin: 0 0 16px;
  letter-spacing: 0.01em;
}

.wm-rule {
  width: 80px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--vermillion) 40%, var(--vermillion) 60%, transparent);
  margin: 0 auto 20px;
}

.wm-desc {
  font-size: 13.5px;
  color: rgba(244,227,188,0.6);
  margin: 0 0 16px;
  line-height: 1.6;
}

.wm-how {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wm-how li {
  font-size: 13px;
  color: rgba(244,227,188,0.72);
  line-height: 1.55;
  padding-left: 16px;
  position: relative;
}
.wm-how li::before {
  content: "·";
  position: absolute;
  left: 4px;
  color: var(--gold);
  font-weight: 700;
}

.wm-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 28px;
  text-align: left;
}

.wm-opt {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border: 1px solid rgba(183,130,63,0.2);
  background: rgba(183,130,63,0.06);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.wm-opt:hover {
  background: rgba(183,130,63,0.12);
  border-color: rgba(183,130,63,0.35);
}
.wm-opt input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--vermillion);
  flex-shrink: 0;
  cursor: pointer;
}
.wm-opt-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.wm-opt strong {
  font-size: 13.5px;
  font-weight: 600;
  color: rgba(244,227,188,0.9);
}
.wm-opt small {
  font-size: 11.5px;
  color: rgba(244,227,188,0.5);
}

.wm-start {
  display: inline-block;
  padding: 11px 32px;
  background: linear-gradient(135deg, var(--blood), var(--vermillion));
  color: rgba(244,227,188,0.95);
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 14px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: opacity 0.2s, transform 0.2s;
}
.wm-start:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

@media (max-width: 520px) {
  .wm-panel { padding: 36px 24px 28px; }
  .wm-title { font-size: 17px; }
}
