*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --font-ui: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --font-round: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --ink: #3a2a24;
  --ink-soft: #7a6258;
  --accent: #e8473a;
  --warm: #c2410c;
  --bg: #7cd2ff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  font-family: var(--font-ui);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

p,
h1 {
  margin: 0;
}

/* Keep the home link apart from the play area and other controls. */
.home-link {
  position: absolute;
  top: calc(var(--safe-top, 0px) + 12px);
  left: calc(var(--safe-left, 0px) + 12px);
  z-index: 18;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(58, 47, 40, 0.15);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: #514636;
  box-shadow: 0 3px 10px rgba(58, 47, 40, 0.12);
  text-decoration: none;
  touch-action: manipulation;
  cursor: pointer;
}

.home-link svg {
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.home-link:hover {
  background: #fff;
}

.home-link:focus-visible {
  outline: 3px solid #4c88ce;
  outline-offset: 3px;
}

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}

.stage {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* Invisible box that tells game.js where the play area goes (below the HUD, inside safe areas). */
.field-guide {
  position: absolute;
  top: calc(var(--safe-top) + 132px);
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  left: var(--safe-left);
  visibility: hidden;
  pointer-events: none;
}

/* HUD */
.hud {
  position: absolute;
  top: calc(var(--safe-top) + 8px);
  left: 0;
  right: 0;
  height: 96px;
  color: #fff;
  text-shadow: 0 2px 8px rgba(20, 50, 80, 0.45);
  pointer-events: none;
}

.hud[hidden] {
  display: none;
}

.hud-side {
  position: absolute;
  top: 64px;
  left: calc(var(--safe-left) + 16px);
  font-weight: 800;
  line-height: 1.1;
}

.hud-label {
  font-size: 12px;
  color: #fff;
}

/* The tanuki's energy: it goes down when a note is missed and the game ends at zero. */
.gauge {
  width: 92px;
  height: 14px;
  margin-top: 6px;
  padding: 2px;
  border-radius: 999px;
  background: rgba(20, 30, 60, 0.4);
  box-shadow: 0 2px 8px rgba(20, 30, 60, 0.3);
}

.gauge-fill {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #7be06a, #ffe45c);
  transition: width 0.2s;
}

.gauge.is-low .gauge-fill {
  background: linear-gradient(90deg, #ff5a4f, #ff9a5c);
  animation: gauge-warn 0.5s ease-in-out infinite;
}

@keyframes gauge-warn {
  50% {
    opacity: 0.45;
  }
}

.hud-main {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.hud-score {
  font-family: var(--font-round);
  font-size: 40px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.hud-score.bump {
  animation: bump 0.2s ease-out;
}

.hud-score.long {
  font-size: 33px;
}

.hud-unit {
  margin-left: 2px;
  font-size: 16px;
}

.hud-next {
  margin-top: 8px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(20, 50, 80, 0.34);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  text-shadow: none;
}

.hud-next:empty {
  display: none;
}

.hud-goal {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 800;
  color: #fff3b0;
}

.hud-goal[hidden] {
  display: none;
}

@keyframes bump {
  from {
    transform: scale(1.2);
  }
  to {
    transform: scale(1);
  }
}

/* Milestone banner */
.banner {
  position: absolute;
  top: calc(var(--safe-top) + 128px);
  left: 50%;
  min-width: 200px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 22px 12px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.95);
  text-align: center;
  box-shadow: 0 8px 22px rgba(20, 50, 80, 0.25);
  opacity: 0;
  transform: translate(-50%, -12px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

.banner.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.banner-title {
  font-family: var(--font-round);
  font-size: 22px;
  font-weight: 900;
  color: var(--ink);
}

.banner-sub {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.5;
  color: var(--warm);
  white-space: pre-line;
}

.banner-sub:empty {
  display: none;
}

/* The first-time hint sits just above the drums, not on them. */
.hint {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 214px);
  left: 50%;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  transform: translateX(-50%);
  box-shadow: 0 6px 18px rgba(20, 50, 80, 0.3);
  pointer-events: none;
  animation: hint-pulse 1.4s ease-in-out infinite;
}

.hint[hidden] {
  display: none;
}

/* Title, pause and result screens. Taps are handled by .app, so screens ignore pointer events. */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(var(--safe-top) + 72px) 16px calc(var(--safe-bottom) + 28px);
  text-align: center;
  pointer-events: none;
}

.screen[hidden] {
  display: none;
}

.title-screen {
  padding-top: calc(var(--safe-top) + 72px);
}

.title-space {
  flex: 1;
  min-height: 12px;
}

.title {
  font-family: var(--font-round);
  font-size: clamp(40px, 12.5vw, 64px);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 5px 0 #c93a2e, 0 12px 28px rgba(20, 50, 80, 0.35);
}

.card {
  width: min(100%, 340px);
  margin-top: 14px;
  padding: 14px 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.7;
  box-shadow: 0 8px 24px rgba(20, 50, 80, 0.18);
}

.card strong {
  color: var(--warm);
}

.card-best {
  margin-top: 6px;
  color: var(--warm);
}

.challenge-card {
  border: 2px solid #ff7a45;
}

.challenge-label {
  color: #ff5a1f;
  font-size: 13px;
}

.challenge-text {
  font-size: 17px;
}

.cta {
  margin-top: 16px;
  padding: 12px 30px;
  border-radius: 999px;
  background: #ffd84d;
  color: #5a3b00;
  font-family: var(--font-round);
  font-size: 18px;
  font-weight: 900;
  box-shadow: 0 5px 0 #d9a300;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.06);
  }
}

@keyframes hint-pulse {
  50% {
    transform: translateX(-50%) scale(1.05);
  }
}

.pause-screen {
  justify-content: center;
  background: rgba(20, 50, 80, 0.3);
}

.pause-title {
  font-family: var(--font-round);
  font-size: 24px;
  font-weight: 900;
}

.result-card {
  margin-top: 0;
}

.result-label {
  font-size: 14px;
  color: var(--ink-soft);
}

.result-score {
  font-family: var(--font-round);
  font-size: 64px;
  font-weight: 900;
  line-height: 1.1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.result-unit {
  margin-left: 4px;
  font-size: 24px;
}

.result-line {
  font-size: 15px;
  white-space: pre-line;
}

.result-line:empty {
  display: none;
}

.result-reached {
  font-size: 16px;
  font-weight: 800;
}

.result-next,
.result-challenge {
  color: var(--warm);
}

.result-line.is-new {
  color: var(--warm);
  font-size: 17px;
}

.result-detail {
  margin-top: 4px;
  font-size: 14px;
  color: var(--ink-soft);
}

/* Result buttons. Screens ignore pointer events, so interactive parts opt back in. */
.actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: min(100%, 340px);
  margin-top: auto;
}

.btn {
  pointer-events: auto;
  padding: 12px 20px;
  border: 0;
  border-radius: 999px;
  font-family: var(--font-round);
  font-size: 17px;
  font-weight: 900;
  line-height: 1.3;
  cursor: pointer;
}

.btn:active {
  transform: translateY(2px);
}

.btn:focus-visible,
.more-games:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.btn-gold {
  background: #ffd84d;
  color: #5a3b00;
  box-shadow: 0 5px 0 #d9a300;
}

.btn-sub {
  background: rgba(20, 50, 80, 0.42);
  color: #fff;
}

/* Ignore taps for a moment after the result appears, so a late tap cannot hit a button. */
.screen.arming .btn,
.screen.arming .more-games {
  pointer-events: none;
}

.more-games {
  pointer-events: auto;
  align-self: center;
  margin-top: 10px;
  padding: 6px 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(20, 50, 80, 0.7);
  text-underline-offset: 3px;
}

/* The same branded share choices are available on every device. */
.share-sheet {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 20px 12px calc(var(--safe-bottom) + 12px);
  background: rgba(5, 20, 45, 0.55);
  cursor: default;
}

.share-sheet[hidden] {
  display: none;
}

.share-panel {
  width: min(100%, 440px);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px;
  border: 1px solid #e5edf7;
  border-radius: 28px;
  background: #fff;
  color: #1d3b66;
  box-shadow: 0 18px 60px rgba(4, 24, 56, 0.28);
  text-align: left;
  overscroll-behavior: contain;
}

.share-panel::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  margin: -6px auto 20px;
  border-radius: 2px;
  background: #d9e3ef;
}

.share-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.share-heading-icon {
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  height: 46px;
  border-radius: 15px;
  background: #e8f2ff;
  color: #286bce;
}

.share-heading-icon svg {
  width: 24px;
  height: 24px;
}

.share-title {
  font-family: var(--font-round);
  font-size: 20px;
  font-weight: 900;
  line-height: 1.4;
}

.share-subtitle {
  margin-top: 3px;
  color: #526984;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.share-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 72px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 18px;
  font-family: var(--font-ui);
  text-align: left;
  box-shadow: 0 3px 0 rgba(18, 43, 75, 0.08);
  transition: transform 140ms ease, box-shadow 140ms ease;
  cursor: pointer;
}

.share-option[data-share="x"] {
  background: #171c26;
  color: #fff;
}

.share-option[data-share="threads"] {
  border-color: #e1e6ee;
  background: #f2f4f8;
  color: #202b3a;
}

.share-option[data-share="line"] {
  background: #06c755;
  color: #062f1e;
}

.share-option[data-share="image"] {
  background: #2468c6;
  color: #fff;
}

.share-mark {
  display: grid;
  place-items: center;
  flex: 0 0 36px;
  height: 36px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.14);
  pointer-events: none;
}

