* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  color-scheme: dark;
  --bg: #090b0f;
  --panel: rgba(18, 21, 26, 0.95);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e7e9ed;
  --muted: #7d858f;
  --accent: #c9d0d8;
}

html,
body {
  min-height: 100%;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 20%, rgba(90, 100, 120, 0.16), transparent 38%),
    linear-gradient(180deg, #0c0f14 0%, var(--bg) 100%);
  color: var(--text);
  font-family:
    Inter,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
}

.page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.game-card {
  width: min(1040px, 100%);
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  background: var(--panel);
  box-shadow:
    0 32px 90px rgba(0, 0, 0, 0.42),
    inset 0 1px rgba(255, 255, 255, 0.025);
  backdrop-filter: blur(8px);
}

.game-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 18px;
  border-bottom: 1px solid var(--panel-border);
  color: #707782;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5e6671;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.025);
}

.character-state strong,
.speed strong,
.score strong {
  color: #c4c9d0;
  font-weight: 500;
}

.speed {
  margin-left: auto;
}

.score {
  margin-left: 6px;
}

.canvas-wrap {
  position: relative;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 960 / 360;
  background: #101318;
  cursor: pointer;
  touch-action: manipulation;
}

.start-overlay,
.game-over-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 18px;
  background: rgba(7, 9, 12, 0.52);
  backdrop-filter: blur(2px);
}

.start-overlay[hidden],
.game-over-overlay[hidden] {
  display: none;
}

.overlay-box {
  width: min(760px, 100%);
  padding: 24px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  background: rgba(16, 19, 24, 0.92);
  box-shadow: 0 18px 50px rgba(0,0,0,0.28);
  text-align: center;
}

.overlay-box.compact {
  width: min(420px, 100%);
}

.overlay-box h1 {
  font-size: 1.65rem;
  margin-bottom: 10px;
}

.overlay-subtitle,
.controls-hint,
.final-score,
.final-character {
  color: var(--muted);
  font-size: 0.95rem;
}

.overlay-subtitle {
  max-width: 640px;
  margin: 0 auto 22px;
  line-height: 1.55;
}

.controls-hint {
  margin-top: 14px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.character-card {
  appearance: none;
  width: 100%;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.025)),
    #151920;
  color: var(--text);
  text-align: left;
  padding: 16px;
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease;
}

.character-card:hover {
  transform: translateY(-1px);
  border-color: rgba(255,255,255,0.18);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.035)),
    #181d25;
}

.character-card.selected {
  border-color: rgba(255,255,255,0.34);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08) inset;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.045)),
    #1a2028;
}

.character-card .emoji {
  display: block;
  font-size: 1.7rem;
  margin-bottom: 10px;
}

.character-card .name {
  display: block;
  font-size: 1.03rem;
  font-weight: 650;
  margin-bottom: 6px;
}

.character-card .obstacle {
  display: block;
  color: #8a929d;
  font-size: 0.88rem;
  line-height: 1.45;
}

.start-button,
.restart-button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 14px 26px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.11), rgba(255,255,255,0.05)),
    #181c22;
  color: #f1f3f5;
  font: inherit;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.28),
    inset 0 1px rgba(255, 255, 255, 0.08);
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    opacity 140ms ease;
}

.start-button {
  min-width: 210px;
  font-size: 1.05rem;
  padding: 15px 30px;
}

.start-button:hover:not(:disabled),
.restart-button:hover {
  transform: translateY(-1px);
  border-color: rgba(255,255,255,0.28);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0.07)),
    #1a1f26;
}

.start-button:active:not(:disabled),
.restart-button:active {
  transform: translateY(1px);
}

.start-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.start-button:focus-visible,
.restart-button:focus-visible,
.character-card:focus-visible {
  outline: 2px solid rgba(255,255,255,0.55);
  outline-offset: 4px;
}

