:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --bg: #090a0f;
  --panel: rgba(13, 16, 24, 0.84);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f7f8ff;
  --muted: #aeb8c8;
  --hot: #ff477e;
  --cyan: #38e8ff;
  --lime: #9cff3b;
  --gold: #ffd166;
  --app-height: 100svh;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  touch-action: manipulation;
  background:
    radial-gradient(circle at 18% 8%, rgba(56, 232, 255, 0.2), transparent 30%),
    radial-gradient(circle at 88% 22%, rgba(255, 71, 126, 0.18), transparent 28%),
    linear-gradient(135deg, #07080c 0%, #12131a 44%, #06080d 100%);
  color: var(--text);
}

button {
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
}

.stage-wrap {
  position: relative;
  min-width: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none;
}

#gameCanvas {
  width: min(100%, calc((100vh - 16px) * 1.68));
  height: auto;
  max-height: calc(100vh - 16px);
  display: block;
}

.title-screen,
.pause-screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 28px;
  text-align: center;
  background: linear-gradient(180deg, rgba(5, 7, 12, 0.18), rgba(5, 7, 12, 0.6));
}

.pause-screen {
  z-index: 9;
  background: rgba(4, 8, 16, 0.58);
  backdrop-filter: blur(12px) saturate(1.25);
}

.pause-screen[hidden],
.title-screen.is-hidden {
  display: none;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(46px, 8vw, 112px);
  line-height: 0.9;
  letter-spacing: 0;
  text-shadow:
    0 0 24px rgba(56, 232, 255, 0.54),
    0 0 46px rgba(255, 71, 126, 0.35);
}

.version-badge,
.hud-version {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: var(--gold);
  background: rgba(8, 12, 20, 0.5);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.version-badge {
  margin: 14px 0 0;
  box-shadow: 0 0 18px rgba(255, 209, 102, 0.2);
}

.tagline {
  width: min(680px, 92vw);
  margin: 14px 0 30px;
  color: #dce6f5;
  font-size: clamp(15px, 2.3vw, 21px);
  line-height: 1.65;
}

.title-actions,
.control-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  font-weight: 850;
  cursor: pointer;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background 150ms ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(56, 232, 255, 0.7);
  background: rgba(56, 232, 255, 0.13);
  outline: 0;
}

#startButton,
#riftButton,
.drop-button {
  color: #091018;
  background: linear-gradient(135deg, var(--cyan), var(--lime));
  border-color: transparent;
}

.rotate-mode-button {
  display: none;
}

.rotate-mode-button[hidden] {
  display: none;
}

