/* ============================================================
   八月三十一日、君と。 — スタイルシート
   ============================================================ */

:root {
  --tb-h-l: 27%;
  --tb-h-p: 24%;
  --ink: #fff;
  --panel: linear-gradient(180deg, rgba(9, 15, 32, 0.86), rgba(9, 15, 32, 0.95));
  --coral: #ff8f66;
  --blue: #6fa8dc;
  --mint: #7cc47c;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* 言語切り替え */
.lang-select {
  position: fixed;
  /* 右上端に配置する */
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
  z-index: 300;
  background: rgba(8, 14, 38, 0.72);
  color: #dfe7ff;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 9px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.lang-select option { background: #0c1536; color: #dfe7ff; }

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0c1536;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", Meiryo, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* ---------------- ステージレイアウト ---------------- */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05080f;
}

#stage {
  position: relative;
  overflow: hidden;
  background: #0c1536;
  flex: none;
}

@media (orientation: landscape) {
  #stage {
    width: min(100vw, calc(100dvh * 16 / 9));
    height: min(100dvh, calc(100vw * 9 / 16));
    width: min(100vw, calc(100vh * 16 / 9));
    height: min(100vh, calc(100vw * 9 / 16));
  }
}

@media (orientation: portrait) {
  #stage {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
  }
}

#bgLayer,
#fxLayer,
#spriteLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#bgLayer > * {
  position: absolute;
  inset: 0;
}

.bg-svg {
  width: 100%;
  height: 100%;
}

.bg-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  image-rendering: auto;
}

#sceneVeil {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  z-index: 20;
}

#sceneVeil.veil-on {
  opacity: 1;
}

/* ---------------- 背景パーツ ---------------- */

.cloud {
  position: absolute;
  left: -180px;
  width: 130px;
  height: 40px;
  --c: #ffffff;
  background: var(--c);
  border-radius: 60px;
  opacity: 0.88;
  box-shadow:
    34px 8px 0 -6px var(--c),
    70px 4px 0 -8px var(--c),
    -18px 10px 0 -8px var(--c);
  animation: drift linear infinite;
  will-change: transform;
  z-index: 3;
}

.cloud.cl-0 { animation-duration: 46s; animation-delay: -8s; }
.cloud.cl-1 { width: 170px; height: 52px; animation-duration: 64s; animation-delay: -30s; opacity: 0.75; }
.cloud.cl-2 { width: 100px; height: 32px; animation-duration: 80s; animation-delay: -52s; opacity: 0.85; }
.cloud.tone-dusk { --c: #ffd9b0; opacity: 0.65; }

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(calc(100vw + 380px)); }
}

.star {
  position: absolute;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
  animation: twinkle ease-in-out infinite;
  z-index: 2;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.08; }
  50% { opacity: 0.95; }
}

.lanterns {
  position: absolute;
  left: 0;
  right: 0;
  height: 46px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='130' height='46'%3E%3Cline x1='0' y1='12' x2='130' y2='12' stroke='%236b5a46' stroke-width='2'/%3E%3Cellipse cx='65' cy='26' rx='14' ry='15' fill='%23e8695a'/%3E%3Cellipse cx='65' cy='26' rx='7' ry='8' fill='%23ffd98a'/%3E%3Cellipse cx='65' cy='26' rx='22' ry='22' fill='%23ffd98a' opacity='0.16'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-size: 130px 46px;
  animation: sway 5.5s ease-in-out infinite;
  transform-origin: top center;
  z-index: 3;
}

.l-row-2 {
  top: 21%;
  transform: scale(0.72);
  opacity: 0.7;
  animation-delay: -2.6s;
}

@keyframes sway {
  0%, 100% { transform: rotate(-1.2deg) translateX(0); }
  50% { transform: rotate(1.2deg) translateX(6px); }
}

.l-row-2 { animation-name: sway2; }
@keyframes sway2 {
  0%, 100% { transform: scale(0.72) rotate(1.2deg); }
  50% { transform: scale(0.72) rotate(-1.2deg) translateX(-6px); }
}

