:root {
  --ink: #1B1C1A;
  --steel: #2F3230;
  --dust: #6E5A44;
  --cream: #E7DCC6;
  --amber: #C08A4E;
  --teal: #4E6B68;
  --red: #A8342A;
  --display: "Big Shoulders Stencil", "Arial Narrow", sans-serif;
  --text: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --mono: "Azeret Mono", "Courier New", monospace;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --gauge-h: clamp(200px, 46vh, 420px);
  --card-w: clamp(250px, 28vw, 380px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

body {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--ink);
}

#scene {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #2a2723;
}

#vignette {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 46%, rgba(27, 28, 26, 0) 42%, rgba(27, 28, 26, 0.42) 100%),
    linear-gradient(to bottom, rgba(27, 28, 26, 0.28), transparent 18%, transparent 72%, rgba(27, 28, 26, 0.5));
}

#grain {
  position: absolute;
  inset: 0;
  z-index: 11;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("assets/grain.png");
  background-size: 180px 180px;
  animation: grainShift 0.7s steps(2) infinite;
}

@keyframes grainShift {
  0% { background-position: 0 0; }
  50% { background-position: 37px 61px; }
  100% { background-position: -23px 19px; }
}

/* ---------------- title plate ---------------- */

#title {
  position: absolute;
  inset: 0;
  z-index: 40;
  overflow: hidden;
  background: #2a241e;
  transition: opacity 0.7s ease, visibility 0.7s;
}

#title.gone {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#title-bg {
  position: absolute;
  inset: -4%;
  background-image: url("assets/wrecktown_key_art.webp");
  background-size: cover;
  background-position: 58% 52%;
  background-repeat: no-repeat;
  filter: saturate(0.94) contrast(1.03) brightness(0.94);
  animation: plateBreath 18s ease-in-out infinite;
}

@keyframes plateBreath {
  0%, 100% { transform: scale(1.015) translate3d(0, 0, 0); }
  50% { transform: scale(1.045) translate3d(-0.6%, -0.4%, 0); }
}

#title-grade {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 18% 74%, rgba(192, 138, 78, 0.19), transparent 48%),
    linear-gradient(to bottom, rgba(27, 28, 26, 0.6), transparent 26%, transparent 58%, rgba(27, 28, 26, 0.88) 100%),
    linear-gradient(to right, rgba(27, 28, 26, 0.46), transparent 28%, transparent 78%, rgba(27, 28, 26, 0.2));
}

#title-dust {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.7;
}

.title-inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  padding: calc(var(--safe-t) + 4vh) calc(var(--safe-r) + 5vw) calc(var(--safe-b) + 4vh) calc(var(--safe-l) + 5vw);
}

.title-head {
  text-align: center;
  transform: translateX(-4vw);
}

#wordmark {
  display: block;
  width: clamp(250px, 36vw, 500px);
  height: auto;
  margin: 0 auto;
  filter: drop-shadow(0 14px 24px rgba(0, 0, 0, 0.58));
}

.tagline {
  margin: 1.4vh 0 0;
  font-family: var(--text);
  font-size: clamp(8px, 0.8vw, 11px);
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(231, 220, 198, 0.74);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.title-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

#start-btn {
  position: relative;
  width: min(360px, 78vw);
  padding: 18px 30px 14px;
  border: 1px solid rgba(192, 138, 78, 0.62);
  border-radius: 2px;
  background:
    linear-gradient(180deg, rgba(47, 50, 48, 0.96), rgba(20, 21, 19, 0.97)),
    repeating-linear-gradient(90deg, transparent 0 9px, rgba(231, 220, 198, 0.02) 9px 10px);
  box-shadow:
    0 14px 40px rgba(0, 0, 0, 0.58),
    inset 0 1px 0 rgba(231, 220, 198, 0.15),
    inset 0 -2px 0 rgba(0, 0, 0, 0.55);
  color: var(--cream);
  cursor: pointer;
  transition: border-color 0.18s, transform 0.12s, box-shadow 0.18s;
}

