:root {
  --paper: #f4e6c8;
  --paper-deep: #ead7b4;
  --ink: #4a301c;
  --muted: #7a5b40;
  --line: rgba(74, 48, 28, 0.28);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: #1c140e;
  color: var(--ink);
  font-family: Literata, "Iowan Old Style", Palatino, serif;
}

button, input { font: inherit; color: inherit; }
button, .chips button, .word-link { touch-action: manipulation; }
:focus-visible { outline: 2px solid #8d5a32; outline-offset: 2px; }

#app { position: relative; height: 100%; }

#map {
  position: absolute;
  inset: 0;
  background: #243028;
  z-index: 0;
}

.leaflet-container { font-family: Literata, Palatino, serif; background: #1d241c; }

.leaflet-control-zoom a {
  background: #f6edd8;
  color: #4a301c;
  border: 0;
  width: 36px;
  height: 36px;
  line-height: 36px;
}

.leaflet-control-zoom { border: 0 !important; border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }

.leaflet-bar a:hover { background: #efe0c4; }

.leaflet-control-attribution {
  background: rgba(20, 16, 12, 0.72) !important;
  color: #f3e6cc !important;
  font-size: 12px;
  letter-spacing: 0.01em;
  max-width: min(420px, 70vw);
  border-radius: 8px 0 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.leaflet-control-attribution a { pointer-events: none; text-decoration: none; color: inherit; }

.rf-flag {
  display: inline-block;
  width: 16px;
  height: 11px;
  vertical-align: -1px;
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.leaflet-control-scale-line {
  background: rgba(246, 237, 216, 0.92);
  border-color: #4a301c;
  color: #4a301c;
}

.leaflet-top.leaflet-right {
  top: calc(var(--chrome-top, 8px) + env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
}

.leaflet-bottom.leaflet-right { margin-bottom: env(safe-area-inset-bottom); }

.pin-anchor { background: transparent; border: 0; }

.pin {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.seal {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #f6edd8;
  border: 2px solid #5c3a1e;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.88), 0 1px 5px rgba(0, 0, 0, 0.55);
}

.pin-city .seal { background: #f3d7a2; }

.pin-stanitsa .seal { border-radius: 3px; }

.pin.is-active .seal {
  background: #8d3b2c;
  border-color: #f6edd8;
  box-shadow: 0 0 0 3px rgba(255, 244, 220, 0.95), 0 0 0 6px rgba(141, 59, 44, 0.45);
}

.pin-name {
  display: none;
  position: absolute;
  left: calc(100% + 4px);
  top: -3px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(246, 237, 216, 0.95);
  color: #3e2a1c;
  font-size: 12.5px;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

#map.zoomed-in .pin-name,
.pin.is-active .pin-name,
.pin:hover .pin-name { display: inline-block; }

#panel-toggle {
  display: none;
  position: absolute;
  z-index: 960;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: #f6edd8;
  color: #4a301c;
  box-shadow: var(--shadow);
  cursor: pointer;
}

#panel-toggle[hidden] { display: none !important; }

#panel {
  position: absolute;
  z-index: 900;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  width: min(332px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  padding: 16px 14px 12px;
  border-radius: 16px;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 252, 245, 0.7), transparent 42%),
    linear-gradient(180deg, #f8efdc, #f1e0c2);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(92, 58, 30, 0.18);
  overflow: hidden;
}

.panel-kicker {
  margin: 0;
  font-family: "Marck Script", cursive;
  font-size: 20px;
  color: #8d3b2c;
}

#panel h1 {
  margin: 0 0 4px;
  font-family: Oranienbaum, "Times New Roman", serif;
  font-size: 30px;
  font-weight: 400;
  letter-spacing: 0.03em;
  line-height: 0.95;
}

.panel-lead {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.35;
}

.chips button,
.place-row,
.pager button,
.tabs button,
.close-plaque {
  cursor: pointer;
}

.chips button {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.55);
  border-radius: 999px;
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
}

.chips button:hover,
.chips button.is-on {
  background: #5c3a1e;
  color: #f6edd8;
  border-color: #5c3a1e;
}

#search {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.8);
  border-radius: 10px;
  padding: 9px 11px;
  outline: none;
  margin-bottom: 8px;
  font-size: 16px;
}

#search:focus { border-color: #8d5a32; box-shadow: 0 0 0 3px rgba(141, 90, 50, 0.15); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

.list-meta {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

#list {
  overflow: auto;
  flex: 1;
  margin: 0 -6px;
  padding: 0 6px 10px;
  min-height: 0;
}

.place-row {
  width: 100%;
  text-align: left;
  border-radius: 10px;
  padding: 7px 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 8px;
}

.row-open {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.word-link {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}


.dot { white-space: pre; }

.place-row:hover, .place-row.is-active { background: rgba(92, 58, 30, 0.08); }

.row-name { font-weight: 650; font-size: 15px; min-width: 0; overflow-wrap: anywhere; }

.row-kind { color: var(--muted); font-size: 12px; font-style: italic; }

.row-words {
  grid-column: 1 / -1;
  color: #6d4c34;
  font-size: 12.5px;
  line-height: 1.3;
}

.empty {
  margin: 12px 8px;
  color: var(--muted);
  font-size: 14px;
}

#plaque {
  position: absolute;
  z-index: 820;
  top: 0;
  left: 0;
  width: min(530px, calc(100vw - 24px));
  pointer-events: none;
}

#plaque.is-in { pointer-events: auto; }

.plaque-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 4px;
  position: relative;
  z-index: 2;
}

.place-ribbon {
  font-family: "Marck Script", cursive;
  font-size: 22px;
  line-height: 1;
  background: #f7f1e4;
  color: #6e2430;
  padding: 8px 14px 10px;
  border-radius: 10px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
}

.close-plaque {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: #f6edd8;
  color: #4a301c;
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 4px 0;
}

.tabs button {
  border: 0;
  background: rgba(246, 237, 216, 0.92);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: Oranienbaum, serif;
  font-size: 16px;
  letter-spacing: 0.04em;
}

.tabs button.is-on {
  background: #5c3a1e;
  color: #f6edd8;
}


.poster-card {
  display: block;
  width: min(100%, 460px);
  height: auto;
  margin: 4px auto 0;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 8px;
  background: #f4e6c8;
}


.sheet {
  position: relative;
  margin-top: 6px;
  padding: 18px 16px 12px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 252, 245, 0.75), transparent 36%),
    radial-gradient(circle at 100% 100%, rgba(120, 72, 36, 0.08), transparent 40%),
    linear-gradient(180deg, #f8f0de, #f3e4c6 45%, #efe0c2);
  box-shadow:
    inset 0 0 0 1px rgba(90, 52, 24, 0.2),
    inset 0 0 40px rgba(90, 50, 20, 0.08),
    0 22px 50px rgba(0, 0, 0, 0.42),
    8px 10px 0 #ead9b8,
    9px 11px 0 rgba(90, 58, 32, 0.45);
  max-height: min(620px, calc(100dvh - 180px));
  overflow: auto;
}

.sheet::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1.5px solid var(--rule, rgba(92, 58, 30, 0.28));
  border-radius: 8px;
  pointer-events: none;
}

