:root {
  --paper: #e7dcc0;
  --paper-light: #f3ebd7;
  --paper-dark: #cbbb95;
  --ink: #3b2c22;
  --ink-soft: #7a6552;
  --madder: #9e2b3b;
  --indigo: #2f5573;
  --ochre: #c08a2e;
  --edge: rgba(59, 44, 34, 0.55);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #b8a884;
  color: var(--ink);
  font-family: Alegreya, Georgia, serif;
  font-size: 17px;
  overscroll-behavior: none;
}

#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }

/* ---------------------------------------------------------- бумажные кнопки */
.tag {
  font-family: Neucha, cursive;
  font-size: 19px;
  line-height: 1;
  color: var(--ink);
  background: linear-gradient(176deg, var(--paper-light), var(--paper));
  border: 1.6px solid var(--edge);
  border-radius: 14px 7px 15px 8px / 8px 15px 7px 14px;
  padding: 8px 14px 9px;
  cursor: pointer;
  box-shadow: 1px 2px 0 rgba(59, 44, 34, 0.18);
  transform: rotate(-0.7deg);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.tag:nth-child(even) { transform: rotate(0.8deg); }
.tag:hover { transform: rotate(0deg) translateY(-1px); box-shadow: 1px 3px 0 rgba(59, 44, 34, 0.22); }
.tag:active { transform: rotate(0deg) translateY(1px); box-shadow: 0 1px 0 rgba(59, 44, 34, 0.2); }
.tag[aria-pressed="true"] { background: linear-gradient(176deg, #e8cfa8, #dcc396); }
.tag.round { padding: 10px 16px; font-size: 22px; }
.tag:focus-visible { outline: 2.5px dashed var(--madder); outline-offset: 3px; }

/* главная кнопка и меню живут внизу по центру, где их ищут пальцем */
#bar {
  position: fixed;
  left: 50%;
  bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 6;
}

.tag.primary {
  font-size: 22px;
  padding: 11px 22px 12px;
  color: #f7efdd;
  background: linear-gradient(176deg, #b3394a, #8a2131);
  border-color: #6f1c28;
  box-shadow: 1px 3px 0 rgba(59, 44, 34, 0.3);
}
.tag.primary:hover { background: linear-gradient(176deg, #c04256, #93283a); }
.tag.primary::after { content: " →"; }

#progress {
  font-family: Neucha, cursive;
  font-size: 15px;
  color: var(--ink-soft);
  background: linear-gradient(176deg, var(--paper-light), var(--paper));
  border: 1.4px solid var(--edge);
  border-radius: 11px 6px 12px 7px / 7px 12px 6px 11px;
  padding: 6px 10px 7px;
  transform: rotate(-0.6deg);
  white-space: nowrap;
}

#menu {
  position: fixed;
  left: 50%;
  bottom: calc(126px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: min(520px, calc(100vw - 24px));
  z-index: 6;
}

/* ---------------------------------------------------------- шкала времени */
#scalebar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 32px));
  height: 44px;
  background: linear-gradient(176deg, var(--paper-light), var(--paper));
  border: 1.6px solid var(--edge);
  border-radius: 10px 6px 12px 7px / 7px 12px 6px 10px;
  box-shadow: 1px 2px 0 rgba(59, 44, 34, 0.18);
  cursor: pointer;
  z-index: 5;
  overflow: hidden;
}
#scalebar .months { display: flex; height: 100%; align-items: stretch; }
#scalebar .m {
  flex: 1 1 auto;
  border-right: 1px solid rgba(59, 44, 34, 0.25);
  font-family: Neucha, cursive;
  font-size: 15px;
  color: var(--ink-soft);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 3px;
  position: relative;
}
#scalebar .m:last-child { border-right: 0; }
#scalebar .m:nth-child(odd)::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 11px;
  background: repeating-linear-gradient(90deg, rgba(59,44,34,.5) 0 6px, transparent 6px 12px);
  opacity: .5;
}
#scalebar .cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--madder);
  box-shadow: 0 0 0 1px rgba(243, 235, 215, 0.8);
  pointer-events: none;
}
#scalebar .cursor::after {
  content: "";
  position: absolute;
  top: -1px;
  left: -5px;
  border: 6px solid transparent;
  border-top-color: var(--madder);
}

