@font-face {
  font-family: "PT Sans Narrow";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/ptsansnarrow-400-cyr.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "PT Sans Narrow";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/ptsansnarrow-400-lat.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "PT Sans Narrow";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/ptsansnarrow-700-cyr.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "PT Sans Narrow";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/ptsansnarrow-700-lat.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --paper: #efe8d6;
  --paper-deep: #e4dcc5;
  --ink: #1e1b16;
  --ink-soft: #4b4437;
  --orange: #e2572b;
  --straw: #c9a65a;
  --rule: rgba(30, 27, 22, 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #c9a65a;
  font-family: "PT Sans Narrow", "Arial Narrow", Arial, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
#game canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  filter: saturate(1.5) brightness(1.08) contrast(1.03);
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}
#hud.prestart .route-card,
#hud.prestart .hint-chip,
#hud.ended .route-card,
#hud.ended .hint-chip {
  opacity: 0;
}
.route-card,
.hint-chip {
  transition: opacity 0.55s ease;
}

.route-card {
  position: absolute;
  left: env(safe-area-inset-left, 0px);
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  width: clamp(112px, 15.5vw, 152px);
  padding: 11px 12px 13px 13px;
  background:
    repeating-linear-gradient(0deg, rgba(30, 27, 22, 0.045) 0px, rgba(30, 27, 22, 0.045) 1px, transparent 1px, transparent 21px),
    linear-gradient(168deg, #f3eddc 0%, var(--paper) 48%, #e7dfc9 100%);
  border: 1px solid rgba(30, 27, 22, 0.24);
  border-left: none;
  box-shadow: 4px 6px 14px rgba(63, 46, 24, 0.26);
  transform: rotate(-0.7deg);
  clip-path: polygon(0 0, 100% 0, 99.2% 6%, 100% 12%, 99.4% 22%, 100% 34%, 99.6% 48%, 100% 62%, 99.3% 74%, 100% 86%, 99.5% 100%, 0 100%);
}

.route-card::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(30, 27, 22, 0.14);
  pointer-events: none;
}

.rc-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: 9px;
  letter-spacing: 0.13em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 4px;
  margin-bottom: 8px;
  font-weight: 700;
}
.rc-no { font-size: 10px; color: var(--ink); }

.rc-cap {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

.segbar {
  display: flex;
  gap: 2px;
  height: 9px;
  margin-bottom: 3px;
}
.segbar i {
  flex: 1;
  background: transparent;
  border: 1px solid rgba(30, 27, 22, 0.45);
  transform: skewX(-8deg);
  transition: background 0.18s ease;
}
.segbar i.on { background: var(--ink); border-color: var(--ink); }

.rc-small {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-align: right;
  margin-bottom: 10px;
}

.rc-sec + .rc-sec {
  border-top: 1px solid var(--rule);
  padding-top: 8px;
}

.route-wrap {
  position: relative;
  height: 96px;
  margin: 0 auto 4px;
  width: 46px;
}
.route-track {
  position: absolute;
  left: 21px;
  top: 0;
  bottom: 0;
  width: 10px;
  border-left: 1px solid rgba(30, 27, 22, 0.5);
  border-right: 1px solid rgba(30, 27, 22, 0.5);
  background: repeating-linear-gradient(0deg, transparent 0, transparent 9px, rgba(30, 27, 22, 0.25) 9px, rgba(30, 27, 22, 0.25) 10px);
}
.route-start,
.route-end {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--ink);
  opacity: 0.5;
}
.route-start { bottom: 0; }
.route-end { top: 0; }
.route-marker {
  position: absolute;
  left: -1px;
  width: 13px;
  height: 13px;
  transition: top 0.14s linear;
  color: var(--ink);
}
.route-marker::before {
  content: "";
  position: absolute;
  left: 0;
  top: 3px;
  width: 0;
  height: 0;
  border-left: 11px solid var(--ink);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}
