/* Interface externa ao canvas: pergaminho e madeira, mínima, sem cara de dashboard. */
:root {
  --parchment: #f3e2bd;
  --parchment-2: #e8d2a2;
  --parchment-hi: #fff3d4;
  --ink: #3b2a1e;
  --ink-soft: #6d5338;
  --wood: #6b4226;
  --wood-dark: #3f2615;
  --wood-light: #9a6a3e;
  --gold: #e0b04a;
  --red: #a8352c;
  --night: #1d2340;
  --focus: #1d2340;
  --shadow: 0 3px 0 var(--wood-dark), 0 6px 14px rgba(20, 12, 6, 0.35);
  --font: 'Alegreya Sans', 'Segoe UI', system-ui, sans-serif;
  --font-title: 'Alegreya SC', Georgia, serif;
  --gutter: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  /* Medidos em tempo real pelo HUD (ResizeObserver) para encaixar painéis sem sobreposição. */
  --hud-bottom: 110px;
  --actions-bottom: 140px;
  --ctl: 44px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2f5a2c;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  /* O mapa trata arrastar e pinça; o navegador não rola nem amplia a página. */
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
button, input { font-family: var(--font); touch-action: manipulation; }
/* Áreas roláveis dentro da interface continuam roláveis no toque. */
.chronicle__list, .drawer__body, .search__results { touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
input { user-select: text; -webkit-user-select: text; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip-link {
  position: fixed;
  left: 8px;
  top: -60px;
  z-index: 40;
  padding: 10px 14px;
  background: var(--night);
  color: var(--parchment);
  font-weight: 700;
  border-radius: 3px;
}
.skip-link:focus { top: calc(8px + var(--safe-t)); outline: 3px solid var(--gold); }

#game, #game canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ---------- painéis ---------- */
.panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.25), transparent 40%),
    var(--parchment);
  border: 3px solid var(--wood);
  outline: 2px solid var(--wood-dark);
  box-shadow: var(--shadow), inset 0 0 0 2px var(--parchment-2);
  border-radius: 4px;
  padding: 8px 12px;
}

.hud {
  position: fixed;
  top: calc(var(--gutter) + var(--safe-t));
  left: calc(var(--gutter) + var(--safe-l));
  right: calc(var(--gutter) + var(--safe-r));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
  z-index: 10;
}
.hud .panel { pointer-events: auto; display: flex; align-items: center; gap: 12px; }

.crest { width: 34px; height: 34px; image-rendering: pixelated; flex: none; }
.kingdom { min-width: 0; }
.kingdom h1 { margin: 0; font-family: var(--font-title); font-size: 22px; font-weight: 700; letter-spacing: 0.3px; line-height: 1.05; }
.milestone { margin: 3px 0 0; font-size: 15px; color: var(--ink-soft); }
.milestone__desc::before { content: ' · '; }
.milestone__desc:empty { display: none; }
.milestone__pop { display: none; }
.milestone__pop::before { content: ' · '; }

.stats { display: flex; gap: 14px; margin: 0; padding-left: 12px; border-left: 2px dashed var(--wood-light); }
.stats div { display: flex; flex-direction: column; align-items: flex-start; }
.stats dt { font-size: 12px; font-weight: 500; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.8px; }
.stats dd { margin: 0; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stats--compact { padding-left: 10px; }

.sky { width: 30px; height: 30px; position: relative; flex: none; }
.sky svg { position: absolute; inset: 0; width: 100%; height: 100%; transition: opacity 0.6s, transform 0.6s; }
.sky .moon { opacity: 0; transform: translateY(6px); }
.sky[data-phase='night'] .sun { opacity: 0; transform: translateY(6px); }
.sky[data-phase='night'] .moon { opacity: 1; transform: none; }
.sky[data-phase='dusk'] .sun, .sky[data-phase='dawn'] .sun { filter: hue-rotate(-25deg) saturate(1.4); }

.clock { display: flex; flex-direction: column; }
#clock { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.clock small { font-size: 14px; color: var(--ink-soft); margin-top: 2px; white-space: nowrap; }
/* Computador: dia da semana numa linha própria, embaixo da fase do dia. */
.clock__day { display: block; font-size: 13px; }
@media (min-width: 721px) { .clock small { display: flex; flex-direction: column; } }

.panel--time { transition: background-color 1s; }
body.is-night .panel { background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 40%), #e3cfa6; }

/* ---------- ações (instalar / ranking) ---------- */
.actions {
  position: fixed;
  top: calc(var(--time-bottom, 92px) + 10px);
  right: calc(var(--gutter) + var(--safe-r));
  display: flex;
  gap: 8px;
  z-index: 10;
}
.action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--ctl);
  padding: 0 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  background: var(--parchment);
  border: 3px solid var(--wood);
  outline: 2px solid var(--wood-dark);
  border-radius: 4px;
  box-shadow: 0 3px 0 var(--wood-dark);
  cursor: pointer;
}
.action[hidden] { display: none; }
.action svg { width: 18px; height: 18px; fill: var(--wood-dark); shape-rendering: crispEdges; flex: none; }
.action:hover { background: var(--parchment-hi); }
.action:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood-dark); }
.action:focus-visible { outline: 3px solid var(--focus); }
.action[aria-expanded='true'] { background: var(--wood); color: var(--parchment); }
.action[aria-expanded='true'] svg { fill: var(--gold); }
.action--install svg { fill: var(--red); }