.sheet[data-palette="umber"] { --ink: #5c3317; --floral: #a33b32; --rule: rgba(92, 51, 23, 0.35); }
.sheet[data-palette="wine"] { --ink: #6b1d3a; --floral: #8e2f4a; --rule: rgba(107, 29, 58, 0.32); }
.sheet[data-palette="olive"] { --ink: #5c4a22; --floral: #8a6230; --rule: rgba(92, 74, 34, 0.32); }
.sheet[data-palette="clay"] { --ink: #6a3b28; --floral: #b85a38; --rule: rgba(106, 59, 40, 0.3); }
.sheet[data-palette="gold"] { --ink: #6a4a16; --floral: #b86a30; --rule: rgba(106, 74, 22, 0.3); }
.sheet[data-palette="moss"] { --ink: #2c4a32; --floral: #c45c3e; --rule: rgba(44, 74, 50, 0.3); }
.sheet[data-palette="rose"] { --ink: #7a3148; --floral: #b84a62; --rule: rgba(122, 49, 72, 0.28); }
.sheet[data-palette="sea"] { --ink: #2c4a55; --floral: #c46b4a; --rule: rgba(44, 74, 85, 0.3); }
.sheet[data-palette="night"] { --ink: #3a342c; --floral: #8a4030; --rule: rgba(58, 52, 44, 0.32); }

.corner {
  position: absolute;
  width: 78px;
  height: 78px;
  color: var(--floral);
  pointer-events: none;
}

.corner.tl { top: 4px; left: 4px; }
.corner.tr { top: 4px; right: 4px; transform: scaleX(-1); }
.corner.bl { bottom: 4px; left: 4px; transform: scaleY(-1); }
.corner.br { bottom: 4px; right: 4px; transform: scale(-1); }


.pager {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  color: #f6edd8;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  font-size: 13px;
}

.pager button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: rgba(246, 237, 216, 0.94);
  color: #4a301c;
}

#plaque.is-in .sheet { animation: rise 0.28s ease; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  #plaque.is-in .sheet { animation: none; }
}

@media (min-width: 1400px) {
  #panel { width: min(380px, calc(100vw - 40px)); }
  #panel h1 { font-size: 34px; }
}

@media (max-width: 800px), (max-height: 520px) {
  #panel-toggle { display: inline-flex; align-items: center; }
  #panel.is-collapsed { display: none; }
  #panel {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    width: auto;
    max-height: min(62dvh, 520px);
    padding-top: 58px;
  }
  .panel-lead { display: none; }
  #panel h1 { font-size: 26px; }
  #plaque.docked {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    top: auto;
    width: auto;
    transform: none !important;
    max-height: min(68dvh, calc(100dvh - var(--chrome-top, 8px) - 24px));
    overflow: auto;
  }
  #plaque.docked .sheet { max-height: none; width: 100%; }
  .corner { width: 52px; height: 52px; }
  .leaflet-control-attribution { font-size: 11px; max-width: min(240px, 62vw); }
}

@media (max-height: 520px) and (min-width: 700px) {
  #panel {
    right: auto;
    width: min(300px, 42vw);
    max-height: calc(100dvh - 16px - env(safe-area-inset-top));
  }
  #plaque.docked {
    left: auto;
    width: min(460px, 50vw);
    max-height: calc(100dvh - 16px);
  }
}

@media (max-width: 380px) {
  #panel h1 { font-size: 22px; }
  .place-ribbon { font-size: 18px; }
  .tabs button { font-size: 15px; }
}

@media (pointer: coarse) {
  .leaflet-control-zoom a { width: 44px; height: 44px; line-height: 44px; }
  .word-link { padding: 4px 0; }
}

