* {
  touch-action: manipulation; /* タブレット連打時の拡大防止 */
}

html {
  margin: 0;
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  font-family: -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    sans-serif;
  background: #f2f2f2;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  margin: 0 auto;
  border: 2px solid #333;
  width: 100%;
  max-width: 1196px;
  height: 540px;
  display: flex;
  flex-direction: column;
}

.game-header {
  height: 50px;
  flex: 0 0 50px;
  align-items: center;
}

.game-main {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: grid;
  place-items: center;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.container {
  position: relative;
  overflow: hidden;
  color: #5b3a1e;
  background: radial-gradient(circle at 93% 12%,#ffe066 0 40px,#ffd43b 41px 52px,transparent 53px),
    radial-gradient(ellipse 120px 34px at 12% 10%,#fff 0 98%,transparent 100%),
    radial-gradient(ellipse 90px 26px at 60% 6%,#fff 0 98%,transparent 100%),
    radial-gradient(ellipse 100px 30px at 82% 30%,#ffffffcc 0 98%,transparent 100%),
    radial-gradient(ellipse 60% 90px at 20% 100%,#8ce99a 0 98%,transparent 100%),
    radial-gradient(ellipse 70% 110px at 85% 100%,#69db7c 0 98%,transparent 100%),
    linear-gradient(#a5e3ff,#d7f4ff 70%,#fff6d6);
  box-shadow: 0 8px 24px #0003;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  padding: 22px 26px;
}

.screen.on {
  display: flex;
}

.container button {
  font: inherit;
  color: #fff;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  border-radius: 999px;
  transition: transform .1s;
}

button:active {
  transform: scale(.94);
}

.big {
  min-width: 300px;
  min-height: 92px;
  padding: 0 40px;
  background: #ff8a3d;
  box-shadow: 0 8px 0 #c9601a;
}

.big.blue {
  background: #3b9cf0;
  box-shadow: 0 8px 0 #1f70bd;
}

.big.small {
  min-height: 76px;
  min-width: 260px;
}

#start,#result {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 22px;
}

.title {
  font-size: 74px;
  font-weight: bold;
  margin: 0;
  color: #ff6b6b;
  letter-spacing: 4px;
  text-shadow: 4px 4px 0 #fff,-2px -2px 0 #fff,2px -2px 0 #fff,-2px 2px 0 #fff,0 8px 0 #0002;
}

#result h2 {
  font-size: 56px;
  margin: 0;
  color: #ff6b6b;
  text-shadow: 3px 3px 0 #fff,-2px -2px 0 #fff,2px -2px 0 #fff,-2px 2px 0 #fff;
}

.btns {
  display: flex;
  gap: 26px;
  flex-wrap: wrap;
  justify-content: center;
}

#play {
  flex-direction: column;
}

.top {
  align-items: center;
  gap: 22px;
  flex: none;
}

.card {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 6px solid #ffc94d;
  border-radius: 28px;
  padding: 0 20px;
}

#target {
  display: flex;
  gap: 8px;
  font-weight: bold;
  line-height: 1;
  color: #ff6b6b;
  white-space: nowrap;
}

#target span {
  display: block;
  text-align: center;
  border-radius: 14px;
}

#target span.done {
  color: #2f9e44;
}

#target span.next {
  background: #ffd8a8;
}

#quit {
  background: #9775fa;
  font-weight: bold;
}

#grid {
  flex: 1;
  min-height: 0;
  align-self: center;
  width: 100%;
  max-width: 1040px;
  display: grid;
  grid-template-columns: repeat(4,1fr);
  grid-template-rows: repeat(3,1fr);
}

.cell {
  background: #fff;
  box-shadow: 0 6px 0 #e6a700;
  padding: 0;
  line-height: 1;
}

.cell:active {
  background: #fff3c4;
}

.container .cell.ok {
  background: #8ce99a;
  border-color: #2f9e44;
  box-shadow: 0 6px 0 #2f9e44;
  animation: pop .4s;
}

.container .cell.ng {
  background: #ffc9c9;
  border-color: #ff6b6b;
  animation: shake .35s;
}

@keyframes pop {
  50% {
    transform: scale(1.15);
  }
}

@keyframes shake {
  25% {
    transform: translateX(-8px);
  }

  75% {
    transform: translateX(8px);
  }
}

