:root {
  --bg-top: #f1ead5;
  --bg-bottom: #d6dfef;
  --panel: rgba(255, 250, 240, 0.82);
  --panel-strong: rgba(255, 248, 232, 0.94);
  --line: rgba(112, 95, 67, 0.18);
  --text: #433424;
  --accent: #d4a54d;
  --accent-strong: #ac6e1d;
  --danger: #9e4124;
  --shadow: 0 18px 40px rgba(99, 77, 43, 0.14);
  --stage-size: min(90vw, calc(100vh - 210px), 720px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.8), transparent 36%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body {
  min-height: 100vh;
}

button {
  font: inherit;
}

img,
video {
  max-width: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  gap: 18px;
  padding: 20px 16px 28px;
}

.app-header {
  text-align: center;
}

.app-header h1 {
  margin: 4px 0 0;
  font-size: clamp(1.9rem, 5vw, 3rem);
  line-height: 1.05;
  letter-spacing: 0.04em;
}

.eyebrow {
  margin: 0;
  color: rgba(67, 52, 36, 0.72);
  font-size: 0.78rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.game-shell {
  width: min(100%, 920px);
  display: grid;
  place-items: center;
}

.stage-frame {
  position: relative;
  width: var(--stage-size);
  height: var(--stage-size);
  border-radius: 30px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.46);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  isolation: isolate;
}

.stage-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.36), transparent 35%),
    radial-gradient(circle at bottom right, rgba(212, 165, 77, 0.2), transparent 25%);
  pointer-events: none;
  z-index: 0;
}

.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms ease;
  z-index: 1;
}

.screen.is-active {
  opacity: 1;
  pointer-events: auto;
}

.full-video,
.playfield {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.full-video {
  object-fit: contain;
  background:
    radial-gradient(circle at center, rgba(250, 243, 229, 0.32), transparent 55%),
    linear-gradient(180deg, rgba(53, 42, 25, 0.86), rgba(28, 21, 12, 0.95));
}

.intro-video {
  opacity: 0;
  transition: opacity 120ms ease;
}

.intro-video.is-active {
  opacity: 1;
}

.face-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.landing-reveal .face-layer {
  object-fit: contain;
}

.screen-overlay {
  position: absolute;
  inset: auto 0 0;
  padding: 20px;
  display: flex;
  justify-content: center;
  background: linear-gradient(180deg, transparent, rgba(31, 27, 18, 0.44));
  transition: opacity 240ms ease;
}

.overlay-label {
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 249, 238, 0.82);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
}

.screen-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.intro-hud {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 6;
}

.title-action {
  position: absolute;
  left: 50%;
  bottom: 56px;
  z-index: 6;
  transform: translateX(-50%);
}

.title-action .primary-button {
  min-width: 148px;
  padding-inline: 28px;
  font-size: 1rem;
  letter-spacing: 0.08em;
  box-shadow: 0 14px 28px rgba(172, 110, 29, 0.34);
}

.intro-countdown {
  position: absolute;
  left: 50%;
  bottom: 88px;
  z-index: 6;
  display: grid;
  justify-items: center;
  gap: 8px;
  transform: translateX(-50%) scale(0.9);
  opacity: 0;
  transition: opacity 220ms ease, transform 220ms ease;
}

.intro-countdown.is-visible {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.intro-countdown-label {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 248, 235, 0.84);
  color: var(--text);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
}

.intro-countdown strong {
  font-size: clamp(3.6rem, 15vw, 6rem);
  line-height: 1;
  color: #fff8ef;
  text-shadow: 0 10px 28px rgba(30, 21, 12, 0.5);
}

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.hud-overlay {
  left: 10px;
  top: 10px;
  right: auto;
  z-index: 3;
  pointer-events: none;
}

.timer-box {
  position: relative;
  width: clamp(132px, 22vw, 176px);
  min-height: clamp(104px, 16vw, 136px);
  padding: 10px 12px;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(23, 16, 8, 0.3);
  color: #fff8ef;
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(4px);
  display: grid;
  align-content: space-between;
  gap: 6px;
  box-shadow: 0 10px 24px rgba(32, 27, 15, 0.18);
}

.timer-box::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(20, 14, 8, 0.12), rgba(20, 14, 8, 0.42)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 36%);
  pointer-events: none;
}

.timer-box > :not(.fall-video) {
  position: relative;
  z-index: 1;
}

.timer-label {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  opacity: 0.88;
}

.timer-box strong {
  font-size: clamp(1.35rem, 4.2vw, 2rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
}

.timer-box.is-danger {
  background: rgba(135, 42, 21, 0.38);
}

.timer-box.is-danger::after {
  background:
    linear-gradient(180deg, rgba(92, 24, 12, 0.12), rgba(92, 24, 12, 0.46)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 36%);
}

.playfield {
  background: #efe7d9;
  overflow: hidden;
}

[data-screen="game"] {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 12px 14px;
  background: linear-gradient(180deg, rgba(247, 241, 228, 0.92), rgba(236, 228, 213, 0.96));
}

[data-screen="game"].is-active {
  pointer-events: auto;
}

[data-screen="game"] .playfield {
  position: relative;
  inset: auto;
  width: 100%;
  height: auto;
  min-height: 0;
  border-radius: 24px;
}

[data-screen="intro"],
[data-screen="landing"] {
  background:
    radial-gradient(circle at top, rgba(255, 251, 244, 0.46), transparent 42%),
    linear-gradient(180deg, rgba(67, 50, 27, 0.86), rgba(29, 21, 11, 0.94));
}

.parts-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
}

