:root {
  --bg: #07100f;
  --panel: rgba(6, 20, 18, 0.82);
  --ink: #eafff7;
  --muted: #83a89b;
  --line: #56f7c7;
  --line2: #8ee7ff;
  --red: #ff3b5f;
  --green: #34ff9d;
  --gold: #ffd36c;
  --dark: #041110;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 8%, rgba(86, 247, 199, 0.15), transparent 30%),
    radial-gradient(circle at 86% 80%, rgba(255, 59, 95, 0.12), transparent 28%),
    linear-gradient(180deg, #07100f 0%, #020706 100%);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

button {
  border: 0;
  color: var(--ink);
  font: 800 14px/1 "Avenir Next", "Segoe UI", sans-serif;
  letter-spacing: 0;
  cursor: pointer;
}

.shell {
  width: min(100vw, calc(83.333dvh - 128px));
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: minmax(132px, 17dvh) minmax(0, 1fr);
  padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  gap: 8px;
}

.hud {
  min-height: 132px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border: 1px solid rgba(86, 247, 199, 0.18);
  background: linear-gradient(180deg, rgba(7, 24, 22, 0.88), rgba(4, 13, 13, 0.72));
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22), inset 0 0 30px rgba(86, 247, 199, 0.04);
  backdrop-filter: blur(16px);
  border-radius: 8px;
}

.readout {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: minmax(94px, 1.1fr) minmax(90px, 1fr) minmax(94px, 1fr);
  align-items: end;
  gap: 10px;
  min-width: 0;
}

.metric {
  min-width: 0;
  display: grid;
  gap: 3px;
  justify-items: center;
}

.metric span:first-child {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.metric strong {
  display: flex;
  align-items: baseline;
  justify-content: center;
  min-width: 0;
  color: var(--ink);
  font-family: "DIN Condensed", "Avenir Next Condensed", "Impact", sans-serif;
  font-size: 42px;
  line-height: 0.9;
  font-weight: 800;
  text-shadow: 0 0 18px rgba(86, 247, 199, 0.3);
}

.metricTime strong {
  color: #34ff9d;
  font-size: 56px;
}

.metric small {
  margin-left: 5px;
  color: rgba(234, 255, 247, 0.58);
  font: 800 14px/1 "Avenir Next", "Segoe UI", sans-serif;
}

#timer,
#drop,
#speed {
  display: inline-block;
  font-family: "DIN Condensed", "Avenir Next Condensed", "Impact", sans-serif;
  font-weight: 900;
  line-height: 0.82;
}

#timer {
  color: #34ff9d;
  font-size: 72px;
}

#drop,
#speed {
  font-size: 58px;
}

.metric.speed-green span,
.metric.speed-green strong,
.metric.speed-green small,
#speed.speed-green {
  color: #34ff9d !important;
}

.metric.speed-yellow span,
.metric.speed-yellow strong,
.metric.speed-yellow small,
#speed.speed-yellow {
  color: #ffd33d !important;
}

.metric.speed-red span,
.metric.speed-red strong,
.metric.speed-red small,
#speed.speed-red {
  color: #ff264f !important;
  text-shadow: 0 0 22px rgba(255, 38, 79, 0.55);
}

.actions {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.primary,
.ghost {
  min-height: 52px;
  padding: 0 15px;
  border-radius: 7px;
  white-space: nowrap;
  transition: transform 160ms ease, opacity 160ms ease, filter 160ms ease;
}

#challengeBtn {
  grid-column: 1;
  grid-row: 1;
}

.primary {
  background: linear-gradient(135deg, #21d894, #6bf4de);
  color: #03201a;
  box-shadow: 0 0 20px rgba(86, 247, 199, 0.22);
}

.ghost {
  border: 1px solid rgba(234, 255, 247, 0.15);
  background: rgba(234, 255, 247, 0.06);
}

.primary:active,
.ghost:active {
  transform: translateY(1px) scale(0.98);
}

.stageWrap {
  position: relative;
  width: min(100%, calc(83.333dvh - 154px));
  max-height: 100%;
  aspect-ratio: 5 / 6;
  align-self: center;
  justify-self: center;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid rgba(86, 247, 199, 0.16);
  background:
    linear-gradient(rgba(86, 247, 199, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(86, 247, 199, 0.04) 1px, transparent 1px),
    radial-gradient(circle at 50% 14%, rgba(86, 247, 199, 0.10), transparent 25%),
    #061210;
  background-size: 50px 50px, 50px 50px, auto, auto;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.54);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hint {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  min-height: 18px;
  text-align: center;
  color: rgba(234, 255, 247, 0.72);
  font-size: 12px;
  pointer-events: none;
  text-shadow: 0 1px 10px #000;
}

.contextMenu {
  position: absolute;
  z-index: 5;
  display: flex;
  gap: 7px;
  padding: 7px;
  transform: translate(-50%, -112%);
  border-radius: 8px;
  border: 1px solid rgba(234, 255, 247, 0.14);
  background: rgba(3, 12, 11, 0.92);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
}

.contextMenu button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  background: rgba(234, 255, 247, 0.1);
}

.contextMenu button:first-child {
  color: #fff;
  background: rgba(255, 59, 95, 0.78);
}

.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  max-width: calc(100% - 30px);
  padding: 10px 14px;
  color: #061210;
  background: rgba(234, 255, 247, 0.92);
  border-radius: 7px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  font-weight: 800;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  white-space: pre-line;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(0, 5, 5, 0.72);
  backdrop-filter: blur(10px);
}

.modalPanel {
  width: min(360px, 100%);
  padding: 22px;
  border-radius: 8px;
  border: 1px solid rgba(86, 247, 199, 0.25);
  background:
    linear-gradient(145deg, rgba(9, 35, 31, 0.96), rgba(4, 13, 13, 0.96));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}

.modalPanel h1 {
  margin: 0 0 10px;
  font-family: "DIN Condensed", "Avenir Next Condensed", "Impact", sans-serif;
  font-size: 36px;
  letter-spacing: 0;
}

.modalPanel p {
  margin: 0 0 18px;
  color: rgba(234, 255, 247, 0.78);
  line-height: 1.6;
}

.shareUrl {
  width: 100%;
  height: 42px;
  margin: 0 0 13px;
  padding: 0 10px;
  border: 1px solid rgba(234, 255, 247, 0.16);
  border-radius: 7px;
  outline: none;
  color: var(--ink);
  background: rgba(234, 255, 247, 0.08);
  font: 700 13px/1 "Avenir Next", "Segoe UI", sans-serif;
  user-select: text;
  touch-action: auto;
}

.modalActions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  justify-content: flex-end;
}

.hidden {
  display: none !important;
}

@media (max-width: 430px) {
  .shell {
    padding-left: 6px;
    padding-right: 6px;
  }

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

  .readout {
    gap: 4px;
    grid-template-columns: minmax(58px, 1fr) minmax(56px, 1fr) minmax(58px, 1fr);
  }

  .metric span:first-child {
    font-size: 12px;
  }

  .metric strong {
    font-size: 36px;
  }

  .metricTime strong {
    font-size: 46px;
  }

  #timer {
    font-size: 62px;
  }

  #drop,
  #speed {
    font-size: 50px;
  }

  .primary,
  .ghost {
    min-height: 44px;
    padding: 0 10px;
    font-size: 12px;
  }
}
