:root {
  --sea-night: #13303a;
  --sea-deep: #0d232b;
  --parchment: #efe0ba;
  --parchment-edge: #d8bd85;
  --ink: #3a2516;
  --ink-soft: #6b4a2b;
  --seal: #9b2a1f;
  --seal-dark: #6e1c14;
  --gold: #d6a640;

  --font-display: "Ruslan Display", "Georgia", "Times New Roman", serif;
  --font-body: "Kurale", "Georgia", "Times New Roman", serif;
  --font-hand: "Marck Script", "Segoe Script", "Comic Sans MS", cursive;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: inherit; }

html { height: 100%; background: #13303a; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.6;
  color: var(--parchment);
  background-color: var(--sea-night);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(214, 166, 64, .12), transparent 55%),
    radial-gradient(ellipse at 100% 100%, var(--sea-deep), transparent 60%),
    repeating-linear-gradient(170deg, rgba(255,255,255,.025) 0 2px, transparent 2px 22px);
}

/* ---------- Шапка ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px 24px 8px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { font-size: 34px; line-height: 1; color: var(--gold); }
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(26px, 4vw, 40px);
  letter-spacing: .02em;
  color: var(--parchment);
  text-shadow: 0 2px 0 var(--sea-deep);
}

.clock {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 12px;
  align-items: baseline;
  padding: 8px 16px;
  border: 1px solid rgba(214, 166, 64, .45);
  border-radius: 6px;
  background: rgba(13, 35, 43, .6);
}
.clock-label { color: var(--gold); font-size: 15px; }
.clock-time {
  font-family: var(--font-display);
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  color: var(--parchment);
  grid-row: span 2;
}
.clock-date { font-size: 14px; color: rgba(239, 224, 186, .7); }

.error {
  max-width: 1272px;
  margin: 8px auto 0;
  padding: 10px 16px;
  border-radius: 6px;
  background: var(--seal);
  color: #fff;
}

/* ---------- Раскладка ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr);
  gap: 28px;
  align-items: start;
  max-width: 1320px;
  margin: 0 auto;
  padding: 16px 24px 48px;
}

@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; padding: 12px 12px 40px; gap: 18px; }
  .topbar { padding: 14px 12px 4px; }
}

/* ---------- Карта ---------- */

.map-paper {
  padding: 10px;
  border-radius: 4px;
  background: var(--parchment);
  box-shadow:
    inset 0 0 50px rgba(120, 80, 30, .45),
    0 18px 40px rgba(0, 0, 0, .45);
  transform: rotate(-.4deg);
}
#map { display: block; width: 100%; height: auto; }

#fog { transition: opacity 3s ease; }
#fog.lifted { opacity: 0; }

.compass-letter, .cartouche, .mark-label, .target-q {
  text-anchor: middle;
  fill: var(--ink);
}
.compass-letter { font-family: var(--font-display); font-size: 16px; }
.cartouche { font-family: var(--font-display); font-size: 22px; }

.mark-x { stroke: var(--seal); stroke-width: 4.5; stroke-linecap: round; fill: none; }
.mark-start { fill: var(--ink); }
.mark-label {
  font-family: var(--font-hand);
  font-size: 23px;
  paint-order: stroke;
  stroke: #efe1bb;
  stroke-width: 5px;
  stroke-linejoin: round;
}
.mark.fresh { opacity: 0; animation: appear .8s ease 1.6s forwards; }

.target-ring {
  fill: rgba(239, 225, 187, .85);
  stroke: var(--seal);
  stroke-width: 2.5;
  stroke-dasharray: 5 4;
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 2.4s ease-in-out infinite;
}
.target-q { font-family: var(--font-display); font-size: 24px; fill: var(--seal); }

.player-bob { animation: bob 2.6s ease-in-out infinite; }
#chestOpen.show { animation: appear 1.2s ease 1.2s both; }

@keyframes appear { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 50% { transform: scale(1.18); } }
@keyframes bob { 50% { transform: translateY(-5px); } }

/* ---------- Свиток с заданием ---------- */

.card {
  position: relative;
  padding: 30px 30px 32px;
  border-radius: 3px;
  color: var(--ink);
  background:
    radial-gradient(ellipse at center, #f5e9cb 50%, var(--parchment-edge) 100%);
  box-shadow:
    inset 0 0 40px rgba(120, 80, 30, .35),
    0 18px 40px rgba(0, 0, 0, .45);
}
.card::before, .card::after {
  content: "";
  position: absolute;
  left: -8px; right: -8px;
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(#b48a52, #7a5530);
  box-shadow: 0 2px 4px rgba(0,0,0,.35);
}
.card::before { top: -7px; }
.card::after { bottom: -7px; }

.card h2 {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.2;
  color: var(--seal-dark);
}
.card p { margin: 0 0 12px; max-width: 62ch; }
.muted { color: var(--ink-soft); }

.riddle {
  margin: 20px 0;
  padding: 16px 20px;
  border: 2px dashed rgba(91, 58, 30, .55);
  border-radius: 4px;
  background: rgba(214, 189, 133, .28);
  font-family: var(--font-hand);
  font-size: 26px;
  line-height: 1.4;
  white-space: pre-line;
}

.answer-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.answer-form input {
  flex: 1 1 200px;
  min-width: 0;
  padding: 10px 4px 6px;
  border: 0;
  border-bottom: 2px solid var(--ink);
  background: transparent;
  font: inherit;
  font-size: 20px;
  color: var(--ink);
}
.answer-form input::placeholder { color: rgba(58, 37, 22, .45); }
.answer-form input:focus { outline: none; border-bottom-color: var(--seal); }

.btn {
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 30%, #c0463a, var(--seal) 60%, var(--seal-dark));
  box-shadow: 0 3px 0 var(--seal-dark), 0 6px 14px rgba(0,0,0,.25);
  font: inherit;
  font-size: 18px;
  color: #fbe9c4;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--seal-dark); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:focus-visible, .answer-form input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.feedback { min-height: 1.6em; margin-top: 12px; font-size: 18px; color: var(--seal); }

.hint {
  margin-top: 16px;
  padding: 10px 14px;
  border-left: 4px solid var(--gold);
  background: rgba(214, 166, 64, .18);
}

.shake { animation: shake .45s; }
@keyframes shake {
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

/* Ожидание */
.danger-icon { font-size: 46px; line-height: 1; margin-bottom: 8px; }
.note {
  margin: 0 0 18px;
  padding: 10px 14px;
  border-left: 4px solid var(--seal);
  background: rgba(155, 42, 31, .08);
}
.unlock-at { font-size: 19px; }
.countdown { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.countdown div {
  flex: 1 1 0;
  min-width: 0;
  max-width: 92px;
  padding: 8px 6px 4px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  text-align: center;
  background: rgba(255, 255, 255, .18);
}
.countdown b {
  display: block;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.countdown span { font-size: 14px; color: var(--ink-soft); }

.code-input {
  font-family: var(--font-display) !important;
  font-size: 24px !important;
  letter-spacing: .08em;
  text-align: center;
}

/* Успех и финал */
.success h2 { color: #4b6b2a; }
.final h2 { font-size: clamp(28px, 3.6vw, 38px); }
.coins { position: relative; height: 0; }
.coin {
  position: absolute;
  left: 50%; top: 0;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe7a0, var(--gold) 60%, #8a6414);
  animation: fly 1.3s cubic-bezier(.2,.7,.4,1) forwards;
}
@keyframes fly {
  from { transform: translate(0, 0) scale(.4); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .player-bob, .target-ring { animation: none; }
}
