:root {
  --bg0: #071018;
  --bg1: #0d1a24;
  --ink: #e8eef7;
  --muted: #8aa0b5;
  --accent: #ff2d55;
  --accent-hot: #ff6b8a;
  --mint: #2ef2c3;
  --mint-dim: rgba(46, 242, 195, 0.2);
  --hole: #152230;
  --shock: #d9fff3;
  --font-display: "Noto Sans SC", "Bebas Neue", sans-serif;
  --font-en: "Bebas Neue", "Noto Sans SC", sans-serif;
  --font-body: "Noto Sans SC", sans-serif;
  --radius: 18px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --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);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

html {
  height: 100%;
}

body {
  min-height: 100dvh;
  min-height: 100svh;
  cursor: none;
  overflow-x: hidden;
  background:
    radial-gradient(1000px 620px at 50% -15%, rgba(255, 45, 85, 0.22), transparent 55%),
    radial-gradient(700px 480px at 100% 100%, rgba(46, 242, 195, 0.1), transparent 50%),
    linear-gradient(180deg, #0b1620 0%, #050b11 100%);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

body.playing,
html.playing {
  overflow: hidden;
  height: 100%;
  touch-action: none;
}

button,
input,
label {
  cursor: none;
  font: inherit;
}

[hidden] {
  display: none !important;
}

#shake-root {
  width: 100%;
  min-height: calc(100svh - var(--safe-top) - var(--safe-bottom));
  transition: transform 0.05s linear;
}

body.playing #shake-root {
  display: flex;
  flex-direction: column;
  height: calc(100svh - var(--safe-top) - var(--safe-bottom));
  min-height: 0;
  overflow: hidden;
}

#shake-root.shake {
  animation: screen-shake 0.35s ease-out;
}

#shake-root.shake-hard {
  animation: screen-shake-hard 0.45s ease-out;
}

@keyframes screen-shake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  20% { transform: translate(-6px, 3px) rotate(-0.4deg); }
  40% { transform: translate(7px, -4px) rotate(0.5deg); }
  60% { transform: translate(-4px, -2px) rotate(-0.2deg); }
  80% { transform: translate(3px, 3px) rotate(0.15deg); }
}

@keyframes screen-shake-hard {
  0%, 100% { transform: translate(0, 0) scale(1); }
  15% { transform: translate(-10px, 6px) scale(1.015) rotate(-0.8deg); }
  30% { transform: translate(12px, -8px) scale(1.02) rotate(0.8deg); }
  45% { transform: translate(-8px, -6px) rotate(-0.6deg); }
  60% { transform: translate(8px, 4px) rotate(0.5deg); }
  80% { transform: translate(-3px, 2px); }
}

#fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  overflow: hidden;
}

.flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), rgba(217, 255, 243, 0.5), transparent 45%);
  animation: flash-out 0.28s ease-out forwards;
}

@keyframes flash-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.float-text {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(24px, 6vw, 48px);
  letter-spacing: 0.04em;
  line-height: 1.2;
  color: var(--mint);
  text-shadow: 0 2px 0 #000, 0 0 24px rgba(46, 242, 195, 0.55);
  animation: float-up 0.85s ease-out forwards;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

.float-text.crit {
  color: var(--accent-hot);
  font-size: clamp(30px, 7vw, 60px);
  text-shadow: 0 3px 0 #000, 0 0 30px rgba(255, 45, 85, 0.7);
}

@keyframes float-up {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.6) rotate(-6deg); }
  30% { opacity: 1; transform: translate(-50%, -70%) scale(1.12) rotate(2deg); }
  100% { opacity: 0; transform: translate(-50%, -140%) scale(1) rotate(-2deg); }
}

.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
  animation: particle-fly 0.55s ease-out forwards;
}

