:root {
  --bg: #0b1220;
  --bg2: #121b33;
  --panel: rgba(11, 18, 32, 0.92);
  --line: #2b3655;
  --text: #e9f1ff;
  --dim: #8fa3c7;
  --green: #20a34e;
  --blue: #246dff;
  --orange: #f86606;
  --gold: #f2c14e;
  --red: #ff4d5e;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

html,
body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
  color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: absolute;
  inset: 0;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #0e1730 0%, #04060c 75%);
}

#game {
  display: block;
  width: 480px;
  height: 270px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #070b16;
  box-shadow: 0 0 0 1px #1a2440, 0 10px 40px rgba(0, 0, 0, 0.6);
}

/* Touch controls */
#touch {
  position: absolute;
  inset: 0;
  display: none;
  touch-action: none;
}
body.touch #touch.live {
  display: block;
}
#stick-base,
#stick-knob {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
}
#stick-base {
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border: 2px solid rgba(233, 241, 255, 0.35);
  background: rgba(10, 16, 30, 0.35);
}
#stick-knob {
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  background: rgba(233, 241, 255, 0.55);
  box-shadow: 0 0 12px rgba(127, 216, 255, 0.5);
}
#stick-base.on,
#stick-knob.on {
  opacity: 1;
}
.tbtn {
  position: absolute;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.35);
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}
#btn-jump {
  width: 84px;
  height: 84px;
  right: calc(16px + var(--sar));
  bottom: calc(18px + var(--sab));
  background: rgba(32, 163, 78, 0.38);
}
#btn-hop {
  width: 68px;
  height: 68px;
  right: calc(104px + var(--sar));
  bottom: calc(78px + var(--sab));
  background: rgba(36, 109, 255, 0.38);
  font-size: 13px;
}
.tbtn.on {
  transform: scale(0.92);
  background: rgba(248, 102, 6, 0.6);
  border-color: rgba(255, 255, 255, 0.8);
}

#topbar {
  position: absolute;
  top: calc(6px + var(--sat));
  left: calc(8px + var(--sal));
  right: calc(8px + var(--sar));
  display: none;
  justify-content: space-between;
  pointer-events: none;
}
#topbar.live {
  display: flex;
}
.ibtn {
  pointer-events: auto;
  touch-action: manipulation;
  width: 40px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(233, 241, 255, 0.25);
  background: rgba(5, 8, 16, 0.55);
  color: var(--text);
  font-weight: 800;
  font-size: 14px;
}

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: calc(10px + var(--sat)) calc(14px + var(--sar)) calc(10px + var(--sab)) calc(14px + var(--sal));
  box-sizing: border-box;
  touch-action: manipulation;
  overflow: auto;
}
.screen.show {
  display: flex;
}
#screen-title {
  background: linear-gradient(90deg, rgba(4, 6, 12, 0.92) 0%, rgba(4, 6, 12, 0.7) 45%, rgba(4, 6, 12, 0.05) 100%);
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
}
#screen-pause,
#screen-practice,
#screen-howto,
#screen-board,
#screen-settings,
#screen-result {
  background: rgba(3, 5, 10, 0.72);
  backdrop-filter: blur(2px);
}
.loading {
  color: var(--dim);
  font-weight: 700;
  letter-spacing: 0.08em;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink {
  50% {
    opacity: 0.4;
  }
}

.title-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 0;
}
.title-left {
  max-width: 440px;
}
#logo {
  display: block;
  image-rendering: pixelated;
  max-width: 100%;
  height: auto;
}
.by {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 2px;
  color: var(--dim);
  font-size: 14px;
  letter-spacing: 0.04em;
}
.by img {
  height: 20px;
  width: auto;
  margin: 0 2px;
}
.tagline {
  margin: 4px 0 10px;
  color: #cfe0ff;
  font-size: 14px;
}
.menu {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-width: 420px;
}
.btn {
  touch-action: manipulation;
  appearance: none;
  border: 2px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  font: 800 14px/1 system-ui, sans-serif;
  letter-spacing: 0.06em;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 3px 0 #05070d;
}
.btn small {
  font-weight: 600;
  opacity: 0.7;
  font-size: 11px;
  margin-left: 4px;
}
.btn:hover,
.btn:focus-visible {
  border-color: #4b5f92;
  outline: none;
}
.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #05070d;
}
.btn.primary {
  background: linear-gradient(180deg, #2b7bff, #1b55d0);
  border-color: #6a9dff;
}
.btn:disabled {
  opacity: 0.45;
}
.menu .primary {
  grid-column: 1 / -1;
  font-size: 18px;
  padding: 13px;
}
.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.small-row {
  margin-top: 8px;
}
.chip {
  touch-action: manipulation;
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--dim);
  font: 600 12px system-ui, sans-serif;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.status {
  margin-top: 6px;
  min-height: 1em;
  color: var(--gold);
  font-size: 12px;
}
.title-right {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-self: flex-end;
}
.pb-box {
  background: rgba(5, 8, 16, 0.7);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--dim);
}
.pb-box:empty {
  display: none;
}
.pb-box b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.disclaimer {
  font-size: 10.5px;
  color: #6f82a8;
  max-width: 820px;
}
.disclaimer a {
  color: #9fb4dc;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-height: 100%;
  overflow: auto;
  box-sizing: border-box;
}
.panel.wide {
  max-width: 820px;
}
.panel h2 {
  margin: 0 0 8px;
  font-size: 20px;
  letter-spacing: 0.04em;
}
.panel p {
  margin: 6px 0;
  color: #cfe0ff;
  font-size: 14px;
}
.note {
  color: var(--gold) !important;
}
.brief {
  color: var(--gold) !important;
}
.howto-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 8px 0;
}
.hcard {
  background: rgba(26, 36, 64, 0.6);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}
