/* Ночной музей — интерфейс в языке музейной этикетки:
   слоновая кость, чернила, сусальное золото, красный штамп. */
:root {
  --bg: #0b0a09;
  --ink: #17130f;
  --ink-2: #4a4136;
  --paper: #ede5d3;
  --paper-2: #dcd1ba;
  --paper-3: #c4b69a;
  --gold: #c9a45a;
  --gold-ink: #7a5a1e;
  --red: #b63a2b;
  --fog: rgba(237, 229, 211, 0.74);
  --fog-2: rgba(237, 229, 211, 0.58);
  --glass: rgba(12, 11, 10, 0.62);
  --line: rgba(237, 229, 211, 0.2);
  --serif: 'Bona Nova', Georgia, 'Times New Roman', serif;
  --sc: 'Bona Nova SC', 'Bona Nova', Georgia, serif;
  --sans: 'Ysabeau Office', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --pad: clamp(16px, 2.2vw, 28px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--paper); overflow: hidden; }
body { font-family: var(--sans); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; touch-action: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; }
kbd { font-family: var(--sans); }
.smallcaps { font-family: var(--sc); letter-spacing: 0.16em; }
[hidden] { display: none !important; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; background: var(--bg); cursor: crosshair; }
body.locked #view { cursor: none; }

/* ---------- кнопки ---------- */
.btn { display: inline-flex; align-items: center; gap: 10px; height: 50px; padding: 0 24px; border-radius: 3px; border: 0; cursor: pointer;
  font-weight: 600; font-size: 16px; letter-spacing: 0.01em; transition: transform 0.25s var(--ease), background-color 0.25s var(--ease), box-shadow 0.25s var(--ease); }
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--paper); color: var(--ink); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.38); padding-left: 20px; }
.btn.primary:hover { background: #f7f1e3; transform: translateY(-1px); box-shadow: 0 16px 38px rgba(0, 0, 0, 0.42); }
.btn.primary:active { transform: translateY(0) scale(0.985); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px rgba(23, 19, 15, 0.35); }
.btn.ghost:hover { background: rgba(23, 19, 15, 0.06); }
.btn.ghost:active { transform: scale(0.985); }
.btn:focus-visible, .ibtn:focus-visible, .close:focus-visible, .tbtn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.keys { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0; padding: 0; }
.keys li { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--fog); }
.keys li span { margin-left: 4px; }
.keys kbd { min-width: 26px; height: 26px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 4px;
  border: 1px solid rgba(237, 229, 211, 0.34); border-bottom-width: 2px; font-weight: 600; font-size: 12px; color: var(--paper); }
.keys kbd.wide { min-width: 44px; }

/* ---------- заставка ---------- */
.intro { position: fixed; inset: 0; display: flex; align-items: center; padding: 0 clamp(24px, 6.5vw, 104px);
  background: linear-gradient(90deg, rgba(8, 7, 6, 0.9) 0%, rgba(8, 7, 6, 0.72) 32%, rgba(8, 7, 6, 0.18) 58%, rgba(8, 7, 6, 0) 70%);
  transition: opacity 0.9s var(--ease), visibility 0s linear 0.9s; }