@keyframes particle-fly {
  to {
    transform: translate(var(--dx), var(--dy)) rotate(180deg) scale(0.2);
    opacity: 0;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px clamp(14px, 4vw, 40px) 0;
  flex-shrink: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-mark {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(22px, 5vw, 34px);
  letter-spacing: 0.04em;
  color: var(--accent-hot);
  line-height: 1.2;
}

.brand-sub {
  font-family: var(--font-en);
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.2;
}

.hud {
  display: flex;
  gap: clamp(10px, 3vw, 18px);
  flex-shrink: 0;
}

.hud-item {
  text-align: right;
  min-width: 3em;
}

.hud-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  line-height: 1.2;
}

.hud-value {
  font-family: var(--font-en);
  font-size: clamp(22px, 5vw, 32px);
  line-height: 1.15;
  color: var(--ink);
}

main {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 8px clamp(14px, 4vw, 24px) 28px;
}

body.playing main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 920px;
  padding-top: 4px;
  padding-bottom: 10px;
  overflow: hidden;
}

#screen-setup,
#screen-play,
#screen-result {
  width: 100%;
}

#screen-play:not([hidden]) {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  justify-content: space-between;
  gap: 8px;
}

.setup-hero {
  text-align: center;
  padding: 12px 0 10px;
}

.logo {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(48px, 14vw, 108px);
  letter-spacing: 0.06em;
  line-height: 1.4;
  padding: 0.08em 0.04em 0.18em;
  background-image: linear-gradient(180deg, #ffd0da 0%, var(--accent-hot) 40%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--accent-hot);
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35));
  animation: brand-pulse 2.4s ease-in-out infinite;
  overflow: visible;
}

@keyframes brand-pulse {
  0%, 100% { filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35)); }
  50% { filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35)) drop-shadow(0 0 24px rgba(255, 45, 85, 0.45)); }
}

.tagline {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(13px, 3.5vw, 16px);
  line-height: 1.4;
}

.setup-panel {
  width: min(440px, 100%);
  margin: 4px auto 0;
  display: grid;
  gap: 14px;
}

.upload-zone {
  display: block;
  width: 100%;
  border: 2px dashed rgba(46, 242, 195, 0.4);
  border-radius: var(--radius);
  background:
    linear-gradient(145deg, rgba(255, 45, 85, 0.1), rgba(0, 0, 0, 0.28)),
    var(--bg1);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s;
}

.upload-zone:hover,
.upload-zone.drag {
  border-color: var(--mint);
  transform: translateY(-2px);
}

.upload-preview {
  width: 100%;
  height: clamp(150px, 42vw, 240px);
  display: grid;
  place-items: center;
  position: relative;
}

.upload-placeholder {
  display: grid;
  gap: 8px;
  place-items: center;
  text-align: center;
  padding: 16px;
  color: var(--muted);
  width: 100%;
}

.upload-placeholder strong {
  color: var(--ink);
  font-size: clamp(15px, 4vw, 18px);
  line-height: 1.35;
}

.upload-placeholder span:last-child {
  font-size: clamp(11px, 3vw, 13px);
  line-height: 1.45;
  max-width: 22em;
}

.upload-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #ffa0b4, var(--accent) 55%, #9f1239);
  box-shadow: inset 0 -8px 16px rgba(0, 0, 0, 0.35), 0 8px 20px rgba(255, 45, 85, 0.35);
  position: relative;
  margin-bottom: 2px;
}

.upload-icon::after {
  content: "+";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 32px;
  font-weight: 900;
  color: #fff;
  line-height: 1;
}

#preview-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.field {
  display: grid;
  gap: 8px;
  width: 100%;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field label,
.field-label {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.06em;
  line-height: 1.3;
}

.speed-readout {
  font-size: 13px;
  font-weight: 700;
  color: var(--mint);
  letter-spacing: 0.06em;
}

.field input[type="text"] {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.3;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.field input[type="text"]:focus {
  border-color: rgba(46, 242, 195, 0.55);
  box-shadow: 0 0 0 3px rgba(46, 242, 195, 0.16);
}

.speed-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1d3348, var(--mint) 55%, var(--accent));
  outline: none;
  cursor: none;
}

.speed-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(180deg, #fff, var(--mint));
  border: 2px solid #062018;
  box-shadow: 0 4px 12px rgba(46, 242, 195, 0.45);
  cursor: none;
}