.waves {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 24%;
  pointer-events: none;
  z-index: 3;
}

.waves i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='64' viewBox='0 0 220 64'%3E%3Cpath d='M0 30 Q27.5 10 55 30 T110 30 T165 30 T220 30 V64 H0 Z' fill='%239fe0f5'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-size: 220px 100%;
  animation: waveMove linear infinite;
}

.waves .w1 { animation-duration: 8s; opacity: 0.55; }
.waves .w2 { bottom: -8px; animation-duration: 14s; opacity: 0.3; }

.waves-night i {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='64' viewBox='0 0 220 64'%3E%3Cpath d='M0 30 Q27.5 10 55 30 T110 30 T165 30 T220 30 V64 H0 Z' fill='%233d6f98'/%3E%3C/svg%3E");
}

@keyframes waveMove {
  from { background-position: 0 0; }
  to { background-position: -220px 0; }
}

#fxCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
}

.room-vignette {
  background: radial-gradient(ellipse at 50% 45%, rgba(0, 0, 0, 0) 55%, rgba(30, 20, 5, 0.22) 100%);
}

.town-vignette {
  background: linear-gradient(180deg, rgba(60, 40, 70, 0.28), rgba(30, 20, 40, 0) 35%, rgba(20, 14, 30, 0.42) 100%);
}

.beach-night-glow {
  background: radial-gradient(ellipse at 50% 30%, rgba(90, 120, 220, 0.10), rgba(0, 0, 0, 0) 55%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.38));
}

.festival-mist {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 55%, rgba(255, 170, 80, 0.08) 85%, rgba(20, 10, 0, 0.28));
}

.heat-haze {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 70%, rgba(255, 220, 150, 0.10));
}

.shrine-glow {
  background: radial-gradient(ellipse at 50% 85%, rgba(255, 210, 120, 0.12), rgba(0, 0, 0, 0) 60%);
}

.sand-glow {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 82%, rgba(255, 230, 170, 0.14));
}

.window-light {
  left: 54%;
  top: 30%;
  width: 30%;
  height: 38%;
  background: linear-gradient(135deg, rgba(200, 220, 255, 0.12), rgba(200, 220, 255, 0));
  clip-path: polygon(0 0, 100% 0, 78% 100%, 0 100%);
}

/* ---------------- 立ち絵 ---------------- */

.sprite {
  position: absolute;
  bottom: 0;
  height: 66%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
  animation: spriteIn 0.55s ease both;
}

.sprite.pos-right { right: 1%; }
.sprite.pos-left { left: 1%; }

.sprite svg,
.sprite img {
  height: 100%;
  width: auto;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.28));
}

@keyframes spriteIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- テキストUI ---------------- */

#textBox {
  position: absolute;
  left: 3%;
  right: 3%;
  bottom: 2.6%;
  height: var(--tb-h-l);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  padding: 2.2% 3.4%;
  display: flex;
  align-items: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10;
}

#text {
  width: 100%;
  color: var(--ink);
  font-size: clamp(13px, 2.35vh, 17px);
  line-height: 1.8;
  letter-spacing: 0.045em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
  white-space: pre-line;
  overflow: hidden;
  max-height: 100%;
}

#tapHint {
  position: absolute;
  right: 12px;
  bottom: 7px;
  color: #ffd98a;
  font-size: 12px;
  animation: hintPulse 1.1s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(3px); }
}

#namePlate {
  position: absolute;
  left: 3%;
  bottom: calc(2.6% + var(--tb-h-l) + 8px);
  background: var(--coral);
  color: #fff;
  font-size: clamp(13px, 2vh, 16px);
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 5px 16px 6px;
  border-radius: 11px 11px 11px 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 11;
}

#namePlate::after {
  content: "";
  position: absolute;
  left: 12px;
  bottom: -7px;
  border: 7px solid transparent;
  border-top-color: inherit;
  border-bottom: 0;
}

#namePlate[data-c="blue"] { background: var(--blue); }
#namePlate[data-c="mint"] { background: var(--mint); color: #173018; }

/* ---------------- 操作ボタン ---------------- */