/* ---------- crônicas (eventos) ---------- */
.chronicle {
  position: fixed;
  left: calc(var(--gutter) + var(--safe-l));
  bottom: calc(var(--gutter) + var(--safe-b));
  width: min(360px, calc(100vw - 2 * var(--gutter) - 64px));
  z-index: 10;
  background: var(--parchment);
  border: 3px solid var(--wood);
  outline: 2px solid var(--wood-dark);
  box-shadow: var(--shadow);
  border-radius: 4px;
}
.chronicle__toggle {
  all: unset;
  box-sizing: border-box;
  width: 100%;
  min-height: 38px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  background: var(--wood);
  color: var(--parchment);
  font-family: var(--font-title);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.chronicle__toggle > span:first-child { flex: 1; }
.chronicle__toggle:focus-visible { outline: 3px solid var(--gold); outline-offset: -3px; }
.chronicle__badge {
  min-width: 22px;
  padding: 1px 6px;
  font-family: var(--font);
  font-size: 13px;
  text-align: center;
  color: var(--wood-dark);
  background: var(--gold);
  border-radius: 10px;
}
.chronicle__badge[hidden] { display: none; }
.chev { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid var(--gold); transition: transform 0.2s; }
.chronicle.is-collapsed .chev { transform: rotate(180deg); }
.chronicle.is-collapsed .chronicle__list { display: none; }

.chronicle__list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  max-height: min(34vh, 260px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--wood-light) transparent;
  user-select: text;
}
.chronicle__list li {
  padding: 6px 12px 7px;
  font-size: 15.5px;
  line-height: 1.35;
  border-bottom: 1px dashed rgba(107, 66, 38, 0.25);
  animation: ink-in 0.6s ease-out;
}
.chronicle__list li:last-child { border-bottom: 0; }
.chronicle__list time { display: block; font-size: 12.5px; font-weight: 500; color: var(--ink-soft); }
.chronicle__list li[data-type='population.milestone'], .chronicle__list li[data-type='settlement.milestone'], .chronicle__list li[data-type='district.founded'] { color: var(--red); }
.chronicle__empty { color: var(--ink-soft); font-style: italic; }

@keyframes ink-in {
  from { opacity: 0; transform: translateX(-6px); background: rgba(224, 176, 74, 0.35); }
  to { opacity: 1; transform: none; background: transparent; }
}

/* ---------- controles ---------- */
.controls {
  position: fixed;
  right: calc(var(--gutter) + var(--safe-r));
  bottom: calc(var(--gutter) + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}
.controls button {
  width: var(--ctl);
  height: var(--ctl);
  display: grid;
  place-items: center;
  background: var(--parchment);
  border: 3px solid var(--wood);
  outline: 2px solid var(--wood-dark);
  border-radius: 4px;
  box-shadow: 0 3px 0 var(--wood-dark);
  cursor: pointer;
  padding: 0;
}
.controls button svg { width: 20px; height: 20px; fill: var(--wood-dark); shape-rendering: crispEdges; }
.controls button:hover { background: var(--parchment-hi); }
.controls button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood-dark); }
.controls button:focus-visible { outline: 3px solid var(--focus); }

