@font-face {
  font-family: "Ktegaki";
  src: url("ktegaki.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

:root {
  --bg-cream: #dbcade;
  --ink: #0e0e0e;
  --card: #ffffff;
  --card-muted: #f7f3ee;
  --live: #ff4d6d;
  --plum: #5a2c6b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Ktegaki", "Trebuchet MS", sans-serif;
  font-size: 18px;
  color: var(--ink);
  background: #147e73;
  display: grid;
  place-items: center;
  padding: 32px 20px 48px;
  transition: background 220ms ease, color 220ms ease;
}

body.is-gameplay-active {
  overflow: hidden;
  overscroll-behavior: none;
}

.stage {
  width: min(820px, 100%);
  display: grid;
  gap: 14px;
}

.card {
  background: var(--card);
  border-radius: 28px;
  box-shadow: none;
  padding: 22px;
  border: 3px solid #0f0f0f;
  transition: background 220ms ease, border-color 220ms ease, color 220ms ease, box-shadow 220ms ease;
}

.header {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  justify-content: space-between;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border: 2px dashed #111;
  border-radius: 999px;
  padding: 6px 12px;
  color: #111111;
}

.time-pill {
  color: #111111;
}

.live,
.time-pill {
  font-size: 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tune-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.tune-text {
  margin-left: 1px;
}

.tune-chip button {
  font-family: "Ktegaki", "Trebuchet MS", sans-serif;
  font-size: 20px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid #111;
  border-bottom-width: 5px;
  background: var(--bg-cream);
  color: #111111;
  cursor: pointer;
  min-width: 68px;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}

.tune-chip button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
  border-color: var(--plum);
}

.live-dot {
  width: 10px;
  height: 10px;
  background: var(--live);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(255, 77, 109, 0.6);
  animation: pulse 1.6s infinite;
}

.live.is-replay .live-dot {
  animation: none;
  background: #111111;
  box-shadow: none;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 77, 109, 0.6);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(255, 77, 109, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 77, 109, 0);
  }
}

.video-shell {
  border-radius: 22px;
  overflow: hidden;
  border: 3px solid #111;
  background: #000;
  position: relative;
  aspect-ratio: 16 / 9;
}

body.is-night {
  background: #101a31;
  color: #e7ecff;
}

body.is-night .card {
  background: #14182d;
  border-color: #2a3558;
  color: #e7ecff;
  box-shadow: none;
}

body.is-night .live {
  background: #1e294b;
  border-color: #4a5984;
  color: #e7ecff;
}

body.is-night .time-pill {
  color: #e7ecff;
}

body.is-night .tune-chip button {
  background: #1f2b4e;
  color: #ecf2ff;
  border-color: #4a5984;
}

body.is-night .tune-chip button:hover {
  border-color: #5b6f9f;
  box-shadow: 0 6px 14px rgba(5, 10, 28, 0.45);
}

body.is-night .tune-emoji {
  filter: invert(1) hue-rotate(180deg) brightness(1.08);
}

body.is-night .video-shell {
  border-color: #4a5984;
  background: #0e152b;
}

.video-shell video {
  width: 100%;
  height: 100%;
  display: block;
  background: #111;
  object-fit: cover;
}

.video-fade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 2;
}

.video-fade.is-on {
  opacity: 1;
}

.card-game {
  border-radius: 12px;
  background: #fff9ef;
  padding: 22px;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.treat-title {
  margin: 0;
  font-size: 20px;
}

.treat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.treat-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
}

.treat-score,
.treat-best {
  font-size: 18px;
  line-height: 1.2;
}

.treat-time {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 3;
  padding: 2px 8px;
  border-radius: 999px;
  border: 2px solid #111;
  background: rgba(255, 255, 255, 0.9);
  color: #1d514b;
  font-size: 16px;
  line-height: 1;
}

.treat-best {
  color: #5a2c6b;
}

.treat-start {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  font-family: "Ktegaki", "Trebuchet MS", sans-serif;
  font-size: 20px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid #111;
  border-bottom-width: 5px;
  background: var(--bg-cream);
  color: #111111;
  cursor: pointer;
  min-width: 68px;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}

