/* ことみんゲーム */

:root {
  --pink: #f26383;
  --pink-deep: #d9466b;
  --pink-soft: #ffd3dc;
  --pink-bg: #fff3f6;
  --ink: #4a2a33;
  --ink-sub: #7d5a64;
  --white: #ffffff;
  --yellow: #f9cf4a;
  --purple: #b18cf2;
  --green: #6fd35a;
  --blue: #4cc3e6;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  color: var(--ink);
  background-color: var(--pink-bg);
  background-image: radial-gradient(var(--pink-soft) 2px, transparent 2px);
  background-size: 26px 26px;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.game {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  touch-action: none;
}

/* ---------- 上のバー ---------- */
.hud {
  position: relative;
  z-index: 2;
  padding: 12px 16px 10px;
  background: var(--white);
  border-bottom: 4px solid var(--pink);
  border-radius: 0 0 24px 24px;
  box-shadow: 0 6px 0 var(--pink-soft);
}

.hud__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.hud__label {
  margin-right: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-sub);
}

.hud strong {
  font-size: 32px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--pink);
  font-variant-numeric: tabular-nums;
}

.hud__unit {
  margin-left: 2px;
  font-size: 14px;
  font-weight: 700;
}

.hud__time.is-hurry strong { color: var(--pink-deep); animation: hurry .5s ease-in-out infinite alternate; }
@keyframes hurry { to { transform: scale(1.15); } }
.hud__time strong { display: inline-block; }

.timebar {
  height: 8px;
  margin: 6px 0 10px;
  background: var(--pink-soft);
  border-radius: 999px;
  overflow: hidden;
}
.timebar__fill {
  width: 100%;
  height: 100%;
  background: var(--pink);
  border-radius: 999px;
  transform-origin: left center;
}

.word {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.word li {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 800;
  color: var(--pink-soft);
  background: var(--pink-bg);
  border: 3px dashed var(--pink-soft);
  border-radius: 14px;
  transition: transform .12s;
}
.word li.is-on {
  color: var(--white);
  background: var(--pink);
  border: 3px solid var(--pink-deep);
  transform: scale(1.08);
}
.word.is-miss { animation: shake .3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* ---------- 文字が落ちてくるところ ---------- */
.field {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  overflow: hidden;
}

.lane {
  border-right: 2px dashed rgba(242, 99, 131, .18);
}
.lane:last-child { border-right: none; }

.drop {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
  font-weight: 800;
  line-height: 1;
  background: var(--white);
  border: 4px solid currentColor;
  border-radius: 50%;
  box-shadow: 0 5px 0 rgba(74, 42, 51, .12);
  cursor: pointer;
  will-change: transform;
}

.drop.is-hit {
  pointer-events: none;
  animation: pop .25s ease-out forwards;
}
@keyframes pop {
  to { opacity: 0; scale: 1.6; }
}

.drop.is-wrong {
  pointer-events: none;
  animation: wrong .35s ease-out forwards;
}
@keyframes wrong {
  0% { rotate: 0deg; }
  30% { rotate: -15deg; }
  60% { rotate: 15deg; }
  100% { rotate: 0deg; opacity: 0; }
}

/* ---------- スタート画面 ---------- */
.start {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 16px;
  font: inherit;
  color: var(--ink);
  text-align: center;
  background: rgba(255, 243, 246, .92);
  border: none;
  cursor: pointer;
}
.start[hidden] { display: none; }
.start__face {
  width: 140px;
  height: auto;
  margin-bottom: -12px;
  animation: face-bob 1.2s ease-in-out infinite alternate;
}
@keyframes face-bob {
  from { transform: translateY(0) rotate(-4deg); }
  to   { transform: translateY(-8px) rotate(4deg); }
}
.start__title {
  font-size: 36px;
  font-weight: 800;
  color: var(--pink);
  text-shadow: 0 4px 0 var(--white), 0 7px 0 var(--pink-soft);
}
.start__rule {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.8;
}
.start__rule b { color: var(--pink-deep); }
.start__rule small { font-size: 13px; color: var(--ink-sub); }
.start__btn {
  padding: 14px 32px;
  font-size: 20px;
  font-weight: 800;
  color: var(--white);
  background: var(--pink);
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--pink-deep);
  animation: start-pulse 1s ease-in-out infinite alternate;
}
@keyframes start-pulse { to { transform: scale(1.06); } }
.start__note { font-size: 13px; color: var(--ink-sub); }

/* ---------- 音のオン・オフ ---------- */
.sound-btn {
  position: absolute;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 9;
  width: 44px;
  height: 44px;
  font-size: 20px;
  line-height: 1;
  background: var(--white);
  border: 3px solid var(--pink);
  border-radius: 50%;
  box-shadow: 0 4px 0 var(--pink-soft);
  cursor: pointer;
}
.sound-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--pink-soft); }