.hud-panel {
  height: 100vh;
  overflow: auto;
  padding: 24px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.hud-panel header {
  margin-bottom: 20px;
}

.hud-version {
  margin-top: 8px;
  font-size: 11px;
}

.hud-panel header p {
  margin: 0 0 5px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h2,
h3,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 27px;
  line-height: 1.05;
}

h3 {
  margin-bottom: 10px;
  color: #f7f8ff;
  font-size: 13px;
  text-transform: uppercase;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-grid > div,
.mini-board,
.rift-meter,
.key-guide {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.stat-grid > div {
  min-height: 76px;
  padding: 12px;
}

.stat-grid span,
.mini-board span,
.rift-meter span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.stat-grid strong,
.rift-meter strong {
  font-size: 28px;
  font-variant-numeric: tabular-nums;
}

.preview-stack {
  display: grid;
  gap: 12px;
  margin: 14px 0;
}

.mini-board {
  padding: 12px;
}

.mini-board canvas {
  width: 100%;
  height: auto;
  display: block;
}

.rift-meter {
  padding: 14px;
}

.rift-meter.is-ready {
  border-color: rgba(88, 255, 79, 0.72);
  box-shadow:
    0 0 18px rgba(88, 255, 79, 0.32),
    0 0 38px rgba(56, 232, 255, 0.18);
}

.rift-meter.is-ready strong {
  color: var(--lime);
  text-shadow: 0 0 18px rgba(88, 255, 79, 0.68);
}

.rift-meter.is-ready meter {
  filter: drop-shadow(0 0 12px rgba(88, 255, 79, 0.72));
}

.drop-button {
  width: 100%;
  margin-top: 12px;
}

.rift-meter div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

meter {
  width: 100%;
  height: 12px;
  margin: 10px 0 12px;
  accent-color: var(--hot);
}

.control-strip {
  margin: 14px 0;
}

.control-strip button {
  flex: 1 1 92px;
  padding: 0 10px;
}

.key-guide {
  padding: 14px;
}

.key-guide p {
  margin: 8px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #d6deec;
  font-size: 13px;
}

kbd {
  min-width: 28px;
  min-height: 24px;
  margin-right: 4px;
  padding: 3px 7px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-color: rgba(255, 255, 255, 0.38);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.32);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}

.pause-screen strong {
  animation: pausePulse 2.4s ease-in-out infinite;
  letter-spacing: 0;
  color: #f7f8ff;
  font-size: clamp(54px, 10vw, 96px);
  font-weight: 900;
  line-height: 1;
  text-shadow:
    0 0 26px rgba(56, 232, 255, 0.72),
    0 0 58px rgba(255, 71, 126, 0.38);
}

.pause-screen span {
  margin: 10px 0 20px;
  color: var(--muted);
}

@keyframes pausePulse {
  0%,
  100% {
    opacity: 0.42;
    text-shadow:
      0 0 16px rgba(56, 232, 255, 0.45),
      0 0 36px rgba(255, 71, 126, 0.18);
  }

  50% {
    opacity: 1;
    text-shadow:
      0 0 30px rgba(56, 232, 255, 0.86),
      0 0 68px rgba(255, 71, 126, 0.46);
  }
}

@media (max-width: 1100px) and (orientation: portrait) {
  html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    width: 100vw;
    height: var(--app-height);
    overflow: hidden;
    overscroll-behavior: none;
    position: fixed;
    inset: 0;
    touch-action: none;
  }

  .game-shell {
    position: fixed;
    inset: 0;
    display: block;
    width: 100vw;
    max-width: 100vw;
    min-height: 100svh;
    min-height: var(--app-height);
    height: 100svh;
    height: var(--app-height);
    overflow: hidden;
    transform: translate3d(0, 0, 0);
  }

  .stage-wrap {
    min-height: 100svh;
    min-height: var(--app-height);
    height: 100svh;
    height: var(--app-height);
  }

  #gameCanvas {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .hud-panel {
    position: absolute;
    inset: 0;
    z-index: 4;
    height: 100svh;
    height: var(--app-height);
    min-height: 100svh;
    min-height: var(--app-height);
    overflow: hidden;
    padding: 0;
    pointer-events: none;
    background: transparent;
    border-left: 0;
    border-top: 0;
    backdrop-filter: none;
  }

  .hud-panel header {
    display: none;
  }

  .stat-grid {
    position: absolute;
    top: max(22px, calc(env(safe-area-inset-top) + 14px));
    left: 50%;
    width: min(42vw, 156px);
    transform: translateX(-50%);
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
  }

  .stat-grid > div {
    min-height: 44px;
    padding: 7px 5px;
    border-radius: 7px;
    background: rgba(8, 12, 20, 0.54);
    backdrop-filter: blur(12px);
  }

  .stat-grid span,
  .mini-board span,
  .rift-meter span {
    margin-bottom: 4px;
    font-size: 8px;
  }

  .stat-grid strong,
  .rift-meter strong {
    font-size: 15px;
  }

  .preview-stack {
    display: contents;
  }

  .mini-board {
    position: absolute;
    top: max(22px, calc(env(safe-area-inset-top) + 14px));
    width: 86px;
    padding: 7px;
    background: rgba(8, 12, 20, 0.52);
    backdrop-filter: blur(12px);
  }

  .mini-board canvas {
    width: 100%;
    max-height: 82px;
    object-fit: contain;
  }

  .mini-board:first-child {
    left: 8px;
  }

  .mini-board:nth-child(2) {
    right: 8px;
  }

  body[data-tutorial-demo="true"] .stat-grid,
  body[data-tutorial-demo="true"] .preview-stack {
    display: none;
  }

  .rift-meter {
    position: absolute;
    left: 18px;
    right: 96px;
    bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px));
    padding: 0;
    background: transparent;
    border: 0;
    backdrop-filter: none;
    pointer-events: auto;
  }

  .rift-meter div {
    margin-bottom: 4px;
    justify-content: flex-end;
  }

  .rift-meter span {
    display: none;
  }

  .rift-meter strong {
    color: rgba(247, 248, 255, 0.72);
    font-size: 12px;
    text-shadow: 0 0 12px rgba(56, 232, 255, 0.34);
  }

  .rift-meter meter {
    height: 5px;
    margin: 0;
    filter: drop-shadow(0 0 8px rgba(56, 232, 255, 0.36));
    opacity: 0.72;
  }

  .rift-meter button {
    display: none;
  }

  .rift-meter.is-ready {
    right: 96px;
  }

  .rift-meter.is-ready strong::before {
    content: "READY ";
    color: var(--lime);
  }

  .rift-meter.is-ready meter {
    width: 100%;
    opacity: 1;
  }

  .rift-meter.is-ready button {
    position: absolute;
    right: 0;
    bottom: 12px;
    display: grid;
    place-items: center;
    width: 72px;
    min-height: 38px;
    padding: 0 8px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--lime), var(--cyan));
    color: #071018;
    border-color: transparent;
    box-shadow:
      0 0 22px rgba(88, 255, 79, 0.42),
      0 12px 26px rgba(0, 0, 0, 0.36);
    font-size: 12px;
    font-weight: 950;
    text-transform: uppercase;
    pointer-events: auto;
  }

  .drop-button {
    position: absolute;
    right: 12px;
    bottom: max(104px, calc(env(safe-area-inset-bottom) + 98px));
    z-index: 6;
    width: 76px;
    min-height: 48px;
    margin: 0;
    padding: 0 10px;
    pointer-events: auto;
    border-radius: 8px;
    box-shadow:
      0 0 22px rgba(56, 232, 255, 0.32),
      0 14px 30px rgba(0, 0, 0, 0.34);
    text-transform: uppercase;
  }

  .rotate-mode-button {
    position: absolute;
    left: 12px;
    bottom: max(104px, calc(env(safe-area-inset-bottom) + 98px));
    z-index: 6;
    display: grid;
    place-items: center;
    width: 54px;
    min-height: 48px;
    padding: 0;
    pointer-events: auto;
    border-radius: 8px;
    color: #091018;
    background: linear-gradient(135deg, var(--gold), var(--cyan));
    border-color: transparent;
    box-shadow:
      0 0 22px rgba(255, 209, 102, 0.32),
      0 14px 30px rgba(0, 0, 0, 0.34);
    font-size: 26px;
    font-weight: 950;
    line-height: 1;
  }

  .rotate-mode-button[data-mode="x"] {
    background: linear-gradient(135deg, var(--hot), var(--gold));
  }

  .rotate-mode-button[data-mode="z"] {
    background: linear-gradient(135deg, var(--cyan), var(--hot));
  }

  .rotate-mode-button[data-mode="auto"] {
    background: linear-gradient(135deg, var(--lime), var(--cyan), var(--gold));
    font-size: 22px;
  }

  .control-strip,
  .key-guide,
  #soundButton,
  #restartButton {
    display: none;
  }

  .control-strip {
    display: contents;
  }

  #pauseButton {
    position: absolute;
    top: max(142px, calc(env(safe-area-inset-top) + 126px));
    right: 10px;
    z-index: 7;
    display: grid;
    place-items: center;
    width: 76px;
    min-height: 38px;
    padding: 0 10px;
    pointer-events: auto;
    border-radius: 8px;
    background: rgba(8, 12, 20, 0.64);
    border-color: rgba(255, 255, 255, 0.2);
    color: #f7f8ff;
    box-shadow:
      0 0 18px rgba(56, 232, 255, 0.24),
      0 12px 26px rgba(0, 0, 0, 0.32);
    font-size: 12px;
    text-transform: uppercase;
    backdrop-filter: blur(12px);
  }

  #pauseButton[hidden] {
    display: none;
  }

  .title-screen,
  .pause-screen {
    padding: clamp(118px, calc(var(--app-height) * 0.15), 152px) 16px clamp(74px, calc(var(--app-height) * 0.1), 110px);
  }

  .title-screen {
    z-index: 5;
  }

  .pause-screen {
    z-index: 9;
    place-content: center;
    padding: 28px;
  }

  h1 {
    font-size: clamp(38px, 13vw, 72px);
  }

  .tagline {
    width: min(520px, 92vw);
    font-size: 15px;
    line-height: 1.55;
  }
}