#start-btn::before,
#start-btn::after {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  width: 5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #8b7a62, #2a2b28 70%);
  box-shadow: 0 1px 2px #000;
}

#start-btn::before { left: 8px; }
#start-btn::after { right: 8px; }

#start-btn:hover,
#start-btn:focus-visible {
  border-color: var(--amber);
  outline: none;
  box-shadow:
    0 14px 44px rgba(0, 0, 0, 0.62),
    0 0 18px rgba(192, 138, 78, 0.24),
    inset 0 1px 0 rgba(231, 220, 198, 0.2);
}

#start-btn:active { transform: translateY(1px); }

#start-btn:disabled {
  cursor: default;
  opacity: 0.62;
}

.start-label {
  display: block;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(28px, 3.2vw, 38px);
  line-height: 0.94;
  letter-spacing: 0.09em;
  color: var(--cream);
  text-shadow: 0 2px 0 #000, 0 0 18px rgba(192, 138, 78, 0.18);
}

.start-sub {
  display: block;
  margin-top: 7px;
  font-family: var(--text);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.34em;
  color: var(--amber);
}

.load-wrap {
  width: min(330px, 72vw);
}

#load-bar {
  height: 2px;
  background: rgba(231, 220, 198, 0.16);
  overflow: hidden;
}

#load-bar i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--amber);
  box-shadow: 0 0 8px rgba(192, 138, 78, 0.7);
  transition: width 0.25s ease;
}

#load-note {
  margin: 7px 0 0;
  font-family: var(--text);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: rgba(231, 220, 198, 0.54);
}

.controls-hint {
  margin: 0;
  font-family: var(--text);
  font-size: clamp(8px, 0.72vw, 10px);
  font-weight: 500;
  letter-spacing: 0.18em;
  color: rgba(231, 220, 198, 0.56);
}

.controls-hint b { color: var(--amber); font-weight: 500; }
.touch-hint { display: none; }

/* ---------------- hud ---------------- */

#hud {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

#quest-card {
  position: absolute;
  top: calc(var(--safe-t) + 12px);
  left: calc(var(--safe-l) + 14px);
  width: var(--card-w);
  aspect-ratio: 1024 / 347;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
}

#quest-card .frame {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.quest-portrait {
  position: absolute;
  z-index: 2;
  left: 7.1%;
  top: 14.2%;
  width: 17.8%;
  height: 70.5%;
  background-image: url("assets/driver_portrait_01_idle.webp");
  background-size: cover;
  background-position: 50% 4%;
  background-color: #171816;
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
  filter: saturate(0.9) brightness(0.92);
}

.quest-portrait::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 55%, rgba(27, 28, 26, 0.55));
  clip-path: inherit;
}

.quest-icon {
  position: absolute;
  z-index: 3;
  left: 1.6%;
  top: 1.4%;
  width: 6.4%;
  height: auto;
  opacity: 0.86;
  filter: drop-shadow(0 1px 2px #000);
}

.objective {
  position: absolute;
  z-index: 3;
  left: 29.8%;
  top: 20.4%;
  width: 60%;
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(14px, 1.36vw, 21px);
  line-height: 1;
  letter-spacing: 0.055em;
  color: var(--cream);
  text-shadow: 0 1px 2px #000, 0 0 8px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.objective-hint {
  position: absolute;
  z-index: 3;
  left: 29.8%;
  top: 45%;
  width: 62%;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--text);
  font-size: clamp(8px, 0.72vw, 10px);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(231, 220, 198, 0.76);
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#distance {
  margin-left: auto;
  flex: none;
  font-family: var(--mono);
  font-size: clamp(8px, 0.68vw, 10px);
  letter-spacing: 0.02em;
  color: var(--amber);
}

#level-row {
  position: absolute;
  z-index: 3;
  left: 7%;
  top: 96%;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px;
  background: rgba(27, 28, 26, 0.82);
  border-left: 1px solid rgba(192, 138, 78, 0.55);
}

