:root {
  --ink: #3b2412;
  --ink-soft: #6b4a2b;
  --paper: #f3e4bf;
  --paper-dark: #d9bf8a;
  --red: #a3241b;
  --gold: #e0a925;
  --gold-bright: #ffcf40;
  --sea: #5d7f8c;
  --bg: #2a1d12;
  /* la mappa occupa tutto lo spazio disponibile mantenendo le proporzioni 1376x768 */
  --map-w: min(100vw - 24px, (100dvh - 110px) * 1376 / 768);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 30%, #3d2a18, var(--bg));
  color: var(--paper);
  font-family: 'IM Fell English', Georgia, serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px;
  overflow-x: hidden;
}

header {
  width: var(--map-w);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 12px 24px;
  margin-bottom: 6px;
}

h1 {
  font-family: 'Pirata One', serif;
  font-weight: 400;
  font-size: clamp(32px, 5vw, 52px);
  margin: 0;
  color: var(--gold);
  letter-spacing: 1px;
}

#meta { margin: 0 0 0 auto; font-style: italic; opacity: 0.85; }

#stage {
  --night: 0;
  position: relative;
  width: var(--map-w);
  aspect-ratio: 1376 / 768;
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#map-bg { border-radius: 6px; }
#fx, #map-fg { pointer-events: none; }

#error {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  max-width: 90%;
  background: var(--red);
  color: #fff;
  padding: 10px 14px;
  border-radius: 4px;
}

/* --- ambiente --- */

#night { mix-blend-mode: multiply; transition: opacity 3s, fill 3s; }

.wave {
  fill: none;
  stroke: #3f6670;
  stroke-width: 1.6;
  stroke-linecap: round;
  opacity: 0;
  transform-box: fill-box;
  animation: wave 7s ease-in-out infinite;
}
@keyframes wave {
  0% { opacity: 0; transform: translateX(-9px); }
  50% { opacity: 0.6; }
  100% { opacity: 0; transform: translateX(9px); }
}

