/* css/08-night.css — 08 よるの えんで かくれんぼ（unit=night-exit）
   6-39 空の明暗 / 5-16 ライトの暗幕 / 5-38 タッチ・キー代替 / 8-51 照準ブラケット / 3-4 円形リビール /
   8-27 丸とチェック / 1-23 文字の崩れ / 8-26 枠のぶるぶる / 7-9 星屑 / 8-30 昼夜ワイプ / 5-17 照らして読む文
   約束: 原画（img.chara）には filter / blend をかけない。暗幕は画像の「上」に重ねる別の層で、マスクで穴を開けるだけ。 */

@property --nightness { syntax: '<number>'; inherits: true; initial-value: 0; }
@property --nightmul { syntax: '<number>'; inherits: true; initial-value: 1; }

#night {
  --nightness: 0;
  --nightmul: 1;
  --nt-dark: calc(var(--nightness) * var(--nightmul));
  --nt-fg: color-mix(in oklab, var(--paper-hi) calc(var(--nt-dark) * 100%), var(--ink));
  --nt-soft: color-mix(in oklab, #C9C5E8 calc(var(--nt-dark) * 100%), var(--ink-soft));
  color: var(--nt-fg);
  transition: --nightmul .9s var(--ease-soft);
  padding-bottom: var(--sp-9);
}
#night[data-daymode="day"] { --nightmul: .28; }

/* ---------- 6-39 空（区画の地の上・中身の下） ---------- */
#night .sky {
  position: absolute; inset: 0; z-index: -1; pointer-events: none; overflow: hidden;
  background: var(--night);
  opacity: var(--nt-dark);
}
#night .sky-dots {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle, rgba(255, 243, 196, .9) 0 1.4px, transparent 2px),
    radial-gradient(circle, rgba(43, 195, 255, .7) 0 1.2px, transparent 1.8px),
    radial-gradient(circle, rgba(255, 225, 74, .8) 0 1.6px, transparent 2.2px);
  background-size: 190px 170px, 260px 230px, 330px 290px;
  background-position: 20px 30px, 120px 80px, 60px 150px;
  opacity: .8;
}
#night .sky-moon {
  position: absolute; right: -30px; top: 28px; width: clamp(110px, 15vw, 230px); aspect-ratio: 1;
  border-radius: 50%; background: var(--moon);
  box-shadow: inset -18px -10px 0 rgba(28, 27, 51, .12), 0 0 0 10px rgba(255, 243, 196, .08), 0 0 0 24px rgba(255, 243, 196, .05);
  transform: translateY(calc((1 - var(--nt-dark)) * 60px));
}
#night .sky-moon::before, #night .sky-moon::after {
  content: ''; position: absolute; border-radius: 50%; background: rgba(28, 27, 51, .1);
}
#night .sky-moon::before { width: 22%; height: 22%; left: 24%; top: 30%; }
#night .sky-moon::after { width: 13%; height: 13%; left: 56%; top: 58%; }

/* ---------- 見出しと数 ---------- */
#night .nt { position: relative; }
#night .nt-head {
  display: grid; grid-template-columns: 1fr auto; align-items: end; gap: var(--sp-5) var(--sp-7);
  margin-bottom: var(--sp-6);
}
#night .night-title { margin-bottom: var(--sp-4); }
#night .night-title.is-scatter { overflow: visible; }
#night .night-title .ch { will-change: auto; }
#night .nt-lead { color: var(--nt-fg); max-width: 34em; margin: 0; }
#night .nt-tally {
  display: grid; justify-items: end; gap: 6px;
  color: var(--nt-fg);
}
#night .nt-tally-label { letter-spacing: .3em; opacity: .75; }
#night .nt-tally-num { font-family: var(--f-pop); font-size: clamp(2.4rem, 6vw, 4.2rem); line-height: 1; }
#night .nt-tally-num b { font-weight: 400; color: var(--mi); -webkit-text-stroke: .06em var(--ink); paint-order: stroke fill; text-shadow: .05em .06em 0 var(--ink); display: inline-block; }
#night .nt-tally-num span { font-size: .5em; opacity: .7; margin-left: 4px; }
#night .nt-tally-slots { display: flex; gap: 6px; }
#night .tally-slot {
  position: relative; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  border: 2.5px dashed color-mix(in oklab, var(--nt-fg) 55%, transparent);
}
#night .tally-slot.is-on { border: 3px solid var(--ink); background: var(--mi); box-shadow: 0 3px 0 var(--ink); }
#night .tally-slot img.chara { width: 30px; height: 30px; object-fit: contain; }

