:root {
  color-scheme: light;
  --ink: #5c463c;
  --red: #ff3b4a;
  --blue: #2f74ff;
  --green: #1fce8e;
  --card: rgba(255, 250, 246, 0.97);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  background: #f3c7aa;
  touch-action: none;
  overscroll-behavior: none;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "YuGothic", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
  color: var(--ink);
}

button {
  font-family: inherit;
  cursor: pointer;
}

#stage {
  position: relative;
  width: min(100vw, 520px, calc(100dvh * 0.62));
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  touch-action: none;
  background: #fff3e8;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  z-index: 0;
}

#sound {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 12px;
  z-index: 6;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(120, 80, 50, 0.1);
  display: grid;
  place-items: center;
  padding: 0;
}

#sound .icon-off { display: none; }
#sound.muted .icon-on { display: none; }
#sound.muted .icon-off { display: block; }
#sound.pressed { transform: translateY(2px); }

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  min-height: 102px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.2s linear;
}

#stage[data-phase="title"] #hud {
  opacity: 0;
}

#score-wrap {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.75);
}

#score-label {
  font-size: 13px;
  letter-spacing: 0.08em;
}

#score {
  font-size: 42px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  display: inline-block;
}

#score.pop {
  animation: pop 0.28s ease;
}

.unit { font-size: 18px; }

#legend {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 800;
  color: #7d675c;
}

#legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}

.dot.red { background: var(--red); }
.dot.blue { background: var(--blue); }
.dot.green { background: var(--green); }

#time-track {
  margin: 8px auto 0;
  height: 14px;
  max-width: 100%;
  border-radius: 999px;
  background: rgba(90, 60, 50, 0.12);
  overflow: hidden;
}

#time-fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(1);
  border-radius: inherit;
  background: linear-gradient(90deg, #ffd36a, #ff8d62);
}

#time-track.low #time-fill {
  background: linear-gradient(90deg, #ff8d62, #ff4d57);
}

#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  gap: 10px;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
}

#controls.locked,
#controls.gone {
  pointer-events: none;
}

#controls.locked .action {
  opacity: 0.5;
}

#controls.gone {
  opacity: 0;
}

.action {
  flex: 1;
  height: 76px;
  border: none;
  border-radius: 26px;
  color: white;
  font-size: 18px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: none;
}

.action.jump {
  background: #ff4d57;
  box-shadow: 0 6px 0 #d83340;
}

.action.wave {
  background: #3a78ff;
  box-shadow: 0 6px 0 #245ed4;
}

.action.pressed,
.action:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}

.action.hint {
  animation: glow 1s ease-in-out infinite;
}

.action.jump.hint { box-shadow: 0 6px 0 #d83340, 0 0 0 4px rgba(255, 77, 87, 0.28); }
.action.wave.hint { box-shadow: 0 6px 0 #245ed4, 0 0 0 4px rgba(58, 120, 255, 0.28); }

#title,
#result {
  z-index: 4;
}

#title {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(255, 246, 238, 0) 0 60%, rgba(255, 246, 238, 0.9) 74%, #fff6ee 100%);
  pointer-events: none;
}

#title[hidden],
#result[hidden],
[hidden] {
  display: none !important;
}

.card {
  pointer-events: auto;
  background: var(--card);
  border-radius: 28px;
  box-shadow: 0 14px 40px rgba(120, 70, 40, 0.14);
  padding: 20px 18px 16px;
}

#title h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.15;
  letter-spacing: 0.02em;
}

.lead,
.how,
.best-line,
.keys,
.note {
  margin: 8px 0 0;
  font-weight: 700;
}

.lead { font-size: 15px; }
.how, .keys, .note { font-size: 13px; color: #8a7268; }

#title .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 12px 0 4px;
  font-size: 14px;
  font-weight: 800;
}

#title .legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.primary,
.secondary {
  border: none;
  border-radius: 18px;
  min-height: 54px;
  padding: 0 16px;
  font-size: 17px;
  font-weight: 800;
  touch-action: none;
}

.primary {
  background: #ff7468;
  color: white;
  box-shadow: 0 5px 0 #e25b52;
}

.secondary {
  background: white;
  color: var(--ink);
  box-shadow: 0 5px 0 rgba(120, 80, 50, 0.12);
}

.primary.pressed,
.secondary.pressed,
.primary:active,
.secondary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(120, 80, 50, 0.12);
}

#start {
  width: 100%;
  margin-top: 14px;
}

#title-best:empty { display: none; }

#result {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
}

.result-copy {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
}

.result-count {
  margin: 2px 0;
  text-align: center;
  font-weight: 800;
}

#result-score {
  font-size: 72px;
  line-height: 0.95;
  color: #ff4d57;
  font-variant-numeric: tabular-nums;
}

.result-count span { font-size: 22px; margin-left: 2px; }

.banner {
  margin: 0 0 6px;
  text-align: center;
  font-weight: 800;
  color: #e07a12;
}

.best-line { text-align: center; }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.result-actions button { flex: 1 1 140px; }

#share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#legend span,
#title .legend span {
  white-space: nowrap;
}

button:focus-visible {
  outline: 3px solid #ffb15a;
  outline-offset: 2px;
}

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

@keyframes glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.1); }
}

@media (max-width: 360px) {
  .action { font-size: 15px; height: 68px; gap: 4px; }
  #title h1 { font-size: 28px; }
  #legend { gap: 8px; font-size: 11px; }
}
