:root {
  color-scheme: light;
  --ink: #171717;
  --paper: #fff9e8;
  --gold: #ffd447;
  --red: #ff4d44;
  --blue: #1479ff;
  --green: #20b56b;
  --shadow: rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #181818;
  color: var(--ink);
  font-family: "Arial Rounded MT Bold", "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  touch-action: none;
}

button,
input {
  font: inherit;
}

.app {
  width: 100vw;
  height: 100dvh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(255, 212, 71, 0.18), transparent 32%, transparent 68%, rgba(20, 121, 255, 0.18)),
    #202020;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.game-shell {
  position: relative;
  width: min(100vw, calc(100dvh * 390 / 844));
  height: min(100dvh, calc(100vw * 844 / 390));
  max-width: 430px;
  max-height: 932px;
  overflow: hidden;
  background: #87dcff;
  box-shadow: 0 18px 70px var(--shadow);
  isolation: isolate;
}

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

.hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  pointer-events: none;
}

.hud-item {
  min-width: 0;
  padding: 8px 6px 7px;
  border: 3px solid #141414;
  border-radius: 8px;
  background: rgba(255, 249, 232, 0.9);
  box-shadow: 0 4px 0 #141414;
  text-align: center;
}

.hud-item span {
  display: block;
  font-size: 10px;
  letter-spacing: 0;
  line-height: 1;
}

.hud-item strong {
  display: block;
  margin-top: 3px;
  font-size: clamp(16px, 4.3vw, 22px);
  line-height: 1;
  white-space: nowrap;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 3px solid #141414;
  border-radius: 8px;
  background: var(--paper);
  color: #141414;
  box-shadow: 0 4px 0 #141414;
  font-weight: 900;
}

#soundToggle {
  position: absolute;
  right: 10px;
  bottom: 12px;
}

.overlay,
.ranking-panel {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 24px;
  background: rgba(255, 249, 232, 0.78);
  backdrop-filter: blur(8px);
  text-align: center;
}

.overlay.active,
.ranking-panel.active {
  display: flex;
}

.mascot-preview {
  width: min(52%, 220px);
  max-height: 280px;
  object-fit: contain;
  filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.16));
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 10px;
  font-size: clamp(38px, 12vw, 58px);
  line-height: 0.95;
  letter-spacing: 0;
  text-shadow: 0 5px 0 #fff, 0 8px 0 #141414;
}

h2 {
  font-size: clamp(28px, 8vw, 42px);
  letter-spacing: 0;
}

.primary-button,
.ghost-button {
  width: min(260px, 82vw);
  min-height: 52px;
  margin-top: 18px;
  border: 3px solid #141414;
  border-radius: 8px;
  box-shadow: 0 5px 0 #141414;
  font-weight: 900;
}

.primary-button {
  background: var(--gold);
  color: #141414;
}

.ghost-button {
  background: #fff;
  color: #141414;
}

.result-score {
  margin-top: 8px;
  font-size: clamp(50px, 15vw, 76px);
  font-weight: 900;
  line-height: 1;
}

.result-stats {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  font-weight: 900;
}

.result-stats span {
  min-width: 88px;
  padding: 8px 10px;
  border: 3px solid #141414;
  border-radius: 8px;
  background: #fff;
}

.score-form {
  width: min(300px, 88vw);
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 16px;
}

.score-form input {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  border: 3px solid #141414;
  border-radius: 8px;
  background: #fff;
  color: #141414;
  box-shadow: 0 5px 0 #141414;
  text-align: center;
  text-transform: uppercase;
  font-weight: 900;
}

.ranking-panel {
  justify-content: flex-start;
  padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  background: rgba(255, 249, 232, 0.94);
  z-index: 5;
}

.ranking-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ranking-list {
  width: 100%;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  list-style: none;
}

.ranking-list li {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 10px;
  border: 3px solid #141414;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 0 #141414;
  font-weight: 900;
}

.rank-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
}

.rank-score {
  color: var(--red);
  white-space: nowrap;
}

@media (max-height: 680px) {
  .mascot-preview {
    width: min(42%, 160px);
  }

  h1 {
    font-size: clamp(34px, 10vw, 46px);
  }

  .primary-button,
  .ghost-button {
    min-height: 48px;
    margin-top: 12px;
  }
}
