:root {
  --serif: "Hiragino Mincho ProN", "Hiragino Mincho Pro", "Yu Mincho", "YuMincho", "BIZ UDPMincho", "Noto Serif JP", "Noto Serif CJK JP", serif;
  --sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "YuGothic", "BIZ UDPGothic", "Noto Sans JP", "Meiryo", sans-serif;
  --ink: #f5f1e6;
  --sub: #c7cde6;
  --gold: #f0c869;
  --red: #b8341f;
  --red-hi: #d24a32;
  --night: #0b1030;
  --panel: rgba(9, 13, 38, 0.82);
  --line: rgba(240, 200, 105, 0.45);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--gold); }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 3px solid #ffe08a;
  outline-offset: 3px;
}
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

#scene {
  position: fixed; inset: 0; width: 100%; height: 100%;
  display: block; z-index: 0; pointer-events: none;
}
#app { position: relative; z-index: 1; }

.screen {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column; align-items: center;
  padding: calc(14px + var(--safe-t)) 16px calc(14px + var(--safe-b));
  height: 100vh; height: 100dvh;
}
.screen.is-active { display: flex; }
.screen-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---- ボタン ---- */
.btn {
  font: inherit; font-weight: 700;
  border: 2px solid transparent; border-radius: 999px;
  padding: 10px 20px; cursor: pointer; color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  transition: transform .12s ease, background .2s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--red); border-color: #e7826c; color: #fff; }
.btn-primary:hover { background: var(--red-hi); }
.btn-ghost { background: rgba(10, 14, 40, 0.6); border-color: var(--line); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }
.btn-link { background: none; border: none; color: var(--gold); text-decoration: underline; padding: 6px 8px; font-weight: 500; }
.btn-big { font-size: 1.3rem; padding: 16px 38px; box-shadow: 0 6px 24px rgba(184, 52, 31, 0.45); }
.btn-small { font-size: .88rem; padding: 7px 14px; background: rgba(10, 14, 40, 0.72); border-color: var(--line); }
.btn[disabled] { opacity: .5; cursor: default; }
.actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.btn .nb { display: inline-block; } /* 括弧の中は途中で折り返さない */
#screen-consent .actions .btn { max-width: 100%; line-height: 1.4; }
.actions.row { flex-direction: row; flex-wrap: wrap; justify-content: center; }

/* ---- トップ ---- */
#screen-top { justify-content: space-between; text-align: center; }
.sound-badge {
  margin: 0; align-self: flex-end;
  font-size: .82rem; color: #1b1405; background: var(--gold);
  border-radius: 999px; padding: 2px 12px; font-weight: 700;
}
.logo {
  font-family: var(--serif); font-weight: 800;
  font-size: clamp(2rem, 9vw, 3.4rem); line-height: 1.15;
  margin: 2px 0 0; letter-spacing: .06em;
  text-shadow: 0 2px 18px rgba(0, 0, 0, .8), 0 0 30px rgba(240, 200, 105, .25);
}
.bell-slot { flex: 1 1 auto; width: 100%; max-width: 520px; min-height: 140px; }
.copy {
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(1.1rem, 4.8vw, 1.6rem); margin: 6px 0 12px; line-height: 1.5;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .9);
}
.note {
  font-size: .76rem; color: var(--sub); max-width: 34em; margin: 12px auto 4px;
  background: rgba(5, 8, 24, 0.7); padding: 8px 12px; border-radius: 10px; line-height: 1.55;
}
.foot { font-size: .8rem; margin: 4px 0 0; color: var(--sub); }

