:root {
  --ink: #070610;
  --panel: #100d1f;
  --gold: #ffd35a;
  --cream: #fff4d2;
  --violet: #6d4f9e;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, #211733 0%, #0c0916 48%, #06050b 100%);
  color: var(--cream);
  font-family: "Courier New", monospace;
  display: grid;
  place-items: center;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game-shell {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #0b0918;
  box-shadow:
    0 0 0 1px rgba(255, 226, 157, 0.1),
    0 20px 80px rgba(0, 0, 0, 0.7),
    0 0 120px rgba(90, 56, 143, 0.12);
  isolation: isolate;
}

/* Wide screens get the whole viewport; the canvas widens its view instead of pillarboxing. */
body.wide-aspect #game-shell {
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
  box-shadow: none;
}

#game-shell:fullscreen,
#game-shell:-webkit-full-screen {
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  aspect-ratio: auto;
  box-shadow: none;
}

#game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 62%, rgba(5, 3, 12, 0.35) 100%);
  mix-blend-mode: multiply;
}

#screen {
  position: relative;
  width: 100%;
  height: 100%;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: default;
  outline: none;
  touch-action: none;
}

canvas.is-actionable {
  cursor: pointer;
}

#quick-sound {
  position: absolute;
  z-index: 8;
  top: 12.5%;
  right: max(10px, 1.8vw);
  width: clamp(28px, 3.2vw, 38px);
  height: clamp(22px, 2.6vw, 30px);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(216, 193, 240, 0.4);
  background: rgba(9, 7, 20, 0.64);
  color: var(--gold);
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 140ms ease, background 140ms ease;
  touch-action: manipulation;
}

#quick-sound:hover {
  opacity: 1;
  background: rgba(29, 21, 52, 0.9);
}

#quick-sound:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

#quick-sound.muted {
  opacity: 0.4;
}

#quick-sound.muted::after {
  content: "";
  position: absolute;
  width: 70%;
  height: 1px;
  background: #e9baba;
  transform: rotate(-43deg);
}

.sound-bars {
  height: 12px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.sound-bars i {
  display: block;
  width: 2px;
  background: currentColor;
  box-shadow: 1px 0 rgba(0, 0, 0, 0.35);
}

.sound-bars i:nth-child(1) { height: 4px; }
.sound-bars i:nth-child(2) { height: 8px; }
.sound-bars i:nth-child(3) { height: 11px; }

#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding:
    0 max(16px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transition: opacity 180ms ease;
}

#screen.is-playing #touch-controls {
  visibility: visible;
  opacity: 1;
}

.touch-dpad {
  position: relative;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(255, 236, 186, 0.16);
  border-radius: 21px;
  background: linear-gradient(180deg, rgba(22, 16, 38, 0.55), rgba(7, 5, 15, 0.34));
  box-shadow:
    0 10px 26px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 244, 210, 0.07);
  pointer-events: none;
}

.touch-dpad::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 20%;
  bottom: 20%;
  width: 1px;
  background: rgba(255, 241, 208, 0.14);
  transform: translateX(-50%);
  pointer-events: none;
}

.touch-btn {
  position: relative;
  pointer-events: auto;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid rgba(255, 236, 186, 0.6);
  background: linear-gradient(180deg, rgba(54, 39, 78, 0.88), rgba(16, 12, 29, 0.9));
  box-shadow:
    inset 0 0 0 2px rgba(12, 8, 23, 0.78),
    inset 0 1px 0 rgba(255, 255, 255, 0.13),
    0 3px 0 rgba(7, 5, 14, 0.85);
  color: var(--cream);
  touch-action: none;
  cursor: pointer;
  transform: translateY(0);
  transition:
    transform 60ms ease,
    background 60ms ease,
    border-color 60ms ease,
    box-shadow 60ms ease;
}

.touch-btn:active,
.touch-btn.is-pressed {
  transform: translateY(2px);
  background: linear-gradient(180deg, rgba(112, 78, 143, 0.94), rgba(43, 27, 65, 0.95));
  border-color: var(--gold);
  box-shadow:
    inset 0 0 0 2px rgba(12, 8, 23, 0.7),
    0 1px 0 rgba(7, 5, 14, 0.9);
}