.route-num {
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.route-num small {
  display: block;
  font-size: 8px;
  font-weight: 400;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  margin-top: 1px;
}

.sound-chip {
  position: fixed;
  z-index: 30;
  right: calc(10px + env(safe-area-inset-right, 0px));
  top: calc(10px + env(safe-area-inset-top, 0px));
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(30, 27, 22, 0.35);
  background: rgba(239, 232, 214, 0.86);
  color: var(--ink);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 7px 9px 6px;
  box-shadow: 2px 3px 7px rgba(63, 46, 24, 0.2);
  cursor: pointer;
}
.sound-chip:active { transform: translateY(1px); }

.gas-btn {
  position: absolute;
  right: calc(12px + env(safe-area-inset-right, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  width: 88px;
  height: 88px;
  z-index: 8;
  pointer-events: auto;
  touch-action: none;
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(30, 27, 22, 0.62);
  background:
    radial-gradient(circle at 38% 30%, #f6f0df 0%, #efe8d6 52%, #ddd3ba 100%);
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  box-shadow: 3px 5px 12px rgba(63, 46, 24, 0.3), inset 0 0 0 4px rgba(239, 232, 214, 0.6);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.gas-btn .gas-arrow {
  font-size: 20px;
  line-height: 1;
  margin-top: 3px;
}
.gas-btn .gas-word {
  font-size: 13px;
  letter-spacing: 0.14em;
  line-height: 1;
  margin-bottom: 4px;
}
.gas-btn.pressed,
.gas-btn:active {
  transform: translateY(2px) scale(0.97);
  background:
    radial-gradient(circle at 38% 30%, #e6dcc4 0%, #d8cdb2 55%, #c8bca0 100%);
  box-shadow: 1px 2px 5px rgba(63, 46, 24, 0.28), inset 0 0 0 4px rgba(201, 166, 90, 0.5);
}
#hud.ended .gas-btn,
#hud.ended .fire-btn {
  opacity: 0;
  pointer-events: none;
}
#hud.prestart .gas-btn,
#hud.prestart .fire-btn {
  pointer-events: none;
}
.gas-btn { transition: opacity 0.4s ease, transform 0.08s ease, background 0.12s ease, box-shadow 0.12s ease; }

.fire-btn {
  position: absolute;
  right: calc(112px + env(safe-area-inset-right, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  width: 88px;
  height: 88px;
  z-index: 8;
  pointer-events: auto;
  touch-action: none;
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(143, 58, 31, 0.8);
  background:
    radial-gradient(circle at 38% 30%, #f8e9df 0%, #f0dccd 52%, #e2c3ae 100%);
  color: #7a2f18;
  font-family: inherit;
  font-weight: 700;
  box-shadow: 3px 5px 12px rgba(63, 46, 24, 0.3), inset 0 0 0 4px rgba(226, 87, 43, 0.16);
  cursor: pointer;
  transition: opacity 0.4s ease, transform 0.08s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.fire-ring {
  position: relative;
  display: block;
  width: 26px;
  height: 26px;
  border: 2px solid currentColor;
  border-radius: 50%;
  transform: rotate(var(--aim, 0deg));
  transition: transform 0.05s linear;
}
.fire-tip {
  position: absolute;
  left: 50%;
  top: -7px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid currentColor;
  transform: translate(-50%, -2px);
}
.fire-ring::before,
.fire-ring::after {
  content: "";
  position: absolute;
  background: currentColor;
  opacity: 0.9;
}
.fire-ring::before {
  left: 50%;
  top: -7px;
  bottom: -7px;
  width: 2px;
  transform: translateX(-50%);
}
.fire-ring::after {
  top: 50%;
  left: -7px;
  right: -7px;
  height: 2px;
  transform: translateY(-50%);
}
.fire-word {
  font-size: 12px;
  letter-spacing: 0.14em;
  line-height: 1;
}
.fire-btn.pressed,
.fire-btn:active {
  transform: translateY(2px) scale(0.97);
  background:
    radial-gradient(circle at 38% 30%, #eccbb6 0%, #dfb79d 55%, #cf9f83 100%);
  color: #5b1f0e;
  box-shadow: 1px 2px 5px rgba(63, 46, 24, 0.28), inset 0 0 0 4px rgba(143, 58, 31, 0.3);
}

.hint-chip {
  position: absolute;
  right: calc(8px + env(safe-area-inset-right, 0px));
  bottom: calc(112px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100vw - 136px);
  padding: 6px 12px 5px;
  background: rgba(239, 232, 214, 0.82);
  border: 1px solid rgba(30, 27, 22, 0.28);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.11em;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 2px 3px 7px rgba(63, 46, 24, 0.16);
  transition: opacity 0.5s ease;
}
.hint-chip.hide { opacity: 0; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background:
    radial-gradient(120% 90% at 50% 46%, rgba(70, 52, 26, 0.02) 30%, rgba(62, 44, 22, 0.22) 100%);
  transition: opacity 0.45s ease;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.overlay.solid { background: rgba(62, 44, 22, 0.16); }

#start {
  align-items: flex-start;
  padding-top: max(18px, 7vh);
}

@media (min-aspect-ratio: 1/1) {
  #start {
    align-items: center;
    justify-content: flex-start;
    padding-top: 16px;
    padding-left: max(18px, calc(env(safe-area-inset-left, 0px) + 12px));
  }
  #start .sheet {
    width: min(48vw, 500px);
    max-height: 88vh;
  }
}

.sheet {
  position: relative;
  width: min(540px, 92vw);
  max-height: 88vh;
  overflow: auto;
  padding: clamp(18px, 4vh, 30px) clamp(18px, 4vw, 36px) clamp(16px, 3vh, 24px);
  background:
    repeating-linear-gradient(0deg, rgba(30, 27, 22, 0.035) 0px, rgba(30, 27, 22, 0.035) 1px, transparent 1px, transparent 23px),
    linear-gradient(172deg, #f4eedd 0%, var(--paper) 52%, #e6dec8 100%);
  border: 1px solid rgba(30, 27, 22, 0.3);
  box-shadow: 7px 10px 26px rgba(50, 35, 16, 0.34);
  transform: rotate(-0.35deg);
}
.sheet::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(30, 27, 22, 0.16);
  pointer-events: none;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
}

h1 {
  margin: 14px 0 2px;
  font-size: clamp(40px, 9vw, 74px);
  font-weight: 700;
  line-height: 0.88;
  letter-spacing: 0.015em;
  color: var(--ink);
}
.subtitle {
  font-size: clamp(11px, 2.4vw, 14px);
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
  margin: 0 0 12px;
}

.divider {
  height: 1px;
  background: var(--rule);
  margin: 12px 0;
}

.brief {
  font-size: clamp(12px, 2.7vw, 14px);
  line-height: 1.42;
  color: #2e2a22;
  margin: 0 0 12px;
}
.brief b { font-weight: 700; }

.control-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
  font-size: clamp(10px, 2.3vw, 12px);
  letter-spacing: 0.06em;
  margin: 10px 0 14px;
}
.control-list dt {
  font-weight: 700;
  letter-spacing: 0.12em;
  white-space: nowrap;
}
.control-list dd { margin: 0; color: var(--ink-soft); }

.begin-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--rule);
  padding-top: 12px;
  margin-top: 4px;
}
.begin-line .cta {
  font-size: clamp(15px, 3.6vw, 20px);
  font-weight: 700;
  letter-spacing: 0.09em;
  animation: breathe 2.1s ease-in-out infinite;
}
.begin-line .best {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  text-align: right;
}
@keyframes breathe {
  0%, 100% { opacity: 0.82; }
  50% { opacity: 1; }
}

.stamp {
  display: inline-block;
  margin: 16px 0 4px;
  padding: 6px 12px 4px;
  border: 3px double var(--ink);
  font-size: clamp(34px, 8vw, 56px);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;
  transform: rotate(-2.4deg);
  color: var(--ink);
  opacity: 0.9;
}
.stamp.lost { color: #7a2f18; border-color: #7a2f18; }

.report {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 18px;
  font-size: clamp(12px, 2.7vw, 14px);
  margin: 12px 0 4px;
  border-top: 1px solid var(--rule);
  padding-top: 10px;
}
.report dt { letter-spacing: 0.11em; color: var(--ink-soft); font-weight: 700; font-size: clamp(10px, 2.3vw, 12px); align-self: center; }
.report dd { margin: 0; font-weight: 700; text-align: right; letter-spacing: 0.05em; }

.end-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--rule);
  margin-top: 12px;
  padding-top: 12px;
}
.end-best { font-size: 10px; letter-spacing: 0.12em; color: var(--ink-soft); }
.again {
  appearance: none;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(13px, 3vw, 16px);
  letter-spacing: 0.16em;
  padding: 9px 18px 8px;
  cursor: pointer;
}
.again:active { transform: translateY(1px); }

.stage-pick {
  display: flex;
  gap: 8px;
  margin: 12px 0 4px;
}
.end-pick { margin-top: 4px; }
.stage-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  appearance: none;
  font-family: inherit;
  text-align: left;
  background: transparent;
  border: 1px solid rgba(30, 27, 22, 0.35);
  color: var(--ink-soft);
  padding: 6px 9px 5px;
  cursor: pointer;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.12em;
}
.stage-btn b {
  font-size: 21px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0;
  min-width: 13px;
  text-align: center;
}
.stage-btn > span { display: block; }
.stage-btn small {
  display: block;
  margin-top: 1px;
  font-size: 8px;
  letter-spacing: 0.07em;
  font-weight: 700;
  color: rgba(30, 27, 22, 0.5);
}
.stage-btn.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.stage-btn.on small { color: rgba(239, 232, 214, 0.62); }
.stage-btn.next { animation: stage-pulse 1.6s ease-in-out infinite; }
@keyframes stage-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226, 87, 43, 0); }
  50% { box-shadow: 0 0 0 3px rgba(226, 87, 43, 0.34); }
}