.intro.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-col { max-width: 560px; transform: translateY(-2vh); }
.kicker { color: var(--gold); font-size: 14px; }
.title { font-family: var(--serif); font-weight: 400; font-size: clamp(58px, 8vw, 116px); line-height: 0.92; letter-spacing: -0.012em; margin: 14px 0 22px; color: var(--paper); }
.lead { font-size: 17px; line-height: 1.58; color: var(--fog); margin: 0; max-width: 31em; }
.lost { margin: 28px 0 32px; }
.lost-head { font-size: 13px; color: var(--fog-2); margin-bottom: 12px; }
.lost-row { list-style: none; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin: 0; padding: 0; }
.lost-row li { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.lost-row .fr { padding: 3px; background: linear-gradient(135deg, #e8c77c, #9a7630 45%, #d9b565 70%, #7a5a22); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5); }
.lost-row .fr canvas { display: block; height: 46px; border: 1px solid rgba(0, 0, 0, 0.55); }
.lost-row .num { font-family: var(--serif); font-size: 13px; color: var(--gold); }
.cta { display: flex; flex-wrap: wrap; align-items: center; gap: 22px 28px; }
.intro-foot { position: absolute; left: clamp(24px, 6.5vw, 104px); bottom: 24px; font-size: 13px; color: var(--fog-2); max-width: 60ch; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.8s var(--ease) 0.2s; }
.hud.on { opacity: 1; }
.hud > * { position: absolute; }
.inventory { top: var(--pad); left: var(--pad); }
.inv-head { display: flex; align-items: baseline; gap: 12px; font-size: 13px; color: var(--fog); margin-bottom: 8px; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8); }
.inv-count { font-family: var(--serif); font-size: 15px; color: var(--paper); font-feature-settings: 'lnum' 1; }
.slots { list-style: none; display: flex; gap: 6px; margin: 0; padding: 0; }
.slot { position: relative; width: 46px; height: 36px; display: grid; place-items: center; border: 1px dashed rgba(201, 164, 90, 0.6); border-radius: 2px;
  background: rgba(11, 10, 9, 0.5); font-family: var(--serif); font-size: 13px; color: var(--gold); overflow: hidden;
  transition: transform 0.4s var(--ease), border-color 0.4s var(--ease); pointer-events: auto; }
.slot canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; transition: opacity 0.5s var(--ease); }
.slot.carried { border: 1px solid var(--paper); transform: translateY(-3px); }
.slot.carried canvas, .slot.returned canvas { opacity: 1; }
.slot.returned { border: 2px solid var(--gold); }
.slot .tick { position: absolute; right: 1px; bottom: 1px; width: 14px; height: 14px; background: var(--gold); border-radius: 1px; display: none; }
.slot .tick svg { width: 14px; height: 14px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.slot.returned .tick { display: block; }
.slot.pulse { animation: pulse 0.9s var(--ease); }
@keyframes pulse { 0% { transform: translateY(-3px) scale(1.25); } 100% { transform: translateY(-3px) scale(1); } }

.clockbox { top: var(--pad); right: calc(var(--pad) + 4 * 46px + 12px); text-align: right; text-shadow: 0 1px 10px rgba(0, 0, 0, 0.8); }
.clock { font-family: var(--serif); font-size: 26px; line-height: 1; color: var(--paper); letter-spacing: 0.02em; font-variant-numeric: lining-nums tabular-nums; font-feature-settings: 'lnum' 1, 'tnum' 1; }
.clock-sub { font-size: 12.5px; color: var(--fog); margin-top: 5px; }
.topbtns { top: var(--pad); right: var(--pad); display: flex; gap: 6px; pointer-events: auto; }
.ibtn { position: relative; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 3px; cursor: pointer;
  background: var(--glass); border: 1px solid var(--line); transition: background-color 0.2s var(--ease), transform 0.2s var(--ease); }
.ibtn:hover { background: rgba(44, 38, 32, 0.78); }
.ibtn:active { transform: scale(0.95); }
.ibtn svg { width: 21px; height: 21px; fill: none; stroke: var(--paper); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ibtn .x { display: none; }
#btnSound[aria-pressed="false"] .w1, #btnSound[aria-pressed="false"] .w2 { display: none; }
#btnSound[aria-pressed="false"] .x { display: inline; }
#btnUV[aria-pressed="true"] { background: rgba(66, 34, 120, 0.8); border-color: rgba(190, 160, 255, 0.5); }
.uvbar { position: absolute; left: 7px; right: 7px; bottom: 5px; height: 2px; background: rgba(237, 229, 211, 0.18); overflow: hidden; }
.uvbar i { position: absolute; inset: 0; background: #b89bff; transform-origin: left center; transform: scaleX(1); transition: transform 0.2s linear; }

.mapcard { left: var(--pad); bottom: var(--pad); padding: 7px; background: var(--paper); border-radius: 2px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5); pointer-events: auto; cursor: pointer; }
.mapcard canvas { display: block; width: 222px; height: 162px; }

.reticle { left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; background: rgba(237, 229, 211, 0.55); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35); }

.prompt { left: 50%; bottom: 110px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 7px 16px 7px 7px;
  background: rgba(12, 11, 10, 0.74); border: 1px solid var(--line); border-radius: 3px; font-size: 14.5px; font-weight: 500; color: var(--paper); white-space: nowrap;
  animation: rise 0.35s var(--ease); }
.prompt kbd { min-width: 28px; height: 28px; display: grid; place-items: center; background: var(--paper); color: var(--ink); border-radius: 3px; font-weight: 700; font-size: 13px; padding: 0 6px; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.label { right: var(--pad); bottom: var(--pad); width: 272px; padding: 16px 18px 14px; background: var(--paper); color: var(--ink); border-radius: 2px;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.5); transform-origin: 100% 100%; animation: card 0.45s var(--ease); }
@keyframes card { from { opacity: 0; transform: translateY(10px) rotate(0.6deg); } to { opacity: 1; transform: none; } }
.l-author { font-family: var(--sc); font-weight: 700; font-size: 13.5px; letter-spacing: 0.06em; padding-right: 70px; }
.l-life { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.l-title { font-family: var(--serif); font-style: italic; font-size: 20px; line-height: 1.18; margin: 9px 0 6px; }
.l-meta { font-size: 13px; color: #3a3229; }
.l-note { font-size: 13px; line-height: 1.4; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--paper-3); color: var(--ink); }
.l-note:empty { display: none; }
.l-note b { color: var(--red); font-weight: 700; }
.stamp { position: absolute; top: 14px; right: 12px; transform: rotate(-8deg); border: 2px solid var(--red); color: var(--red); font-family: var(--sc); font-weight: 700;
  font-size: 12px; letter-spacing: 0.12em; padding: 2px 7px 3px; border-radius: 2px; display: none; }
.label.stolen .stamp { display: block; }
.label.found .stamp { display: block; border-color: #2f6a3e; color: #2f6a3e; }

.toast { left: 50%; top: calc(var(--pad) + 6px); transform: translate(-50%, -8px); text-align: center; opacity: 0; transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.9); max-width: min(560px, 70vw); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.t-kick { color: var(--gold); font-size: 13px; }
.t-title { font-family: var(--serif); font-size: 32px; line-height: 1.1; margin-top: 6px; color: var(--paper); }
.t-sub { font-size: 14px; color: var(--fog); margin-top: 6px; }
.t-sub:empty, .t-kick:empty { display: none; }

.hint { left: 50%; bottom: calc(var(--pad) + 2px); transform: translateX(-50%); font-size: 13px; color: var(--fog); padding: 6px 12px; border-radius: 3px;
  background: rgba(12, 11, 10, 0.55); opacity: 0; transition: opacity 0.4s var(--ease); white-space: nowrap; }
.hint.on { opacity: 1; }

/* ---------- большой план ---------- */
.bigmap { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(8, 7, 6, 0.64); z-index: 5; animation: fade 0.3s var(--ease); }
.bigmap-card { background: var(--paper); color: var(--ink); padding: 16px 18px 14px; border-radius: 2px; box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6); max-width: calc(100vw - 24px); }
.bigmap-head { display: flex; align-items: center; justify-content: space-between; font-size: 14px; color: var(--gold-ink); margin-bottom: 10px; }
.close { width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: transparent; cursor: pointer; border-radius: 3px; }
.close:hover { background: rgba(23, 19, 15, 0.07); }
.close svg { width: 20px; height: 20px; stroke: var(--ink); stroke-width: 1.7; fill: none; stroke-linecap: round; }
#bigmapCanvas { display: block; width: min(740px, calc(100vw - 60px)); height: auto; aspect-ratio: 37 / 27; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 12.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px; border-radius: 1px; }
.lg-you { background: var(--red); clip-path: polygon(0 100%, 50% 0, 100% 100%); }
.lg-empty { box-shadow: inset 0 0 0 2px var(--red); }
.lg-back { background: var(--gold); }
.lg-win { box-shadow: inset 0 -3px 0 #6f8fbf; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- пауза и финал ---------- */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(8, 7, 6, 0.62); z-index: 6; animation: fade 0.35s var(--ease); padding: 16px; }
.card { position: relative; background: var(--paper); color: var(--ink); width: min(470px, calc(100vw - 32px)); padding: 28px 30px 26px; border-radius: 2px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  max-height: calc(100vh - 32px); overflow: auto; animation: card 0.5s var(--ease); }
.card.wide { width: min(760px, calc(100vw - 32px)); }
.card .kicker { color: var(--gold-ink); font-size: 13px; }
.card-title { font-family: var(--serif); font-weight: 400; font-size: 38px; line-height: 1.05; margin: 8px 0 14px; }
.card-lead { font-size: 15px; line-height: 1.55; color: #33291f; margin: 0 0 18px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 18px; margin: 4px 0 22px; padding: 14px 0; border-top: 1px solid var(--paper-3); border-bottom: 1px solid var(--paper-3); }
.stats div { min-width: 0; }
.stats dt { font-size: 12.5px; color: var(--ink-2); }
.stats dd { margin: 3px 0 0; font-family: var(--serif); font-size: 22px; font-feature-settings: 'lnum' 1; }
.card-btns { display: flex; flex-wrap: wrap; gap: 12px; }
.card .btn.primary { background: var(--ink); color: var(--paper); box-shadow: none; }
.card .btn.primary:hover { background: #2a231c; }
.card .keys { margin-top: 22px; }
.card .keys li { color: var(--ink-2); }
.card .keys kbd { color: var(--ink); border-color: rgba(23, 19, 15, 0.35); }
.final-row { list-style: none; display: flex; flex-wrap: wrap; gap: 14px; margin: 6px 0 18px; padding: 0; }
.final-row li { display: flex; flex-direction: column; gap: 6px; width: 88px; }
.final-row .fr { padding: 3px; background: linear-gradient(135deg, #e8c77c, #9a7630 45%, #d9b565 70%, #7a5a22); align-self: flex-start; }
.final-row canvas { display: block; height: 60px; }
.final-row span { font-size: 12px; line-height: 1.3; color: #3a3229; }

/* ---------- сенсорное управление ---------- */
.touch { display: none; }
body.touchui.playing .touch { display: block; position: fixed; inset: 0; pointer-events: none; }
body.touchui .mapcard, body.touchui .hint, body.touchui .clock-sub { display: none; }
.stick { position: absolute; left: 22px; bottom: calc(22px + env(safe-area-inset-bottom)); width: 124px; height: 124px; border-radius: 50%; border: 1px solid var(--line); background: rgba(12, 11, 10, 0.35); pointer-events: auto; }
.stick i { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(237, 229, 211, 0.85); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); }
.tbtn { position: absolute; pointer-events: auto; border-radius: 50%; border: 0; cursor: pointer; font-weight: 700; display: grid; place-items: center; transition: transform 0.2s var(--ease), opacity 0.3s var(--ease); }
.tbtn:active { transform: scale(0.94); }
.tbtn.take { right: 22px; bottom: calc(34px + env(safe-area-inset-bottom)); width: 76px; height: 76px; background: var(--paper); color: var(--ink); font-size: 15px; box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5); opacity: 0.55; }
.tbtn.take.on { opacity: 1; }
.tbtn.uv { right: 110px; bottom: calc(42px + env(safe-area-inset-bottom)); width: 54px; height: 54px; background: var(--glass); color: var(--paper); border: 1px solid var(--line); font-size: 14px; }
.tbtn.uv.on { background: rgba(66, 34, 120, 0.85); }

.fatal { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 10; }

/* ---------- узкие экраны ---------- */
@media (max-width: 760px) {
  .intro { align-items: flex-start; padding: calc(28px + env(safe-area-inset-top)) 20px 0; background: linear-gradient(180deg, rgba(8, 7, 6, 0.92) 0%, rgba(8, 7, 6, 0.78) 46%, rgba(8, 7, 6, 0.2) 72%, rgba(8, 7, 6, 0.55) 100%); }
  .intro-col { transform: none; }
  .title { font-size: clamp(50px, 15vw, 72px); margin: 10px 0 14px; }
  .lead { font-size: 15px; line-height: 1.55; }
  .lost { margin: 20px 0 22px; }
  .lost-row { gap: 6px; }
  .lost-row .fr canvas { height: 30px; }
  .cta .keys { display: none; }
  .cta .btn { width: 100%; justify-content: center; height: 54px; }
  .intro-foot { left: 20px; right: 20px; bottom: calc(18px + env(safe-area-inset-bottom)); font-size: 12px; }
  .inventory { top: calc(12px + 40px + 12px + env(safe-area-inset-top)); left: 12px; }
  .slot { width: 38px; height: 30px; font-size: 12px; }
  .slots { gap: 5px; }
  .inv-head { margin-bottom: 6px; }
  .clockbox { right: auto; left: 12px; top: calc(20px + env(safe-area-inset-top)); text-align: left; }
  .clock { font-size: 22px; }
  .topbtns { gap: 4px; top: calc(12px + env(safe-area-inset-top)); right: 12px; }
  .topbtns .ibtn { width: 40px; height: 40px; }
  .topbtns #btnUV { display: none; }
  .label { left: 12px; right: 12px; width: auto; bottom: calc(150px + env(safe-area-inset-bottom)); padding: 12px 14px 11px; }
  .l-title { font-size: 18px; margin: 6px 0 4px; }
  .prompt { bottom: calc(160px + env(safe-area-inset-bottom)); font-size: 13.5px; }
  .toast { top: calc(128px + env(safe-area-inset-top)); max-width: calc(100vw - 32px); }
  .t-title { font-size: 26px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 22px 20px 20px; }
  .card-title { font-size: 30px; }
}
@media (max-height: 560px) and (min-width: 761px) {
  .title { font-size: 64px; margin: 8px 0 12px; }
  .lost { margin: 16px 0 18px; }
  .lead { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
