:root {
  --ink: #1f2529;
  --paper: #fffaf0;
  --gold: #f4bd2f;
  --amber: #ffdb63;
  --teal: #2bb8a6;
  --coral: #ff6b57;
  --shadow: 0 18px 45px rgba(25, 29, 32, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f3d36b url("/assets/playground-bg.png") center / cover fixed;
  overflow-x: hidden;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

.game-shell {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(128px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 16px;
  align-items: stretch;
}

.stage,
.side-panel {
  background: rgba(255, 250, 240, 0.9);
  border: 3px solid rgba(31, 37, 41, 0.86);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stage {
  min-height: 680px;
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.hud > div,
.next-panel {
  background: rgba(255, 255, 255, 0.86);
  border: 2px solid rgba(31, 37, 41, 0.78);
  border-radius: 8px;
  padding: 10px;
}

.label {
  display: block;
  color: #596067;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
}

.hud strong {
  display: block;
  font-size: clamp(1.4rem, 4vw, 2rem);
  line-height: 1;
}

.lane {
  position: relative;
  min-height: 590px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.2), rgba(255, 247, 213, 0.66)),
    repeating-linear-gradient(90deg, transparent 0 48px, rgba(255, 255, 255, 0.22) 48px 50px);
}

.current-step {
  position: absolute;
  z-index: 2;
  right: 12px;
  top: 12px;
  min-width: min(190px, calc(100% - 24px));
  padding: 9px 14px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 7px 0 var(--ink);
  text-align: center;
  font-size: clamp(1.35rem, 5vw, 2.4rem);
  font-weight: 950;
  line-height: 1;
}

.current-step::before {
  content: "いま";
  display: block;
  margin-bottom: 4px;
  color: #596067;
  font-size: 0.72rem;
  font-weight: 900;
}

.current-step.pa {
  background: #c9fff5;
}

.hop-targets {
  position: absolute;
  inset: 260px 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.target-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  min-height: 52px;
  animation: stream-down 160ms ease-out;
}

.pad-pair {
  grid-column: 2;
  display: flex;
  gap: min(11vw, 62px);
  align-items: center;
  justify-content: center;
}

.step-label {
  grid-column: 3;
  min-width: 54px;
  padding: 6px 10px;
  border: 2px solid rgba(31, 37, 41, 0.7);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  font-weight: 950;
  text-align: center;
}

.foot-pad {
  width: clamp(74px, 16vw, 118px);
  aspect-ratio: 1 / 0.62;
  border: 3px dashed rgba(31, 37, 41, 0.72);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: inset 0 -8px 0 rgba(244, 189, 47, 0.26);
}

.target-row.active .foot-pad {
  border-style: solid;
  background: var(--amber);
  transform: translateY(-2px);
}

.target-row.active .step-label {
  background: var(--gold);
  border-color: var(--ink);
}

.target-row.pa .foot-pad:first-child {
  background: rgba(43, 184, 166, 0.78);
}

.target-row.pa .foot-pad:last-child {
  background: rgba(255, 107, 87, 0.78);
}

.onikin {
  position: absolute;
  left: 50%;
  top: 12px;
  width: clamp(92px, 20vw, 132px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 16px 12px rgba(0, 0, 0, 0.18));
  transform: translateX(-50%);
  transition: transform 120ms ease, filter 120ms ease;
  user-select: none;
  -webkit-user-drag: none;
}

.onikin.hop-ken {
  transform: translateX(-50%) translateY(10px) rotate(-5deg) scale(1.03);
}

.onikin.hop-pa {
  transform: translateX(-50%) translateY(10px) scale(1.08);
}

.onikin.miss {
  filter: saturate(0.55) drop-shadow(0 16px 12px rgba(0, 0, 0, 0.18));
  transform: translateX(-50%) rotate(8deg);
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: white;
  font-size: clamp(2rem, 10vw, 5.8rem);
  font-weight: 950;
  text-align: center;
  text-shadow: 0 5px 0 var(--ink), 0 12px 22px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.countdown.hidden {
  display: none;
}

@keyframes stream-down {
  from {
    opacity: 0.2;
    transform: translateY(-26px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.next-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
}

.next-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(38px, 1fr));
  gap: 8px;
}

.step-chip {
  min-height: 38px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: white;
  font-weight: 900;
}

.step-chip.pa {
  background: #c9fff5;
}

.side-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.title-lockup p {
  margin: 0;
  font-weight: 900;
}

.title-lockup h1 {
  margin: 0;
  font-size: clamp(2.25rem, 7vw, 4.2rem);
  line-height: 0.96;
}

.start-button {
  min-height: 58px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--gold);
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 950;
  box-shadow: 0 7px 0 var(--ink);
}

.start-button:active,
.control-button:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 var(--ink);
}

.leaderboard {
  min-height: 0;
  padding-top: 10px;
  border-top: 2px solid rgba(31, 37, 41, 0.2);
}

.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.leaderboard h2 {
  margin: 0;
  font-size: 1.2rem;
}

#refreshRanks {
  width: 38px;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: white;
  font-weight: 900;
}

#rankList {
  margin: 12px 0 0;
  padding-left: 28px;
}