.share-mark svg {
  width: 25px;
  height: 25px;
}

.share-option[data-share="threads"] .share-mark {
  background: #fff;
}

.share-option[data-share="line"] .share-mark svg {
  width: 32px;
  height: 32px;
}

.share-option-label {
  min-width: 0;
  pointer-events: none;
}

.share-option-name,
.share-option-action {
  display: block;
}

.share-option-name {
  font-size: 16px;
  font-weight: 900;
  line-height: 1.35;
}

.share-option-action {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.share-option[data-share="x"] .share-option-action {
  color: #d2dbe9;
}

.share-option[data-share="threads"] .share-option-action {
  color: #536276;
}

.share-option:active {
  transform: scale(0.97);
  box-shadow: none;
}

@media (hover: hover) {
  .share-option:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(18, 43, 75, 0.12);
  }
}

.share-option[hidden] {
  display: none;
}

.share-wide {
  grid-column: 1 / -1;
}

.share-status {
  margin-top: 14px;
  font-size: 13px;
  font-weight: 700;
  color: #4a6a94;
  line-height: 1.6;
}

.share-status:empty {
  display: none;
}

.share-copy {
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  border: 1px solid #d5deea;
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  user-select: text;
  -webkit-user-select: text;
}

.share-copy[hidden] {
  display: none;
}

