@font-face {
  font-family: "DotGothic16";
  src: url("assets/font/DotGothic16-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --ink: #222034;
  --ui: rgba(24, 26, 52, 0.86);
  --ui-line: #f4f1e8;
  --text: #f8f6ee;
  --fx: 3px; /* 背景・漫符・枠の1ドット */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: #111; overflow: hidden; }
body {
  font-family: "DotGothic16", sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
button { font-family: inherit; }
[hidden] { display: none !important; }

.pix { image-rendering: pixelated; image-rendering: crisp-edges; }

#screen {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #c7c9cc;
  cursor: pointer;
}

#bg {
  position: absolute; inset: 0;
  background-repeat: no-repeat;
  background-position: center top;
  transition: opacity .5s;
}

#stage, #fx { position: absolute; inset: 0; pointer-events: none; }

/* ---- 立ち絵 ---- */
.sprite {
  position: absolute;
  transition: left .3s ease-out, top .3s ease-out, filter .3s linear, opacity .45s ease;
}
.sprite img { display: block; width: 100%; height: 100%; }
.sprite.flip img { transform: scaleX(-1); }
.sprite.listen { filter: brightness(.58) saturate(.8); }
.sprite.behind { filter: brightness(.5) saturate(.5); }

/* ---- 漫符 ---- */
.manpu {
  position: absolute;
  z-index: 8;
  animation: pop .5s steps(4) both;
}
@keyframes pop {
  0% { transform: translateY(6px) scale(.6); opacity: 0; }
  60% { transform: translateY(-4px) scale(1.1); opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}

/* ---- 吹き出し ---- */
.bubble {
  --bubble: #fffdf6;
  --border: var(--ink);
  --name: var(--ink);
  position: absolute; z-index: 10;
  width: max-content; max-width: 74%; min-width: 7em;
  background: var(--bubble);
  color: var(--ink);
  padding: 10px 14px 14px;
  font-size: 16px; line-height: 1.7;
  border: var(--fx) solid var(--border);
  box-shadow: 0 var(--fx) 0 0 var(--border), var(--fx) var(--fx) 0 0 rgba(0, 0, 0, .25);
  line-break: strict;
  animation: pop .3s steps(3) both;
}
.bubble .who { display: block; font-size: 12px; line-height: 1.4; margin-bottom: 2px; color: var(--name); }
.bubble .text { white-space: pre-line; display: block; }
.bubble .tail {
  position: absolute; bottom: calc(var(--fx) * -7); width: calc(var(--fx) * 8); height: calc(var(--fx) * 7);
  background: var(--border);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.bubble .tail::after {
  content: ""; position: absolute; left: var(--fx); right: var(--fx); top: 0; height: calc(100% - var(--fx) * 3);
  background: var(--bubble); clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.bubble .next {
  position: absolute; right: 6px; bottom: 1px;
  font-size: 10px; color: var(--border);
  animation: blink 1s steps(2) infinite;
}
.bubble.notail .tail { display: none; }
@keyframes blink { 50% { opacity: 0; } }

/* ---- 上の帯のボタン ---- */
#topbar {
  position: absolute; z-index: 55; /* タイトル・おわりの画面の上にも出す */
  top: calc(var(--safe-top) + 8px); right: 8px;
  display: flex; gap: 8px;
}
.ui-btn {
  font-size: 13px; color: var(--text);
  background: var(--ui);
  border: 2px solid var(--ui-line);
  box-shadow: 0 0 0 2px var(--ink);
  padding: 5px 10px 4px;
  cursor: pointer;
}
.ui-btn:active { background: #3b3f86; }

/* ---- 選択肢 ---- */
#choices {
  position: absolute; left: 0; right: 0; top: 24%;
  z-index: 20;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
#choices button {
  font-size: 16px; color: var(--text);
  width: 78%; padding: 13px 8px 12px;
  background: var(--ui);
  border: var(--fx) solid var(--ui-line);
  box-shadow: 0 0 0 var(--fx) var(--ink), inset 0 0 0 var(--fx) var(--ink);
  cursor: pointer;
  animation: pop .3s steps(3) both;
}
#choices button:active { background: #3b3f86; }

/* ---- ログ ---- */
#log {
  position: absolute; inset: 0; z-index: 60;
  background: rgba(18, 19, 38, .94);
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  cursor: default;
}
.log-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; font-size: 16px;
  border-bottom: 2px solid #3a3c6a;
}
#log-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 16px 24px;
  user-select: text; -webkit-user-select: text;
}
.log-item { margin-bottom: 14px; font-size: 15px; line-height: 1.7; }
.log-item .who { display: block; font-size: 12px; }
.log-item.choice { color: #c9c3ff; font-size: 14px; }
.log-item.scene { color: #8f8fb0; font-size: 12px; text-align: center; margin: 18px 0; }

/* ---- タイトル・おわり ---- */
#title, #end, #loading {
  position: absolute; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
  padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 24px);
  text-align: center;
}
#loading { background: #111; font-size: 14px; }
.title-tap, .end-tap { font-size: 15px; animation: blink 1.2s steps(2) infinite; text-shadow: 0 2px 0 var(--ink); }