#rankList li {
  margin: 8px 0;
  padding-left: 4px;
  font-weight: 800;
}

.rank-score {
  float: right;
  margin-left: 10px;
  color: #9b392f;
}

.controls {
  position: fixed;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: linear-gradient(180deg, transparent, rgba(255, 250, 240, 0.98) 26%);
}

.control-button {
  min-height: 82px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  color: var(--ink);
  box-shadow: 0 7px 0 var(--ink);
}

.control-button span,
.control-button small {
  display: block;
}

.control-button span {
  font-size: clamp(1.65rem, 8vw, 2.55rem);
  font-weight: 950;
  line-height: 1;
}

.control-button small {
  margin-top: 4px;
  font-weight: 800;
}

.control-button.ken {
  background: white;
}

.control-button.pa {
  background: var(--teal);
}

dialog {
  width: min(420px, calc(100vw - 28px));
  border: 3px solid var(--ink);
  border-radius: 8px;
  padding: 20px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(31, 37, 41, 0.44);
}

dialog h2 {
  margin: 0 0 8px;
}

dialog label {
  display: grid;
  gap: 6px;
  font-weight: 900;
}

dialog input {
  width: 100%;
  min-height: 48px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
}

dialog menu {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0 0;
  padding: 0;
}

dialog button {
  min-height: 46px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: white;
  font-weight: 900;
}

dialog button[type="submit"] {
  background: var(--gold);
}

@media (max-width: 820px) {
  body {
    background-attachment: scroll;
  }

  .game-shell {
    grid-template-columns: 1fr;
    padding-inline: 10px;
    gap: 10px;
  }

  .stage {
    min-height: min(72svh, 690px);
    padding: 10px;
  }

  .side-panel {
    order: -1;
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .leaderboard {
    grid-column: 1 / -1;
  }

  .start-button {
    min-width: 132px;
  }
}

@media (max-width: 520px) {
  .game-shell {
    padding-bottom: calc(122px + env(safe-area-inset-bottom));
  }

  .hud > div {
    padding: 8px;
  }

  .lane {
    min-height: 510px;
  }

  .hop-targets {
    inset: 200px 6px 16px;
    gap: 5px;
  }

  .current-step {
    top: 8px;
    right: 8px;
    min-width: 118px;
    padding: 7px 10px;
  }

  .onikin {
    width: clamp(82px, 25vw, 104px);
  }

  .target-row {
    grid-template-columns: 1fr auto minmax(42px, 0.7fr);
    min-height: 44px;
  }

  .step-label {
    min-width: 42px;
    padding: 5px 7px;
    font-size: 0.9rem;
  }

  .foot-pad {
    width: clamp(58px, 22vw, 86px);
  }

  .next-steps {
    grid-template-columns: repeat(5, minmax(30px, 1fr));
  }

  .step-chip {
    min-height: 32px;
    font-size: 0.86rem;
  }

  .controls {
    padding-inline: 10px;
    gap: 8px;
  }

  .control-button {
    min-height: 78px;
  }
}