.hcard h3 {
  margin: 6px 0 2px;
  font-size: 14px;
}
.hcard p {
  font-size: 12px !important;
  margin: 0 !important;
  color: var(--dim) !important;
}
.hpic {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border-radius: 6px;
  background: #0b1220;
  display: block;
}
.rules {
  font-size: 12px !important;
  color: var(--dim) !important;
}
.rules.small {
  font-size: 11px !important;
}
kbd {
  background: #1a2440;
  border: 1px solid #2b3655;
  border-radius: 4px;
  padding: 0 4px;
  font-size: 11px;
}
.grid-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.grid-buttons .btn {
  font-size: 12px;
  padding: 10px 6px;
}

.result {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.res-label {
  color: var(--dim);
  font-weight: 800;
  letter-spacing: 0.1em;
  font-size: 12px;
}
.res-label.ok {
  color: #39e07a;
}
.res-label.err {
  color: var(--red);
}
.res-time {
  font: 800 44px/1.05 ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(36, 109, 255, 0.55);
}
.res-badge {
  display: inline-block;
  min-height: 1em;
  color: #111;
  background: var(--gold);
  font-weight: 900;
  font-size: 12px;
  letter-spacing: 0.08em;
  border-radius: 6px;
  padding: 2px 8px;
  margin: 4px 0;
}
.res-badge:empty {
  display: none;
}
.res-rank {
  font-size: 18px;
  font-weight: 800;
}
.res-title {
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 6px;
}
.res-stats {
  list-style: none;
  padding: 0;
  margin: 6px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
  font-size: 12.5px;
  color: var(--dim);
}
.res-stats b {
  color: var(--text);
}
.res-reveal {
  font-size: 12px !important;
  color: #cfe0ff !important;
}
.claim h3 {
  margin: 0 0 6px;
}
.claim label {
  display: block;
  font-size: 12px;
  color: var(--dim);
  margin: 6px 0;
}
.claim input[type='email'],
.claim input:not([type]) {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 3px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
  font-size: 16px;
  user-select: text;
  -webkit-user-select: text;
}
.check {
  display: flex !important;
  gap: 8px;
  align-items: flex-start;
  line-height: 1.3;
}
.check input {
  margin-top: 2px;
  flex: none;
  width: 18px;
  height: 18px;
}
.check a {
  color: #9fb4dc;
}
.msg {
  min-height: 1.2em;
  font-size: 12px;
  color: var(--red);
}
.claim-done {
  font-size: 14px;
  color: #39e07a;
}
.claim-done:empty {
  display: none;
}

.board {
  display: grid;
  grid-template-columns: 3em 1fr auto auto;
  gap: 4px 12px;
  font-size: 14px;
  max-height: 52vh;
  overflow: auto;
}
.board .h {
  color: var(--dim);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.board .t {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}
.board .me {
  color: var(--gold);
  font-weight: 800;
}
.board .empty {
  grid-column: 1 / -1;
  color: var(--dim);
}
.settings label {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
  font-size: 14px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(14px + var(--sab));
  transform: translateX(-50%);
  background: rgba(5, 8, 16, 0.9);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
}

#rotate {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #0b1220;
  z-index: 50;
  text-align: center;
  padding: 24px;
}
#rotate p {
  font-weight: 800;
  font-size: 18px;
  max-width: 280px;
}
.phone {
  width: 54px;
  height: 92px;
  border: 4px solid #cfe0ff;
  border-radius: 12px;
  position: relative;
  animation: rot 2.2s ease-in-out infinite;
}
.phone-screen {
  position: absolute;
  inset: 6px;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--green), var(--blue) 60%, var(--orange));
}
@keyframes rot {
  0%,
  25% {
    transform: rotate(0deg);
  }
  55%,
  100% {
    transform: rotate(-90deg);
  }
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotate {
    display: flex;
  }
}

@media (max-height: 430px) {
  .panel {
    padding: 10px 14px;
  }
  .panel h2 {
    font-size: 17px;
    margin-bottom: 4px;
  }
  .howto-grid {
    gap: 6px;
  }
  .res-time {
    font-size: 36px;
  }
  .btn {
    padding: 9px 12px;
  }
  .menu .primary {
    padding: 11px;
  }
  .tagline {
    margin: 2px 0 8px;
  }
}
@media (max-width: 700px) {
  .howto-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .result {
    grid-template-columns: 1fr;
  }
}
@media (prefers-reduced-motion: reduce) {
  .phone,
  .loading {
    animation: none;
  }
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-head h2 {
  margin: 0;
}
@media (max-height: 430px) {
  .hpic {
    height: 64px;
    width: auto;
    margin: 0 auto;
  }
  .howto-grid .hcard p {
    font-size: 11.5px !important;
    line-height: 1.3;
  }
  .brief,
  .rules {
    margin: 4px 0 !important;
  }
}