.game-over-title {
  color: #e8ebef;
  font-size: 1.55rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.final-character {
  margin-bottom: 8px;
}

.final-score {
  margin-bottom: 18px;
}

.game-help {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 18px;
  padding: 13px 18px 15px;
  border-top: 1px solid var(--panel-border);
  color: #646b75;
  font-size: 0.78rem;
}

kbd {
  padding: 2px 6px;
  border: 1px solid #363c45;
  border-bottom-color: #252a31;
  border-radius: 5px;
  background: #181c22;
  color: #9299a3;
  font: inherit;
  box-shadow: inset 0 -1px rgba(0, 0, 0, 0.4);
}

@media (max-width: 760px) {
  .page {
    padding: 12px;
  }

  .game-card {
    border-radius: 13px;
  }

  .game-topbar {
    min-height: 44px;
    padding: 0 13px;
    gap: 8px;
    font-size: 0.68rem;
  }

  .character-grid {
    grid-template-columns: 1fr;
  }

  .game-help {
    justify-content: center;
    padding-inline: 12px;
  }
}


.game-actions,
.game-over-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.game-over-actions {
  justify-content: center;
  flex-wrap: wrap;
}

.change-character-button,
.secondary-button {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  background: rgba(255,255,255,0.035);
  color: #8f97a2;
  font: inherit;
  cursor: pointer;
  transition:
    color 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    transform 140ms ease;
}

.change-character-button {
  padding: 5px 9px;
  font-size: 0.76rem;
}

.secondary-button {
  padding: 14px 22px;
  font-size: 0.95rem;
}

.change-character-button:hover,
.secondary-button:hover {
  color: #d9dde3;
  border-color: rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.07);
}

.change-character-button:active,
.secondary-button:active {
  transform: translateY(1px);
}

.change-character-button:focus-visible,
.secondary-button:focus-visible {
  outline: 2px solid rgba(255,255,255,0.5);
  outline-offset: 3px;
}

@media (max-width: 760px) {
  .speed {
    display: none;
  }

  .game-actions {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }
}


/* ---------- Mobile playability ---------- */

.mobile-jump-button {
  display: none;
}

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    min-height: 100%;
    overscroll-behavior: none;
  }

  body {
    min-height: 100dvh;
  }

  .page {
    min-height: 100dvh;
    place-items: stretch;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .game-card {
    width: 100%;
    min-height: calc(100dvh - 16px);
    display: flex;
    flex-direction: column;
    border-radius: 14px;
  }

  .game-topbar {
    min-height: 46px;
    flex-wrap: wrap;
    row-gap: 4px;
    padding: 7px 12px;
    font-size: 0.65rem;
    letter-spacing: 0.07em;
  }

  .game-label {
    margin-right: auto;
  }

  .character-state {
    order: 3;
    width: 50%;
  }

  .score {
    order: 4;
    width: 50%;
    margin-left: 0;
    text-align: right;
  }

  .speed {
    display: inline;
    margin-left: auto;
  }

  .canvas-wrap {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #101318;
    overflow: hidden;
  }

  canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 8 / 3;
    max-width: 960px;
    max-height: none;
    object-fit: contain;
  }

  .start-overlay,
  .game-over-overlay {
    align-items: center;
    overflow-y: auto;
    padding: 12px;
  }

  .overlay-box {
    width: 100%;
    max-width: 560px;
    padding: 18px 14px;
    border-radius: 14px;
  }

  .overlay-box h1 {
    font-size: 1.35rem;
  }

  .overlay-subtitle {
    margin-bottom: 14px;
    font-size: 0.87rem;
  }

  .character-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
  }

  .character-card {
    min-height: 112px;
    padding: 12px;
    border-radius: 12px;
    text-align: center;
  }

  .character-card .emoji {
    font-size: 1.8rem;
    margin-bottom: 6px;
  }

  .character-card .name {
    font-size: 0.98rem;
    margin-bottom: 4px;
  }

  .character-card .obstacle {
    font-size: 0.76rem;
    line-height: 1.3;
  }

  .start-button {
    width: 100%;
    min-height: 52px;
    padding: 13px 18px;
  }

  .controls-hint {
    display: none;
  }

  .game-help {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    min-height: 78px;
    padding:
      10px
      10px
      max(10px, env(safe-area-inset-bottom));
  }

  .desktop-help {
    display: none;
  }

  .mobile-jump-button {
    display: block;
    min-height: 58px;
    width: 100%;
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 14px;
    background:
      linear-gradient(180deg, rgba(255,255,255,0.13), rgba(255,255,255,0.05)),
      #1a1f26;
    color: #f3f4f6;
    font: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .mobile-jump-button:active {
    transform: translateY(1px);
    background:
      linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0.07)),
      #20262e;
  }

  .game-actions {
    width: auto;
    justify-content: flex-end;
    gap: 8px;
  }

  .change-character-button {
    min-height: 46px;
    padding: 8px 12px;
    font-size: 0.74rem;
    white-space: nowrap;
  }

  .game-over-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .restart-button,
  .secondary-button {
    width: 100%;
    min-height: 50px;
  }
}

