:root {
  --ink: #1d2433;
  --card: #fffdf5;
  --yellow: #ffd23f;
  --blue: #8fbfff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #14213d; color: var(--ink);
  font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
canvas#game { display: block; width: 100vw; height: 100vh; }
.hidden { display: none !important; }

.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 20, 45, .45);
}
.card {
  background: var(--card); border: 5px solid var(--ink); border-radius: 28px;
  box-shadow: 0 10px 0 var(--ink);
  padding: 26px 34px; width: calc(100% - 32px); max-width: 640px; text-align: center;
}
.logo { font-size: 42px; font-weight: 800; line-height: 1.15; }
.sub { font-size: 18px; font-weight: 700; color: #3b5b92; margin-top: 6px; }
.story { font-size: 20px; line-height: 1.45; margin: 16px 0; }
.story.big { font-size: 26px; font-weight: 700; }
.stars { font-size: 64px; color: #f5b301; letter-spacing: 8px; -webkit-text-stroke: 2px var(--ink); margin: 6px 0; }

.keys {
  display: grid; grid-template-columns: auto 1fr; gap: 10px 14px; align-items: center;
  text-align: left; margin: 14px auto 22px; max-width: 470px; font-size: 18px;
}
kbd {
  display: inline-block; min-width: 32px; padding: 3px 7px; margin-right: 3px;
  border: 3px solid var(--ink); border-radius: 8px; background: #fff;
  font: 700 16px 'Rubik', system-ui, sans-serif; text-align: center; box-shadow: 0 3px 0 var(--ink);
}
kbd.wide { min-width: 110px; }

.vol {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin: 4px auto 16px; font-size: 24px;
}
.vol input {
  width: min(260px, 50vw); height: 34px; accent-color: #1f5cff; cursor: pointer; touch-action: none;
}
.row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.btn {
  font: 800 24px 'Rubik', system-ui, sans-serif; color: var(--ink);
  padding: 12px 30px; border-radius: 18px; border: 4px solid var(--ink);
  background: var(--yellow); box-shadow: 0 6px 0 var(--ink); cursor: pointer;
}
.btn.blue { background: var(--blue); }
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }

.subtitle {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 5;
  background: rgba(255, 253, 245, .97); border: 4px solid var(--ink); border-radius: 18px;
  box-shadow: 0 5px 0 var(--ink);
  padding: 10px 20px; max-width: min(900px, 92vw);
  font-size: 23px; font-weight: 700; text-align: center;
}
.subtitle .who { font-weight: 800; margin-right: 10px; }

@media (max-width: 600px) {
  .logo { font-size: 30px; }
  .story { font-size: 17px; }
  .subtitle { font-size: 18px; }
}

/* ---------- Планшеты и телефоны ---------- */
html, body {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.screen { overflow-y: auto; padding: 12px 0; touch-action: pan-y; }
.card { margin: auto; }
.keys-touch { display: none; }
body.touch .keys-kb { display: none; }
body.touch .keys-touch { display: grid; }
.keys .ico { font-size: 22px; font-weight: 800; text-align: center; }

.touch-ui { display: none; }
body.touch .touch-ui { display: block; }
body.touch[data-ctl="menu"] .touch-ui { display: none; }

.touch-ui button {
  font: 800 16px 'Rubik', system-ui, sans-serif; color: var(--ink);
  border: 4px solid var(--ink); cursor: pointer; touch-action: none;
}
.touch-ui .t-drive, .touch-ui .t-walk { display: none; }
body[data-ctl="drive"] .touch-ui .t-drive { display: flex; }
body[data-ctl="walk"] .touch-ui .t-walk { display: block; }

.t-top {
  position: fixed; z-index: 6; display: flex; gap: 8px;
  top: calc(64px + env(safe-area-inset-top)); left: calc(16px + env(safe-area-inset-left));
}
.t-small {
  width: 48px; height: 48px; border-radius: 50%; font-size: 22px !important;
  background: rgba(255, 253, 245, .92); box-shadow: 0 3px 0 var(--ink); padding: 0;
}
.t-small.off { opacity: .45; }

.t-left, .t-right {
  position: fixed; z-index: 6;
  bottom: calc(18px + env(safe-area-inset-bottom));
}
.t-left { left: calc(18px + env(safe-area-inset-left)); }
.t-right {
  right: calc(18px + env(safe-area-inset-right));
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
}

/* Руль: одна панель, левая половина — влево, правая — вправо (можно скользить пальцем) */
.t-steer {
  width: clamp(190px, 32vmin, 300px); height: clamp(92px, 16vmin, 140px);
  border: 4px solid var(--ink); border-radius: 26px; overflow: hidden;
  background: rgba(255, 253, 245, .85); box-shadow: 0 5px 0 var(--ink);
}
.t-steer span {
  flex: 1; display: flex; align-items: center; justify-content: center;
  font-size: clamp(34px, 7vmin, 54px); color: var(--ink);
}
.t-steer span + span { border-left: 4px solid var(--ink); }
.t-steer span.on { background: var(--yellow); }

/* Джойстик для ходьбы */
.t-joy {
  position: relative;
  width: clamp(130px, 24vmin, 190px); height: clamp(130px, 24vmin, 190px); border-radius: 50%;
  border: 4px solid var(--ink); background: rgba(255, 253, 245, .55); box-shadow: 0 5px 0 var(--ink);
}
.t-joy .knob {
  position: absolute; left: 50%; top: 50%; width: 42%; height: 42%; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: #9cc7ff; border: 4px solid var(--ink);
}

.t-pedals { gap: 12px; align-items: flex-end; }
.t-gas, .t-brake { border-radius: 24px; box-shadow: 0 5px 0 var(--ink); }
.t-gas {
  width: clamp(100px, 17vmin, 150px); height: clamp(110px, 20vmin, 170px);
  background: #7bd36b; font-size: clamp(18px, 3.4vmin, 24px) !important;
}
.t-brake {
  width: clamp(84px, 14vmin, 120px); height: clamp(70px, 12vmin, 100px);
  background: #ff8a80; font-size: clamp(13px, 2.4vmin, 17px) !important;
}
.t-gas.on, .t-brake.on, .t-small.on, .t-action.on { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }

.t-action {
  min-width: clamp(96px, 17vmin, 140px); height: clamp(64px, 11vmin, 86px);
  border-radius: 40px; padding: 0 18px;
  background: var(--yellow); box-shadow: 0 5px 0 var(--ink);
  font-size: clamp(18px, 3.4vmin, 24px) !important;
  visibility: hidden;
}
.t-action.show { visibility: visible; }
.t-action.pulse { animation: pulse .7s ease-in-out infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.1); } }

/* Субтитры не должны залезать под кнопки */
body.touch .subtitle {
  max-width: calc(100vw - 2 * clamp(236px, 36vmin, 340px));
  font-size: clamp(14px, 2.6vmin, 21px); padding: 8px 14px; bottom: calc(14px + env(safe-area-inset-bottom));
}

/* Поверни экран */
.rotate {
  display: none; position: fixed; inset: 0; z-index: 30;
  align-items: center; justify-content: center; background: #14213d;
}
@media (orientation: portrait) {
  body.touch .rotate { display: flex; }
}

@media (max-height: 500px) {
  .card { padding: 14px 20px; }
  .logo { font-size: 28px; }
  .story { font-size: 16px; margin: 8px 0; }
  .keys { font-size: 15px; margin: 8px auto 12px; gap: 6px 12px; }
  .stars { font-size: 44px; }
  .btn { font-size: 20px; padding: 9px 22px; }
}