/* ---------- 舞台 ---------- */
#night .stage {
  position: relative; padding: 0; background: none; border: 0; box-shadow: none; overflow: visible;
  border-radius: var(--r-l);
  margin: 0 auto; max-width: 1120px;
}
#night .stage-frame {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  border-radius: var(--r-l);
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 10px var(--mi), 0 0 0 13px var(--ink), 0 22px 0 6px rgba(0, 0, 0, .18);
}
#night .stage.is-shake .stage-frame { animation: nt-shake .5s cubic-bezier(.36, .07, .19, .97) both; }
@keyframes nt-shake {
  10%, 90% { transform: translateX(-2px) rotate(-.15deg); }
  20%, 80% { transform: translateX(5px) rotate(.2deg); }
  30%, 50%, 70% { transform: translateX(-8px) rotate(-.3deg); }
  40%, 60% { transform: translateX(8px) rotate(.3deg); }
}
#night .stage-view {
  --lx: 40%; --ly: 42%; --lr: 120px;
  --f0x: 0px; --f0y: 0px; --f0r: 0px; --f1x: 0px; --f1y: 0px; --f1r: 0px; --f2x: 0px; --f2y: 0px; --f2r: 0px;
  --f3x: 0px; --f3y: 0px; --f3r: 0px; --f4x: 0px; --f4y: 0px; --f4r: 0px; --f5x: 0px; --f5y: 0px; --f5r: 0px;
  --f6x: 0px; --f6y: 0px; --f6r: 0px;
  --dx: 50%; --dy: 50%; --dr: 0px; --mx: -100px; --my: -100px; --mr: 0px;
  position: relative; overflow: hidden; isolation: isolate;
  aspect-ratio: 16 / 9;
  border-radius: var(--r-l);
  background: #0f0e25;
  cursor: crosshair;
  -webkit-tap-highlight-color: transparent;
}
#night[data-input="touch"] .stage-view { cursor: default; }
#night .stage-still { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
#night .stage-dim {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: rgba(20, 18, 52, .5);
  transition: background-color .8s var(--ease-soft);
}
#night .stage-view[data-mode="day"] .stage-dim { background: rgba(242, 234, 219, .58); }
#night .stage-ground { position: absolute; left: 0; right: 0; bottom: 0; height: 30%; width: 100%; z-index: 1; pointer-events: none; }
#night .stage-ground path { fill: rgba(28, 27, 51, .28); }
#night .stage-ground .stage-ground-line { fill: none; stroke: rgba(28, 27, 51, .45); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-dasharray: 2 8; stroke-linecap: round; }

/* 3-4 見つけた子の足もとの光（暗幕の穴の中に見える） */
#night .found-bursts { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
#night .found-burst {
  position: absolute; left: 0; top: 0; width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 243, 196, .75), rgba(255, 225, 74, .35) 55%, rgba(255, 225, 74, 0) 100%);
  clip-path: circle(0% at 50% 50%);
  transform: translate(-50%, -50%);
}
#night .found-burst.is-on { clip-path: circle(50% at 50% 50%); }
#night .found-burst::after {
  content: ''; position: absolute; inset: 4%; border-radius: 50%;
  border: 3px dashed rgba(255, 225, 74, .8);
}

/* 隠れ場所 */
#night .spots { position: absolute; inset: 0; z-index: 3; }
#night .spot {
  position: absolute; left: var(--x); top: var(--y); width: var(--w); aspect-ratio: 1;
  transform: translate(-50%, -100%);
}
#night .hidden-chara {
  position: absolute; inset: var(--bi, 0 0 0 0);
  display: block; padding: 0; margin: 0; border: 0; background: none; cursor: inherit;
  z-index: 1; border-radius: 40%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#night .hc-fig {
  position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center;
  transform: rotate(var(--rot, 0deg)); transform-origin: 50% 100%;
}
#night .hc-fig img.chara { width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; pointer-events: none; }
#night .hidden-chara.is-found { z-index: 4; cursor: default; }
#night .hidden-chara:focus-visible { outline-offset: 0; }
#night .occ { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; z-index: 2; pointer-events: none; }
#night .occ path, #night .occ circle, #night .occ rect { stroke: var(--ink); stroke-width: 3; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
#night .occ .o-bush { fill: #43D66B; }
#night .occ .o-bush2 { fill: #2FA851; }
#night .occ .o-rock { fill: #C9B79C; }
#night .occ .o-rock2 { fill: none; }
#night .occ .o-grass { fill: #6BDC5A; }
#night .occ .o-grass2 { fill: #36B24E; }
#night .occ .o-trunk { fill: #9B5E3C; }
#night .occ .o-leaf { fill: #2FA851; }
#night .occ .o-bark { fill: none; stroke-width: 2; }
#night .occ .o-moon { fill: var(--moon); }
#night .occ .o-crater { fill: rgba(28, 27, 51, .1); stroke: none; }
#night .occ .o-sign { fill: var(--paper-hi); }
#night .occ .o-post { fill: #9B5E3C; }
#night .occ .o-q { fill: var(--do); stroke: none; font-family: var(--f-q); font-style: italic; font-weight: 700; font-size: 34px; }
#night .occ .o-box { fill: var(--clay); }
#night .occ .o-plank { fill: none; stroke-width: 2; }
#night .occ .o-dot { stroke: none; fill: rgba(28, 27, 51, .22); }