.part {
  position: absolute;
  transform-origin: center center;
  touch-action: none;
  cursor: grab;
  will-change: transform, left, top;
  transition:
    transform 180ms ease,
    filter 180ms ease,
    opacity 180ms ease;
}

.part.is-dragging {
  cursor: grabbing;
  filter: drop-shadow(0 14px 22px rgba(24, 16, 9, 0.24));
  z-index: 20;
}

.part.is-snapped {
  cursor: default;
  filter: drop-shadow(0 8px 18px rgba(76, 112, 67, 0.18));
}

.fall-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.98;
  pointer-events: none;
}

.landing-reveal {
  position: absolute;
  inset: 0;
  z-index: 4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
  overflow: hidden;
}

.landing-reveal.is-visible {
  opacity: 1;
}

.landing-reveal::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 247, 233, 0.08);
  pointer-events: none;
}

.landing-capture {
  position: absolute;
  inset: 0;
  --landing-media-height: 56.25%;
  --landing-media-top: clamp(52px, 12%, 88px);
  --landing-gutter-bottom: calc(100% - var(--landing-media-top) - var(--landing-media-height));
}

.landing-media-frame {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--landing-media-top);
  height: var(--landing-media-height);
  overflow: hidden;
}

.landing-media-frame .full-video,
.landing-media-frame .landing-reveal {
  inset: 0;
}

.landing-result-hud {
  position: absolute;
  inset: 0;
  padding: clamp(10px, 2vw, 16px);
  z-index: 7;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows:
    minmax(0, var(--landing-media-top))
    minmax(0, 1fr)
    auto
    auto;
  gap: 8px;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 320ms ease, transform 320ms ease;
}

.landing-result-hud.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.landing-result-hud .result-top {
  grid-column: 1 / -1;
  grid-row: 1;
  align-self: start;
}

.landing-result-hud .result-copy {
  grid-column: 1;
  grid-row: 3;
  align-self: end;
  justify-self: end;
  width: min(100%, 420px);
  margin: 0;
}

.landing-result-hud .result-actions {
  grid-column: 1;
  grid-row: 4;
  align-self: end;
  justify-self: end;
  width: min(100%, 420px);
  margin: 0;
  justify-content: flex-start;
}

.help-text {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 10px 14px;
  border-radius: 18px;
  background: rgba(255, 248, 235, 0.8);
  text-align: center;
  font-size: 0.82rem;
  line-height: 1.4;
  border: 1px solid rgba(112, 95, 67, 0.14);
  backdrop-filter: blur(12px);
}

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

.result-label {
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
}

.score-badge {
  padding: 10px 14px;
  border-radius: 18px;
  background: rgba(23, 16, 8, 0.78);
  color: #fff7ea;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.score-badge span {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.score-badge strong {
  font-size: clamp(1.5rem, 4.5vw, 2.2rem);
  line-height: 1;
}

.result-copy {
  padding: 10px 14px;
  border-radius: 20px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: 0 16px 36px rgba(35, 25, 12, 0.18);
}

.result-quote {
  margin: 0;
  font-size: clamp(1rem, 3.1vw, 1.45rem);
  line-height: 1.3;
}

.result-detail {
  margin: 6px 0 0;
  color: rgba(67, 52, 36, 0.72);
  font-size: 0.85rem;
  line-height: 1.4;
}

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

.result-actions {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: stretch;
}

.primary-button,
.ghost-button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 11px 16px;
  min-height: 42px;
  cursor: pointer;
  transition: transform 160ms ease, opacity 160ms ease, background 160ms ease;
}

.landing-result-hud .primary-button,
.landing-result-hud .ghost-button {
  flex: 1 1 0;
  width: auto;
  white-space: nowrap;
}

.primary-button:active,
.ghost-button:active {
  transform: translateY(1px) scale(0.99);
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fffaf0;
  box-shadow: 0 10px 24px rgba(172, 110, 29, 0.28);
}

.ghost-button {
  background: rgba(255, 248, 235, 0.86);
  color: var(--text);
  border: 1px solid var(--line);
}

.hidden {
  display: none !important;
}

@media (max-width: 768px) {
  :root {
    --stage-size: min(94vw, calc(100vh - 168px));
  }

  .app-shell {
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .stage-frame {
    border-radius: 24px;
  }

  .hud {
    top: 10px;
    left: 10px;
    right: 10px;
  }

  [data-screen="game"] {
    gap: 10px;
    padding: 10px;
  }

  .hud-overlay {
    top: 8px;
    left: 8px;
    right: auto;
  }

  .timer-box {
    width: min(34vw, 156px);
    min-height: 96px;
    padding: 8px 10px;
  }

  .help-text {
    font-size: 0.76rem;
    padding: 9px 12px;
  }

  .intro-hud {
    top: 10px;
    right: 10px;
  }

  .title-action {
    bottom: 42px;
  }

  .intro-countdown {
    bottom: 78px;
  }

  .landing-result-hud {
    gap: 8px;
  }

  .landing-result-hud .result-copy {
    width: min(100%, 360px);
  }

  .landing-result-hud .result-actions {
    width: min(100%, 360px);
  }

  .primary-button,
  .ghost-button {
    padding: 10px 14px;
  }
}
