:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #101014;
  color: #fff8e8;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #101014;
}

.game-shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 15%, rgba(252, 199, 73, 0.28), transparent 28%),
    linear-gradient(135deg, #101014 0%, #1a2735 46%, #151216 100%);
}

canvas {
  width: 100vw;
  height: 100vh;
  display: block;
  image-rendering: auto;
}

.hud {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  pointer-events: none;
  z-index: 2;
}

.hud div {
  min-width: 92px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(12, 12, 16, 0.66);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(8px);
}

.label {
  display: block;
  color: #9ee6d0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  margin-top: 1px;
  font-size: 22px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.trick-hud {
  position: fixed;
  left: 50%;
  top: 78px;
  z-index: 2;
  width: min(100ch, calc(100vw - 32px));
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}

.trick-hud strong {
  display: block;
  color: #ffd766;
  font-size: clamp(18px, 4vw, 34px);
  line-height: 1.05;
  text-shadow: 3px 3px 0 #101014;
}

.trick-hud span {
  display: block;
  margin-top: 4px;
  color: #fff8e8;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.18;
  max-height: 76.7px;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
  text-shadow: 2px 2px 0 #101014;
}

.trick-pop {
  position: fixed;
  left: 50%;
  top: 42%;
  z-index: 3;
  transform: translate(-50%, -50%) scale(0.94);
  opacity: 0;
  color: #ffd766;
  font-size: clamp(28px, 7vw, 78px);
  font-weight: 1000;
  line-height: 0.95;
  text-align: center;
  text-shadow: 4px 4px 0 #101014, 7px 7px 0 #ba3f59;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.trick-pop.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.donate-link {
  position: fixed;
  right: 16px;
  bottom: 14px;
  z-index: 4;
  padding: 7px 10px;
  border: 1px solid rgba(255, 215, 102, 0.46);
  border-radius: 8px;
  background: rgba(12, 12, 16, 0.58);
  color: #ffd766;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  text-shadow: 1px 1px 0 #101014;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

.donate-link:hover,
.donate-link:focus-visible {
  border-color: rgba(255, 215, 102, 0.82);
  background: rgba(12, 12, 16, 0.78);
  outline: none;
}

.settings {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 5;
  width: min(360px, calc(100vw - 32px));
}

.settings details {
  max-height: calc(100vh - 32px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(12, 12, 16, 0.72);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(10px);
  overflow: hidden;
}

.settings details[open] {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #35d0a3 rgba(255, 255, 255, 0.08);
}

.settings summary {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 42px;
  display: flex;
  align-items: center;
  padding: 0 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(12, 12, 16, 0.92);
  color: #ffd766;
  font-weight: 900;
  cursor: pointer;
  user-select: none;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  padding: 0 12px 12px;
}

.settings label {
  min-width: 0;
  cursor: help;
}

.settings-section {
  grid-column: 1 / -1;
  padding-top: 4px;
  color: #ffd766;
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: 0;
  text-transform: uppercase;
}

.settings span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  margin-bottom: 4px;
  color: #fff8e8;
  font-size: 12px;
  font-weight: 800;
}

.settings b {
  min-width: 0;
  max-width: 72px;
  overflow: hidden;
  color: #9ee6d0;
  font-variant-numeric: tabular-nums;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings input,
.settings select {
  width: 100%;
  accent-color: #35d0a3;
}

.settings input[type="checkbox"] {
  position: relative;
  width: 44px;
  height: 24px;
  justify-self: end;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
}

.settings input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff8e8;
  transition: transform 120ms ease, background 120ms ease;
}

.settings input[type="checkbox"]:checked {
  background: #35d0a3;
  border-color: rgba(158, 230, 208, 0.78);
}

.settings input[type="checkbox"]:checked::after {
  transform: translateX(20px);
  background: #101014;
}

.settings .toggle-setting {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: end;
  gap: 8px;
}

.settings .toggle-setting span {
  margin-bottom: 2px;
}

.settings select {
  height: 34px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(5, 5, 8, 0.88);
  color: #fff8e8;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
}

.settings-template {
  display: grid;
  grid-template-columns: 1fr 122px;
  gap: 8px;
  padding: 0 12px 10px;
}

.settings-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 12px 10px;
}

.settings button {
  width: 100%;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff8e8;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.keybinds {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.keybind-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  align-items: center;
  gap: 8px;
}

.keybind-row span {
  margin: 0;
}

.keybind-row button,
.keybind-reset {
  height: 30px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keybind-reset {
  grid-column: 1 / -1;
}

.settings textarea {
  display: block;
  width: calc(100% - 24px);
  min-height: 110px;
  margin: 0 12px 12px;
  padding: 8px;
  resize: vertical;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(5, 5, 8, 0.78);
  color: #fff8e8;
  font: 700 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.message {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  transform: translate(-50%, -50%);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(15, 15, 20, 0.78);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(12px);
  text-align: center;
  z-index: 4;
  overflow-y: auto;
}

.message.hidden {
  display: none;
}

.error {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 88px;
  z-index: 5;
  padding: 12px 14px;
  border: 1px solid rgba(255, 118, 118, 0.5);
  border-radius: 8px;
  background: rgba(45, 10, 14, 0.88);
  color: #ffe4e4;
  font: 700 13px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.error.hidden {
  display: none;
}

.message h1 {
  margin: 0 0 8px;
  color: #ffd766;
  font-size: clamp(32px, 8vw, 58px);
  line-height: 0.95;
  letter-spacing: 0;
  text-shadow: 4px 4px 0 #ba3f59;
}

.message p {
  margin: 0 0 18px;
  color: #fff8e8;
  line-height: 1.45;
}

.scoreboard {
  margin: 0 0 18px;
  text-align: left;
}

.scoreboard h2 {
  margin: 0 0 8px;
  color: #9ee6d0;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.scoreboard table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.scoreboard th,
.scoreboard td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.scoreboard th {
  color: #ffd766;
  font-size: 11px;
  text-transform: uppercase;
}

.scoreboard td {
  color: #fff8e8;
  font-weight: 800;
}

.scoreboard tr:last-child td {
  border-bottom: 0;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.message button {
  width: 128px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: #35d0a3;
  color: #081011;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 0 #17785d;
}

.message button.hidden {
  display: none;
}

.message button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #17785d;
}

.touch {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 3;
  pointer-events: none;
  touch-action: none;
}

.touch.hidden-by-setting {
  display: none !important;
}

.touch.editing {
  display: block;
  background:
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 32px 32px;
}

.touch button {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(64px * var(--touch-scale, 1));
  height: calc(56px * var(--touch-scale, 1));
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(10, 10, 14, 0.66);
  color: #fff8e8;
  font-size: calc(24px * var(--touch-scale, 1));
  font-weight: 900;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  transform: translate(-50%, -50%);
  touch-action: none;
  user-select: none;
}

.touch button[data-action="pause"],
.touch button[data-action="restart"] {
  width: calc(46px * var(--touch-scale, 1));
  height: calc(42px * var(--touch-scale, 1));
  border-color: rgba(255, 215, 102, 0.42);
  color: #ffd766;
  font-size: calc(22px * var(--touch-scale, 1));
}

.touch.editing button {
  border-color: rgba(255, 215, 102, 0.78);
  background: rgba(12, 12, 16, 0.82);
  cursor: grab;
}

.touch.editing button.touch-dragging {
  border-color: #35d0a3;
  cursor: grabbing;
}

@media (hover: none), (max-width: 760px) {
  .touch {
    display: block;
  }

  .hud {
    top: 10px;
    left: 10px;
    right: 84px;
    display: grid;
    gap: 0;
    max-width: 224px;
    padding: 6px 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    background: rgba(12, 12, 16, 0.72);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(8px);
  }

  .hud div {
    min-width: 0;
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    align-items: baseline;
    gap: 6px;
    padding: 2px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  .hud .label {
    font-size: 9px;
  }

  .hud strong {
    margin-top: 0;
    min-width: 0;
    overflow: hidden;
    font-size: 14px;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .trick-hud {
    top: 116px;
    left: 10px;
    width: min(280px, calc(100vw - 20px));
    transform: none;
    text-align: left;
  }

  .trick-hud strong {
    font-size: 16px;
    line-height: 1;
    text-shadow: 2px 2px 0 #101014;
  }

  .trick-hud span {
    max-height: 35.9px;
    font-size: 10.5px;
    line-height: 1.14;
  }

  .trick-pop {
    top: 176px;
    left: 10px;
    width: calc(100vw - 24px);
    max-width: 280px;
    transform: scale(0.94);
    transform-origin: top left;
    font-size: clamp(18px, 6.5vw, 34px);
    line-height: 0.96;
    text-align: left;
    text-shadow: 2px 2px 0 #101014, 4px 4px 0 #ba3f59;
  }

  .trick-pop.show {
    transform: scale(1);
  }

  .settings {
    top: 10px;
    right: 10px;
    width: 74px;
  }

  .donate-link {
    top: 58px;
    right: 10px;
    bottom: auto;
    padding: 6px 8px;
    font-size: 10px;
  }

  .settings details[open] {
    max-height: calc(100vh - 20px);
    width: min(340px, calc(100vw - 20px));
    transform: translateX(calc(74px - min(340px, calc(100vw - 20px))));
  }

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

@media (hover: none) and (orientation: landscape), (max-width: 760px) and (orientation: landscape) {
  .hud {
    top: 8px;
    left: 8px;
    max-width: 204px;
    padding: 5px 7px;
  }

  .hud div {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 5px;
    padding: 1px 0;
  }

  .hud .label {
    font-size: 8px;
  }

  .hud strong {
    font-size: 12.5px;
  }

  .trick-hud {
    top: 92px;
    left: 8px;
    width: min(250px, calc(100vw - 16px));
  }

  .trick-hud strong {
    font-size: 14px;
  }

  .trick-hud span {
    max-height: 31.9px;
    font-size: 9.5px;
    line-height: 1.12;
  }

  .trick-pop {
    top: 138px;
    left: 8px;
    max-width: 250px;
    font-size: clamp(16px, 5vw, 28px);
  }

  .donate-link {
    top: 54px;
    right: 8px;
  }
}