.speed-range::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(180deg, #fff, var(--mint));
  border: 2px solid #062018;
  box-shadow: 0 4px 12px rgba(46, 242, 195, 0.45);
  cursor: none;
}

.speed-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-top: -2px;
}

.cta {
  border: 0;
  border-radius: 999px;
  padding: 16px 20px;
  width: 100%;
  min-height: 50px;
  font-weight: 900;
  font-size: 17px;
  line-height: 1.2;
  color: #061018;
  background: linear-gradient(180deg, #ffb3c2, var(--accent-hot) 40%, var(--accent));
  box-shadow: 0 12px 28px rgba(255, 45, 85, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s;
}

.cta:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.01);
  filter: brightness(1.05);
}

.cta:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

.cta:disabled {
  opacity: 0.45;
  filter: grayscale(0.4);
}

.cta.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: none;
}

.hint {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  padding: 0 2px;
}

.rage-wrap {
  display: grid;
  gap: 6px;
  margin: 4px 0 12px;
  flex-shrink: 0;
  width: 100%;
}

.rage-label {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--muted);
  line-height: 1.2;
}

.rage-bar {
  height: 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
  border: 1px solid rgba(255, 45, 85, 0.28);
}

.rage-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #ff6b8a 55%, var(--mint));
  box-shadow: 0 0 18px rgba(255, 45, 85, 0.5);
  transition: width 0.2s ease;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(8px, 2.5vw, 16px);
  width: min(100%, 52vmin, 460px);
  margin: auto;
  flex: 0 1 auto;
  align-content: center;
  touch-action: manipulation;
  min-height: 0;
}

.hole {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 35%, #24384c, var(--hole) 55%, #081018 100%);
  box-shadow:
    inset 0 14px 22px rgba(0, 0, 0, 0.65),
    0 8px 0 rgba(0, 0, 0, 0.35);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.hole::before {
  content: "";
  position: absolute;
  inset: 12% 12% auto;
  height: 28%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  pointer-events: none;
  z-index: 2;
}

/* Full face centered in the hole when up */
.mole {
  position: absolute;
  inset: 11%;
  transform: translateY(125%);
  transition: transform 0.16s cubic-bezier(0.2, 1.35, 0.4, 1);
  will-change: transform;
  z-index: 1;
}

.mole.up {
  transform: translateY(0);
}

.mole.hit {
  animation: mole-hit 0.28s ease-out forwards;
}

@keyframes mole-hit {
  0% { transform: translateY(0) scale(1) rotate(0); filter: brightness(1); }
  35% { transform: translateY(10%) scale(0.9) rotate(-8deg); filter: brightness(1.55); }
  100% { transform: translateY(130%) scale(0.72) rotate(12deg); filter: brightness(0.55); opacity: 0.15; }
}

.mole-face {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center center;
  border: 3px solid #0b1520;
  box-shadow:
    0 4px 0 rgba(0, 0, 0, 0.3),
    0 0 0 2px rgba(46, 242, 195, 0.5);
  background: #1a2a38;
  display: block;
  pointer-events: none;
}

.mole-crack {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  background:
    linear-gradient(120deg, transparent 46%, rgba(255, 255, 255, 0.85) 48%, transparent 50%),
    linear-gradient(40deg, transparent 48%, rgba(255, 45, 85, 0.9) 50%, transparent 52%),
    linear-gradient(160deg, transparent 40%, rgba(0, 0, 0, 0.7) 42%, transparent 44%);
  mix-blend-mode: screen;
}

.mole.hit .mole-crack {
  opacity: 1;
  animation: crack-flash 0.28s ease-out;
}

@keyframes crack-flash {
  from { opacity: 1; transform: scale(0.9); }
  to { opacity: 0.35; transform: scale(1.1); }
}

.play-tip {
  text-align: center;
  margin: 10px 0 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(18px, 5vw, 26px);
  letter-spacing: 0.06em;
  line-height: 1.25;
  color: var(--accent-hot);
  min-height: 1.25em;
  flex-shrink: 0;
}

#screen-result:not([hidden]) {
  display: grid;
  place-items: center;
  padding: 12px 0 20px;
  width: 100%;
}

