/* ---- Ты — платформер: минималистичное оформление ---- */

:root {
  --paper: #f5f4f0;
  --ink: #14140f;
  --ink-soft: #6d6c62;
  --line: #d9d7cf;
  --accent: #e0a500;
  --danger: #c0442d;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(20, 20, 15, .06), 0 12px 32px rgba(20, 20, 15, .10);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121311;
    --ink: #eceae2;
    --ink-soft: #91908a;
    --line: #2b2c29;
    --accent: #e8b027;
    --danger: #e2705a;
    --card: #191a18;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

@supports (height: 100dvh) {
  html, body { height: 100dvh; }   /* чтобы адресная строка телефона не резала верстку */
}

body {
  margin: 0;
  position: fixed;          /* iOS: страница не тянется резинкой */
  inset: 0;
  touch-action: manipulation;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Верхняя панель ---------- */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(12px, 3vw, 28px);
  padding-top: calc(14px + env(safe-area-inset-top));
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--accent);
}

.brand-name { white-space: nowrap; }

.topbar-actions { display: flex; gap: 8px; }

/* ---------- Кнопки ---------- */

.btn {
  appearance: none;
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, background-color .15s, transform .08s;
}

.btn:hover { border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.btn-primary:hover { opacity: .88; }

.btn-big { padding: 12px 28px; font-size: 16px; }

.btn-icon {
  width: 38px;
  padding: 8px 0;
  text-align: center;
  line-height: 1;
}

.btn-icon[aria-pressed="false"] {
  color: var(--ink-soft);
  opacity: .6;
  text-decoration: line-through;
}

/* ---------- Игровая область ---------- */

.play {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stage {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 clamp(8px, 3vw, 28px);
  min-height: 0;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 1120px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  touch-action: none;
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 0 clamp(20px, 4vw, 34px);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  max-width: 1120px;
  width: 100%;
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.hud-key {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ---------- Оверлей поверх игры ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--card);
  background: color-mix(in srgb, var(--card) 80%, transparent);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  border-radius: var(--radius);
}

.overlay[hidden] { display: none; }

.overlay-card { text-align: center; max-width: 380px; }

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: clamp(21px, 4vw, 30px);
  letter-spacing: -.02em;
}

.overlay-card p {
  margin: 0 0 20px;
  color: var(--ink-soft);
  white-space: pre-line;
}

/* ---------- Подсказки внизу ---------- */

.hints {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  color: var(--ink-soft);
  font-size: 12.5px;
}

.hints-priv { opacity: .75; }

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  margin-right: 3px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--card);
  font: inherit;
  font-size: 11px;
  text-align: center;
}

/* ---------- Экранные кнопки ---------- */
/* по умолчанию (телефон лёжа, планшет) кнопки лежат поверх поля */

.touch {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 clamp(14px, 4vw, 34px) 16px;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch[hidden] { display: none; }
.touch-move { display: flex; gap: 14px; }

.tbtn {
  pointer-events: auto;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--card);
  background: color-mix(in srgb, var(--card) 82%, transparent);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .08s, color .08s, transform .08s;
}

.tbtn.is-down {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  transform: scale(.94);
}

.tbtn-jump { width: 92px; height: 92px; font-size: 30px; }

/* телефон вертикально: кнопки живут отдельной полосой под полем,
   чтобы пальцы не закрывали игру */
@media (pointer: coarse) and (orientation: portrait) {
  /* поле держим ближе к квадрату: так герой крупнее и виден путь вперёд */
  .stage { max-height: 118vw; }
  .touch {
    position: static;
    flex: none;
    margin-top: auto;
    padding: 10px clamp(16px, 6vw, 40px) calc(10px + env(safe-area-inset-bottom));
  }
  .tbtn { width: 78px; height: 78px; }
  .tbtn-jump { width: 96px; height: 96px; }
  .hints { display: none; }
  .stage { padding: 0 8px; }
}

/* телефон лёжа: экономим каждый пиксель по высоте */
@media (pointer: coarse) and (orientation: landscape) {
  .topbar { padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 8px; }
  .hints { display: none; }
  .tbtn { width: 62px; height: 62px; font-size: 22px; }
  .tbtn-jump { width: 78px; height: 78px; font-size: 26px; }
  .touch { padding-bottom: 10px; }
}

/* ---------- Модальное окно с лицом ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 20, 15, .45);
  animation: fade .18s ease-out;
}

.modal[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }

.modal-card {
  position: relative;
  width: min(460px, 100%);
  max-height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 26px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 21px;
  letter-spacing: -.02em;
}

.modal-sub {
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: 13.5px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover { background: var(--paper); color: var(--ink); }

/* ---------- Зона загрузки ---------- */

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 26px 18px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background-color .15s;
}

.drop:hover, .drop.is-over {
  border-color: var(--ink);
  background: var(--paper);
}

.drop-icon { font-size: 22px; color: var(--ink-soft); }
.drop-title { font-weight: 600; }
.drop-note { font-size: 12.5px; color: var(--ink-soft); }
.drop.is-busy { pointer-events: none; opacity: .55; }

/* ---------- Статус обработки ---------- */

.status {
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: 11px;
  font-size: 13.5px;
  background: var(--paper);
  border: 1.5px solid var(--line);
}

.status[hidden] { display: none; }
.status.is-error { border-color: var(--danger); color: var(--danger); }
.status.is-ok { border-color: var(--accent); }

/* ---------- Превью лица ---------- */

.preview-row {
  display: flex;
  gap: 18px;
  align-items: center;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1.5px solid var(--line);
}

.preview { text-align: center; flex: none; }

.preview-frame {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid var(--line);
  background: var(--paper);
}

#preview-canvas { display: block; width: 100%; height: 100%; }

.preview-label {
  display: block;
  margin-top: 7px;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.preview-actions { flex: 1 1 auto; }
.preview-tip { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-soft); }

/* ---------- Узкие экраны ---------- */

@media (max-width: 700px) {
  body { font-size: 14px; }
  .hints span:not(.hints-priv) { display: none; }
  .brand-name { display: none; }
  .btn { padding: 9px 14px; }
  #game { border-radius: 12px; }
  .hud { top: 12px; gap: 6px 14px; padding: 0 16px; }
  .hud-item { font-size: 12px; }
  .modal-card { padding: 20px 18px; }
  .preview-row { gap: 14px; }
}

@media (max-width: 420px) {
  .hud-deaths { display: none; }
}

@media (max-height: 520px) and (pointer: fine) {
  .hints { display: none; }
}
