:root{
  --card: rgba(255,255,255,.20);
  --border: rgba(15, 23, 42, .10);
  --text: #0f172a;
  --muted: rgba(15, 23, 42, .60);
  --shadow: 0 18px 50px rgba(2, 6, 23, .10);
  --radius: 18px;
  --veil: 0.18;
}

*{ box-sizing: border-box; }

html, body{ height: 100%; }

body{
  margin: 0;
  overflow: hidden;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: #eef6ff;
}

#app{
  position: relative;
  height: 100vh;
  width: 100vw;
  padding: 0;
}

/* 背景canvas */
#bgCanvas{
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: -3;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

body::after{
  content:"";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: rgba(255,255,255,var(--veil));
  pointer-events: none;
}

/* Splash */
#splash{
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 6000ms ease;
}
body.is-booting #splash{ opacity: 1; }
body.is-ready  #splash{ opacity: 0; }

body.is-booting #app{ opacity:0; pointer-events:none; transform: translateY(10px); }
body.is-ready #app{
  opacity:1;
  pointer-events:auto;
  transform: translateY(0);
  transition: opacity 2400ms ease, transform 2400ms ease;
}

.pixel-title{
  font-size: clamp(72px, 10vw, 140px);
  letter-spacing: .12em;
  color: rgba(255,255,255,.92);
  text-shadow:
    0 2px 0 rgba(0,0,0,.30),
    0 16px 60px rgba(0,0,0,.35);
  filter:
    drop-shadow(6px 0 0 rgba(0,0,0,.22))
    drop-shadow(-6px 0 0 rgba(0,0,0,.22))
    drop-shadow(0 6px 0 rgba(0,0,0,.22))
    drop-shadow(0 -6px 0 rgba(0,0,0,.22));
}

/* scenes */
.scene{
  position: absolute;
  inset: 0;
  display: flex;
  visibility: hidden;
  pointer-events: none;
  padding: 42px 18px;
  align-items: center;
  justify-content: center;

  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1200ms ease, transform 1200ms ease, visibility 0s linear 1200ms;
}
.scene.is-active{
  visibility: visible;
  pointer-events: auto;

  opacity: 1;
  transform: translateY(0);
  transition: opacity 1200ms ease, transform 1200ms ease, visibility 0s;
}

/* 消え中（フェードアウト用） */
.scene.is-leaving{
  visibility: visible;          /* フェード中は見える状態を維持 */
  pointer-events: none;

  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1200ms ease, transform 1200ms ease, visibility 0s;
}

.wrap{
  width: min(900px, 92vw);
  margin: 0 auto;
}

.card input,
.card textarea{
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 12px;
  font-size: 14px;
  background: rgba(255,255,255,.85);
  outline: none;
}

input:focus, textarea:focus{
  border-color: rgba(37,99,235,.45);
  box-shadow: 0 0 0 4px rgba(37,99,235,.12);
}

.walk-text{
  font-size: clamp(28px, 4vw, 44px);
  letter-spacing: .08em;
  color: rgba(255,255,255,.92);
  text-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.walk-sub{ margin-top: 10px; color: rgba(255,255,255,.75); }

.choice-stack, .read-stack{
  width: min(900px, 92vw);
  display: grid;
  gap: 18px;
  justify-items: center;
  text-align: center;
}

.choice-line, .read-action{
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  user-select: none;
  color: rgba(255,255,255,.94);
  font-size: clamp(22px, 3.4vw, 42px);
  font-weight: 780;
  letter-spacing: .06em;
  line-height: 1.25;
  text-shadow:
    0 2px 0 rgba(0,0,0,.22),
    0 18px 70px rgba(0,0,0,.38);
  transform: translateY(0) scale(1);
  opacity: 1;
  filter: blur(0px);
  transition: transform 520ms ease, opacity 520ms ease, filter 520ms ease;
}
.choice-line:hover, .read-action:hover{ transform: translateY(-2px) scale(1.01); }

#scene-choice.is-selected .choice-line{ pointer-events:none; }
#scene-choice.is-selected .choice-line.is-picked{ transform: translateY(-6px) scale(1.035); }
#scene-choice.is-selected .choice-line.is-faded{
  opacity:0;
  filter: blur(6px);
  transform: translateY(8px) scale(.985);
}