#walkbar {
  position: fixed;
  left: 50%;
  bottom: calc(126px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 5;
}
body:not(.walking) #walkbar { display: none; }

/* ---------------------------------------------------------- листы */
#sheets { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

.sheet {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 16px;
  width: min(430px, calc(100vw - 32px));
  max-height: calc(100vh - 150px - env(safe-area-inset-top, 0px));
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0) 22%),
    var(--paper-tex, none) 0 0 / 300px repeat,
    linear-gradient(174deg, var(--paper-light), var(--paper) 60%, var(--paper-dark));
  background-blend-mode: normal, multiply, normal;
  border: 1.6px solid var(--edge);
  border-radius: 6px 10px 5px 12px / 12px 5px 11px 6px;
  box-shadow: 3px 7px 0 rgba(59, 44, 34, 0.16), 0 18px 40px rgba(40, 30, 20, 0.22);
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  overflow: visible;
  pointer-events: auto;
  transform: rotate(-0.35deg);
  animation: drop 0.22s ease-out;
}
.sheet.wide { width: min(620px, calc(100vw - 32px)); }
@keyframes drop {
  from { opacity: 0; transform: rotate(-2.4deg) translateY(-18px) scale(0.965); }
  60% { opacity: 1; transform: rotate(0.4deg) translateY(2px) scale(1.004); }
}
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet::before {  /* скотч */
  content: "";
  position: absolute;
  top: -11px;
  left: 50%;
  width: 96px;
  height: 22px;
  transform: translateX(-50%) rotate(-1.4deg);
  background: rgba(222, 206, 160, 0.65);
  border-left: 1px dashed rgba(59,44,34,.25);
  border-right: 1px dashed rgba(59,44,34,.25);
  box-shadow: 0 1px 2px rgba(59,44,34,.15);
}