/* 5-16 暗幕: ライトの穴 ∩ 見つけた子の穴 ∩ 昼の穴 */
#night .darkness {
  position: absolute; inset: -1px; z-index: 5; pointer-events: none;
  background: rgba(14, 13, 38, .93);
  --hole: rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, .55) 80%, #000 100%;
  --fhole: rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 66%, #000 100%;
  -webkit-mask-image:
    radial-gradient(circle var(--lr) at var(--lx) var(--ly), var(--hole)),
    radial-gradient(circle var(--f0r) at var(--f0x) var(--f0y), var(--fhole)),
    radial-gradient(circle var(--f1r) at var(--f1x) var(--f1y), var(--fhole)),
    radial-gradient(circle var(--f2r) at var(--f2x) var(--f2y), var(--fhole)),
    radial-gradient(circle var(--f3r) at var(--f3x) var(--f3y), var(--fhole)),
    radial-gradient(circle var(--f4r) at var(--f4x) var(--f4y), var(--fhole)),
    radial-gradient(circle var(--f5r) at var(--f5x) var(--f5y), var(--fhole)),
    radial-gradient(circle var(--f6r) at var(--f6x) var(--f6y), var(--fhole)),
    radial-gradient(circle var(--dr) at var(--dx) var(--dy), rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 97%, #000 100%),
    radial-gradient(circle var(--mr) at var(--mx) var(--my), rgba(0, 0, 0, .12) 0, rgba(0, 0, 0, .12) 98.5%, #000 100%);
  mask-image:
    radial-gradient(circle var(--lr) at var(--lx) var(--ly), var(--hole)),
    radial-gradient(circle var(--f0r) at var(--f0x) var(--f0y), var(--fhole)),
    radial-gradient(circle var(--f1r) at var(--f1x) var(--f1y), var(--fhole)),
    radial-gradient(circle var(--f2r) at var(--f2x) var(--f2y), var(--fhole)),
    radial-gradient(circle var(--f3r) at var(--f3x) var(--f3y), var(--fhole)),
    radial-gradient(circle var(--f4r) at var(--f4x) var(--f4y), var(--fhole)),
    radial-gradient(circle var(--f5r) at var(--f5x) var(--f5y), var(--fhole)),
    radial-gradient(circle var(--f6r) at var(--f6x) var(--f6y), var(--fhole)),
    radial-gradient(circle var(--dr) at var(--dx) var(--dy), rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 97%, #000 100%),
    radial-gradient(circle var(--mr) at var(--mx) var(--my), rgba(0, 0, 0, .12) 0, rgba(0, 0, 0, .12) 98.5%, #000 100%);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
}
#night .lamp {
  position: absolute; left: 0; top: 0; z-index: 6; pointer-events: none;
  width: calc(var(--lr) * 1.62); aspect-ratio: 1; border-radius: 50%;
  transform: translate(calc(var(--lx) - 50%), calc(var(--ly) - 50%));
  box-shadow: 0 0 0 2px rgba(255, 243, 196, .22), 0 0 40px 6px rgba(255, 243, 196, .12);
  transition: opacity .6s;
}
#night .stage-view[data-mode="day"] .lamp, #night .stage-view.is-idle .lamp { opacity: 0; }

/* 5-17 照らした所だけ読める文（タッチでは常に読める） */
#night .dark-copy {
  position: absolute; inset: 0; z-index: 6; margin: 0; pointer-events: none;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 26%;
  font-family: var(--f-pop); font-size: clamp(1.4rem, 4.4vw, 3.6rem); line-height: 1.2; letter-spacing: .04em;
  color: var(--moon);
  text-shadow: 0 .06em 0 rgba(28, 27, 51, .7);
  -webkit-mask-image: radial-gradient(circle calc(var(--lr) * 1.05) at var(--lx) var(--ly), #000 0, #000 45%, rgba(0, 0, 0, 0) 100%);
  mask-image: radial-gradient(circle calc(var(--lr) * 1.05) at var(--lx) var(--ly), #000 0, #000 45%, rgba(0, 0, 0, 0) 100%);
  transition: opacity .6s var(--ease-soft);
}
#night .dark-copy span { display: block; text-align: center; padding: 0 6%; }
#night[data-input="touch"] .dark-copy, #night .stage-view.is-idle .dark-copy { -webkit-mask-image: none; mask-image: none; }
#night .stage-view[data-mode="day"] .dark-copy, #night .stage-view.is-complete .dark-copy { opacity: 0; }

/* 7-9 星屑 */
#night .stars { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 7; pointer-events: none; transition: opacity .8s; }
#night .stage-view[data-mode="day"] .stars { opacity: .15; }

/* 8-51 照準の四隅ブラケット */
#night .brackets {
  position: absolute; left: 0; top: 0; width: 100px; height: 100px; z-index: 8; pointer-events: none;
  transition: opacity .3s;
}
#night .brackets i {
  position: absolute; width: 22px; height: 22px; border: 4px solid var(--mi);
  filter: drop-shadow(0 2px 0 var(--ink));
  transition: transform .25s cubic-bezier(.16, 1, .3, 1);
}
#night .brackets i:nth-child(1) { left: 0; top: 0; border-width: 4px 0 0 4px; border-radius: 8px 0 0 0; }
#night .brackets i:nth-child(2) { right: 0; top: 0; border-width: 4px 4px 0 0; border-radius: 0 8px 0 0; }
#night .brackets i:nth-child(3) { left: 0; bottom: 0; border-width: 0 0 4px 4px; border-radius: 0 0 0 8px; }
#night .brackets i:nth-child(4) { right: 0; bottom: 0; border-width: 0 4px 4px 0; border-radius: 0 0 8px 0; }
#night .brackets:not(.is-lock) i { opacity: .55; }
#night .brackets.is-lock i { border-color: var(--do); }
#night .brackets.is-lock i:nth-child(1) { transform: translate(-3px, -3px); }
#night .brackets.is-lock i:nth-child(2) { transform: translate(3px, -3px); }
#night .brackets.is-lock i:nth-child(3) { transform: translate(-3px, 3px); }
#night .brackets.is-lock i:nth-child(4) { transform: translate(3px, 3px); }
#night .stage-view.is-idle .brackets, #night .stage-view[data-mode="day"] .brackets, #night .stage-view.is-complete .brackets { opacity: 0; }

/* 8-27 丸とチェック */
#night .marks { position: absolute; inset: 0; z-index: 9; pointer-events: none; }
#night .check { position: absolute; left: 0; top: 0; width: 100px; height: 100px; overflow: visible; display: none; transform: translate(-50%, -50%); }
#night .check.is-on { display: block; }
#night .check path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
#night .check-ring { stroke: var(--mi); stroke-width: 4.5; filter: drop-shadow(0 2px 0 var(--ink)); }
#night .check-tick { stroke: var(--do); stroke-width: 7; filter: drop-shadow(0 2px 0 var(--ink)); }
#night .miss-pop {
  position: absolute; z-index: 10; left: 0; top: 0; transform: translate(-50%, -120%);
  padding: 6px 14px; border-radius: var(--r-pill);
  background: var(--paper-hi); color: var(--ink); border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink);
  font-weight: 900; font-size: var(--fs-small); white-space: nowrap; pointer-events: none;
  animation: nt-miss 1.3s var(--ease-soft) forwards;
}
@keyframes nt-miss { 0% { opacity: 0; transform: translate(-50%, -80%) scale(.7); } 15% { opacity: 1; transform: translate(-50%, -120%) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -150%); } }