.touch-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.dpad-btn {
  width: clamp(54px, 9.8vw, 68px);
  height: clamp(52px, 9.4vw, 66px);
  border-radius: 15px;
}

.touch-actions {
  position: relative;
  pointer-events: none;
}

.jump-btn {
  width: clamp(72px, 13vw, 90px);
  height: clamp(72px, 13vw, 90px);
  border: 2px solid rgba(255, 211, 90, 0.62);
  border-radius: 50%;
  grid-template-rows: 1fr auto;
  padding-bottom: clamp(9px, 1.5vw, 12px);
  background: radial-gradient(circle at 50% 30%, rgba(103, 73, 145, 0.94), rgba(21, 14, 37, 0.96) 70%);
  box-shadow:
    inset 0 0 0 3px rgba(10, 7, 20, 0.72),
    inset 0 2px 0 rgba(255, 255, 255, 0.16),
    0 5px 0 rgba(5, 4, 12, 0.86),
    0 0 30px rgba(255, 211, 90, 0.12);
}

.jump-btn:active,
.jump-btn.is-pressed {
  transform: translateY(3px) scale(0.97);
  background: radial-gradient(circle at 50% 30%, rgba(143, 101, 186, 0.98), rgba(47, 29, 70, 0.98) 72%);
  border-color: #ffe8a2;
  box-shadow:
    inset 0 0 0 3px rgba(10, 7, 20, 0.68),
    inset 0 2px 0 rgba(255, 255, 255, 0.2),
    0 2px 0 rgba(5, 4, 12, 0.9),
    0 0 38px rgba(255, 211, 90, 0.26);
}

/* Secondary controls ride the left edge, clear of the run path and banner. */
.touch-system {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  top: calc(12.5% + clamp(28px, 3.2vw, 38px) + env(safe-area-inset-top));
  bottom: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: clamp(5px, 0.8vw, 8px);
  padding: 5px;
  border: 1px solid rgba(255, 236, 186, 0.14);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(22, 16, 38, 0.48), rgba(7, 5, 15, 0.3));
  transform: none;
  pointer-events: none;
}

.system-btn {
  width: clamp(46px, 7.6vw, 56px);
  height: clamp(38px, 6.6vw, 46px);
  border-radius: 12px;
  grid-template-rows: 1fr auto;
  padding: 4px 0 5px;
  border-color: rgba(255, 236, 186, 0.34);
  background: linear-gradient(180deg, rgba(40, 30, 60, 0.76), rgba(12, 9, 23, 0.84));
  box-shadow:
    inset 0 0 0 2px rgba(9, 6, 18, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 rgba(5, 4, 12, 0.75);
}

.pause-glyph {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pause-glyph[hidden],
.resume-glyph[hidden] {
  display: none;
}

.resume-glyph {
  width: 0;
  height: 0;
  margin-left: 2px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 8px solid var(--cream);
}

.home-glyph {
  display: grid;
  place-items: center;
}

.home-glyph svg {
  width: clamp(10px, 1.5vw, 13px);
  height: clamp(10px, 1.5vw, 13px);
  color: var(--cream);
}

.system-label {
  font-family: "Courier New", monospace;
  font-size: clamp(6px, 0.8vw, 7px);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(255, 244, 210, 0.72);
  text-shadow: 0 1px 0 #1a1020;
}

.sound-btn .sound-bars {
  height: clamp(9px, 1.3vw, 12px);
}

.sound-btn.muted {
  opacity: 0.55;
}

.sound-btn.muted::after {
  content: "";
  position: absolute;
  width: 60%;
  height: 1px;
  background: #e9baba;
  transform: rotate(-43deg);
}

#screen.is-paused .touch-dpad,
#screen.is-paused .touch-actions {
  opacity: 0.35;
}

#screen.is-paused .touch-dpad .touch-btn,
#screen.is-paused .touch-actions .touch-btn {
  pointer-events: none;
}

.pause-glyph i {
  display: block;
  width: 3px;
  height: clamp(8px, 1.4vw, 11px);
  border-radius: 1px;
  background: var(--cream);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}

.pause-label {
  font-family: "Courier New", monospace;
  font-size: clamp(6px, 0.8vw, 7px);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(255, 244, 210, 0.72);
  text-shadow: 0 1px 0 #1a1020;
}

