* { box-sizing: border-box; }

:root {
  color: #241b1b;
  background: #262222;
  font-family: "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  --red: #ca3633;
  --ink-red: #a92825;
  --paper: #fff;
  --outer: clamp(7px, 1.45vw, 16px);
  --gutter: clamp(4px, .85vw, 9px);
}

body {
  margin: 0;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(8px, 2.5vw, 32px);
}

main {
  width: min(100%, 1050px);
  padding: var(--outer);
  background: var(--red);
}

.frame { padding: var(--gutter); background: var(--paper); }

.screen {
  position: relative;
  border: clamp(2px, .33vw, 4px) solid var(--red);
  background: var(--paper);
}

[hidden] { display: none !important; }

.copy {
  display: grid;
  place-items: center;
  min-height: clamp(520px, 76svh, 700px);
  padding: clamp(24px, 5vw, 68px) clamp(12px, 4vw, 40px);
  text-align: center;
}

.copy-inner { max-width: 40rem; }
h1, h2 { margin: 0; line-height: 1.35; }
.copy h1, .copy h2 {
  font-size: clamp(1.48rem, 4vw, 2.7rem);
  font-weight: 900;
  letter-spacing: .04em;
  text-wrap: balance;
}

.copy p {
  margin: clamp(14px, 2.4vh, 24px) 0;
  font-size: clamp(.875rem, 1.6vw, 1rem);
  line-height: 1.85;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.copy .cheer { color: var(--ink-red); font-weight: 800; }

button { font: inherit; cursor: pointer; color: inherit; }

.copy button, #reset, #next {
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--ink-red);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink-red);
  font-weight: 800;
  font-size: .875rem;
}

.copy button, #next {
  background: var(--ink-red);
  color: white;
  box-shadow: 0 3px #731c19;
}

.copy button:hover, #next:hover { background: #8d211f; }
#reset:hover { background: #fff0ed; }
.copy button:active, #next:active { box-shadow: none; transform: translateY(3px); }
button:focus-visible { outline: 2px solid var(--ink-red); outline-offset: 4px; }
.copy button { margin-top: clamp(6px, 2vh, 18px); }

.play {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: clamp(420px, calc(100svh - 90px), 700px);
}

.play header { padding: 17px 10px 0; text-align: center; }
.play h2 { font-size: clamp(.875rem, 2.2vw, 1.35rem); font-weight: 900; text-wrap: balance; }
.game { position: relative; min-height: 0; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; }

#grip {
  position: absolute;
  transform: translate(-50%, -50%);
  min-height: 44px;
  border: 0;
  border-radius: 24px;
  background: transparent;
  touch-action: none;
  cursor: grab;
}

#grip:active { cursor: grabbing; }

#result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-inline: 12px;
  text-align: center;
  background: rgb(38 34 34 / 53%);
}

.result-card {
  display: grid;
  justify-items: center;
  gap: 15px;
  width: min(100%, 18rem);
  padding: clamp(16px, 4vw, 24px);
  border: 1px solid var(--red);
  border-radius: 4px;
  background: var(--paper);
  box-shadow: 0 4px 12px rgb(36 27 27 / 16%);
}

#success {
  margin: 0;
  color: #181515;
  font-size: clamp(1.125rem, 4vw, 1.5rem);
  font-weight: 900;
  line-height: 1.35;
}

footer {
  display: grid;
  grid-template-columns: 1fr minmax(130px, 220px) 1fr;
  align-items: center;
  gap: 6px 12px;
  padding: 4px clamp(8px, 3vw, 30px) 14px;
}

#reset { justify-self: start; white-space: nowrap; }
#level { font-size: .875rem; font-weight: 800; }
.progress { display: flex; gap: 4px; margin: 5px 0 0; padding: 0; list-style: none; }
.progress li { height: 5px; flex: 1; border-radius: 1px; background: #eee0df; }
.progress .active { background: #d9817b; }
.progress .done { background: var(--ink-red); }
.footer-help { grid-column: 1 / -1; text-align: center; }
.footer-help p { margin: 0; font-size: .8125rem; line-height: 1.55; color: #4d4141; }
#hint { min-height: 1.55em; color: var(--ink-red); font-weight: 750; pointer-events: none; }

.leaving { overflow: hidden; }
.paper-pieces { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.paper-piece {
  position: absolute;
  margin: 0;
  animation: scatter 1320ms cubic-bezier(.45, .03, .63, .99) var(--delay) both;
}

.paper-crack {
  position: absolute;
  width: 15px;
  height: clamp(32px, 7vw, 54px);
  margin-left: -5px;
  background: #262222;
  clip-path: polygon(25% 0, 55% 0, 74% 26%, 46% 36%, 76% 60%, 37% 68%, 54% 100%, 22% 66%, 59% 58%, 25% 34%, 53% 24%);
  transform-origin: top;
  animation: crack-open 320ms ease-out both;
}

@keyframes crack-open {
  0% { transform: scaleY(0); opacity: 1; }
  32%, 70% { transform: scaleY(1); opacity: 1; }
  100% { transform: scaleY(1); opacity: 0; }
}

@keyframes scatter {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--spin)); opacity: 0; }
}

@media (max-width: 550px) {
  .copy { min-height: clamp(475px, calc(100svh - 40px), 700px); }
  .play { height: clamp(410px, calc(100svh - 42px), 700px); }
  footer { grid-template-columns: auto 1fr; }
  #reset { padding-inline: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .paper-crack { display: none; }
  .paper-piece { animation-name: dissolve; animation-duration: 1800ms; animation-delay: 0ms; }
}

@keyframes dissolve {
  from { opacity: 1; }
  to { opacity: 0; }
}