@media (max-width: 420px) {
  .page {
    padding: 0;
  }

  .game-card {
    min-height: 100dvh;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .game-topbar {
    min-height: 50px;
    padding: 6px 10px;
  }

  .status-dot {
    width: 7px;
    height: 7px;
  }

  .speed {
    font-size: 0.62rem;
  }

  canvas {
    width: 100%;
    height: auto;
    aspect-ratio: 8 / 3;
  }

  .overlay-box {
    border-radius: 12px;
    padding: 14px 10px;
  }

  .character-grid {
    gap: 8px;
  }

  .character-card {
    min-height: 106px;
    padding: 10px 8px;
  }

  .character-card .obstacle {
    font-size: 0.72rem;
  }

  .game-help {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding-inline: 8px;
  }

  .mobile-jump-button {
    min-height: 60px;
    font-size: 1.08rem;
  }

  .change-character-button {
    max-width: 122px;
    min-height: 48px;
    white-space: normal;
    line-height: 1.15;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .page {
    padding: 4px;
  }

  .game-card {
    min-height: calc(100dvh - 8px);
  }

  .game-topbar {
    min-height: 38px;
    padding: 4px 10px;
  }

  .canvas-wrap {
    flex: 1 1 auto;
    min-height: 0;
    height: calc(100dvh - 108px);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  canvas {
    width: auto;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 8 / 3;
    object-fit: contain;
  }

  .game-help {
    min-height: 62px;
    padding: 6px 8px;
  }

  .mobile-jump-button {
    min-height: 48px;
  }

  .change-character-button {
    min-height: 42px;
  }

  .overlay-box {
    max-width: 720px;
    padding: 12px;
  }

  .character-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
  }

  .character-card {
    min-height: 90px;
    padding: 8px;
  }

  .character-card .emoji {
    margin-bottom: 2px;
    font-size: 1.45rem;
  }

  .character-card .obstacle {
    font-size: 0.68rem;
  }

  .overlay-subtitle,
  .controls-hint {
    display: none;
  }

  .start-button {
    min-height: 44px;
    padding: 10px 18px;
  }
}


/* Всегда сохраняем реальные пропорции canvas 960×360. */
.canvas-wrap {
  background: #101318;
}

canvas {
  aspect-ratio: 8 / 3;
}

/* На мобильных в портретной ориентации ширина определяет высоту. */
@media (max-width: 760px) and (orientation: portrait) {
  .canvas-wrap {
    height: auto;
    min-height: 0;
  }

  canvas {
    width: 100%;
    height: auto;
    max-width: 960px;
    max-height: none;
  }
}

/* В альбомной ориентации высота доступной области определяет ширину.
   За счёт width:auto изображение не растягивается по горизонтали. */
@media (max-width: 960px) and (orientation: landscape) {
  .canvas-wrap {
    height: calc(100dvh - 108px);
    min-height: 180px;
  }

  canvas {
    width: auto;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
  }
}


/* ---------- Portrait orientation guard ---------- */

.orientation-lock {
  display: none;
}

@media (max-width: 760px) and (orientation: portrait) {
  .orientation-lock {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding:
      max(24px, env(safe-area-inset-top))
      max(24px, env(safe-area-inset-right))
      max(24px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-left));
    background:
      radial-gradient(circle at 50% 35%, rgba(94, 106, 128, 0.17), transparent 36%),
      #090b0f;
    color: #eef1f4;
    text-align: center;
  }

  .orientation-lock__content {
    width: min(360px, 100%);
  }

  .orientation-lock h2 {
    margin-top: 26px;
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.02em;
  }

  .orientation-lock p {
    margin-top: 10px;
    color: #858d98;
    font-size: 0.95rem;
    line-height: 1.55;
  }

  .phone-rotate-icon {
    position: relative;
    width: 132px;
    height: 118px;
    margin: 0 auto;
  }

  .phone-shape {
    position: absolute;
    left: 46px;
    top: 4px;
    width: 44px;
    height: 78px;
    border: 3px solid #cfd5dc;
    border-radius: 10px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
  }

  .phone-shape::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 5px;
    width: 12px;
    height: 2px;
    border-radius: 999px;
    background: #6f7781;
    transform: translateX(-50%);
  }

  .phone-shape::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 5px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #6f7781;
    transform: translateX(-50%);
  }

  .rotate-arrow {
    position: absolute;
    left: 16px;
    bottom: 0;
    width: 100px;
    height: 48px;
    color: #7f8995;
    font-size: 4.6rem;
    line-height: 0.62;
    font-family: Arial, sans-serif;
    transform: rotate(-18deg);
    user-select: none;
  }
}