/* ---- パネル ---- */
.panel {
  margin: auto; max-width: 30em; width: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px 20px; text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.panel h2 { font-family: var(--serif); margin: 0 0 12px; font-size: 1.35rem; }
.consent-main { font-size: 1.02rem; font-weight: 700; }
.small { font-size: .8rem; color: var(--sub); }
.center { text-align: center; }

/* ---- 鐘の画面 ---- */
#screen-bell { justify-content: space-between; padding-left: 12px; padding-right: 12px; }
.hud { width: 100%; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.hud-cat {
  display: flex; align-items: center; gap: 6px;
  background: rgba(5, 8, 24, .72); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px 4px 8px; font-weight: 700; font-size: .95rem;
}
.hud-icon { font-size: 1.4rem; line-height: 1; }
.hud-cat.pop { animation: pop .45s ease; }
.hud-right { display: flex; align-items: center; gap: 8px; }
.hud-mute {
  font-size: 1.1rem; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(5, 8, 24, .72); color: var(--ink); cursor: pointer;
}
.hud-count {
  margin: 0; font-family: var(--serif); font-weight: 800; font-size: 1.7rem; line-height: 1;
  background: rgba(5, 8, 24, .72); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px;
  font-variant-numeric: tabular-nums;
}
.hud-count .of { font-size: 1rem; color: var(--sub); }
.hud-count.pop { animation: pop .35s ease; }
.bell-hit {
  background: transparent; border: 0; padding: 0; cursor: default; color: transparent;
  max-width: 560px; border-radius: 24px;
}
.bell-hit.tappable { cursor: pointer; }
.hit-label {
  position: absolute; left: 0; right: 0; top: 42%;
  text-align: center; margin: 0; pointer-events: none;
  font-family: var(--serif); font-weight: 800; font-size: clamp(1.4rem, 7vw, 2.6rem);
  text-shadow: 0 2px 12px #000, 0 0 24px rgba(255, 170, 60, .6);
  opacity: 0;
}
.hit-label.show { animation: label 1.4s ease forwards; }
.hit-label.soul { color: #ffd76a; }
.hit-label.whisper { color: #c9d3ff; font-size: clamp(1rem, 5vw, 1.6rem); }
.bottom { width: 100%; max-width: 560px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.status { margin: 0; font-size: .85rem; color: var(--sub); text-align: center; min-height: 1.3em; text-shadow: 0 1px 6px #000; }
.meter { width: 160px; height: 6px; background: rgba(255, 255, 255, .15); border-radius: 3px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8fb3ff, #ffd76a, #ff7a50); border-radius: 3px; }
.interim {
  margin: 0; min-height: 1.6em; font-family: var(--serif); font-size: 1.25rem; font-weight: 700;
  color: rgba(255, 255, 255, .6); text-align: center; text-shadow: 0 1px 8px #000;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.text-form { display: flex; gap: 8px; width: 100%; }
.text-form[hidden] { display: none; }
.text-form input {
  flex: 1 1 auto; min-width: 0; font: inherit; font-size: 16px; /* iOS の拡大を防ぐ */
  padding: 10px 14px; border-radius: 999px; border: 2px solid var(--line);
  background: rgba(5, 8, 24, .85); color: var(--ink);
}
.text-form input::placeholder { color: #8d94b8; }
.btn-send { padding: 10px 18px; flex: 0 0 auto; }
.hint { margin: 0; font-size: .74rem; color: var(--sub); text-align: center; min-height: 1em; text-shadow: 0 1px 6px #000; }
.bottom-actions { display: flex; gap: 10px; justify-content: center; margin-top: 2px; }

.finale {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(60, 40, 0, .35), rgba(0, 0, 0, .55));
  text-align: center; padding: 20px; animation: fade .8s ease;
}
.finale[hidden] { display: none; }
.finale-pre { margin: 0; color: #ffe7a8; font-weight: 700; text-shadow: 0 2px 10px #000; }
.finale-title {
  margin: 6px 0; font-family: var(--serif); font-weight: 900; color: #ffd76a;
  font-size: clamp(2.4rem, 12vw, 5rem); letter-spacing: .08em;
  text-shadow: 0 0 30px rgba(255, 200, 80, .8), 0 4px 16px #000;
  animation: grand 1.2s cubic-bezier(.2, 1.4, .4, 1);
}
.finale-msg { margin: 0 0 18px; text-shadow: 0 2px 8px #000; max-width: 26em; }

/* ---- 結果 ---- */
#screen-result { justify-content: flex-start; }
.result { width: 100%; max-width: 1100px; margin: 0 auto; }
.result[hidden] { display: none; }
.result-title { font-family: var(--serif); text-align: center; margin: 4px 0 10px; font-size: 1.4rem; }
.result-title:focus { outline: none; }
.result-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.card-wrap {
  border-radius: 10px; overflow: hidden; border: 1px solid var(--line);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .6); background: #070b20;
}
.card-wrap img { display: block; width: 100%; height: auto; }
.share-msg { text-align: center; font-size: .85rem; color: #ffe7a8; min-height: 1.2em; margin: 8px 0 0; }
.chips-col { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.chips-title { margin: 0; font-family: var(--serif); font-size: 1.05rem; }
.chips { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; max-height: 40vh; overflow-y: auto; }
.chip {
  font: inherit; font-size: .9rem; cursor: pointer; text-align: left;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .08); color: var(--ink);
  border-radius: 999px; padding: 5px 12px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip[aria-pressed="false"] { opacity: .65; text-decoration: line-through; background: transparent; border-style: dashed; }
.chip .tag { font-size: .72rem; margin-left: 6px; color: #ffd76a; }
.empty { margin: auto; }
.empty[hidden] { display: none; }

.toast {
  position: fixed; left: 50%; top: calc(72px + var(--safe-t)); transform: translateX(-50%) translateY(-12px);
  z-index: 5; background: rgba(5, 8, 24, .94); border: 1px solid var(--line); color: var(--ink);
  border-radius: 12px; padding: 10px 16px; font-size: .86rem; max-width: min(92vw, 30em);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.noscript { position: fixed; inset: auto 0 0 0; z-index: 9; background: #000; color: #fff; text-align: center; padding: 10px; margin: 0; }

@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes label {
  0% { opacity: 0; transform: translateY(10px) scale(.8); }
  15% { opacity: 1; transform: translateY(0) scale(1.08); }
  70% { opacity: 1; transform: translateY(-6px) scale(1); }
  100% { opacity: 0; transform: translateY(-18px) scale(1); }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes grand { 0% { opacity: 0; transform: scale(.4); } 100% { opacity: 1; transform: scale(1); } }

@media (min-width: 900px) {
  .result-grid { grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); align-items: start; }
  .chips { max-height: 60vh; }
  .note { font-size: .82rem; }
}
@media (max-height: 620px) {
  .logo { font-size: 1.8rem; }
  .btn-big { padding: 12px 30px; font-size: 1.15rem; }
  .note { font-size: .7rem; margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .hit-label.show, .finale-title, .hud-cat.pop, .hud-count.pop { animation-duration: .01s; }
  .hit-label.show { animation: none; opacity: 1; }
}