.gull { fill: none; stroke: var(--ink); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.gull-shadow { stroke: rgba(40, 25, 10, 0.18); }
.gull-wing {
  transform-box: fill-box;
  transform-origin: center;
  animation: flap 0.45s ease-in-out infinite alternate;
}
@keyframes flap { to { transform: scaleY(-0.45); } }

#clouds { opacity: calc(1 - var(--night) * 0.65); transition: opacity 3s; }
.cloud-body { fill: url(#cloud-body); }
.cloud-shadow { fill: url(#cloud-shadow); }

/* --- rotte --- */

.trail {
  fill: none;
  stroke: var(--red);
  stroke-width: 4;
  stroke-opacity: 0.8;
  stroke-dasharray: 2 12;
  stroke-linecap: round;
  animation: march 1.6s linear infinite;
}
@keyframes march { to { stroke-dashoffset: -28; } }

/* --- villaggi --- */

.lantern-halo {
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(calc(1 + var(--night) * 0.9));
  transition: transform 3s;
}
.lantern-glow { fill: url(#lantern-glow); animation: flicker 2.6s infinite; }
.lantern-core { fill: #fff4c2; stroke: #8a4b10; stroke-width: 0.8; }
@keyframes flicker {
  0%, 100% { opacity: 0.85; }
  20% { opacity: 0.55; }
  40% { opacity: 1; }
  60% { opacity: 0.7; }
  80% { opacity: 0.95; }
}

.lantern-label, .city-pop {
  paint-order: stroke;
  stroke: var(--paper);
  stroke-linejoin: round;
}
.lantern-label { font: italic 12px 'IM Fell English', serif; fill: var(--ink); stroke-width: 3.5px; }
.city-pop { font: 21px 'Pirata One', serif; stroke-width: 4.5px; }

/* --- stazioni --- */

.station-dot { fill: var(--red); stroke: var(--paper); stroke-width: 3; }

.plaque rect { fill: var(--paper); fill-opacity: 0.92; stroke: var(--ink); stroke-width: 2.5; }
.plaque .count { font-family: 'Pirata One', serif; font-size: 26px; fill: var(--ink); }
.plaque .name { font-family: 'IM Fell English', serif; font-size: 12px; fill: var(--ink-soft); font-style: italic; }
.plaque .count.bump, .board-count.bump, .board-total.bump { animation: bump 0.9s ease; }

.delta {
  font: 16px 'Pirata One', serif;
  paint-order: stroke;
  stroke: var(--paper);
  stroke-width: 3.5px;
}
.delta.up { fill: #2f6b34; }
.delta.down { fill: #8a6a4a; }

@keyframes bump {
  0% { fill: var(--ink); }
  40% { fill: var(--red); }
  100% { fill: var(--ink); }
}

.ship { filter: drop-shadow(0 3px 2px rgba(40, 25, 10, 0.35)); }

/* --- pannelli (bottino e diario) --- */

.panel-bg { fill: var(--paper); fill-opacity: 0.93; stroke: var(--ink); stroke-width: 2.5; }
.panel-title { font: 21px 'Pirata One', serif; fill: var(--ink); }
.panel-note { font: italic 13px 'IM Fell English', serif; fill: var(--ink-soft); }

.board-total { font: 46px 'Pirata One', serif; fill: var(--ink); }
.board-label { font: 14px 'IM Fell English', serif; fill: var(--ink); }
.board-count { font: 23px 'Pirata One', serif; fill: var(--ink); }
.board-coin {
  transform-box: fill-box;
  transform-origin: center;
  animation: coin-flip 3.2s ease-in-out infinite;
}
@keyframes coin-flip {
  0%, 70%, 100% { transform: scaleX(1); }
  85% { transform: scaleX(0.08); }
}

.spark-area { fill-opacity: 0.2; }
.spark-line { fill: none; stroke-width: 1.6; stroke-linejoin: round; }
.spark-coin { fill: url(#gold-coin); stroke: #7a4e0c; stroke-width: 0.8; }
.spark-tick { stroke: #c9951c; stroke-width: 1; stroke-dasharray: 2 2; }
.spark-live-ring {
  fill: none;
  stroke-width: 1.5;
  transform-box: fill-box;
  transform-origin: center;
  animation: live 1.6s ease-out infinite;
}
@keyframes live {
  from { transform: scale(0.6); opacity: 1; }
  to { transform: scale(2.6); opacity: 0; }
}

.entry-city { font: 15px 'IM Fell English', serif; fill: var(--ink); }
.entry-time { font: 12px 'IM Fell English', serif; fill: var(--ink-soft); }
.entry-verb { font: italic 12.5px 'IM Fell English', serif; fill: var(--ink-soft); }
.entry.purchase .entry-verb { fill: #7a4a00; font-weight: 700; }
.entry.begin_checkout .entry-verb { fill: var(--red); }
.entry-hl { fill: #ffd34d; fill-opacity: 0.4; stroke: #c9951c; stroke-opacity: 0.7; }
.log-empty { font: italic 13px 'IM Fell English', serif; fill: var(--ink-soft); }

/* --- tesoro --- */

.rays-spin {
  transform-box: fill-box;
  transform-origin: center;
  animation: spin 50s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.pile-coin { fill: url(#gold-coin); stroke: #7a4e0c; stroke-width: 0.8; }

/* --- banner acquisto --- */

#toast {
  position: absolute;
  top: 40%;
  left: 47%;
  text-align: center;
  background: linear-gradient(#ffe27a, var(--gold));
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 0.3em 1.4em 0.45em;
  font-size: calc(var(--map-w) * 0.012);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45), 0 0 50px rgba(255, 210, 80, 0.7);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.toast-title { font: 3.2em/1 'Pirata One', serif; }
.toast-sub { font-style: italic; font-size: 1.5em; }

footer {
  width: var(--map-w);
  margin-top: 6px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.75;
  font-style: italic;
}

@media (max-width: 640px) {
  #meta { margin-left: 0; width: 100%; }
}