/* ---------- câmera de perseguição ---------- */
.follow {
  position: fixed;
  left: 50%;
  bottom: calc(var(--gutter) + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 6px 8px 6px 6px;
  background: var(--parchment);
  border: 3px solid var(--wood);
  outline: 2px solid var(--wood-dark);
  box-shadow: var(--shadow);
  border-radius: 4px;
  z-index: 11;
  animation: rise 0.35s ease-out;
}
.follow[hidden] { display: none; }
.follow__portrait {
  width: 40px;
  height: 50px;
  flex: none;
  image-rendering: pixelated;
  background: radial-gradient(circle at 50% 60%, #f7ecd0, var(--parchment-2));
  border: 2px solid var(--wood-light);
}
.follow__info { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; flex: 1; }
.follow__info small { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.8px; color: var(--ink-soft); }
.follow__info strong { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.follow__info span { font-size: 14px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.follow button {
  flex: none;
  min-height: var(--ctl);
  font-size: 15px;
  font-weight: 700;
  color: var(--parchment);
  background: var(--red);
  border: 2px solid var(--wood-dark);
  border-radius: 3px;
  padding: 6px 12px;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--wood-dark);
}
.follow button[hidden] { display: none; }
.follow button:active { transform: translateY(2px); box-shadow: none; }
.hint {
  position: fixed;
  left: 50%;
  bottom: calc(var(--gutter) + 8px + var(--safe-b));
  transform: translateX(-50%);
  max-width: calc(100vw - 2 * var(--gutter));
  margin: 0;
  padding: 5px 12px;
  font-size: 15px;
  text-align: center;
  color: var(--parchment);
  background: rgba(40, 24, 12, 0.86);
  border-radius: 3px;
  pointer-events: none;
  z-index: 9;
  transition: opacity 0.6s;
}
.hint.is-hidden { opacity: 0; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- agora no reino / nome flutuante ---------- */
.now { margin: 4px 0 0; font-size: 14px; color: var(--ink); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.now span { white-space: nowrap; }
.now b { font-weight: 700; font-variant-numeric: tabular-nums; }
.nametag {
  position: fixed;
  left: 0;
  top: 0;
  padding: 2px 8px 3px;
  font-size: 14px;
  font-weight: 700;
  color: var(--parchment);
  background: rgba(40, 24, 12, 0.85);
  border: 1px solid var(--wood-light);
  border-radius: 3px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 9;
  will-change: transform;
}
.nametag small { display: block; font-weight: 400; font-size: 12.5px; color: #eadcbc; }

/* ---------- letreiros dos estabelecimentos ---------- */
.signs { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.sign {
  /* Discreto: só um rótulo translúcido sobre o prédio, sem placa nem moldura. */
  position: absolute;
  left: 0;
  top: 0;
  padding: 1px 6px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 248, 230, 0.92);
  background: rgba(20, 14, 8, 0.32);
  border-radius: 8px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
  white-space: nowrap;
  text-align: center;
  line-height: 1.2;
  opacity: 0.8;
  transition: opacity 0.4s;
  animation: sign-in 0.5s ease-out;
}
.sign small { display: none; font-weight: 400; font-size: 10.5px; color: rgba(255, 248, 230, 0.75); }
.signs.near .sign small { display: block; }
@keyframes sign-in { from { opacity: 0; } }

/* ---------- busca por @ ---------- */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.search {
  position: fixed;
  top: calc(var(--gutter) + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  width: min(300px, 40vw);
  z-index: 12;
}
.search[hidden] { display: none; }
.search__icon { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; margin-top: -8px; fill: var(--ink-soft); pointer-events: none; shape-rendering: crispEdges; }
.search > .search__icon { top: 22px; }
.search input {
  width: 100%;
  min-height: var(--ctl);
  font-size: 16px; /* 16px evita o zoom automático do iOS ao focar */
  padding: 9px 12px 9px 36px;
  color: var(--ink);
  background: var(--parchment);
  border: 3px solid var(--wood);
  outline: 2px solid var(--wood-dark);
  border-radius: 4px;
  box-shadow: var(--shadow);
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: #7d6448; opacity: 1; }
.search input:focus-visible { outline: 3px solid var(--focus); }
.search__results {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px 0;
  background: var(--parchment);
  border: 3px solid var(--wood);
  border-radius: 4px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow: auto;
}
.search__results[hidden] { display: none; }
.search__results li { min-height: var(--ctl); padding: 7px 12px; cursor: pointer; display: flex; flex-direction: column; justify-content: center; font-size: 15px; }
.search__results li:hover, .search__results li[aria-selected='true'] { background: var(--parchment-hi); box-shadow: inset 4px 0 0 var(--red); }
.search__results small { color: var(--ink-soft); }
.search__empty { color: var(--ink-soft); cursor: default !important; }

/* ---------- gavetas: ficha RPG e ranking ---------- */
.follow__sheet { background: var(--wood) !important; }
.drawer {
  position: fixed;
  top: calc(var(--actions-bottom) + 12px);
  right: calc(var(--gutter) + var(--safe-r));
  bottom: calc(var(--gutter) + 170px + var(--safe-b));
  width: min(360px, calc(100vw - 2 * var(--gutter)));
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.3), transparent 120px),
    var(--parchment);
  border: 3px solid var(--wood);
  outline: 2px solid var(--wood-dark);
  border-radius: 4px;
  box-shadow: var(--shadow);
  z-index: 13;
  animation: sheet-in 0.35s ease-out;
}
.drawer[hidden] { display: none; }
.drawer:focus { outline: none; }
.drawer__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--wood-light) transparent;
  user-select: text;
}
.drawer__handle { display: none; }
@keyframes sheet-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
.sheet__close {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 1;
  width: var(--ctl);
  height: var(--ctl);
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 4px;
  font-size: 28px;
  line-height: 1;
  color: var(--wood);
  cursor: pointer;
}
.sheet__close:hover { background: rgba(107, 66, 38, 0.12); }
.sheet__head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; padding-right: 36px; }
.sheet__portrait { width: 48px; height: 60px; flex: none; image-rendering: pixelated; background: radial-gradient(circle at 50% 60%, #f7ecd0, var(--parchment-2)); border: 2px solid var(--wood-light); }
.drawer h2 { margin: 0; font-family: var(--font-title); font-size: 22px; line-height: 1.1; }
.sheet__ig { margin: 2px 0 0; font-size: 14.5px; font-weight: 500; color: var(--red); overflow-wrap: anywhere; }
.drawer h3 { margin: 14px 0 6px; font-family: var(--font-title); font-size: 15px; letter-spacing: 0.5px; color: var(--wood); border-bottom: 2px dashed var(--wood-light); padding-bottom: 3px; }
.sheet__facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 15.5px; line-height: 1.3; }
.sheet__facts dt { color: var(--ink-soft); }
.sheet__facts dd { margin: 0; overflow-wrap: anywhere; }
.sheet__needs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px 12px; margin-top: 10px; font-size: 13.5px; }
.need { display: flex; flex-direction: column; gap: 2px; }
.need__bar { height: 6px; background: #d9c79f; border: 1px solid var(--wood-light); }
.need__bar span { display: block; height: 100%; background: #4f8a35; }
.need__bar span.low { background: #b8402f; }
.sheet__story { margin: 0; font-size: 16px; line-height: 1.5; }
.sheet__list { list-style: none; margin: 0; padding: 0; font-size: 15px; line-height: 1.35; }
.sheet__list li { padding: 4px 0; border-bottom: 1px dashed rgba(107, 66, 38, 0.25); }
.sheet__list time { display: block; font-size: 12.5px; color: var(--ink-soft); }

/* ---------- ranking de moedas ---------- */
.ranking__head { padding-right: 36px; margin-bottom: 8px; }
.ranking__sub { margin: 2px 0 0; font-size: 14.5px; color: var(--ink-soft); }
.ranking__list { list-style: none; margin: 0; padding: 0; }
.ranking__list li + li { border-top: 1px dashed rgba(107, 66, 38, 0.3); }
.ranking__item {
  all: unset;
  box-sizing: border-box;
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 6px;
  cursor: pointer;
  border-radius: 3px;
}
.ranking__item:hover { background: var(--parchment-hi); }
.ranking__item:focus-visible { outline: 3px solid var(--focus); outline-offset: -1px; }
.ranking__pos {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--parchment-2);
  border: 2px solid var(--wood-light);
  border-radius: 50%;
}
.ranking__list li:nth-child(1) .ranking__pos { background: #f2cf5b; border-color: #9a7420; }
.ranking__list li:nth-child(2) .ranking__pos { background: #d9dde3; border-color: #7d838c; }
.ranking__list li:nth-child(3) .ranking__pos { background: #dba06a; border-color: #8a5528; }
.ranking__who { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.ranking__who strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ranking__who small { font-size: 13.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ranking__who .ig { color: var(--red); font-weight: 500; }
.ranking__gold { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ranking__gold::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fbe9a0, #e0b04a 55%, #a87a22);
  box-shadow: 0 0 0 1px #6b4a12;
}
.ranking__status { margin: 10px 0 0; font-size: 14.5px; color: var(--ink-soft); }
.ranking__status:empty { display: none; }
.ranking__skeleton { height: 52px; margin: 2px 0; border-radius: 3px; background: linear-gradient(90deg, rgba(107, 66, 38, 0.08), rgba(107, 66, 38, 0.16), rgba(107, 66, 38, 0.08)); }

/* ---------- estados ---------- */
.status {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 16px;
  background: var(--night);
  color: var(--parchment);
  border: 3px solid var(--wood);
  z-index: 20;
}
.status[hidden] { display: none; }
.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #2f5a2c;
  z-index: 30;
  transition: opacity 0.6s;
}
.loading.is-done { opacity: 0; pointer-events: none; }
.loading__box { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--parchment); text-align: center; padding: 0 20px; }
.loading__title { font-family: var(--font-title); font-size: 44px; font-weight: 700; letter-spacing: 3px; color: var(--gold); text-shadow: 0 3px 0 var(--wood-dark); }

/* ---------- celulares (retrato) ---------- */
@media (max-width: 720px) {
  :root { --gutter: 10px; --ctl: 46px; }
  .hud { gap: 6px; align-items: stretch; }
  .hud .panel { padding: 5px 8px; gap: 8px; min-height: 52px; }
  .panel--kingdom { flex: 1 1 auto; min-width: 0; }
  .panel--time { flex: none; }
  .crest { width: 24px; height: 24px; }
  .kingdom { flex: 1; }
  .kingdom h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .milestone { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
  .milestone__desc, .now { display: none !important; }
  .stats { gap: 8px; padding-left: 8px; }
  .stats dt { font-size: 10.5px; letter-spacing: 0.4px; }
  .stats dd { font-size: 18px; }
  .panel--kingdom .stats, .stats--compact { display: none !important; }
  .milestone__pop { display: inline; color: var(--ink); font-weight: 500; }
  .sky { width: 22px; height: 22px; }
  #clock { font-size: 19px; }
  .clock small { font-size: 12.5px; }
  .clock__day { display: inline; font-size: inherit; }
  .clock__day::before { content: ' · '; }

  .actions { top: calc(var(--time-bottom, 72px) + 8px); }
  .action { font-size: 15px; padding: 0 10px; }

  /* Rodapé: busca à esquerda, controles numa coluna à direita, crônicas como pílula acima da busca. */
  .search {
    top: auto;
    bottom: calc(var(--gutter) + var(--safe-b));
    left: calc(var(--gutter) + var(--safe-l));
    right: calc(var(--gutter) + var(--ctl) + 14px + var(--safe-r));
    width: auto;
    transform: none;
  }
  .search > .search__icon { top: 23px; }
  .search__results {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    margin: 0 0 8px;
    max-height: min(46vh, 320px);
    max-height: min(46dvh, 320px);
  }
  .chronicle {
    bottom: calc(var(--gutter) + var(--safe-b) + var(--ctl) + 16px);
    width: calc(100vw - 2 * var(--gutter) - var(--ctl) - 14px - var(--safe-l) - var(--safe-r));
  }
  .chronicle.is-collapsed { width: auto; }
  .chronicle__toggle { min-height: 40px; font-size: 15px; }
  .chronicle__more { display: none; }
  .chronicle__list { max-height: 34vh; max-height: 34dvh; }
  .chronicle__list li { font-size: 15px; }
  .controls { gap: 10px; }

  .follow {
    left: calc(var(--gutter) + var(--safe-l));
    right: calc(var(--gutter) + var(--ctl) + 14px + var(--safe-r));
    bottom: calc(var(--gutter) + var(--safe-b) + var(--ctl) + 70px);
    transform: none;
    max-width: none;
    animation-name: rise-m;
  }
  .follow__portrait { width: 32px; height: 40px; }
  .follow__info strong { font-size: 16px; }
  .follow button { padding: 6px 10px; }
  .hint {
    bottom: calc(var(--gutter) + var(--safe-b) + var(--ctl) + 72px);
    left: calc(var(--gutter) + var(--safe-l));
    right: calc(var(--gutter) + var(--ctl) + 14px + var(--safe-r));
    transform: none;
    max-width: none;
    font-size: 14.5px;
  }
  body.is-following .hint { display: none; }

  /* Ficha e ranking viram "bottom sheet" arrastável. */
  .drawer {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 58vh;
    height: 58dvh;
    max-height: calc(100vh - var(--safe-t) - 12px);
    max-height: calc(100dvh - var(--safe-t) - 12px);
    border-width: 3px 0 0;
    outline: 0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 0 var(--wood-dark), 0 -10px 24px rgba(20, 12, 6, 0.35);
    padding-bottom: var(--safe-b);
    transform: translateY(var(--drag, 0px));
    transition: height 0.25s ease, transform 0.25s ease;
    animation: drawer-up 0.3s ease-out;
    z-index: 15;
  }
  .drawer.is-expanded { height: calc(100vh - var(--safe-t) - 56px); height: calc(100dvh - var(--safe-t) - 56px); }
  .drawer.is-dragging { transition: none; }
  .drawer__handle {
    display: grid;
    place-items: center;
    flex: none;
    width: 100%;
    height: 28px;
    padding: 0;
    background: none;
    border: 0;
    cursor: grab;
    touch-action: none;
  }
  .drawer__handle span { width: 44px; height: 5px; border-radius: 3px; background: var(--wood-light); }
  .drawer__handle:focus-visible { outline-offset: -4px; }
  .drawer__body { padding: 0 16px 16px; }
  .sheet__close { top: 18px; right: 6px; }
  .drawer h2 { font-size: 20px; }
}
@keyframes rise-m { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes drawer-up { from { transform: translateY(40%); opacity: 0.4; } to { transform: translateY(var(--drag, 0px)); opacity: 1; } }

/* ---------- celulares deitados (paisagem, pouca altura) ---------- */
@media (max-height: 520px) and (min-width: 721px) {
  :root { --gutter: 8px; }
  .hud .panel { padding: 4px 10px; gap: 10px; }
  .crest { width: 24px; height: 24px; }
  .kingdom h1 { font-size: 17px; }
  .milestone { font-size: 13.5px; margin-top: 1px; }
  .milestone__desc, .now { display: none !important; }
  .stats dt { font-size: 10.5px; }
  .stats dd { font-size: 18px; }
  #clock { font-size: 20px; }
  .sky { width: 24px; height: 24px; }
  .clock small { font-size: 12.5px; }
  .actions { top: calc(var(--gutter) + var(--safe-t)); right: auto; left: 50%; transform: translateX(-50%); }
  .search { top: auto; bottom: calc(var(--gutter) + var(--safe-b)); left: auto; right: calc(var(--gutter) + var(--ctl) + 14px + var(--safe-r)); transform: none; width: min(280px, 34vw); }
  .search__results { position: absolute; left: 0; right: 0; bottom: 100%; margin: 0 0 6px; max-height: 60vh; }
  .chronicle { width: min(340px, 40vw); }
  .chronicle__list { max-height: 46vh; }
  .drawer { top: calc(var(--hud-bottom) + 8px); bottom: calc(var(--gutter) + var(--safe-b)); right: calc(var(--gutter) + var(--ctl) + 14px + var(--safe-r)); width: min(380px, 46vw); }
  .follow { bottom: calc(var(--gutter) + var(--safe-b) + var(--ctl) + 14px); }
  .hint { display: none; }
}

@media (hover: none) {
  .action:hover, .controls button:hover { background: var(--parchment); }
  .ranking__item:hover, .search__results li:hover { background: transparent; }
  .action[aria-expanded='true']:hover { background: var(--wood); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* =====================================================================
   Tela da live do TikTok (/live) — em pé 9:16, legível de longe.
   ===================================================================== */
body.is-live .hud, body.is-live .actions, body.is-live .chronicle, body.is-live .controls,
body.is-live .sheet, body.is-live .ranking, body.is-live .status, body.is-live .skip-link, body.is-live .signs small, body.is-live .search, body.is-live .nametag { display: none !important; }
.live { position: fixed; inset: 0; pointer-events: none; z-index: 30; font-family: var(--font); color: var(--parchment-hi); --u: min(1vw, 0.5625vh); }
/* Barra do topo: título, AO VIVO e hora na mesma linha (nada empurra o ranking). */
.live__top { position: absolute; top: calc(2.5 * var(--u)); left: calc(3 * var(--u)); right: calc(3 * var(--u)); display: flex; align-items: center; gap: calc(2 * var(--u));
  padding: calc(1.4 * var(--u)) calc(2.6 * var(--u)); background: rgba(40, 24, 12, 0.8); border: 2px solid var(--gold); border-radius: calc(2 * var(--u)); box-shadow: 0 4px 0 var(--wood-dark); }
.live__crest { font-size: calc(6.5 * var(--u)); color: var(--gold); line-height: 1; }
.live__title { flex: 1; min-width: 0; }
.live__title strong { display: block; font-family: var(--font-title); font-size: calc(5.4 * var(--u)); color: var(--gold); line-height: 1; }
.live__title small { display: block; font-size: calc(2.5 * var(--u)); opacity: 0.9; margin-top: calc(0.5 * var(--u)); }
.live__pills { display: flex; flex-direction: column; gap: calc(0.8 * var(--u)); align-items: stretch; text-align: center; }
.live__pill { padding: calc(0.5 * var(--u)) calc(1.8 * var(--u)); border-radius: 999px; background: rgba(0, 0, 0, 0.35); font-weight: 700; font-size: calc(2.7 * var(--u)); white-space: nowrap; }
.live__pill--on { background: #c0262d; color: #fff; animation: live-pulse 1.6s ease-in-out infinite; }
@keyframes live-pulse { 50% { opacity: 0.75; } }
.live__stats { position: absolute; top: calc(17 * var(--u)); left: calc(3 * var(--u)); right: calc(3 * var(--u)); display: grid; grid-template-columns: repeat(3, 1fr); gap: calc(1.4 * var(--u)); }
.live__stats div { padding: calc(0.8 * var(--u)) calc(1 * var(--u)); background: rgba(20, 14, 8, 0.66); border-radius: calc(1.6 * var(--u)); text-align: center; }
.live__stats b { display: block; font-size: calc(4.2 * var(--u)); color: var(--gold); line-height: 1.1; }
.live__stats small { font-size: calc(2.2 * var(--u)); opacity: 0.9; }
/* Coluna esquerda: quem está em destaque. Coluna direita: ranking com o @ inteiro. */
.live__spot { position: absolute; top: calc(28 * var(--u)); left: calc(3 * var(--u)); width: calc(52 * var(--u)); padding: calc(1.8 * var(--u)) calc(2.4 * var(--u));
  background: linear-gradient(180deg, rgba(92, 38, 110, 0.9), rgba(52, 20, 64, 0.9)); border: 2px solid #f0c850; border-radius: calc(2.2 * var(--u)); box-shadow: 0 4px 0 #2a0f33; animation: live-in 0.5s ease-out; }
.live__spot-tag { font-family: var(--font-title); font-size: calc(2.8 * var(--u)); color: #ffd75e; letter-spacing: 0.04em; }
.live__spot-who { font-size: calc(5 * var(--u)); font-weight: 800; line-height: 1.1; overflow-wrap: anywhere; margin: calc(0.4 * var(--u)) 0; }
.live__spot-gift, .live__spot-life, .live__spot-gold, .live__spot-next { font-size: calc(2.8 * var(--u)); line-height: 1.3; }
.live__spot-gift em, .live__spot-gold { color: #ffd75e; font-style: normal; font-weight: 700; }
.live__spot-next { opacity: 0.85; margin-top: calc(0.6 * var(--u)); overflow-wrap: anywhere; }
.live__spot-bar { height: calc(0.9 * var(--u)); margin-top: calc(1 * var(--u)); background: rgba(255, 255, 255, 0.18); border-radius: 999px; overflow: hidden; }
.live__spot-bar i { display: block; height: 100%; background: #ffd75e; transform-origin: left; animation: live-bar linear forwards; }
@keyframes live-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.live__rank { position: absolute; top: calc(28 * var(--u)); right: calc(3 * var(--u)); width: calc(39 * var(--u)); padding: calc(1.4 * var(--u)) calc(2 * var(--u)); background: rgba(40, 24, 12, 0.8); border: 2px solid var(--wood-light); border-radius: calc(2 * var(--u)); }
.live__rank h2 { margin: 0 0 calc(0.8 * var(--u)); font-family: var(--font-title); font-size: calc(3 * var(--u)); color: var(--gold); }
.live__rank ol { list-style: none; margin: 0; padding: 0; }
.live__rank li { display: grid; grid-template-columns: auto 1fr; column-gap: calc(1.2 * var(--u)); align-items: center; padding: calc(0.6 * var(--u)) 0; border-top: 1px solid rgba(255, 240, 200, 0.12); }
.live__rank li:first-child { border-top: 0; }
.live__pos { grid-row: span 2; width: calc(4 * var(--u)); height: calc(4 * var(--u)); border-radius: 50%; display: grid; place-items: center; background: var(--wood); font-weight: 700; font-size: calc(2.3 * var(--u)); }
.live__rank li:first-child .live__pos { background: var(--gold); color: var(--ink); }
.live__who { font-size: calc(2.7 * var(--u)); font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.live__gold { font-size: calc(2.5 * var(--u)); color: var(--gold); font-weight: 700; }
.live__empty { display: block !important; opacity: 0.8; font-style: italic; font-size: calc(2.6 * var(--u)); }
.live__feed { position: absolute; left: calc(3 * var(--u)); right: calc(3 * var(--u)); bottom: calc(43 * var(--u)); margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column-reverse; gap: calc(1 * var(--u)); }
.live__item { align-self: flex-start; max-width: 100%; padding: calc(0.9 * var(--u)) calc(2.4 * var(--u)); background: rgba(20, 14, 8, 0.72); border-radius: 999px; font-size: calc(3 * var(--u)); animation: live-in 0.45s ease-out; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live__item em { font-style: normal; color: var(--gold); font-weight: 700; margin-left: 0.3em; }
.live__item--gift { background: rgba(120, 40, 120, 0.82); }
.live__item--follow { background: rgba(40, 90, 50, 0.85); }
.live__item--sys { background: rgba(168, 53, 44, 0.85); }
@keyframes live-in { from { transform: translateX(-30%); opacity: 0; } }
.live__alert { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); min-width: calc(70 * var(--u)); max-width: calc(92 * var(--u)); padding: calc(3 * var(--u)) calc(4 * var(--u)); text-align: center; background: linear-gradient(180deg, #4b2a14, #2c180a); border: 3px solid var(--gold); border-radius: calc(3 * var(--u)); box-shadow: 0 0 0 4px rgba(224, 176, 74, 0.25), 0 10px 40px rgba(0, 0, 0, 0.5); font-size: calc(3.6 * var(--u)); animation: live-pop 0.5s cubic-bezier(.2, 1.4, .4, 1); z-index: 2; }
.live__alert-title { font-family: var(--font-title); font-size: calc(5.2 * var(--u)); color: var(--gold); margin-bottom: calc(0.6 * var(--u)); overflow-wrap: anywhere; }
.live__coins { font-size: calc(7.5 * var(--u)); font-weight: 800; color: #ffd75e; text-shadow: 0 3px 0 #7a4e10; margin: calc(1 * var(--u)) 0; }
.live__alert small { font-size: calc(2.8 * var(--u)); opacity: 0.9; }
@keyframes live-pop { from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; } }
.live__coin { position: absolute; top: -40px; animation: live-fall 2.6s ease-in forwards; z-index: 3; }
@keyframes live-fall { to { transform: translateY(105vh) rotate(540deg); } }
.live__how { position: absolute; left: calc(3 * var(--u)); right: calc(3 * var(--u)); bottom: calc(3 * var(--u)); padding: calc(2 * var(--u)) calc(3 * var(--u)) calc(1.2 * var(--u)); background: rgba(243, 226, 189, 0.95); color: var(--ink); border: 3px solid var(--wood); border-radius: calc(2.4 * var(--u)); box-shadow: 0 5px 0 var(--wood-dark); }
.live__step { display: flex; gap: calc(2 * var(--u)); align-items: center; font-size: calc(3.4 * var(--u)); line-height: 1.25; min-height: calc(13 * var(--u)); animation: live-in 0.4s ease-out; }
.live__step b { color: var(--red); font-family: var(--font-title); }
.live__step-icon { font-size: calc(8 * var(--u)); flex: none; }
.live__dots { display: flex; gap: calc(1 * var(--u)); justify-content: center; margin: calc(0.8 * var(--u)) 0; }
.live__dots i { width: calc(1.4 * var(--u)); height: calc(1.4 * var(--u)); border-radius: 50%; background: var(--wood-light); opacity: 0.4; }
.live__dots i.on { opacity: 1; background: var(--wood); }
.live__url { display: flex; flex-direction: column; align-items: center; border-top: 2px dashed var(--wood-light); padding-top: calc(1 * var(--u)); }
.live__url span { font-size: calc(2.7 * var(--u)); color: var(--ink-soft); }
.live__url strong { font-family: var(--font-title); font-size: calc(6 * var(--u)); color: var(--wood-dark); letter-spacing: 0.01em; }
.live__np { text-align: center; font-size: calc(2.3 * var(--u)); color: var(--ink-soft); min-height: 1.2em; }
/* Botão de música (site): riscado quando desligado. */
.action.is-off svg { opacity: 0.55; }

/* ---------- ajuda: botão do TikTok (ao lado do relógio) e "?" (acima do zoom) ---------- */
.tip { position: relative; flex: none; }
.tip__btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--wood-dark); background: #111; cursor: pointer; padding: 0; box-shadow: 0 2px 0 var(--wood-dark); }
.tip__btn svg { width: 18px; height: 18px; fill: #fff; filter: drop-shadow(1.5px 0 0 #25f4ee) drop-shadow(-1.5px 0 0 #fe2c55); }
.tip__btn:focus-visible, .tip__btn--help:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.controls .tip__btn--help { font-family: var(--font-title); font-size: 24px; font-weight: 700; color: var(--wood-dark); line-height: 1; }
.pop { position: absolute; z-index: 40; width: min(320px, calc(100vw - 32px)); padding: 14px 16px; background: var(--parchment-hi); color: var(--ink);
  border: 3px solid var(--wood); border-radius: 8px; box-shadow: var(--shadow); font-size: 15px; line-height: 1.35; text-align: left; }
.pop h2 { margin: 0 0 8px; font-family: var(--font-title); font-size: 19px; color: var(--wood-dark); }
.pop h3 { margin: 10px 0 4px; font-family: var(--font-title); font-size: 16px; color: var(--wood-dark); }
.pop ol, .pop ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.pop ul { list-style: none; padding-left: 0; }
.pop p { margin: 0 0 6px; }
.pop a { color: var(--red); font-weight: 700; }
.pop__muted { color: var(--ink-soft); font-size: 13.5px; }
.pop--down { top: calc(100% + 10px); right: -8px; }
.pop--left { right: calc(100% + 12px); bottom: 0; max-height: min(70vh, 520px); overflow: auto; }
@media (max-width: 720px) {
  .pop--down { position: fixed; top: calc(var(--safe-t) + 120px); left: 16px; right: 16px; width: auto; }
  .pop--left { position: fixed; left: 16px; right: 16px; bottom: calc(var(--gutter) + var(--safe-b) + 12px); width: auto; }
}
/* Balão aberto fica acima de tudo (botões de ação e busca). */
.hud:has(.pop:not([hidden])), .controls:has(.pop:not([hidden])) { z-index: 60; }
@media (max-width: 720px) {
  .pop--left { bottom: calc(var(--safe-b) + 96px); max-height: calc(100dvh - var(--safe-t) - 200px); }
}

/* Clima: chuva e neblina por cima do mapa (não bloqueia cliques). */
.clock__weather { display: inline; }
.clock__weather::before { content: " · "; }
.weather-fx { position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: 0; transition: opacity 4s ease; overflow: hidden; }
.weather-fx[data-weather="rain"], .weather-fx[data-weather="fog"] { opacity: 1; }
.weather-fx i { position: absolute; inset: -20% -20%; display: none; }
.weather-fx[data-weather="rain"] .weather-fx__rain { display: block; }
.weather-fx[data-weather="fog"] .weather-fx__fog { display: block; }
.weather-fx[data-weather="rain"]::before { content: ''; position: absolute; inset: 0; background: rgba(40, 55, 75, .22); }
.weather-fx__rain {
  background-image: repeating-linear-gradient(105deg, transparent 0 18px, rgba(190, 210, 235, .38) 18px 19px, transparent 19px 46px);
  background-size: 120px 120px;
  animation: vilora-rain .45s linear infinite;
}
.weather-fx__rain--far { opacity: .5; background-size: 70px 70px; animation-duration: .7s; }
.weather-fx__fog {
  background:
    radial-gradient(ellipse 60% 40% at 30% 40%, rgba(225, 230, 235, .55), transparent 70%),
    radial-gradient(ellipse 50% 35% at 75% 65%, rgba(225, 230, 235, .5), transparent 70%),
    rgba(215, 222, 228, .28);
  animation: vilora-fog 40s ease-in-out infinite alternate;
}
@keyframes vilora-rain { to { background-position: -30px 120px; } }
@keyframes vilora-fog { to { transform: translateX(6%); } }
@media (prefers-reduced-motion: reduce) { .weather-fx__rain, .weather-fx__fog { animation: none; } }

/* Live: nome de quem a câmera está acompanhando, logo abaixo da pessoa (sem botões). */
body.is-live .follow { --u: min(1vw, 0.5625vh); top: calc(96 * var(--u)); bottom: auto; left: 50%; right: auto; transform: translateX(-50%); animation: none; z-index: 31; gap: calc(1.6 * var(--u)); padding: calc(1 * var(--u)) calc(2.6 * var(--u)) calc(1 * var(--u)) calc(1 * var(--u));
  max-width: calc(88 * var(--u)); border-radius: calc(1.6 * var(--u)); pointer-events: none; }
body.is-live .follow button { display: none !important; }
body.is-live .follow__portrait { width: calc(7 * var(--u)); height: calc(8.75 * var(--u)); }
body.is-live .follow__info small { font-size: calc(2.2 * var(--u)); }
body.is-live .follow__info strong { font-size: calc(4 * var(--u)); white-space: normal; overflow-wrap: anywhere; }
body.is-live .follow__info span { font-size: calc(2.8 * var(--u)); }