#fb {
  position: absolute;
  left: 0;
  right: 0;
  top: 38%;
  text-align: center;
  font-size: 110px;
  font-weight: bold;
  color: #ff6b6b;
  pointer-events: none;
  text-shadow: 4px 4px 0 #fff,-3px -3px 0 #fff,3px -3px 0 #fff,-3px 3px 0 #fff;
  opacity: 0;
}

#fb.show {
  animation: fb .6s;
}

@keyframes fb {
  0% {
    opacity: 0;
    transform: scale(.4);
  }

  30% {
    opacity: 1;
    transform: scale(1.1);
  }

  100% {
    opacity: 0;
    transform: scale(1);
  }
}

.game-main {
  background: transparent;
  min-height: 0;
  width: 100%;
}

.game-header {
  background: transparent;
  display: none;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  padding: 5px 12px;
  z-index: 5;
}

.container.playing .game-header {
  display: grid;
}

.game-header h1 {
  font-size: 22px;
  margin: 0;
  white-space: nowrap;
  text-align: center;
}

.header-info {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 40px;
  padding: 4px 16px;
  font-size: 18px;
  font-weight: bold;
  box-shadow: 0 2px 0 #e8a000;
}

.header-info b {
  font-size: 26px;
  color: #ff6f3c;
  text-align: center;
}

.header-actions {
  justify-self: end;
  display: flex;
  gap: 8px;
  align-items: center;
}

.container #quit {
  font-size: 18px;
  min-height: 36px;
  min-width: 80px;
  box-shadow: 0 3px 0 #6741d9;
  padding: 4px 16px;
}

.container .sound-btn {
  background: #fff0ad;
  border: 3px solid #f2b321;
  border-radius: 50px;
  padding: 5px 14px;
  font-size: 18px;
  font-weight: 700;
  color: #694100;
  letter-spacing: 1px;
  box-shadow: 0 3px 0 #d89500;
  min-width: 104px;
  height: 38px;
}

.container .sound-btn:hover {
  background: #ffe680;
  border-color: #dc9700;
  color: #5a3500;
}

.container .sound-btn.sound-off {
  background: #e9edf1;
  border-color: #aeb7c0;
  color: #66717b;
  box-shadow: 0 3px 0 #929ba4;
}

.start-sound-btn {
  position: absolute;
  right: 12px;
  top: 8px;
  z-index: 10;
}

.container.playing .start-sound-btn {
  display: none;
}

#play {
  gap: 10px;
  padding: 8px 26px 14px;
}

.top {
  display: flex;
  justify-content: center;
  height: 80px;
}

.card {
  height: 80px;
}

#target {
  font-size: 48px;
}

#target span {
  width: 60px;
  height: 60px;
  line-height: 60px;
}

.cell {
  min-height: 0;
}

#result {
  isolation: isolate;
  gap: 16px;
}

.result-animation {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: -1;
}

.result-animation i {
  position: absolute;
  top: -30px;
  left: var(--x);
  width: 14px;
  height: 22px;
  background: var(--color);
  border-radius: 4px;
  animation: confetti 4s linear infinite;
  animation-delay: var(--delay);
}

@keyframes confetti {
  to {
    transform: translateY(590px) rotate(540deg);
  }
}

@media(max-width:700px) {
  .game-header {
    grid-template-columns: 1fr auto 1fr;
    padding: 5px;
    gap: 4px;
  }

  .header-info {
    font-size: 12px;
    padding: 4px 8px;
    gap: 3px;
  }

  .header-actions {
    gap: 5px;
  }

  .container #quit {
    font-size: 14px;
    min-width: 52px;
    padding: 4px 8px;
  }

  .container .sound-btn {
    font-size: 14px;
    min-width: 70px;
    padding: 5px 7px;
  }

  .screen {
    padding: 20px 12px;
  }

  .title {
    font-size: clamp(27px,6vw,52px);
    letter-spacing: 1px;
  }

  #play {
    padding: 8px 12px 14px;
  }

  .cell {
    min-height: 0;
  }

  #result h2 {
    font-size: 40px;
  }

  .btns {
    gap: 18px;
  }

  .big.small {
    min-height: 58px;
    min-width: 220px;
  }
}

.container .big {
  font-size: 38px;
  font-weight: bold;
}

.container .big.small {
  font-size: 28px;
}

.container .cell {
  color: #5b3a1e;
  font-size: 48px;
  font-weight: bold;
  border: 4px solid #ffc94d;
  border-radius: 22px;
  font-family: "Hiragino Maru Gothic ProN","Yu Gothic","Meiryo",sans-serif;
}

