* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --title-font: "Hachi Maru Pop", "Hiragino Sans", sans-serif;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #120d1a;
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  position: relative;
  width: min(100vw, 177.78vh);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
  color: #fff;
  user-select: none;
  cursor: pointer;
}

/* 縦長の画面（スマホの縦持ち）は画面いっぱいに広げる */
@media (orientation: portrait) {
  #game {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
  }

  #sprite {
    width: 90%;
    height: 66%;
    bottom: 32%;
    object-fit: contain;
  }

  #textbox {
    height: 34%;
  }

  #choices {
    bottom: 38%;
    width: 88%;
  }
}

/* 横に短い画面（スマホの横持ち）は文字と枠の大きさを高さに合わせる */
@media (max-height: 500px) and (orientation: landscape) {
  #textbox {
    height: 42%;
  }

  #text {
    font-size: 4.4vh;
  }

  #choices {
    bottom: 46%;
  }

  #choices button {
    font-size: 4vh;
  }
}

#bg {
  position: absolute;
  inset: 0;
  background: #000 center / cover no-repeat;
}

#sprite {
  position: absolute;
  left: 50%;
  bottom: 28%;
  height: 72%;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}

#sprite.on {
  opacity: 1;
}

#hud {
  position: absolute;
  top: 3%;
  left: 3%;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(24, 14, 34, 0.7);
  color: #ff6b9a;
  font-size: clamp(18px, 3vw, 28px);
  letter-spacing: 0.1em;
  pointer-events: none;
}

#textbox {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 30%;
  padding: 3% 6% 2.5%;
  display: flex;
  flex-direction: column;
  background: rgba(24, 14, 34, 0.88);
  border-top: 2px solid #e86fa0;
}

#name {
  align-self: flex-start;
  margin-bottom: 0.6em;
  padding: 2px 18px;
  border-radius: 4px;
  background: #e86fa0;
  font-weight: bold;
  font-size: clamp(14px, 2.2vw, 20px);
}

#text {
  flex: 1;
  font-size: clamp(14px, 2.3vw, 22px);
  line-height: 1.75;
  white-space: pre-line;
}

#textbox.narration #text {
  font-style: italic;
  color: #d8cde6;
}

#choices {
  position: absolute;
  left: 50%;
  bottom: 34%;
  transform: translateX(-50%);
  width: min(80%, 520px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: default;
}

#choices button {
  padding: 12px 20px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.93);
  color: #3a2440;
  font-size: clamp(14px, 2.1vw, 18px);
  cursor: pointer;
}

#choices button:hover {
  background: #ffd6e8;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 0 16px;
  background: rgba(10, 6, 16, 0.72);
  text-align: center;
  cursor: default;
}

.overlay h1 {
  margin: 0;
  font-family: var(--title-font);
  font-size: clamp(32px, 7vw, 56px);
  font-weight: normal;
  letter-spacing: 0.06em;
  color: #ffd6e8;
  background: linear-gradient(90deg, #ffd6e8, #e86fa0 55%, #c18bff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 14px rgba(232, 111, 160, 0.5));
}

#nameField {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: clamp(13px, 2vw, 16px);
  color: #e8dcf0;
}

#nameInput {
  width: min(70vw, 240px);
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background: #fff;
  color: #3a2440;
  font-size: clamp(14px, 2.2vw, 18px);
  text-align: center;
}

#nameInput:focus {
  outline: 2px solid #e86fa0;
}

#credits {
  margin: 0;
  font-size: clamp(10px, 1.6vw, 13px);
  color: rgba(255, 255, 255, 0.55);
}

#credits a {
  color: rgba(255, 214, 232, 0.85);
}

#end {
  position: relative;
  overflow: hidden;
}

#end::before {
  content: "";
  position: absolute;
  inset: -20%;
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.8) 1px, transparent 1.6px);
  background-size: 46px 46px;
  opacity: 0.18;
  animation: sparkleDrift 10s linear infinite;
  pointer-events: none;
}

@keyframes sparkleDrift {
  from { transform: translate(0, 0); }
  to { transform: translate(-46px, -46px); }
}

#endCard {
  position: relative;
  z-index: 1;
  max-width: min(86%, 440px);
  padding: 32px 34px;
  border-radius: 22px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  animation: endCardIn 0.6s cubic-bezier(0.2, 0.8, 0.3, 1.15);
}

@keyframes endCardIn {
  from { opacity: 0; transform: translateY(18px) scale(0.95); }
  to { opacity: 1; transform: none; }
}

#endBadge {
  font-family: var(--title-font);
  font-size: clamp(26px, 6vw, 40px);
  letter-spacing: 0.05em;
  margin-bottom: 16px;
  background: linear-gradient(90deg, #e86fa0, #c18bff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#end[data-type="happy"] #endCard {
  border-color: rgba(255, 210, 130, 0.5);
  box-shadow: 0 0 70px rgba(255, 185, 120, 0.35), 0 24px 70px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

#end[data-type="happy"] #endBadge {
  background: linear-gradient(90deg, #ffd27a, #ff9ecb, #ffd27a);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#end[data-type="happy"]::before {
  opacity: 0.32;
}

#end[data-type="bad"] #endCard {
  border-color: rgba(140, 150, 200, 0.35);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

#end[data-type="bad"] #endBadge {
  background: linear-gradient(90deg, #9aa6d6, #5d6b99);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#end[data-type="bad"]::before {
  opacity: 0.08;
}

#endText {
  margin: 0;
  font-size: clamp(15px, 2.4vw, 24px);
  line-height: 1.8;
}

#endHearts {
  margin-top: 12px;
  font-size: clamp(20px, 4.2vw, 30px);
  letter-spacing: 0.18em;
  color: #ff6b9a;
}

.main-btn {
  padding: 12px 40px;
  border: none;
  border-radius: 999px;
  background: #e86fa0;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