.jump-label {
  font-family: "Courier New", monospace;
  font-size: clamp(8px, 1.2vw, 10px);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--gold);
  text-shadow: 0 1px 0 #1a1020;
}

.arrow {
  display: block;
  width: 0;
  height: 0;
  border-top: clamp(9px, 1.5vw, 12px) solid transparent;
  border-bottom: clamp(9px, 1.5vw, 12px) solid transparent;
}

.arrow-left {
  border-right: clamp(12px, 2.1vw, 16px) solid var(--cream);
  margin-left: -3px;
}

.arrow-right {
  border-left: clamp(12px, 2.1vw, 16px) solid var(--cream);
  margin-right: -3px;
}

.jump-glyph {
  position: relative;
  width: 0;
  height: 0;
  border-left: clamp(9px, 1.6vw, 12px) solid transparent;
  border-right: clamp(9px, 1.6vw, 12px) solid transparent;
  border-bottom: clamp(14px, 2.6vw, 19px) solid var(--cream);
  margin-top: -2px;
}

#rotate-hint {
  display: none;
  position: fixed;
  z-index: 20;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 12px;
  border: 1px solid rgba(255, 225, 159, 0.28);
  background: rgba(9, 7, 18, 0.82);
  color: rgba(255, 241, 208, 0.75);
  font-size: 9px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  pointer-events: none;
}

#rotate-hint span {
  display: inline-block;
  margin-right: 5px;
  color: var(--gold);
  font-size: 12px;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  background: #0b0918;
  color: var(--cream);
  text-align: center;
}

@media (hover: none), (pointer: coarse) {
  #touch-controls {
    display: flex;
  }

  /* On touch the run controls live in the bottom cluster, clear of the HUD. */
  #play-controls {
    display: none !important;
  }

  #screen.is-run #quick-sound {
    display: none !important;
  }

  #quick-sound {
    top: 12.5%;
    right: max(10px, env(safe-area-inset-right));
    bottom: auto;
  }

  canvas {
    cursor: default;
  }
}

@media (max-height: 420px) and (orientation: landscape) {
  #touch-controls {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  #quick-sound {
    top: 11%;
    right: 12px;
    bottom: auto;
  }
}

@media (orientation: portrait) and (pointer: coarse) and (max-width: 700px) {
  #rotate-hint {
    display: block;
  }

  #game-shell {
    align-self: center;
  }
}

#play-controls {
  position: absolute;
  z-index: 8;
  top: calc(12.5% + clamp(34px, 4.2vw, 46px));
  right: max(10px, 1.8vw);
  display: flex;
  gap: 6px;
}

#play-controls[hidden] {
  display: none !important;
}

.play-btn {
  width: clamp(32px, 3.6vw, 40px);
  height: clamp(28px, 3.2vw, 34px);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(216, 193, 240, 0.4);
  background: rgba(9, 7, 20, 0.64);
  color: var(--gold);
  cursor: pointer;
  opacity: 0.78;
  transition: opacity 140ms ease, background 140ms ease;
  touch-action: manipulation;
}

.play-btn:hover {
  opacity: 1;
  background: rgba(29, 21, 52, 0.9);
}

.play-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.play-btn:active {
  background: rgba(54, 39, 78, 0.95);
}

.play-btn svg {
  width: clamp(10px, 1.2vw, 13px);
  height: clamp(10px, 1.2vw, 13px);
}

.play-btn svg[hidden] {
  display: none;
}

@media (hover: none), (pointer: coarse) {
  #play-controls {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
  }

  #screen.is-run #account-button {
    display: none !important;
  }
}

#account-button {
  position: absolute;
  z-index: 8;
  top: 12.5%;
  right: calc(max(10px, 1.8vw) + clamp(36px, 4vw, 46px));
  height: clamp(22px, 2.6vw, 30px);
  padding: 0 clamp(6px, 0.9vw, 10px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(216, 193, 240, 0.4);
  background: rgba(9, 7, 20, 0.64);
  color: var(--gold);
  font-family: "Courier New", monospace;
  font-size: clamp(7px, 0.95vw, 10px);
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  opacity: 0.78;
  transition: opacity 140ms ease, background 140ms ease;
  touch-action: manipulation;
}