.tiny-note {
  font-size: 9px;
  letter-spacing: 0.13em;
  color: rgba(30, 27, 22, 0.52);
  margin-top: 10px;
  text-align: right;
}

@media (max-height: 700px), (max-height: 800px) and (max-aspect-ratio: 1/1) {
  .route-card { top: auto; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); width: 108px; padding: 8px 9px 9px 10px; }
  .gas-btn { width: 72px; height: 72px; right: calc(9px + env(safe-area-inset-right, 0px)); bottom: calc(9px + env(safe-area-inset-bottom, 0px)); }
  .gas-btn .gas-arrow { font-size: 16px; }
  .gas-btn .gas-word { font-size: 11px; }
  .fire-btn { width: 72px; height: 72px; right: calc(91px + env(safe-area-inset-right, 0px)); bottom: calc(9px + env(safe-area-inset-bottom, 0px)); gap: 2px; }
  .fire-ring { width: 21px; height: 21px; }
  .fire-ring::before { top: -6px; bottom: -6px; }
  .fire-ring::after { left: -6px; right: -6px; }
  .fire-word { font-size: 10px; }
  .hint-chip { bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
  .route-wrap { height: 62px; }
  .rc-small { margin-bottom: 6px; }
  .rc-sec + .rc-sec { padding-top: 6px; }
  .sheet { max-height: 92vh; padding: 12px 18px; }
  .sheet-head { font-size: 8.5px; padding-bottom: 4px; }
  h1 { font-size: clamp(28px, 5vw, 38px); line-height: 0.9; margin: 6px 0 1px; }
  .subtitle { font-size: 10px; margin-bottom: 6px; }
  .brief { font-size: 11px; line-height: 1.3; margin-bottom: 6px; }
  .divider { margin: 5px 0; }
  .control-list { font-size: 9.5px; gap: 2px 8px; margin: 4px 0 6px; }
  .control-list dt { letter-spacing: 0.08em; }
  .begin-line { padding-top: 6px; }
  .stage-pick { margin: 6px 0 2px; gap: 6px; }
  .stage-btn { padding: 4px 7px 3px; font-size: 9px; gap: 6px; }
  .stage-btn b { font-size: 17px; }
  .stage-btn small { font-size: 7.5px; }
  .begin-line .cta { font-size: 14px; }
  .begin-line .best { font-size: 8px; }
  .stamp { font-size: clamp(30px, 6vw, 46px); margin-top: 8px; }
  .report { padding-top: 6px; gap: 3px 16px; font-size: 11px; }
  .end-actions { margin-top: 6px; padding-top: 6px; }
  .end-best { font-size: 8px; }
  .tiny-note { display: none; }
}

@media (max-width: 380px) {
  .route-card { width: 104px; }
  .hint-chip { max-width: calc(100vw - 128px); font-size: 9px; }
}

@media (max-width: 350px) {
  .gas-btn { width: 64px; height: 64px; right: calc(8px + env(safe-area-inset-right, 0px)); bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .fire-btn { width: 64px; height: 64px; right: calc(78px + env(safe-area-inset-right, 0px)); bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .fire-ring { width: 18px; height: 18px; }
  .fire-word { font-size: 9px; }
}

.rc-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin-bottom: 3px;
}
.rc-row b {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink);
  font-weight: 700;
}
.rc-row.low b { color: var(--orange); }
.fire-btn.empty { opacity: 0.55; }

@media (max-height: 460px) {
  .sheet { padding-top: 10px; padding-bottom: 10px; }
  #start .divider { display: none; }
  .brief { font-size: 9.5px; line-height: 1.22; margin-bottom: 4px; }
  .control-list { font-size: 8.5px; }
  .stage-btn { padding: 3px 7px; }
  .stage-btn b { font-size: 16px; }
  .stage-btn small { display: none; }
  .stage-pick { margin: 4px 0 2px; }
}