.choice-back, .read-sub{
  margin-top: 10px;
  color: rgba(255,255,255,.78);
  font-size: 13px;
  letter-spacing: .06em;
  text-shadow: 0 12px 40px rgba(0,0,0,.25);
  cursor: pointer;
  user-select:none;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 1200ms ease, transform 1200ms ease;
}
#scene-choice.is-selected .choice-back{
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.read-sub{ opacity: 1; transform: translateY(0); pointer-events: auto; }

.read-title{
  color: rgba(255,255,255,.92);
  font-size: clamp(18px, 2.2vw, 22px);
  letter-spacing: .10em;
  text-shadow: 0 18px 70px rgba(0,0,0,.40);
  margin-bottom: 8px;
  opacity: .9;
}

/* writeだけスクロールOK */
#scene-write.is-active{
  /* display: block; */
  overflow: auto;
  padding: 42px 18px;
}
#scene-write .wrap{ width: min(900px, 92vw); margin: 0 auto; }

/* letter overlay */
.letter-wrap{
  position: relative;
  width: min(720px, 86vw);
}

.letter-overlay{
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1200ms ease;
}
.letter-overlay.is-show{ opacity: 1; pointer-events: auto; }
.letter-img{
  width: 100%;
  max-height: 78vh;
  height: auto;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 26px 80px rgba(0,0,0,.55));
  transform: translateY(10px) scale(.985);
  transition: transform 1200ms ease;
}
.letter-overlay.is-show .letter-img{ transform: translateY(0) scale(1); }

/* 手紙の上に重ねる本文 */
.letter-text{
  position: absolute;
  inset: 0;
  padding: min(7vh, 56px) min(6vw, 52px);

  display: grid;
  place-items: center;   /* 縦横中央 */

  white-space: pre-wrap;
  text-align: center;

  color: rgba(255,255,255,.92);
  text-shadow: 0 10px 30px rgba(0,0,0,.35);
}

.letter-text .inner{
  max-width: 100%;
}

/* 1文字ずつ */
.letter-text .ch{
  opacity: 0;
  filter: blur(2px);
  display: inline-block;
  transform: translateY(2px);
  animation: chIn 0.65s ease forwards;
}

@keyframes chIn{
  to{
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
  }
}

/* 差出人など（任意） */
.letter-meta{
  position:absolute;
  left: 0; right: 0;
  bottom: min(5vh, 40px);
  text-align: center;
  font-size: 12px;
  color: rgba(20,20,20,.55);
  pointer-events: none;
}

body.is-letter-open #scene-read .read-stack{
  opacity: .25;
  filter: blur(2px);
  transition: opacity 1200ms ease, filter 1200ms ease;
}

@media (prefers-reduced-motion: reduce){
  .choice-line, .read-action, .choice-back, .read-sub{
    transition: none !important;
  }
}

/* nickname: 3行（文章 / 下線入力 / 砂浜を歩いてみる。） */
.nick-stack{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
}

.nick-text{
  color: rgba(255,255,255,.92);
  font-weight: 780;
  letter-spacing: .06em;
  font-size: clamp(22px, 3.4vw, 42px);
  text-shadow:
    0 2px 0 rgba(0,0,0,.22),
    0 18px 70px rgba(0,0,0,.38);
}

.nick-form{
  width: 100%;
  display: flex;
  justify-content: center;
}