/* ---------- 操作 ---------- */
#night .nt-controls {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: var(--sp-4) var(--sp-6);
  margin-top: var(--sp-7);
}
#night .nt-howto p { margin: 0; color: var(--nt-fg); font-weight: 700; }
#night .nt-howto .howto--key { color: var(--nt-soft); font-weight: 500; margin-top: 4px; }
#night .howto--touch { display: none; }
#night[data-input="touch"] .howto--mouse { display: none; }
#night[data-input="touch"] .howto--touch { display: block; }
#night .nt-buttons { display: flex; flex-wrap: wrap; gap: var(--sp-3); order: -1; }
#night .nt-howto { flex: 1 1 20em; }
#night .night-here {
  display: inline-flex; margin: 0; height: auto; max-width: none; gap: var(--sp-2);
  background: var(--btn-bg); color: var(--btn-fg);
  border: var(--line); border-radius: var(--r-pill); box-shadow: var(--sh-step);
  font-family: var(--f-pop); font-weight: 400; font-size: 1.15rem; line-height: 1.2;
  padding: var(--sp-2) var(--sp-6);
}
#night .night-here:focus-visible { box-shadow: var(--sh-step), 0 0 0 7px var(--mi); }
#night .daynight { gap: 10px; border-color: var(--paper-hi); box-shadow: 0 4px 0 var(--paper-hi); }
#night .daynight:active, #night .daynight[aria-pressed="true"] { box-shadow: 0 4px 0 var(--paper-hi); transform: none; }
#night .daynight-icon {
  width: 22px; height: 22px; border-radius: 50%; background: var(--mi); border: 2px solid var(--paper-hi);
  box-shadow: inset -7px -3px 0 var(--ink);
  transition: box-shadow .5s var(--ease-spring);
}
#night .daynight[aria-pressed="true"] .daynight-icon { box-shadow: inset 0 0 0 var(--ink), 0 0 0 4px rgba(255, 225, 74, .35); }