/* прокручивается только начинка, крестик остаётся на месте */
.sheet .sbody {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sheet .close {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: 1.4px solid var(--edge);
  border-radius: 50%;
  background: rgba(243, 235, 215, 0.94);
  font-family: Neucha, cursive;
  font-size: 21px;
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(59, 44, 34, 0.18);
}
.sheet .close:hover { color: var(--madder); border-color: var(--madder); }

.sheet h2 {
  font-family: Neucha, cursive;
  font-weight: 400;
  font-size: 30px;
  line-height: 1.12;
  margin: 2px 26px 2px 0;
}
.sheet .when { font-style: italic; color: var(--ink-soft); margin: 4px 0 12px; font-size: 16px; }
.sheet p { margin: 0 0 14px; line-height: 1.5; }
.sheet .caption { font-size: 18px; }
.sheet .sub { font-family: Neucha, cursive; font-size: 20px; margin: 18px 0 8px; color: var(--ink-soft); }

.quote {
  position: relative;
  margin: 0 0 9px;
  padding: 9px 13px 10px;
  background: rgba(255, 253, 244, 0.6);
  border: 1.2px solid rgba(59, 44, 34, 0.3);
  border-radius: 13px 5px 13px 6px / 6px 13px 5px 13px;
  font-size: 16.5px;
  line-height: 1.42;
  white-space: pre-line;   /* стихи и списки приходят с переносами */
}
.quote .who { font-family: Neucha, cursive; font-size: 15px; display: block; margin-bottom: 1px; }
.quote.me { border-color: rgba(47, 85, 115, 0.5); margin-right: 26px; }
.quote.me .who { color: var(--indigo); }
.quote.her { border-color: rgba(158, 43, 59, 0.45); margin-left: 26px; background: rgba(255, 246, 240, 0.6); }
.quote.her .who { color: var(--madder); }
.quote .t { float: right; font-size: 13px; color: var(--ink-soft); font-style: italic; margin-left: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  font-family: Neucha, cursive;
  font-size: 15px;
  padding: 3px 9px 4px;
  border: 1.2px dashed rgba(59, 44, 34, 0.4);
  border-radius: 9px 4px 9px 5px / 5px 9px 4px 9px;
  color: var(--ink-soft);
}
.media img, .media video { max-width: 100%; border: 1.4px solid var(--edge); border-radius: 3px; display: block; margin: 0 0 10px; }
.media audio { width: 100%; margin-bottom: 10px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* лента сообщений */
.msgs { max-height: 46vh; overflow-y: auto; overflow-x: hidden; }
.msg { margin: 0 0 7px; font-size: 16px; line-height: 1.4; overflow-wrap: anywhere; }
.msg .t { font-size: 13px; color: var(--ink-soft); font-style: italic; margin-right: 6px; }
.msg.me .name { color: var(--indigo); }
.msg.her .name { color: var(--madder); }
.msg .name { font-family: Neucha, cursive; margin-right: 6px; }
.msg .mt { font-family: Neucha, cursive; color: var(--ink-soft); }
.daymark { font-family: Neucha, cursive; color: var(--ink-soft); margin: 12px 0 6px; border-bottom: 1px dashed rgba(59,44,34,.3); }

/* поиск */
.field {
  width: 100%;
  font-family: Neucha, cursive;
  font-size: 20px;
  padding: 9px 12px;
  background: rgba(255, 253, 244, 0.7);
  border: 1.4px solid var(--edge);
  border-radius: 10px 5px 11px 6px / 6px 11px 5px 10px;
  color: var(--ink);
}
.field:focus { outline: 2.5px dashed var(--madder); outline-offset: 2px; }
.hit { cursor: pointer; padding: 7px 8px; border-bottom: 1px dotted rgba(59,44,34,.25); }
.hit:hover { background: rgba(255, 253, 244, 0.55); }
.hit mark { background: rgba(224, 194, 92, 0.55); color: inherit; }

/* журнал */
.stat { display: flex; align-items: baseline; gap: 10px; margin-bottom: 7px; }
.stat .num { font-size: 26px; font-family: Neucha, cursive; }
.stat .lbl { color: var(--ink-soft); }
.bars { margin: 6px 0 16px; }
.bar { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 15px; }
.bar i { display: block; height: 11px; background: var(--indigo); opacity: 0.75; border-radius: 2px; }
.bar.her i { background: var(--madder); }
.bar span { font-family: Neucha, cursive; color: var(--ink-soft); min-width: 42px; }
.words { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-bottom: 14px; }
.words b { font-weight: 400; font-family: Neucha, cursive; font-size: 18px; }
.words b i { font-style: normal; color: var(--ink-soft); font-size: 14px; }

/* письмо */
.letter { font-family: "Bad Script", cursive; font-size: 22px; line-height: 1.5; white-space: pre-line; }
.letter .sign { display: block; text-align: right; margin-top: 16px; color: var(--madder); }

#scalebar .fog {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(135deg, rgba(122, 112, 96, 0.3) 0 6px, rgba(155, 147, 130, 0.16) 6px 12px);
  border-left: 1.6px dashed rgba(59, 44, 34, 0.55);
  pointer-events: none;
}

.hint-note {
  position: fixed;
  left: 16px;
  bottom: calc(128px + env(safe-area-inset-bottom, 0px));
  max-width: 320px;
  z-index: 6;
  font-family: Neucha, cursive;
  font-size: 17px;
  line-height: 1.35;
  color: var(--ink-soft);
  background: linear-gradient(176deg, var(--paper-light), var(--paper));
  border: 1.4px solid var(--edge);
  border-radius: 12px 6px 13px 7px / 7px 13px 6px 12px;
  box-shadow: 1px 2px 0 rgba(59, 44, 34, 0.16);
  padding: 9px 13px 10px;
  transform: rotate(-0.8deg);
  transition: opacity 0.8s ease;
  cursor: pointer;        /* по подсказке можно нажать, чтобы убрать */
}
.hint-note.gone { opacity: 0; }
/* лист открыт - подсказка уходит вправо, чтобы не лежать на карточке */
body.sheet-open .hint-note { left: auto; right: 16px; }
body.menu-open .hint-note { bottom: calc(196px + env(safe-area-inset-bottom, 0px)); }

/* ---------------------------------------------------------- конверт */
#intro {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, #6d6350, #2f2a22 80%);
  padding: 20px;
}
#intro.gone { display: none; }
.envelope {
  position: relative;
  width: min(520px, 92vw);
  background: linear-gradient(172deg, var(--paper-light), var(--paper) 70%, var(--paper-dark));
  border: 1.6px solid var(--edge);
  border-radius: 4px;
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.5);
  padding: 46px 30px 34px;
  text-align: center;
  transition: transform 0.5s ease, opacity 0.5s ease;
}
.envelope .flap {
  position: absolute;
  inset: 0 0 auto;
  height: 118px;
  background: linear-gradient(176deg, var(--paper), var(--paper-dark));
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  border-bottom: 1.4px solid rgba(59, 44, 34, 0.25);
  transform-origin: top;
  transition: transform 0.6s ease;
}
#intro.opening .flap { transform: rotateX(180deg); }
#intro.opening .envelope { transform: translateY(24px) scale(1.04); opacity: 0; }
.envelope .to { font-family: "Bad Script", cursive; font-size: 34px; margin: 84px 0 10px; }
.envelope .dedication {
  font-family: Neucha, cursive;
  font-size: 19px;
  line-height: 1.5;
  white-space: pre-line;
  text-align: left;
  color: var(--ink-soft);
  max-width: 30em;
  margin: 0 auto 24px;
}
.envelope .seal {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 36% 32%, #c4485a, #7e1f2d 70%);
  color: #f5e6d0;
  font-family: "Bad Script", cursive;
  font-size: 34px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35), inset 0 -3px 8px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease;
}
.envelope .seal:hover { transform: scale(1.05) rotate(-4deg); }
.envelope .hint { font-family: Neucha, cursive; color: var(--ink-soft); margin-top: 12px; font-size: 16px; }

