:root {
  --shu: #c8382a;
  --shu-dark: #9e2a1f;
  --sumi: #1f1b18;
  --washi: #f7f1e3;
  --washi-2: #efe6d2;
  --gold: #c9a24a;
  --ink-soft: #5b5146;
  --glass: rgba(24, 20, 18, 0.62);
  font-family: 'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d0f14;
  color: var(--sumi);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.hidden { display: none !important; }

/* ---------- ボタン ---------- */
.btn {
  font-family: inherit;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.92);
  color: var(--sumi);
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.08s, background 0.2s;
}
.btn:hover { background: #fff; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--shu); color: #fff; border-color: var(--shu-dark); }
.btn.primary:hover { background: #d8432f; }
.btn.big { font-size: 18px; padding: 14px 28px; letter-spacing: 0.2em; }
.btn.small { font-size: 13px; padding: 7px 12px; background: var(--glass); color: #fff; }
.btn.small:hover { background: rgba(40, 32, 28, 0.85); }
.btn.ghost { background: transparent; border-color: var(--ink-soft); color: var(--ink-soft); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

/* ---------- 入口 ---------- */
.intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(20, 16, 14, 0.35), rgba(10, 8, 7, 0.75));
  z-index: 50;
  padding: 16px;
  overflow-y: auto;
}
.intro-card {
  width: min(460px, 100%);
  background: var(--washi);
  border-radius: 10px;
  padding: 28px 28px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  border-top: 6px solid var(--shu);
}
.intro-torii { font-size: 42px; line-height: 1; }
.intro h1 {
  font-family: 'Yuji Syuku', serif;
  font-size: 40px;
  margin: 6px 0 4px;
  letter-spacing: 0.15em;
}
.lead { color: var(--ink-soft); margin: 0 0 18px; line-height: 1.8; }
.field { display: block; text-align: left; margin: 0 0 14px; }
.field > span { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid #cbbfa6;
  border-radius: 6px;
  background: #fffdf7;
}
.field textarea { resize: none; line-height: 1.6; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.colors button.sel { border-color: var(--sumi); }
.howto {
  margin-top: 18px;
  text-align: left;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.9;
  border-top: 1px dashed #cbbfa6;
  padding-top: 12px;
}

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; color: #fff; }
.hud > * { pointer-events: auto; }
.hud-top-left {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  background: var(--glass);
  padding: 10px 14px;
  border-radius: 8px;
  backdrop-filter: blur(4px);
}
.shrine-name { font-family: 'Yuji Syuku', serif; font-size: 22px; letter-spacing: 0.12em; }
.online { font-size: 13px; margin-top: 2px; }
.online::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6fd17a;
  margin-right: 6px;
  vertical-align: middle;
}
.online.off::before { background: #d16f6f; }
.sub { font-size: 12px; opacity: 0.85; }
.room-btn {
  font-family: inherit;
  font-size: 12px;
  color: #f3d27a;
  background: none;
  border: 1px solid rgba(243, 210, 122, 0.5);
  border-radius: 10px;
  padding: 1px 8px;
  margin: 3px 0 2px;
  cursor: pointer;
}
.room-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.room-row { display: flex; align-items: center; gap: 10px; background: #fffaf0; border: 1px solid #e2d6bb; border-radius: 6px; padding: 8px 12px; }
.room-row.here { border-color: var(--shu); }
.room-row .name { font-weight: 600; min-width: 6em; }
.room-row .bar { flex: 1; height: 6px; border-radius: 3px; background: #e2d6bb; overflow: hidden; }
.room-row .bar span { display: block; height: 100%; background: var(--shu); }
.room-row .n { font-size: 13px; color: var(--ink-soft); min-width: 4.5em; text-align: right; }
.invite { display: flex; gap: 6px; margin-top: 14px; }
.invite input { flex: 1; font-family: inherit; font-size: 13px; padding: 8px 10px; border: 1px solid #cbbfa6; border-radius: 6px; background: #fffdf7; }
.hud-top-right {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 60vw;
}
.etiquette {
  position: absolute;
  top: 138px;
  left: 12px;
  background: var(--glass);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  backdrop-filter: blur(4px);
}
.et-title { font-size: 12px; opacity: 0.8; margin-bottom: 4px; }
.etiquette ol { margin: 0; padding-left: 18px; line-height: 1.8; }
.etiquette li.done, .et-sub span.done { color: #f3d27a; }
.etiquette li.done::after, .et-sub span.done::after { content: ' ✓'; }
.et-sub { margin-top: 6px; display: flex; gap: 10px; font-size: 12px; opacity: 0.9; }

.prompt {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.prompt .btn { box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); }
.prompt .key {
  display: inline-block;
  background: var(--sumi);
  color: #fff;
  border-radius: 4px;
  padding: 0 6px;
  margin-right: 6px;
  font-size: 12px;
}

.chat-log {
  position: absolute;
  left: 12px;
  bottom: 60px;
  width: min(360px, 70vw);
  max-height: 30vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 3px;
  font-size: 13px;
  pointer-events: none;
}
.chat-log div {
  background: rgba(0, 0, 0, 0.42);
  padding: 3px 8px;
  border-radius: 4px;
  width: fit-content;
  max-width: 100%;
  word-break: break-word;
  animation: fadein 0.3s;
}
.chat-log b { color: #f3d27a; font-weight: 600; margin-right: 6px; }
.chat-log .sys { color: #cfe3ff; }
.chat-form {
  position: absolute;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(360px, 70vw);
}
.chat-form input {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
}
.chat-form input::placeholder { color: rgba(255, 255, 255, 0.55); }

.toasts {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: rgba(247, 241, 227, 0.95);
  color: var(--sumi);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  animation: fadein 0.3s;
  transition: opacity 0.5s;
}

.joystick {
  position: absolute;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.15);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.joystick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
}

/* ---------- 儀式パネル ---------- */
.panel {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px));
  background: var(--washi);
  border-radius: 10px;
  border-top: 5px solid var(--shu);
  padding: 16px 20px 18px;
  z-index: 20;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  animation: rise 0.3s;
  max-height: 72dvh;
  overflow-y: auto;
}
.panel h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: 0.1em; }
.panel .steps { display: flex; gap: 4px; margin: 6px 0 10px; }
.panel .steps span { flex: 1; height: 4px; border-radius: 2px; background: #ddd2bb; }
.panel .steps span.on { background: var(--shu); }
.panel .desc { margin: 0 0 12px; line-height: 1.8; color: #3b342d; font-size: 15px; }
.panel .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.panel .close-x {
  position: absolute;
  right: 10px;
  top: 8px;
  border: 0;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--ink-soft);
}
.panel .note { font-size: 12px; color: var(--ink-soft); margin-top: 8px; }
.panel textarea {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  padding: 8px 10px;
  border: 1px solid #cbbfa6;
  border-radius: 6px;
  background: #fffdf7;
  resize: none;
  margin-bottom: 10px;
}
.pray-fade { animation: pray 3s ease-in-out; }

/* カメラで作法 */
.cam { margin-top: 12px; padding-top: 10px; border-top: 1px dashed #d8c9a8; }
.cam-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.panel .btn.small.cam-toggle { background: var(--sumi); }
.cam-note { font-size: 12px; color: var(--ink-soft); flex: 1; min-width: 180px; }
.cam-details { font-size: 12px; color: var(--ink-soft); margin-top: 6px; }
.cam-details summary { cursor: pointer; }
.cam-details ul { margin: 6px 0 0; padding-left: 18px; line-height: 1.7; }
.cam-box { display: flex; gap: 12px; margin-top: 10px; align-items: stretch; }
.cam-view { position: relative; width: 168px; aspect-ratio: 4 / 3; flex: none; border-radius: 6px; overflow: hidden; background: #222; }
.cam-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.cam-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.cam-side { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.cam-hint { font-weight: 600; color: var(--shu); }
.cam-status { color: #3b342d; line-height: 1.6; transition: color 0.2s; }
.cam-status.ok { color: #2f8a4a; font-weight: 600; }
.cam-meter-label { font-size: 11px; color: var(--ink-soft); margin-top: auto; }
.cam-meter { height: 8px; border-radius: 4px; background: #e2d6bb; overflow: hidden; }
.cam-meter span { display: block; height: 100%; width: 0; background: var(--shu); transition: width 0.1s; }

/* ---------- モーダル ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 7, 0.6);
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 12px;
  animation: fadein 0.2s;
}
.modal-card {
  position: relative;
  width: min(640px, 100%);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  background: var(--washi);
  border-radius: 10px;
  padding: 22px 22px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-close {
  position: absolute;
  right: 10px;
  top: 6px;
  border: 0;
  background: none;
  font-size: 26px;
  cursor: pointer;
  color: var(--ink-soft);
}
.modal h2 { margin: 0 0 8px; font-size: 22px; letter-spacing: 0.12em; text-align: center; }
.modal .center { text-align: center; }
.modal .muted { color: var(--ink-soft); font-size: 13px; line-height: 1.7; }
.modal .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* おみくじ */
.mikuji-box {
  width: 90px;
  height: 150px;
  margin: 16px auto;
  background: linear-gradient(90deg, #6b4a2e, #8a6440 40%, #6b4a2e);
  border-radius: 8px 8px 4px 4px;
  position: relative;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
  color: #f7e8c8;
  font-family: 'Yuji Syuku', serif;
  font-size: 22px;
  writing-mode: vertical-rl;
  letter-spacing: 0.3em;
}
.mikuji-box.shake { animation: shake 0.18s infinite; }
.mikuji-stick {
  writing-mode: vertical-rl;
  margin: 10px auto;
  background: #f1e3c4;
  border: 1px solid #c9b48c;
  padding: 10px 6px;
  width: fit-content;
  font-size: 18px;
  letter-spacing: 0.2em;
}
.mikuji-paper {
  background: #fffdf6;
  border: 1px solid #d8c9a8;
  padding: 18px 14px;
  margin: 10px auto 0;
  writing-mode: vertical-rl;
  height: 440px;
  max-width: 100%;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.7;
  box-shadow: inset 0 0 30px rgba(200, 170, 120, 0.15);
}
.mikuji-paper > div {
  margin-block-end: 8px;
  padding-block-end: 8px;
  border-block-end: 1px dashed #e2d6bb;
}
.mikuji-paper .head { border-block-end: 2px solid var(--shu); }
.mikuji-paper .num { color: var(--shu); font-size: 15px; }
.mikuji-paper .fortune {
  font-family: 'Yuji Syuku', serif;
  font-size: 46px;
  color: var(--shu);
  letter-spacing: 0.1em;
}
.mikuji-paper .poem { font-size: 15px; }
.mikuji-paper .item b { color: var(--shu); margin-bottom: 4px; display: inline-block; }

/* 絵馬 */
.ema-designs { display: flex; gap: 8px; justify-content: center; margin: 8px 0 12px; }
.ema-designs button {
  font-family: inherit;
  border: 2px solid #d0c3a8;
  background: #fffaf0;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
.ema-designs button.sel { border-color: var(--shu); color: var(--shu); }
.ema-preview { display: block; margin: 0 auto 12px; width: 240px; max-width: 70%; }
.ema-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.ema-card {
  background: linear-gradient(#e9cf9f, #d9b77d);
  clip-path: polygon(50% 0, 100% 22%, 100% 100%, 0 100%, 0 22%);
  padding: 34px 12px 12px;
  min-height: 140px;
  color: #2a1c10;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}
.ema-card .who { font-size: 12px; text-align: right; margin-top: 6px; color: #5a3d22; }
.ema-card .when { font-size: 11px; color: #7a5a3a; }

/* 御朱印 */
.goshuin-canvas {
  display: block;
  margin: 8px auto;
  width: 300px;
  max-width: 80%;
  height: auto;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  border-radius: 2px;
}
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.book-grid button {
  border: 1px solid #d8c9a8;
  background: #fff;
  padding: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}
.book-grid img { width: 100%; display: block; }

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  z-index: 60;
}

/* ---------- 着替え ---------- */
.btn.wide { width: 100%; }
.dress {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(10, 8, 7, 0.6);
  display: grid;
  place-items: center;
  padding: 12px;
  animation: fadein 0.2s;
}
.dress-card {
  width: min(920px, 100%);
  height: min(620px, calc(100dvh - 24px));
  background: var(--washi);
  border-radius: 10px;
  border-top: 6px solid var(--shu);
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.dress-preview { position: relative; min-height: 0; }
.dress-canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.dress-hint { position: absolute; top: 10px; left: 12px; font-size: 12px; color: var(--ink-soft); }
.dress-preview-actions { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; }
.dress-side { display: flex; flex-direction: column; min-height: 0; padding: 16px 18px 14px; }
.dress-side h2 { margin: 0 0 10px; font-size: 20px; letter-spacing: 0.12em; }
.dress-tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid #d8c9a8; padding-bottom: 8px; }
.dress-tabs button {
  font-family: inherit;
  font-size: 14px;
  border: 0;
  background: none;
  padding: 6px 10px;
  border-radius: 14px;
  cursor: pointer;
  color: var(--ink-soft);
}
.dress-tabs button.sel { background: var(--shu); color: #fff; }
.dress-body { flex: 1; overflow-y: auto; padding: 6px 2px; }
.dress-sec { margin: 12px 0; }
.dress-label { font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.chip {
  font-family: inherit;
  font-size: 14px;
  border: 1.5px solid #d0c3a8;
  background: #fffaf0;
  border-radius: 16px;
  padding: 6px 13px;
  cursor: pointer;
}
.chip.sel { border-color: var(--shu); background: var(--shu); color: #fff; }
.chip:disabled { opacity: 0.4; cursor: default; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2); }
.sw.sel { border-color: var(--sumi); }
.swatches input[type='color'] { width: 34px; height: 34px; border: 0; padding: 0; background: none; cursor: pointer; }
.slider { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); }
.slider input { flex: 1; accent-color: var(--shu); }
.dress-actions { display: flex; gap: 8px; align-items: center; padding-top: 10px; border-top: 1px solid #d8c9a8; }

@media (max-width: 720px) {
  .dress-card { grid-template-columns: 1fr; grid-template-rows: 38% 1fr; height: calc(100dvh - 24px); }
  .dress-side { padding: 10px 12px; }
  .dress-side h2 { display: none; }
}

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes shake {
  0% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
  100% { transform: rotate(-8deg); }
}
@keyframes pray {
  0% { opacity: 1; }
  40% { opacity: 0.35; }
  100% { opacity: 1; }
}

@media (max-width: 640px) {
  .hud-top-right { flex-direction: column; align-items: flex-end; }
  .hud-top-left { padding: 8px 10px; }
  .toasts { top: auto; bottom: 260px; width: 90vw; }
  .etiquette { top: auto; bottom: 150px; right: 12px; left: auto; font-size: 11px; padding: 6px 10px; }
  .etiquette .et-sub { display: none; }
  .shrine-name { font-size: 18px; }
  .hud-top-right .btn.small { padding: 6px 8px; font-size: 12px; }
  .chat-log { bottom: 56px; max-height: 22vh; font-size: 12px; }
  .prompt { bottom: 70px; }
}
