:root {
  color-scheme: dark;
  --ink: #f4fff8;
  --muted: #a9c6b8;
  --panel: rgba(10, 18, 26, 0.78);
  --line: rgba(205, 255, 225, 0.2);
  --teal: #4ff0c8;
  --gold: #f7d774;
  --rose: #ff6b93;
  --moss: #86c06c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: var(--app-height, 100dvh);
  overflow: hidden;
  color: var(--ink);
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  background:
    radial-gradient(circle at 18% 12%, rgba(79, 240, 200, 0.2), transparent 26rem),
    radial-gradient(circle at 78% 20%, rgba(247, 215, 116, 0.18), transparent 24rem),
    linear-gradient(145deg, #07111d 0%, #0d1c20 45%, #17121d 100%);
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  width: min(1480px, 100vw);
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  padding: 18px;
}

.game-panel {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  background: #08131c;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 2;
}

.hud div,
.side {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
}

.hud div {
  min-width: 120px;
  padding: 10px 12px;
}

.label,
small {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.hud strong {
  font-size: 1.05rem;
}

.message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  padding: 22px;
  text-align: center;
  background: rgba(4, 8, 14, 0.58);
  z-index: 4;
}

.touch {
  display: none;
  justify-content: space-between;
  pointer-events: auto;
}

.touch div {
  display: flex;
  gap: 10px;
}

.touch-button {
  min-width: 62px;
  min-height: 52px;
  border: 1px solid rgba(244, 255, 248, 0.2);
  color: var(--ink);
  background: rgba(10, 18, 26, 0.72);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.message.hidden {
  display: none;
}

.message h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 5.8rem);
  line-height: 0.95;
  text-shadow: 0 0 32px rgba(79, 240, 200, 0.4);
}

.message p {
  max-width: 560px;
  margin: 0 auto;
  color: #d9f6ea;
  font-size: 1.05rem;
}

button {
  justify-self: center;
  min-width: 132px;
  border: 0;
  padding: 12px 20px;
  color: #062119;
  background: var(--teal);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button:hover,
button:focus-visible {
  background: var(--gold);
  outline: 3px solid rgba(247, 215, 116, 0.35);
}

.side {
  display: flex;
  min-height: 0;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
}

.side h2 {
  margin: 0;
  color: var(--teal);
  font-size: 1.6rem;
}

.status {
  color: #d6eee5;
  font-size: 1rem;
  line-height: 1.5;
}

.controls {
  display: grid;
  grid-template-columns: 72px repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.controls span {
  color: var(--muted);
  font-size: 0.88rem;
}

kbd {
  min-height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(244, 255, 248, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
}

.meters {
  display: grid;
  gap: 18px;
}

.bar {
  height: 12px;
  margin-top: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.09);
}

.bar span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--rose), var(--gold), var(--teal));
}

.well-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.well-row span {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
}

.well-row span.lit {
  background: var(--teal);
  box-shadow: 0 0 20px rgba(79, 240, 200, 0.72);
}

.well-row span.current {
  border-color: var(--gold);
}

@media (max-width: 900px) {
  html,
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .shell {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto auto;
    width: 100vw;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    padding: 0;
    background:
      linear-gradient(180deg, #142225 0%, #07101f 58%, #101417 100%);
  }

  .game-panel {
    width: 100vw;
    height: auto;
    min-height: 0;
    border: 0;
    border-bottom: 6px solid rgba(205, 255, 225, 0.18);
    box-shadow: inset 0 -18px 40px rgba(0, 0, 0, 0.35);
  }

  .side {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 160px;
    gap: 10px 14px;
    margin: 0;
    padding: 10px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
    border-width: 1px 0 0;
    background: rgba(10, 18, 26, 0.92);
    pointer-events: auto;
  }

  .side h2,
  .controls {
    display: none;
  }

  .status {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.25;
  }

  .meters {
    align-self: center;
    gap: 8px;
  }

  .meters small {
    font-size: 0.72rem;
  }

  .well-row span {
    width: 20px;
    height: 20px;
  }

  .touch {
    position: static;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 132px;
    padding: 14px max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    background:
      radial-gradient(circle at 20% 35%, rgba(79, 240, 200, 0.12), transparent 9rem),
      radial-gradient(circle at 82% 30%, rgba(255, 107, 147, 0.13), transparent 8rem),
      linear-gradient(180deg, #171c20, #0f1216);
    border-top: 1px solid rgba(244, 255, 248, 0.16);
  }

  .hud {
    right: auto;
    max-width: calc(100vw - 20px);
    gap: 6px;
  }

  .hud div {
    min-width: 74px;
    padding: 6px 8px;
  }

  .hud div:nth-child(3) {
    display: none;
  }

  .hud strong {
    font-size: 0.9rem;
  }

  .label {
    font-size: 0.7rem;
  }

  .touch div {
    gap: 12px;
  }

  .touch-pad,
  .touch-actions {
    display: flex;
    align-items: center;
  }

  .touch-button {
    min-width: 74px;
    min-height: 66px;
    padding: 0 12px;
    font-size: 0.98rem;
    border-radius: 8px;
    background: rgba(10, 18, 26, 0.82);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  }

  .touch-left,
  .touch-right {
    min-width: 68px;
    border-radius: 10px;
  }

  .touch-jump {
    min-width: 86px;
    min-height: 78px;
    border-radius: 999px;
    background: #4ff0c8;
    color: #062119;
  }

  .touch-dash {
    min-width: 76px;
    min-height: 64px;
    border-radius: 999px;
    background: #ff6b93;
    color: #280f1a;
  }

  .message {
    padding: 22px max(18px, env(safe-area-inset-right)) 22px max(18px, env(safe-area-inset-left));
  }

  .message h1 {
    font-size: clamp(2rem, 14vw, 4rem);
  }

  .message p {
    max-width: min(560px, 88vw);
    font-size: 0.98rem;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  .shell {
    background: #07101f;
  }

  .game-panel {
    min-height: 0;
  }

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

  .status {
    display: none;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
  }

  .hud div {
    min-width: 76px;
    padding: 5px 8px;
  }

  .side {
    width: auto;
    grid-template-columns: 1fr;
    padding: 8px 10px;
  }

  .status {
    display: none;
  }

  .meters {
    gap: 6px;
  }

  .touch {
    min-height: 96px;
    padding-top: 8px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .touch-button {
    min-width: 82px;
    min-height: 54px;
  }

  .touch-jump {
    min-height: 62px;
  }

  .message h1 {
    font-size: clamp(2rem, 8vw, 4rem);
  }

  .message p {
    max-width: min(640px, 78vw);
  }
}