#start {
  gap: 16px;
}

.selection-sample {
  width: 280px;
  flex: none;
}

.sample-target {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 30px;
  font-weight: bold;
  color: #ff6b6b;
}

.sample-target span {
  width: 40px;
  line-height: 40px;
  background: #fff;
  border-radius: 10px;
}

.sample-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4,1fr);
  grid-template-rows: repeat(3,48px);
  gap: 7px;
}

.sample-grid .cell {
  display: grid;
  place-items: center;
  font-size: 28px;
  min-height: 0;
  border-width: 3px;
  border-radius: 12px;
  box-shadow: 0 3px 0 #e6a700;
}

.sample-a {
  animation: sample-a 6s infinite;
}

.sample-i {
  animation: sample-i 6s infinite;
}

.sample-su {
  animation: sample-su 6s infinite;
}

.sample-finger {
  position: absolute;
  z-index: 1;
  left: 12.5%;
  top: 10%;
  font-size: 36px;
  line-height: 1;
  pointer-events: none;
  animation: sample-point 6s infinite;
}

@keyframes sample-point {
  0%,8% {
    left: 12.5%;
    top: 10%;
    transform: translateY(8px);
  }

  15%,25% {
    left: 12.5%;
    top: 10%;
    transform: translateY(0);
  }

  38%,48% {
    left: 62.5%;
    top: 45%;
    transform: translateY(0);
  }

  61%,78% {
    left: 37.5%;
    top: 78%;
    transform: translateY(0);
    opacity: 1;
  }

  90%,100% {
    left: 37.5%;
    top: 78%;
    opacity: 0;
  }
}

@keyframes sample-a {
  0%,14%,100% {
    background: #fff;
    border-color: #ffc94d;
  }

  15%,89% {
    background: #8ce99a;
    border-color: #2f9e44;
  }
}

@keyframes sample-i {
  0%,37%,100% {
    background: #fff;
    border-color: #ffc94d;
  }

  38%,89% {
    background: #8ce99a;
    border-color: #2f9e44;
  }
}

@keyframes sample-su {
  0%,60%,100% {
    background: #fff;
    border-color: #ffc94d;
  }

  61%,89% {
    background: #8ce99a;
    border-color: #2f9e44;
  }
}

@media(max-width:700px) {
  .container .cell {
    font-size: 40px;
    border-radius: 16px;
  }

  .container .big.small {
    font-size: 22px;
  }

  #target {
    font-size: clamp(28px,7vw,48px);
    gap: 4px;
  }

  #target span {
    width: clamp(34px,9vw,60px);
  }

  .card {
    padding: 0 10px;
  }
}

@media(prefers-reduced-motion:reduce) {
  .sample-finger,.sample-grid .cell {
    animation: none;
  }

  .sample-a {
    background: #8ce99a;
    border-color: #2f9e44;
  }
}

#grid {
  gap: 16px;
}

.container #grid .cell {
  font-size: 60px;
}

.top {
  position: relative;
}

.question-progress {
  position: absolute;
  left: 0;
  background: #fff;
  border-radius: 18px;
  padding: 10px 16px;
  font-size: 22px;
  font-weight: bold;
}

.header-info b {
  font-variant-numeric: tabular-nums;
  min-width: 58px;
}

.result-time {
  margin: 0;
  font-size: 28px;
  background: #fff;
  border-radius: 20px;
  padding: 8px 24px;
}

.result-time b {
  font-size: 40px;
  color: #ff6b6b;
  font-variant-numeric: tabular-nums;
}

@media(max-width:700px) {
  #grid {
    gap: 12px;
  }

  .container #grid .cell {
    font-size: 48px;
  }

  .question-progress {
    font-size: 15px;
    padding: 8px;
    position: static;
  }

  .top {
    gap: 8px;
  }

  .header-info {
    gap: 3px;
    white-space: nowrap;
  }

  .header-info b {
    min-width: 40px;
    font-size: 18px;
  }

  .game-header h1 {
    font-size: clamp(10px,2.5vw,19px);
  }

  .result-time {
    font-size: 20px;
    padding: 8px 16px;
  }

  .result-time b {
    font-size: 32px;
  }
}

#record-message {
  margin: 0;
  color: #d9480f;
  background: #fff3bf;
  border: 3px solid #ffc94d;
  border-radius: 20px;
  padding: 8px 24px;
  font-size: 30px;
  font-weight: bold;
}
