:root {
  color-scheme: dark;
  --ink: #f8f7ef;
  --panel: rgba(11, 13, 16, 0.74);
  --yellow: #ffd338;
  --aqua: #38d7c4;
  --red: #ff5c5c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background: #0b0d10;
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
  touch-action: none;
  user-select: none;
}

button {
  border: 0;
  font: inherit;
}

.app {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 15% 8%, rgba(56, 215, 196, 0.24), transparent 26rem),
    linear-gradient(145deg, #15171d 0%, #0b0d10 48%, #111414 100%);
}

.game-shell {
  position: relative;
  width: min(100vw - 20px, 540px);
  height: min(100dvh - 20px, 960px);
  max-height: calc((100vw - 20px) * 1.78);
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: #0e1715;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

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

.hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr 44px;
  gap: 8px;
  align-items: stretch;
  pointer-events: none;
}

.hud > div,
.icon-button {
  min-height: 44px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px);
}

.hud > div {
  display: grid;
  align-content: center;
  padding: 6px 10px;
}

.label {
  color: rgba(248, 247, 239, 0.68);
  font-size: 0.62rem;
  font-weight: 800;
}

.hud strong {
  font-size: clamp(1.1rem, 5vw, 1.55rem);
  line-height: 1;
}

.icon-button {
  color: var(--ink);
  font-weight: 900;
  pointer-events: auto;
}

.menu {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 18px;
  text-align: center;
  background: linear-gradient(180deg, rgba(8, 12, 14, 0.2), rgba(8, 12, 14, 0.72));
}

.menu.hidden {
  display: none;
}

.title-block p {
  margin: 0 0 8px;
  color: var(--yellow);
  font-size: clamp(0.8rem, 3vw, 1rem);
  font-weight: 900;
}

.title-block h1 {
  margin: 0;
  text-shadow: 0 5px 0 #111;
  font-size: clamp(2.55rem, 11vw, 4.6rem);
  line-height: 0.92;
}

.final-score {
  display: block;
  min-height: 1.2em;
  margin-top: 8px;
  color: var(--yellow);
  font-size: clamp(1rem, 4vw, 1.25rem);
}

.primary-button,
.swing-button {
  color: #111;
  background: var(--yellow);
  font-weight: 950;
  box-shadow: 0 7px 0 #101010;
}

.score-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 8px;
  width: min(320px, 86vw);
}

.score-form.hidden {
  display: none;
}

.score-form.busy {
  opacity: 0.7;
  pointer-events: none;
}

.score-form input,
.small-button,
.text-button {
  border-radius: 8px;
  min-height: 42px;
}

.score-form input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.6);
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
  font-weight: 800;
}

.small-button,
.text-button {
  color: #111;
  background: var(--aqua);
  font-weight: 900;
}

.primary-button {
  width: min(280px, 82vw);
  min-height: 56px;
  border-radius: 8px;
  font-size: 1.2rem;
}

.ranking {
  width: min(320px, 86vw);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.58);
  padding: 10px;
  text-align: left;
}

.ranking-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.ranking-head span {
  color: var(--yellow);
  font-size: 0.78rem;
  font-weight: 950;
}

.text-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.ranking ol {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ranking li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 24px;
  color: rgba(248, 247, 239, 0.9);
  font-size: clamp(0.8rem, 3vw, 0.95rem);
  font-weight: 800;
}

.ranking li span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking li strong {
  color: var(--yellow);
}

.tips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 330px;
}

.tips span {
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.58);
  color: rgba(248, 247, 239, 0.88);
  font-size: 0.83rem;
}

.swing-button {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: clamp(86px, 24vw, 124px);
  aspect-ratio: 1;
  border-radius: 999px;
  border: 4px solid #111;
  font-size: clamp(0.86rem, 3.4vw, 1.1rem);
  touch-action: manipulation;
}

.swing-button:active,
.primary-button:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 #101010;
}

@media (min-width: 760px) {
  .app {
    padding: 18px;
  }

  .game-shell {
    height: min(96dvh, 900px);
  }
}