/* ---------- カウントダウン ---------- */
.countdown {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  font-size: 120px;
  font-weight: 800;
  color: var(--pink);
  text-shadow: 0 6px 0 var(--white), 0 10px 0 var(--pink-soft);
  pointer-events: none;
}
.countdown:empty { display: none; }
.countdown.is-start { font-size: 64px; }
.countdown span {
  display: inline-block;
  animation: count-in .5s ease-out;
}
@keyframes count-in {
  0% { transform: scale(2); opacity: 0; }
  60% { transform: scale(.9); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---------- 「ことみん！」完成 ---------- */
.complete {
  position: absolute;
  top: 45%;
  left: 50%;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.complete__face {
  width: 120px;
  height: auto;
  margin-bottom: -14px;
  filter: drop-shadow(0 4px 0 rgba(255, 255, 255, .9));
}
.complete__text {
  position: relative;
  padding: 6px 24px;
  font-size: 34px;
  font-weight: 800;
  color: var(--white);
  background: var(--pink);
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--pink-deep);
}
.complete.is-show { animation: complete 0.8s ease-out; }
@keyframes complete {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  40% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 10px 22px;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  color: var(--white);
  text-decoration: none;
  background: var(--pink);
  border: none;
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--pink-deep);
  cursor: pointer;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--pink-deep); }
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.btn--ghost {
  color: var(--pink-deep);
  background: var(--white);
  border: 3px solid var(--pink);
  box-shadow: 0 5px 0 var(--pink-soft);
}
.btn--ghost:active { box-shadow: 0 1px 0 var(--pink-soft); }
.btn--text {
  min-height: 40px;
  color: var(--ink-sub);
  background: none;
  box-shadow: none;
  text-decoration: underline;
}
.btn--text:active { transform: none; box-shadow: none; }

.back-btn {
  position: absolute;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 9;
  padding: 8px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  color: var(--pink-deep);
  background: var(--white);
  border: 3px solid var(--pink);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--pink-soft);
  cursor: pointer;
}
.back-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--pink-soft); }

/* ---------- モーダル ---------- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(74, 42, 51, .45);
}
.modal[hidden] { display: none; }

.modal__box {
  width: 100%;
  max-width: 380px;
  padding: 28px 22px 24px;
  text-align: center;
  background: var(--white);
  border: 4px solid var(--pink);
  border-radius: 28px;
  box-shadow: 0 8px 0 var(--pink-soft);
  animation: box-in .25s ease-out;
}
@keyframes box-in {
  from { transform: scale(.85); opacity: 0; }
}

.modal__title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 800;
  color: var(--pink-deep);
}
.modal__text {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--ink-sub);
}
.modal__actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 結果 */
.result__lead {
  display: inline-block;
  margin: 0 0 8px;
  padding: 2px 18px;
  font-size: 16px;
  font-weight: 800;
  color: var(--white);
  background: var(--pink);
  border-radius: 999px;
}
.result__title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.5;
}
.result__title strong {
  font-size: 64px;
  line-height: 1.1;
  color: var(--pink);
}
.result__best {
  margin: 10px 0 20px;
  font-size: 13px;
  color: var(--ink-sub);
}
.result__best.is-new { color: var(--pink-deep); font-weight: 800; }

/* 作った数だけ落ちてくる顔 */
.result__faces {
  --face: 44px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-end;
  gap: 2px;
  min-height: var(--face);
  margin: 4px 0 8px;
}
.result__faces:empty { display: none; }
.result__faces img {
  width: var(--face);
  height: var(--face);
  animation: face-drop .35s cubic-bezier(.4, 0, 1, 1) both;
}
@keyframes face-drop {
  0%   { transform: translateY(-100vh); }
  80%  { transform: translateY(0) scaleY(.85); }
  100% { transform: translateY(0) scaleY(1); }
}

/* 顔が落ち終わるまで、回数とボタンは隠しておく */
.result__later {
  visibility: hidden;
  opacity: 0;
}
.result.is-done .result__later {
  visibility: visible;
  animation: later-in .35s ease-out both;
}
.result.is-done .result__title { animation-name: score-in; }
@keyframes later-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes score-in {
  0%   { opacity: 0; transform: scale(.5); }
  60%  { opacity: 1; transform: scale(1.12); }
  100% { opacity: 1; transform: scale(1); }
}
.result__actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