.nick-input{
  width: clamp(200px, 34vw, 420px);
  background: transparent !important;
  border: 0 !important;
  border-bottom: 2px solid rgba(255,255,255,.65) !important;
  border-radius: 0 !important;
  padding: 2px 2px 8px 2px !important;
  box-shadow: none !important;

  color: rgba(255,255,255,.95);
  font-size: clamp(20px, 3vw, 36px);
  font-weight: 760;
  letter-spacing: .04em;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
/* Chrome autofill が白い箱を作るのを潰す */
.nick-input:-webkit-autofill,
.nick-input:-webkit-autofill:hover,
.nick-input:-webkit-autofill:focus{
  -webkit-text-fill-color: rgba(255,255,255,.95) !important;

  /* autofill の塗りを「透明」で上書き（これが本命） */
  -webkit-box-shadow: 0 0 0px 1000px transparent inset !important;
          box-shadow: 0 0 0px 1000px transparent inset !important;

  /* 変な遷移で色が戻るのも防ぐ */
  transition: background-color 9999s ease-out 0s;
}

.nick-input::placeholder{
  color: rgba(255,255,255,.55);
}

.nick-input:focus{
  border-bottom-color: rgba(255,255,255,.95) !important;
  box-shadow: none !important;
}

.nick-enter{
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  user-select: none;

  color: rgba(255,255,255,.94);
  font-weight: 780;
  letter-spacing: .06em;
  font-size: clamp(20px, 3vw, 36px);
  text-shadow:
    0 2px 0 rgba(0,0,0,.22),
    0 18px 70px rgba(0,0,0,.38);

  opacity: .85;
  transform: translateY(0);
  transition: opacity 250ms ease, transform 250ms ease;
}

.nick-enter:hover{
  opacity: 1;
  transform: translateY(-1px);
}
.nick-enter:active{
  transform: translateY(1px);
}

/* =========================
   write: 下線6行 + 海に流す
   ========================= */

#scene-write{
  padding: 0;
}

.write-stack{
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 36px;
  text-align: center;
  padding: 42px 18px;
}

.write-title{
  color: rgba(255,255,255,.92);
  font-weight: 760;
  letter-spacing: .08em;
  font-size: clamp(20px, 3vw, 28px);
  text-shadow:
    0 2px 0 rgba(0,0,0,.22),
    0 18px 70px rgba(0,0,0,.38);
}

/* 下線だけの6行 */
.write-lines{
  width: min(380px, 90vw);
}

.write-input{
  display:block;
  width: 100%;
  resize: none;

  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  padding: 0 !important;
  outline: none !important;
  box-shadow: none !important;

  line-height: 2.1;
  font-size: clamp(18px, 2.4vw, 24px);
  letter-spacing: .04em;
  color: rgba(255,255,255,.95);

  /* 6行が確実に出るように高さ固定 */
  height: calc(2.1em * 6);
  overflow: hidden;

  /* 下線 */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(2.1em - 1px),
    rgba(255,255,255,.55) calc(2.1em - 1px),
    rgba(255,255,255,.55) 2.1em
  ) !important;
  background-size: 100% 2.1em;
  background-repeat: repeat;
}

/* autofill 念のため */
.write-input:-webkit-autofill{
  -webkit-box-shadow: 0 0 0 1000px transparent inset !important;
  -webkit-text-fill-color: rgba(255,255,255,.95) !important;
}

/* 海に流す */
.write-submit{
  border: 0;
  background: transparent;
  cursor: pointer;

  color: rgba(255,255,255,.94);
  font-weight: 780;
  letter-spacing: .08em;
  font-size: clamp(20px, 3vw, 32px);
  text-shadow: 0 2px 0 rgba(0,0,0,.22), 0 18px 70px rgba(0,0,0,.38);
  opacity: .85;
}

.write-submit:hover{
  opacity: 1;
  transform: translateY(-1px);
}
.write-submit:active{
  transform: translateY(1px);
}

.write-count{
  font-size: 12px;
  letter-spacing: .08em;
  color: rgba(255,255,255,.55);
  margin-top: 8px;
}