#account-button:hover {
  opacity: 1;
  background: rgba(29, 21, 52, 0.9);
}

#account-button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

#account-button.is-signed-in {
  color: #a9e5d6;
  border-color: rgba(169, 229, 214, 0.5);
}

#account-button[hidden] {
  display: none !important;
}

#account-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vw, 24px);
  overflow: auto;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(58, 38, 88, 0.32), transparent 62%),
    rgba(5, 3, 12, 0.82);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  -webkit-user-select: text;
  user-select: text;
}

#account-overlay[hidden],
#account-overlay [hidden] {
  display: none !important;
}

.account-card {
  position: relative;
  width: min(92%, 360px);
  max-height: calc(100vh - 16px);
  overflow: auto;
  padding: clamp(12px, 2vw, 18px);
  color: var(--cream);
  background: linear-gradient(180deg, rgba(22, 16, 40, 0.98), rgba(10, 7, 20, 0.98));
  border: 2px solid rgba(240, 207, 136, 0.5);
  box-shadow:
    0 0 0 2px rgba(9, 6, 18, 0.9),
    0 18px 50px rgba(0, 0, 0, 0.65),
    0 0 40px rgba(255, 211, 90, 0.08);
}

.account-close {
  position: absolute;
  top: 4px;
  right: 6px;
  padding: 4px 6px;
  border: 0;
  background: none;
  color: #cbb8e0;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.account-close:hover,
.account-close:focus-visible {
  color: var(--gold);
}

#account-title {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: clamp(14px, 2.2vw, 18px);
  letter-spacing: 0.12em;
}

.account-status {
  margin: 0 0 9px;
  color: #cbb8e0;
  font-size: 11px;
  line-height: 1.4;
}

.account-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 9px;
}

.account-tab {
  flex: 1;
  padding: 8px 6px;
  border: 1px solid rgba(216, 193, 240, 0.22);
  background: rgba(12, 9, 24, 0.7);
  color: #a99ac0;
  font-family: "Courier New", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.account-tab.is-active {
  color: #1a1020;
  background: linear-gradient(180deg, #ffe08c, #e8b95a);
  border-color: #ffe8a2;
}

.account-tab:focus-visible,
.account-primary:focus-visible,
.account-secondary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.account-field {
  display: block;
  margin: 0 0 8px;
  color: #b9a8cc;
  font-size: 10px;
  letter-spacing: 0.12em;
}

.account-field input {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid rgba(216, 193, 240, 0.28);
  background: #0a0714;
  color: var(--cream);
  font-family: "Courier New", monospace;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  outline: none;
}

.account-field input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(255, 211, 90, 0.35);
}

.account-error {
  min-height: 13px;
  margin: 0 0 6px;
  color: #ffb3a7;
  font-size: 10px;
  line-height: 1.35;
}

.account-primary {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #ffe8a2;
  background: linear-gradient(180deg, #ffe08c, #e8b95a);
  color: #221321;
  font-family: "Courier New", monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.account-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.account-secondary {
  width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(216, 193, 240, 0.3);
  background: rgba(18, 13, 32, 0.8);
  color: #d8c7e8;
  font-family: "Courier New", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.account-secondary:hover {
  background: rgba(44, 32, 68, 0.9);
  border-color: rgba(255, 211, 90, 0.45);
}

.account-signedin {
  padding: 8px 0 2px;
}

.account-name {
  margin: 0 0 2px;
  color: #ffe8b0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.account-email {
  margin: 0 0 4px;
  color: #a997bd;
  font-size: 11px;
  word-break: break-all;
}

.account-sync {
  margin: 0 0 4px;
  color: #a9e5d6;
  font-size: 10px;
  letter-spacing: 0.14em;
}

.account-sync[data-tone="warn"] {
  color: #ffd58a;
}

.account-hint {
  margin: 10px 0 0;
  color: #8d7da4;
  font-size: 9px;
  line-height: 1.5;
}

@media (max-width: 520px) {
  #account-button {
    top: 13.5%;
    right: calc(max(8px, 2vw) + 36px);
  }
}

@media (prefers-reduced-motion: reduce) {
  #touch-controls,
  #quick-sound,
  #account-button {
    transition: none;
  }
}