/* ---------- 第9話の箱 ---------- */
#night .ep-box {
  display: grid; grid-template-columns: minmax(0, 300px) 1fr; gap: var(--sp-6); align-items: center;
  margin-top: var(--sp-8);
  padding: var(--sp-5);
  background: var(--paper-hi); color: var(--ink);
  border: var(--line); border-radius: var(--r-l); box-shadow: var(--sh-step-lg);
  max-width: 920px;
  position: relative;
}
#night .ep-box::before {
  content: 'EP.09'; position: absolute; right: var(--sp-5); top: calc(var(--sp-3) * -1 - 12px);
  font-family: var(--f-mono); font-size: var(--fs-mono); letter-spacing: .2em;
  background: var(--mi); border: 3px solid var(--ink); border-radius: var(--r-pill); padding: 2px 12px;
}
#night .ep-box-poster { padding: 6px; transform: rotate(-2deg); }
#night .ep-box-poster img { display: block; width: 100%; height: auto; border-radius: 6px; }
#night .ep-box-label { font-family: var(--f-pop); font-size: var(--fs-h3); line-height: 1.35; margin: 0 0 var(--sp-2); }
#night .ep-box-summary { color: var(--ink-soft); margin-bottom: var(--sp-4); }

/* 統合: PC では数の札が空の月に重なり、明るい字が月に沈んで読めなかった。月の前に夜空色の札を敷く */
@media (min-width: 600px) {
  #night .nt-tally {
    position: relative; z-index: 1;
    padding: 12px 16px 14px; color: var(--moon);
    background: var(--night-sky); border: 3px solid var(--ink); border-radius: var(--r-m); box-shadow: var(--sh-step);
  }
}

/* ---------- スマホ ---------- */
@media (max-width: 599px) {
  #night .nt-head { grid-template-columns: 1fr; gap: var(--sp-4); }
  #night .nt-tally { justify-items: start; grid-template-columns: auto auto; align-items: center; column-gap: var(--sp-4); }
  #night .nt-tally-label { display: none; }
  #night .tally-slot { width: 28px; height: 28px; }
  #night .tally-slot img.chara { width: 22px; height: 22px; }
  #night .stage-view { aspect-ratio: 4 / 5; border-radius: var(--r-m); }
  #night .stage, #night .stage-frame { border-radius: var(--r-m); }
  #night .stage-frame { box-shadow: 0 0 0 3px var(--ink), 0 0 0 8px var(--mi), 0 0 0 11px var(--ink); }
  #night .dark-copy { padding-top: 54%; font-size: 1.3rem; }
  #night .ep-box { grid-template-columns: 1fr; gap: var(--sp-4); padding: var(--sp-4); }
  #night .ep-box-poster { transform: none; }
  #night .nt-controls { margin-top: var(--sp-6); }
  #night .nt-buttons { width: 100%; }
  #night .nt-buttons .btn { flex: 1 1 auto; }
  #night .sky-moon { top: 60px; right: -20px; }
}

/* ---------- 止める ---------- */
html[data-motion="off"] #night, html[data-motion="off"] #night * { transition-duration: 0s !important; }
html[data-motion="off"] #night .stage.is-shake .stage-frame, html[data-motion="off"] #night .miss-pop { animation: none; }
@media (prefers-reduced-motion: reduce) {
  #night, #night * { transition-duration: 0s !important; }
  #night .stage.is-shake .stage-frame, #night .miss-pop { animation: none; }
}