@media (max-width: 520px) and (orientation: portrait) {
  .title-screen {
    align-content: start;
    padding-top: max(118px, calc(env(safe-area-inset-top) + 96px));
  }

  .pause-screen {
    align-content: center;
    padding: 24px;
  }

  .stage-wrap {
    min-height: 100svh;
    min-height: var(--app-height);
    height: 100svh;
    height: var(--app-height);
  }

  .hud-panel {
    height: 100svh;
    height: var(--app-height);
  }

  .stat-grid {
    width: min(42vw, 150px);
    gap: 4px;
  }

  .stat-grid > div {
    min-height: 40px;
    padding: 6px 4px;
  }

  .mini-board {
    width: 75px;
    padding: 6px;
  }

  .rift-meter {
    left: 16px;
    right: 90px;
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 10px));
  }

  .drop-button {
    right: 10px;
    bottom: max(100px, calc(env(safe-area-inset-bottom) + 94px));
    width: 70px;
    min-height: 46px;
    font-size: 13px;
  }

  .rotate-mode-button {
    left: 10px;
    bottom: max(100px, calc(env(safe-area-inset-bottom) + 94px));
    width: 50px;
    min-height: 46px;
  }
}

@media (max-width: 520px) and (max-height: 780px) and (orientation: portrait) {
  .stat-grid {
    width: min(43vw, 148px);
  }

  .mini-board {
    width: 70px;
  }

  h1 {
    font-size: clamp(34px, 12vw, 56px);
  }

  .tagline {
    margin: 12px 0 22px;
    font-size: 13px;
  }

  .title-screen,
  .pause-screen {
    padding-top: 116px;
    padding-bottom: 72px;
  }
}