.level-icon {
  width: 13px;
  height: auto;
  opacity: 0.9;
}

.level-value {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--cream);
}

.xp-track {
  display: block;
  width: 48px;
  height: 3px;
  background: rgba(231, 220, 198, 0.2);
}

.xp-track i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--amber);
  transition: width 0.3s ease;
}

.xp-value {
  font-family: var(--mono);
  font-size: 7px;
  color: var(--dust);
}

#gauge {
  position: absolute;
  top: calc(var(--safe-t) + 12px);
  right: calc(var(--safe-r) + 16px);
  height: var(--gauge-h);
  aspect-ratio: 146 / 1024;
}

.gauge-frame {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.45));
}

#gauge-fill {
  position: absolute;
  z-index: 2;
  left: 24.7%;
  right: 19.9%;
  bottom: 4.9%;
  height: 0%;
  background: linear-gradient(to top, #2f4b48, #4E6B68 45%, #a8b88c 78%, var(--amber));
  mix-blend-mode: screen;
  box-shadow: 0 0 12px rgba(192, 138, 78, 0.4);
  transition: height 0.35s ease;
}

#gauge-fill::after {
  content: "";
  position: absolute;
  left: -10%;
  right: -10%;
  top: 0;
  height: 2px;
  background: var(--amber);
  box-shadow: 0 0 7px var(--amber);
}

#gauge::after {
  content: "GARAGE";
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: -14px;
  transform: translateX(-50%);
  font-family: var(--display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: rgba(231, 220, 198, 0.68);
}

#gauge-read {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: -31px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.gauge-icon {
  width: 15px;
  height: auto;
  opacity: 0.8;
}

#gauge-pct {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--amber);
}

#speed-plate {
  position: absolute;
  right: calc(var(--safe-r) + 18px);
  bottom: calc(var(--safe-b) + 22px);
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 9px;
  background: rgba(27, 28, 26, 0.72);
  border-left: 2px solid var(--amber);
}

.speed-icon {
  width: 15px;
  height: auto;
  opacity: 0.75;
  align-self: center;
}

#speed-value {
  font-family: var(--mono);
  font-size: 21px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}

.speed-unit {
  font-family: var(--text);
  font-size: 7px;
  letter-spacing: 0.14em;
  color: var(--dust);
}

#part-chip {
  position: absolute;
  right: calc(var(--safe-r) + 18px);
  top: calc(var(--safe-t) + 12px + var(--gauge-h) + 70px);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  background: rgba(27, 28, 26, 0.82);
  border: 1px solid rgba(192, 138, 78, 0.4);
  font-family: var(--text);
  font-size: 7px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--cream);
}

#part-chip[hidden] { display: none; }

#part-chip img {
  width: 16px;
  height: auto;
  opacity: 0.85;
}

#prompt {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 108px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 5px;
  background: rgba(27, 28, 26, 0.86);
  border: 1px solid rgba(192, 138, 78, 0.52);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}

#prompt[hidden] { display: none; }

.prompt-key img {
  display: block;
  width: 34px;
  height: auto;
}

#prompt-text {
  font-family: var(--text);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cream);
}

#keybar {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 16px);
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 18px;
  opacity: 0.86;
}

.key-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.key-group img {
  width: 34px;
  height: auto;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.45));
}

.keys {
  display: flex;
  gap: 2px;
}

.keys img {
  width: 29px;
}

.key-group em {
  font-family: var(--text);
  font-size: 7px;
  font-style: normal;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: rgba(231, 220, 198, 0.55);
}

#touch-controls { display: none; }

#touch-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 48%;
  height: 58%;
  pointer-events: auto;
  touch-action: none;
}

#stick-base {
  position: absolute;
  left: 72px;
  bottom: 78px;
  width: 104px;
  height: 104px;
  margin: 0;
  transform: translate(-50%, 50%);
  border-radius: 50%;
  border: 1px solid rgba(192, 138, 78, 0.32);
  background: radial-gradient(circle, rgba(192, 138, 78, 0.13), rgba(192, 138, 78, 0.02) 62%, transparent 72%);
  transition: opacity 0.18s;
  opacity: 0.9;
}