/* мобильная раскладка вынесена в mobile.css */

/* письмо в меню светится, пока его не открыли */
.tag.glow {
  color: var(--madder);
  border-color: rgba(158, 43, 59, 0.6);
  background-image: linear-gradient(176deg, #fff7e2, #f4e2b8),
    linear-gradient(100deg, rgba(255, 244, 214, 0) 36%, rgba(255, 233, 168, 0.98) 50%, rgba(255, 244, 214, 0) 64%);
  background-size: 100% 100%, 260% 100%;
  background-repeat: no-repeat;
  animation: tagShine 2.8s linear infinite, tagGlow 2.2s ease-in-out infinite;
}
@keyframes tagShine {
  from { background-position: 0 0, 150% 0; }
  to { background-position: 0 0, -50% 0; }
}
@keyframes tagGlow {
  0%, 100% { box-shadow: 1px 2px 0 rgba(59, 44, 34, 0.18), 0 0 8px 1px rgba(224, 178, 74, 0.4); }
  50% { box-shadow: 1px 2px 0 rgba(59, 44, 34, 0.18), 0 0 20px 5px rgba(224, 178, 74, 0.8); }
}
@media (prefers-reduced-motion: reduce) {
  .tag.glow { animation: none; box-shadow: 1px 2px 0 rgba(59, 44, 34, 0.18), 0 0 12px 2px rgba(224, 178, 74, 0.5); }
}

/* кнопка «стрелка» в верхнем углу: убрать подсказку, когда хочется просто смотреть карту */
#topbar {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 6;
}
#topbar .tag { font-size: 17px; padding: 7px 12px 8px; opacity: 0.92; }
#topbar .tag[aria-pressed="false"] { color: var(--ink-soft); text-decoration: line-through; }