.result-card {
  width: min(420px, 100%);
  text-align: center;
  display: grid;
  gap: 14px;
  animation: result-in 0.5s cubic-bezier(0.2, 1.2, 0.4, 1);
}

@keyframes result-in {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.result-kicker {
  margin: 0;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.result-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(40px, 11vw, 64px);
  letter-spacing: 0.04em;
  line-height: 1.2;
  color: var(--mint);
  text-shadow: 0 0 30px rgba(46, 242, 195, 0.35);
}

.result-face {
  width: min(140px, 36vw);
  height: min(140px, 36vw);
  margin: 4px auto;
  position: relative;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.result-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  filter: grayscale(0.25) contrast(1.1);
}

.result-crack {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(115deg, transparent 45%, rgba(255, 255, 255, 0.75) 47%, transparent 49%),
    linear-gradient(25deg, transparent 48%, rgba(255, 45, 85, 0.85) 50%, transparent 52%),
    radial-gradient(circle at 60% 40%, transparent 30%, rgba(0, 0, 0, 0.35) 70%);
  mix-blend-mode: soft-light;
  opacity: 0.9;
}

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

.result-stats .stat-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
}

.result-stats .stat-value {
  font-family: var(--font-en);
  font-size: clamp(26px, 7vw, 36px);
  line-height: 1.15;
}

.result-actions {
  display: grid;
  gap: 10px;
  width: 100%;
}

.hammer {
  position: fixed;
  left: 0;
  top: 0;
  width: 64px;
  height: 64px;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transform: translate(-9999px, -9999px);
  filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.45));
  will-change: transform;
}

.hammer.ready {
  opacity: 1;
}

.hammer.smash {
  animation: hammer-smash 0.18s ease-out;
}

@keyframes hammer-smash {
  0% { transform: translate(var(--hx, 0px), var(--hy, 0px)) rotate(-25deg) scale(1); }
  40% { transform: translate(var(--hx, 0px), var(--hy, 0px)) rotate(15deg) scale(1.15); }
  100% { transform: translate(var(--hx, 0px), var(--hy, 0px)) rotate(-25deg) scale(1); }
}

@media (max-width: 640px) {
  .topbar {
    padding: 8px 14px 0;
  }

  body.playing .brand-sub {
    display: none;
  }

  body.playing .hud {
    flex: 1;
    justify-content: flex-end;
  }

  body.playing .hud-item {
    text-align: center;
  }

  .setup-hero {
    padding: 6px 0 8px;
  }

  .upload-preview {
    height: clamp(140px, 38vw, 200px);
  }

  .board {
    width: min(100%, 58vmin, 420px);
  }
}

@media (max-height: 700px) {
  .setup-hero {
    padding: 2px 0 4px;
  }

  .logo {
    font-size: clamp(40px, 11vw, 64px);
  }

  .upload-preview {
    height: clamp(110px, 28vh, 160px);
  }

  .setup-panel {
    gap: 10px;
  }

  body.playing .play-tip {
    font-size: 18px;
    margin-top: 6px;
  }

  body.playing .rage-wrap {
    margin-bottom: 8px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  body.playing .brand {
    display: none;
  }

  body.playing .play-tip {
    display: none;
  }

  body.playing .rage-wrap {
    margin: 2px 0 6px;
  }

  body.playing .board {
    width: min(42vh * 3 + 40px, 70vw, 100%);
  }

  .logo {
    font-size: 36px;
  }

  .upload-preview {
    height: 96px;
  }
}

@media (hover: none) {
  body {
    cursor: auto;
  }

  button,
  input,
  label {
    cursor: pointer;
  }

  .speed-range,
  .speed-range::-webkit-slider-thumb,
  .speed-range::-moz-range-thumb {
    cursor: pointer;
  }

  .hammer {
    display: none !important;
  }

  .upload-zone:hover {
    transform: none;
  }

  .cta:hover:not(:disabled) {
    transform: none;
    filter: none;
  }
}