#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, #454943, #20211f 72%);
  border: 1px solid rgba(192, 138, 78, 0.5);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

#stick-base.active { opacity: 1; }

#stick-base::after {
  content: "DRIVE";
  position: absolute;
  left: 50%;
  bottom: -16px;
  transform: translateX(-50%);
  font-family: var(--text);
  font-size: 7px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: rgba(231, 220, 198, 0.48);
}

#action-btn {
  position: absolute;
  right: calc(var(--safe-r) + 22px);
  bottom: calc(var(--safe-b) + 30px);
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 2px solid rgba(192, 138, 78, 0.72);
  background:
    radial-gradient(circle at 34% 28%, rgba(78, 107, 104, 0.22), transparent 48%),
    radial-gradient(circle at 40% 34%, #3a3d39, #1b1c1a 72%);
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.58),
    inset 0 0 0 4px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(231, 220, 198, 0.14);
  color: var(--cream);
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.06em;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
}

#action-btn.pulse {
  border-color: var(--amber);
  box-shadow: 0 0 24px rgba(192, 138, 78, 0.45), inset 0 0 14px rgba(192, 138, 78, 0.2);
}

#action-btn:active,
#action-btn.held {
  transform: scale(0.96);
  border-color: var(--amber);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6), inset 0 0 12px rgba(192, 138, 78, 0.18);
}

#sound-btn {
  position: absolute;
  right: calc(var(--safe-r) + 18px);
  top: calc(var(--safe-t) + 12px + var(--gauge-h) + 46px);
  padding: 1px 3px;
  border: 0;
  background: none;
  font-family: var(--text);
  font-size: 7px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: rgba(231, 220, 198, 0.48);
  pointer-events: auto;
  cursor: pointer;
}

#sound-btn:hover { color: var(--amber); }

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 178px);
  transform: translateX(-50%) translateY(6px);
  padding: 5px 12px;
  border-left: 2px solid var(--amber);
  background: rgba(27, 28, 26, 0.8);
  font-family: var(--text);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cream);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------- completion ---------------- */

#complete {
  position: absolute;
  inset: 0;
  z-index: 45;
  pointer-events: none;
}

#complete[hidden] { display: none; }

#wrench {
  position: absolute;
  left: 50%;
  top: 31%;
  width: clamp(150px, 18vw, 240px);
  height: auto;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.7));
  animation: badgePop 2.6s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

@keyframes badgePop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.55) rotate(-9deg); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.05) rotate(0deg); }
  24% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  78% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.96) rotate(0deg); }
}

.complete-band {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 22px calc(var(--safe-r) + 5vw) calc(var(--safe-b) + 26px) calc(var(--safe-l) + 5vw);
  background: linear-gradient(to bottom, rgba(27, 28, 26, 0), rgba(27, 28, 26, 0.94) 28%, var(--ink));
  border-top: 1px solid rgba(192, 138, 78, 0.34);
  text-align: center;
  pointer-events: auto;
}

.complete-kicker {
  margin: 0;
  font-family: var(--text);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.32em;
  color: var(--amber);
}

.complete-title {
  margin: 3px 0 10px;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 0.94;
  letter-spacing: 0.05em;
  color: var(--cream);
  text-shadow: 0 3px 0 #000, 0 0 24px rgba(192, 138, 78, 0.2);
}

.complete-stats {
  display: flex;
  justify-content: center;
  gap: clamp(18px, 4vw, 48px);
  margin-bottom: 14px;
}

.complete-stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-family: var(--text);
  font-size: 7px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: var(--dust);
}

.stat-value {
  font-family: var(--mono);
  font-size: clamp(18px, 2vw, 24px);
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}