#ctrlBar {
  position: absolute;
  /* 右上の言語切り替えボタンの下にずらし、干渉しないようにする */
  top: calc(2% + 52px + env(safe-area-inset-top, 0px));
  right: calc(2% + env(safe-area-inset-right, 0px));
  display: flex;
  gap: 8px;
  z-index: 30;
}

.ctrl-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(10, 18, 36, 0.55);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s ease, background 0.2s ease;
}

.ctrl-btn:active { transform: scale(0.9); }
.ctrl-btn.on { background: #ffd98a; color: #3d2a10; }
.ctrl-btn.off { opacity: 0.5; }

/* ---------------- 選択肢 ---------------- */

#choiceWrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 5%;
  background: rgba(5, 10, 25, 0.22);
  z-index: 25;
}

.choice-btn {
  width: min(78%, 420px);
  padding: 15px 18px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 246, 232, 0.98), rgba(255, 236, 208, 0.98));
  color: #3d2b16;
  font-size: clamp(14px, 2vw, 17px);
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.38);
  animation: choiceIn 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.choice-btn:active {
  transform: scale(0.97);
  background: linear-gradient(180deg, #ffe9c2, #ffd79b);
}

@keyframes choiceIn {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- タイトル ---------------- */

#titleScreen {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  background: #0c1536;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.title-art {
  position: absolute;
  inset: 0;
}

.title-art .sky {
  position: absolute;
  inset: 0;
  background: url("img/title-keyvisual.webp") center / cover no-repeat;
}

.title-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(8, 18, 55, 0.05) 35%, rgba(8, 18, 55, 0.55) 100%);
  pointer-events: none;
  z-index: 2;
}

.title-art .sun {
  position: absolute;
  top: 10%;
  right: 12%;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff6c9 0%, #ffe79a 45%, rgba(255, 231, 154, 0) 72%);
}

.title-art .sea {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 30%;
  background: linear-gradient(180deg, #2d9fd8, #7fd0ec);
}

.title-art .waves {
  height: 18%;
  bottom: 13%;
  opacity: 0.9;
}

.title-inner {
  position: relative;
  z-index: 4;
  padding: 6%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title-orn {
  font-size: clamp(22px, 6vw, 40px);
  margin-bottom: 6px;
  animation: bob 3s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-8px) rotate(5deg); }
}