.treat-start:hover {
  transform: translate(-50%, calc(-50% - 1px));
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
  border-color: var(--plum);
  background: var(--bg-cream);
}

.treat-field {
  position: relative;
  height: 145px;
  border: 2px solid #111;
  border-radius: 12px;
  background: linear-gradient(180deg, #dff3ef 0%, #f9f2e6 100%);
  overflow: hidden;
  touch-action: manipulation;
  transition: background 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

body.is-gameplay-active .treat-field {
  touch-action: none;
}

.card-game.is-night {
  background: #14182d;
  border-color: #2a3558;
  color: #e7ecff;
}

.card-game.is-night .treat-best {
  color: #a9c8ff;
}

.card-game.is-night .treat-start {
  background: #1f2b4e;
  color: #ecf2ff;
  border-color: #4a5984;
}

.card-game.is-night .treat-start:hover {
  border-color: #5b6f9f;
  background: #24335c;
  box-shadow: 0 6px 14px rgba(5, 10, 28, 0.45);
}

.treat-field.is-night {
  background: linear-gradient(180deg, #0f1a35 0%, #263252 100%);
  border-color: #51608a;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.treat-field.is-night .treat-time {
  background: rgba(12, 18, 34, 0.86);
  color: #d8e5ff;
  border-color: #51608a;
}

.treat {
  position: absolute;
  top: 0;
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  padding: 8px;
  min-width: 38px;
  min-height: 38px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transform: translate3d(-50%, -24px, 0);
  will-change: transform;
  animation: treat-fall linear forwards;
}

@keyframes treat-fall {
  0% {
    transform: translate3d(-50%, -24px, 0);
  }
  100% {
    transform: translate3d(-50%, var(--fall-distance, 170px), 0);
  }
}

.rabbit {
  position: absolute;
  border: 0;
  background: transparent;
  font-size: 0;
  line-height: 1;
  padding: 6px;
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  will-change: transform;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
}

.rabbit-glyph {
  display: block;
  font-size: 24px;
}

.rabbit--left {
  animation: rabbit-run-right linear forwards;
}

.rabbit--right {
  animation: rabbit-run-left linear forwards;
}

.rabbit--left .rabbit-glyph {
  animation: rabbit-jiggle-right 430ms ease-in-out infinite;
}

.rabbit--right .rabbit-glyph {
  animation: rabbit-jiggle-left 430ms ease-in-out infinite;
}

@keyframes rabbit-run-right {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(var(--rabbit-distance, 420px), 0, 0);
  }
}

@keyframes rabbit-run-left {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(calc(var(--rabbit-distance, 420px) * -1), 0, 0);
  }
}

@keyframes rabbit-jiggle-right {
  0% {
    transform: translateY(0) scaleX(-1);
  }
  50% {
    transform: translateY(-3px) scaleX(-1);
  }
  100% {
    transform: translateY(0) scaleX(-1);
  }
}

@keyframes rabbit-jiggle-left {
  0% {
    transform: translateY(0) scaleX(1);
  }
  50% {
    transform: translateY(-3px) scaleX(1);
  }
  100% {
    transform: translateY(0) scaleX(1);
  }
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 20;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  animation: confetti-pop 900ms ease-out forwards;
}

@keyframes confetti-pop {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--drift-x), var(--drift-y), 0) rotate(var(--spin));
    opacity: 0;
  }
}

@media (max-width: 640px) {
  body {
    padding: 16px 16px 36px;
  }

  .stage {
    gap: 12px;
  }

  .card,
  .card-game {
    padding: 16px;
  }

  .header,
  .header-left {
    gap: 10px;
  }

  #tuneToggle {
    min-width: 48px;
    padding: 6px 10px;
  }

  #tuneToggle .tune-text {
    display: none;
  }

  .video-shell {
    aspect-ratio: 3 / 2;
  }

  .treat-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .treat-title {
    font-size: 19px;
  }

  .treat-score,
  .treat-best,
  .treat-start {
    font-size: 17px;
  }

  .treat-time {
    font-size: 15px;
  }

  .treat-field {
    height: 132px;
  }
}