#keep-driving {
  padding: 12px 28px 10px;
  border: 1px solid rgba(192, 138, 78, 0.6);
  border-radius: 2px;
  background: linear-gradient(180deg, #2F3230, #171816);
  color: var(--cream);
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(231, 220, 198, 0.14);
}

#keep-driving:hover,
#keep-driving:focus-visible {
  border-color: var(--amber);
  outline: none;
}

/* ---------------- fatal ---------------- */

#fatal {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--ink);
  text-align: center;
}

#fatal[hidden] { display: none; }

#fatal h2 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: 34px;
  letter-spacing: 0.05em;
  color: var(--cream);
}

#fatal p {
  max-width: 420px;
  margin: 0 auto;
  font-family: var(--text);
  font-size: 12px;
  line-height: 1.6;
  letter-spacing: 0.08em;
  color: rgba(231, 220, 198, 0.66);
}

/* ---------------- responsive ---------------- */

@media (pointer: coarse) {
  #touch-controls { display: block; }
  #keybar { display: none; }
  .desk-hint { display: none; }
  .touch-hint { display: inline; }
  #speed-plate { bottom: calc(var(--safe-b) + 140px); }
  #prompt { display: none !important; }
  #toast { bottom: calc(var(--safe-b) + 190px); }
}

@media (max-width: 700px) {
  :root {
    --gauge-h: clamp(170px, 32vh, 300px);
    --card-w: min(72vw, 330px);
  }
  .title-head { transform: none; }
  #wordmark { width: 78vw; }
  .title-inner { padding-left: calc(var(--safe-l) + 5vw); padding-right: calc(var(--safe-r) + 5vw); }
  .tagline { font-size: 8px; letter-spacing: 0.24em; }
  #start-btn { width: 84vw; padding: 16px 22px 12px; }
  .start-label { font-size: 30px; }
  .controls-hint { font-size: 7px; letter-spacing: 0.14em; }
  #quest-card { left: calc(var(--safe-l) + 8px); top: calc(var(--safe-t) + 8px); }
  #gauge { right: calc(var(--safe-r) + 10px); top: calc(var(--safe-t) + 8px); }
  .objective { font-size: 14px; }
  .objective-hint { font-size: 7px; letter-spacing: 0.06em; }
  #distance { font-size: 7px; }
  .complete-title { font-size: 34px; }
  .complete-stats { gap: 18px; }
  #stat-level, #stat-xp { font-size: 18px; }
  #sound-btn { right: calc(var(--safe-r) + 12px); top: calc(var(--safe-t) + 8px + var(--gauge-h) + 44px); }
  #part-chip { right: calc(var(--safe-r) + 12px); top: calc(var(--safe-t) + 8px + var(--gauge-h) + 68px); }
}

@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --gauge-h: clamp(150px, 56vh, 260px);
    --card-w: clamp(220px, 26vw, 300px);
  }
  #wordmark { width: 34vw; }
  .title-inner { padding-top: calc(var(--safe-t) + 2vh); padding-bottom: calc(var(--safe-b) + 2vh); }
  .title-head { transform: translateX(-3vw); }
  .tagline { margin-top: 4px; }
  .title-bottom { gap: 8px; }
  #start-btn { padding: 10px 20px 8px; width: min(300px, 52vw); }
  .start-label { font-size: 24px; }
  .start-sub { margin-top: 3px; }
  #load-note { margin-top: 4px; }
  #toast { bottom: calc(var(--safe-b) + 128px); }
}

@media (prefers-reduced-motion: reduce) {
  #title-bg, #grain { animation: none; }
  #wrench { animation-duration: 0.01ms; opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

body.is-touch #touch-controls { display: block; }
body.is-touch #keybar { display: none; }
body.is-touch .desk-hint { display: none; }
body.is-touch .touch-hint { display: inline; }
body.is-touch #prompt { display: none !important; }
body.is-touch #speed-plate { bottom: calc(var(--safe-b) + 140px); }
body.is-touch #toast { bottom: calc(var(--safe-b) + 190px); }