.share-close {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  margin-top: 14px;
  padding: 10px 16px;
  border: 1px solid #dce5ef;
  border-radius: 14px;
  background: #f6f8fc;
  color: #46617f;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.share-close svg {
  width: 16px;
  height: 16px;
}

.share-option:focus-visible,
.share-close:focus-visible {
  outline: 3px solid #2d6cb5;
  outline-offset: 2px;
}

/* How to play: a round "?" button next to the sound one, and a sheet of short steps */
.help-toggle {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  right: calc(var(--safe-right) + 64px);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 50, 80, 0.3);
  color: #fff;
  font-family: var(--font-round);
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
}

.help-toggle:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.help-sheet {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  background: rgba(14, 36, 60, 0.55);
  cursor: default;
}

.help-sheet[hidden] {
  display: none;
}

.help-panel {
  width: min(100%, 360px);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 18px 16px;
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.help-title {
  font-family: var(--font-round);
  font-size: 21px;
  font-weight: 900;
  text-align: center;
}

.help-steps {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.help-steps li {
  position: relative;
  margin-top: 10px;
  padding-left: 34px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.6;
  counter-increment: step;
}

.help-steps li::before {
  content: counter(step);
  position: absolute;
  top: 1px;
  left: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-round);
  font-size: 14px;
  font-weight: 900;
  line-height: 24px;
  text-align: center;
}

.help-steps strong {
  color: var(--warm);
}

.help-close {
  display: block;
  margin: 16px auto 0;
  padding: 10px 34px;
  border: 0;
  border-radius: 999px;
  background: #ffd84d;
  color: #5a3b00;
  font-family: var(--font-round);
  font-size: 16px;
  font-weight: 900;
  box-shadow: 0 4px 0 #d9a300;
  cursor: pointer;
}

.help-close:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* Sound and vibration toggle */
.sound-toggle {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  right: calc(var(--safe-right) + 12px);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 50, 80, 0.28);
  color: #fff;
  cursor: pointer;
}

.sound-toggle:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.sound-toggle svg {
  width: 24px;
  height: 24px;
}

.sound-toggle .icon-off,
.sound-toggle[aria-pressed="false"] .icon-on {
  display: none;
}

.sound-toggle[aria-pressed="false"] .icon-off {
  display: block;
}

@media (max-height: 640px) {
  .title {
    font-size: clamp(40px, 12vw, 56px);
  }

  .card {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.6;
  }

  .title-screen {
    padding-bottom: calc(var(--safe-bottom) + 12px);
  }

  .cta {
    margin-top: 10px;
    padding: 9px 26px;
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cta,
  .hint,
  .gauge.is-low .gauge-fill,
  .hud-score.bump {
    animation: none;
  }
}