/* タイトル画面：ロゴは上、左右にキャラ、下に「タップしてスタート」とクレジット */
#title {
  display: block; padding: 0;
  /* 空の上のほうを少し桃色に寄せて、華やかにする */
  background: linear-gradient(180deg, rgba(255, 150, 200, .28) 0%, rgba(255, 150, 200, 0) 45%, rgba(10, 12, 30, .25) 100%);
}
#title-cast, #title-fx { position: absolute; inset: 0; pointer-events: none; }
#title-cast img { position: absolute; image-rendering: pixelated; animation: castIn .6s steps(6) both; }
#title-cast img.flip { transform: scaleX(-1); }
@keyframes castIn { from { opacity: 0; translate: 0 24px; } to { opacity: 1; translate: 0 0; } }

#title-logo {
  position: absolute; left: 0; right: 0; top: calc(var(--safe-top) + 9%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-weight: normal;
  transform-origin: 50% 0;
  animation: logoIn .7s steps(7) both;
}
@keyframes logoIn {
  0% { transform: translateY(-40px) scale(.7); opacity: 0; }
  60% { transform: translateY(6px) scale(1.06); opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}

/* ロゴの1行：後ろの層（太い縁取りと影）と前の層（塗り）を重ねる */
.logo-line { position: relative; display: block; line-height: 1.15; white-space: nowrap; }
.logo-line .back, .logo-line .front { display: block; }
.logo-line .front { position: absolute; left: 0; top: 0; }

/* 帯：桃色のリボンに白い文字 */
.logo-line.ribbon {
  font-size: 16px; color: #fff; letter-spacing: .04em;
  padding: 5px 22px 4px;
  background: #e8457f;
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ink), 0 6px 0 3px var(--ink);
  clip-path: none;
  margin-bottom: 10px;
  transform: rotate(-2deg);
}
.logo-line.ribbon .front { display: none; }
.logo-line.ribbon .back { text-shadow: 0 2px 0 #9d1f4f; }

/* 中くらい：白い文字に紺の縁取り、桃色の影 */
.logo-line.sub { font-size: 32px; letter-spacing: .02em; }
.logo-line.sub .back {
  color: var(--ink);
  text-shadow:
    -3px 0 0 var(--ink), 3px 0 0 var(--ink), 0 -3px 0 var(--ink), 0 3px 0 var(--ink),
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    0 6px 0 #e8457f, 3px 6px 0 #e8457f, -3px 6px 0 #e8457f, 0 9px 0 var(--ink), 3px 9px 0 var(--ink), -3px 9px 0 var(--ink);
}
.logo-line.sub .front { color: #fff; }

/* 大きく：桃色から赤の縞の塗りに、白と紺の二重の縁取り */
.logo-line.main { font-size: 64px; letter-spacing: .04em; margin-top: 2px; animation: mainBounce 2.4s steps(2) .8s infinite; }
@keyframes mainBounce { 0%, 80%, 100% { transform: translateY(0); } 90% { transform: translateY(-4px); } }
.logo-line.main .back {
  color: #fff;
  text-shadow:
    -4px 0 0 #fff, 4px 0 0 #fff, 0 -4px 0 #fff, 0 4px 0 #fff,
    -4px -4px 0 #fff, 4px -4px 0 #fff, -4px 4px 0 #fff, 4px 4px 0 #fff,
    -8px 0 0 var(--ink), 8px 0 0 var(--ink), 0 -8px 0 var(--ink), 0 8px 0 var(--ink),
    -8px -4px 0 var(--ink), 8px -4px 0 var(--ink), -8px 4px 0 var(--ink), 8px 4px 0 var(--ink),
    -4px -8px 0 var(--ink), 4px -8px 0 var(--ink), -4px 8px 0 var(--ink), 4px 8px 0 var(--ink),
    0 12px 0 var(--ink), 4px 12px 0 var(--ink), -4px 12px 0 var(--ink), 8px 8px 0 var(--ink), -8px 8px 0 var(--ink);
}
.logo-line.main .front {
  color: transparent;
  background: linear-gradient(180deg, #ffc4de 0 24%, #ff7cae 24% 50%, #ff3f87 50% 76%, #d41a60 76% 100%);
  -webkit-background-clip: text; background-clip: text;
}

/* キラキラとハート */
.title-sparkle { position: absolute; image-rendering: pixelated; animation: twinkle 1.6s steps(2) infinite; }
@keyframes twinkle { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .2; transform: scale(.7); } }
.title-heart { position: absolute; image-rendering: pixelated; opacity: 0; animation: floatUp 6s steps(24) infinite; }
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(0); }
  15% { opacity: .9; }
  80% { opacity: .9; }
  100% { opacity: 0; transform: translateY(-260px); }
}

#title .title-tap {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 92px);
  white-space: nowrap;
  font-size: 16px; padding: 8px 18px 7px;
  background: var(--ui);
  border: 3px solid var(--ui-line);
  box-shadow: 0 0 0 3px var(--ink);
}
#title-credits {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 8px 0 calc(var(--safe-bottom) + 10px);
  background: rgba(14, 15, 34, .62);
  font-size: 11px; line-height: 1.7; color: #f0f0f0; text-align: center;
}
#end { background: rgba(10, 12, 30, .72); }
#end-text { font-size: 26px; letter-spacing: .2em; }