.title-main {
  font-size: clamp(22px, 7.2vw, 60px);
  white-space: nowrap;
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.25;
  color: #fff;
  background: linear-gradient(180deg, #ffffff 20%, #ffe08a 75%, #ffb35c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 8px rgba(20, 40, 90, 0.45));
}

/* 英語タイトルは長いため、スマホでも1行に収まるよう小さめに */
html:lang(en) .title-main {
  font-size: clamp(16px, 5.6vw, 60px);
}

.title-sub {
  margin-top: 12px;
  color: rgba(255, 255, 255, 0.92);
  font-size: clamp(12px, 3.3vw, 17px);
  letter-spacing: 0.12em;
  text-shadow: 0 2px 6px rgba(20, 40, 90, 0.5);
}

.title-btns {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  width: min(84vw, 340px);
}

.title-btns button {
  padding: 14px 20px;
  border: none;
  border-radius: 15px;
  background: linear-gradient(180deg, #ffe6a8, #ffb35c);
  color: #4a2d10;
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 800;
  letter-spacing: 0.08em;
  box-shadow: 0 8px 22px rgba(40, 30, 10, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.65);
  transition: transform 0.12s ease;
}

.title-btns button:active { transform: scale(0.96); }

.title-end {
  margin-top: 26px;
  display: flex;
  gap: 18px;
  font-size: clamp(20px, 5.5vw, 28px);
}

.title-end span {
  opacity: 0.22;
  filter: grayscale(1);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.title-end span.seen {
  opacity: 1;
  filter: none;
}

/* ---------------- モーダル ---------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(4, 8, 20, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4%;
}

.modal-panel {
  width: min(94vw, 500px);
  max-height: 82%;
  background: linear-gradient(180deg, #16224a, #101a38);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  padding: 18px 20px;
  color: #fff;
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-head h2 {
  font-size: clamp(15px, 4vw, 19px);
  letter-spacing: 0.1em;
  color: #ffd98a;
}

.modal-head button {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 14px;
}

.modal-body {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.log-body {
  max-height: 54vh;
}

.log-line {
  padding: 9px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: clamp(12px, 3.2vw, 15px);
  line-height: 1.65;
  white-space: pre-line;
}

.log-line b {
  color: #ffd98a;
}

.help-body p {
  padding: 8px 2px;
  font-size: clamp(13px, 3.4vw, 15.5px);
  line-height: 1.7;
}

.menu-panel {
  align-items: stretch;
  gap: 12px;
}

.menu-panel .modal-head {
  justify-content: center;
  margin-bottom: 4px;
}

.menu-panel button {
  padding: 13px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}

.menu-panel button:active { background: rgba(255, 255, 255, 0.16); }

/* ---------------- エンディング ---------------- */

#endingOverlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(120, 150, 255, 0.18), transparent 55%),
    linear-gradient(180deg, #0c1536, #1c2853 60%, #24315f);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 5%;
  overflow-y: auto;
}

.end-inner {
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.end-icon {
  font-size: clamp(40px, 11vw, 64px);
  animation: bob 3.2s ease-in-out infinite;
}

.end-sub {
  margin-top: 10px;
  color: #9fc0ff;
  font-size: clamp(12px, 3.2vw, 15px);
  letter-spacing: 0.18em;
}

.end-title {
  margin-top: 8px;
  font-size: clamp(26px, 7.5vw, 46px);
  letter-spacing: 0.08em;
  color: #fff;
  background: linear-gradient(180deg, #fff, #ffd98a);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.4));
}

.end-text {
  margin-top: 18px;
  color: rgba(255, 255, 255, 0.92);
  font-size: clamp(14px, 3.8vw, 17px);
  line-height: 1.9;
  white-space: pre-line;
}

.end-btns {
  margin-top: 28px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.end-btns button {
  padding: 12px 22px;
  border: none;
  border-radius: 13px;
  background: linear-gradient(180deg, #ffe6a8, #ffb35c);
  color: #4a2d10;
  font-size: clamp(14px, 3.6vw, 16px);
  font-weight: 800;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.end-btns button:active { transform: scale(0.96); }

/* ---------------- 縦向き（スマホ） ---------------- */

@media (orientation: portrait) {
  #textBox {
    height: var(--tb-h-p);
    bottom: 2.2%;
    padding: 4% 4.5%;
    align-items: flex-start;
  }

  #text {
    font-size: clamp(14px, 4vw, 18px);
    line-height: 1.85;
  }

  #tapHint {
    right: 10px;
    bottom: 8px;
  }

  #namePlate {
    bottom: calc(2.2% + var(--tb-h-p) + 8px);
    font-size: clamp(13px, 3.4vw, 16px);
  }

  .sprite {
    height: 50%;
    bottom: 27.5%;
  }

  .sprite.pos-right { right: -1%; }
  .sprite.pos-left { left: -1%; }
  .sprite.two { height: 40%; }

  /* 選択肢はメッセージウィンドウの位置に表示し、画面中央の立ち絵や
     メッセージウィンドウと干渉しないようにする */
  #choiceWrap {
    inset: auto 3% 2.2%;
    height: calc(var(--tb-h-p) - 2%);
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 2% 3%;
    background: linear-gradient(180deg, rgba(9, 15, 32, 0.62), rgba(9, 15, 32, 0.88));
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
  }

  #choiceWrap .choice-btn {
    width: 100%;
    padding: 12px 16px;
    font-size: clamp(14px, 3.9vw, 17px);
  }

  .ctrl-btn {
    width: 42px;
    height: 42px;
    font-size: 10px;
  }
}

@media (max-height: 420px) and (orientation: landscape) {
  #ctrlBar { top: calc(1% + 52px); right: 1%; }
  .ctrl-btn { width: 36px; height: 36px; font-size: 9px; }
}
