:root {
  --accent: #2f8cff;
  --panel: rgba(18, 22, 28, 0.72);
  --text: #fff;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #0d1014;
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  overflow: hidden;
}

[hidden] { display: none !important; }

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  cursor: grab;
}
.view.dragging { cursor: grabbing; }
/* 開始後はキャンバス上の指の動きをすべて見回しに使う（開始前はページをスクロールできる） */
.app.started .view { touch-action: none; }

.fade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.fade.on { opacity: 1; transition-duration: 0.25s; }

/* ---- 開始画面 ---- */
.poster {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #27384d, #10161e) center / cover no-repeat;
  transition: opacity 0.5s ease;
}
.poster::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}
.poster.hide { opacity: 0; pointer-events: none; }
.poster-inner {
  position: relative;
  text-align: center;
  padding: 16px;
  max-width: 90%;
}
.poster h1 {
  margin: 0 0 18px;
  font-size: clamp(18px, 3.5vw, 28px);
  font-weight: 600;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}
.start {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 14px 34px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.start:hover { filter: brightness(1.1); transform: scale(1.03); }
.poster-note { margin: 12px 0 0; font-size: 13px; opacity: 0.85; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7); }
.progress { margin-top: 14px; font-size: 13px; }
.progress-track {
  width: min(280px, 70vw);
  height: 6px;
  margin: 0 auto 8px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}
.progress-bar { width: 0; height: 100%; background: var(--accent); transition: width 0.2s linear; }
.progress-bar.indeterminate { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { margin-left: -35%; } to { margin-left: 100%; } }

.poster video, .poster .fallback-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message {
  position: absolute;
  inset: auto 16px 50% 16px;
  transform: translateY(50%);
  margin: 0 auto;
  max-width: 420px;
  padding: 18px 20px;
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  text-align: center;
  line-height: 1.7;
  font-size: 14px;
}
.message a { color: #9cc8ff; }

/* ---- 下部バー ---- */
.bar {
  position: absolute;
  left: calc(10px + var(--safe-l));
  right: calc(10px + var(--safe-r));
  bottom: calc(10px + var(--safe-b));
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(8px);
}
.bar-btn {
  flex: none;
  appearance: none;
  border: 0;
  min-width: 40px;
  height: 40px;
  padding: 0 8px;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.bar-btn:hover { background: rgba(255, 255, 255, 0.14); }
.bar-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bar-play svg { fill: currentColor; stroke: none; }
.bar-play.return { background: var(--accent); padding: 0 14px; font-weight: 700; }
.bar-play.return svg { fill: none; stroke: currentColor; }
.seek { flex: 1; min-width: 40px; height: 28px; accent-color: var(--accent); cursor: pointer; }

/* ---- 見どころ ---- */
.chapters {
  position: absolute;
  right: calc(10px + var(--safe-r));
  bottom: calc(72px + var(--safe-b));
  max-height: 50%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(8px);
}
.chapters button {
  appearance: none;
  border: 0;
  padding: 9px 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.chapters button:hover { background: var(--accent); }

/* ---- 一覧へ戻る（シーン一覧から開いたときだけ）---- */
.back {
  position: absolute;
  top: 10px;
  left: calc(10px + var(--safe-l));
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 13px;
  text-decoration: none;
  z-index: 1;
}
.back:hover { background: var(--accent); }
.back:not([hidden]) ~ .brand { left: calc(96px + var(--safe-l)); }

/* ---- ロゴ・問い合わせ ---- */
.brand { position: absolute; top: 10px; left: calc(10px + var(--safe-l)); display: block; }
.brand img { display: block; height: 34px; max-width: 160px; object-fit: contain; filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.5)); }
.contact {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.contact:hover { background: var(--accent); }

/* ---- ミニマップ ---- */
.minimap {
  position: absolute;
  top: 10px;
  right: calc(10px + var(--safe-r));
  width: 150px;
  height: 150px;
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  cursor: pointer;
}

/* ---- ジョイスティック ---- */
.joystick {
  position: absolute;
  left: calc(18px + var(--safe-l));
  bottom: calc(78px + var(--safe-b));
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 2px solid rgba(255, 255, 255, 0.45);
  touch-action: none;
}
.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  will-change: transform;
}
.joystick.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px rgba(47, 140, 255, 0.35); } }

/* ---- 操作ヒント ---- */
.hint {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  padding: 14px 20px;
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.6;
  pointer-events: none;
  animation: hint-in 0.4s ease;
  max-width: 86%;
}
.hint.out { opacity: 0; transition: opacity 0.4s ease; }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, -42%); } }
.hint svg { display: block; width: 56px; height: 56px; margin: 0 auto 6px; fill: none; stroke: #fff; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.hint .hand { animation: swipe 1.6s ease-in-out infinite; }
@keyframes swipe { 0%, 100% { transform: translateX(-16px); } 50% { transform: translateX(16px); } }
.hint .keys { display: inline-grid; grid-template-columns: repeat(3, 30px); gap: 4px; margin-bottom: 8px; }
.hint .keys span {
  height: 30px;
  border-radius: 6px;
  border: 1.5px solid rgba(255, 255, 255, 0.8);
  display: grid;
  place-items: center;
  font-size: 13px;
}
.hint .keys span:first-child { grid-column: 2; }
.hint .keys span:nth-child(2) { grid-column: 1; }
.hint small { display: block; font-weight: 400; opacity: 0.85; }

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(76px + var(--safe-b));
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  font-size: 13px;
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast input { width: min(60vw, 360px); font: inherit; user-select: text; -webkit-user-select: text; }

/* ---- 注釈ピン ---- */
.pins { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pin {
  position: absolute;
  left: 0;
  top: 0;
  appearance: none;
  border: 0;
  padding: 0;
  background: none;
  color: #fff;
  font: inherit;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  will-change: transform, opacity;
}
.pin::before {
  content: "";
  width: 18px;
  height: 18px;
  margin: -9px 0 -9px -9px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}
.pin span {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 12px;
  white-space: nowrap;
}
.card {
  position: absolute;
  left: 50%;
  bottom: calc(76px + var(--safe-b));
  transform: translateX(-50%);
  width: min(360px, calc(100% - 24px));
  max-height: 60%;
  overflow: auto;
  padding: 16px 18px;
  border-radius: 14px;
  background: rgba(18, 22, 28, 0.9);
  backdrop-filter: blur(8px);
  user-select: text;
  -webkit-user-select: text;
}
.card h2 { margin: 0 28px 8px 0; font-size: 16px; }
.card p { margin: 0; font-size: 14px; line-height: 1.7; white-space: pre-wrap; }
.card-image { display: block; width: 100%; border-radius: 8px; margin-bottom: 10px; }
.card-links { display: flex; flex-wrap: wrap; gap: 8px; }
.card-links:not(:empty) { margin-top: 12px; }
.card-link {
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 13px;
  text-decoration: none;
}
.card-link:hover { background: rgba(255, 255, 255, 0.25); }
.card-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

@media (max-width: 560px) {
  .minimap { width: 104px; height: 104px; }
  .contact { top: auto; bottom: calc(66px + var(--safe-b)); left: auto; right: calc(10px + var(--safe-r)); transform: none; }
  .bar-text { padding: 0 6px; }
  .brand img { height: 26px; max-width: 110px; }
}

/* ---- エディタ（?edit=1）---- */
.app.editing { right: 340px; }
.editor {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  overflow: auto;
  background: #171b21;
  border-left: 1px solid #2c333d;
  font-size: 13px;
  user-select: text;
  -webkit-user-select: text;
}
.editor h2 { margin: 0; padding: 12px 14px 4px; font-size: 14px; }
.editor .ed-sub { padding: 0 14px 8px; opacity: 0.7; font-size: 12px; line-height: 1.5; }
.ed-tabs { display: flex; position: sticky; top: 0; background: #171b21; border-bottom: 1px solid #2c333d; z-index: 1; }
.ed-tabs button {
  flex: 1;
  appearance: none;
  border: 0;
  padding: 10px 2px;
  background: none;
  color: #9aa4b1;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.ed-tabs button.on { color: #fff; border-bottom-color: var(--accent); }
.ed-page { padding: 10px 14px 24px; }
.ed-page p { margin: 0 0 10px; line-height: 1.6; color: #b8c0cb; }
.ed-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.ed-row > label { flex: none; min-width: 84px; color: #b8c0cb; }
.editor button.ed-btn {
  appearance: none;
  border: 1px solid #3a4350;
  border-radius: 6px;
  padding: 6px 9px;
  background: #232a33;
  color: #fff;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.editor button.ed-btn:hover { background: #2e3743; }
.editor button.ed-btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 700; }
.editor button.ed-btn.on { background: #1f5fae; border-color: var(--accent); }
.editor button.ed-btn.danger { color: #ff9c9c; }
.editor input[type="number"], .editor input[type="text"], .editor select, .editor textarea {
  flex: 1;
  min-width: 0;
  padding: 5px 7px;
  border: 1px solid #3a4350;
  border-radius: 6px;
  background: #0f1317;
  color: #fff;
  font: inherit;
  font-size: 12px;
}
.editor input[type="number"] { max-width: 90px; }
.editor textarea { width: 100%; min-height: 54px; resize: vertical; }
.ed-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 12px; }
.ed-item { padding: 8px; border: 1px solid #2c333d; border-radius: 8px; background: #1d232b; }
.ed-item.sel { border-color: var(--accent); }
.ed-item .ed-row:last-child { margin-bottom: 0; }
.ed-num { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.ed-warn { padding: 8px 10px; border-radius: 6px; background: #4a2a2a; color: #ffc9c9; margin-bottom: 10px; line-height: 1.5; }
.ed-ok { padding: 8px 10px; border-radius: 6px; background: #1f3a2b; color: #c9ffd9; margin-bottom: 10px; line-height: 1.5; }
.ed-status { position: sticky; bottom: 0; padding: 8px 14px; background: #10141a; border-top: 1px solid #2c333d; font-size: 12px; color: #b8c0cb; }
.ed-markers { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.ed-marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 2px solid #fff;
  will-change: transform;
}
.ed-marker.corner { background: #ff9d2f; pointer-events: auto; cursor: move; touch-action: none; }
.ed-marker.corner.sel { background: #ff4d4d; }
.ed-marker.mid { width: 14px; height: 14px; margin: -7px 0 0 -7px; background: rgba(255, 157, 47, 0.55); border-width: 1px; pointer-events: auto; cursor: copy; }
.ed-marker.pinm { background: #29b36a; }
.ed-cross {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  pointer-events: none;
  background:
    linear-gradient(#fff, #fff) center / 2px 100% no-repeat,
    linear-gradient(#fff, #fff) center / 100% 2px no-repeat;
  mix-blend-mode: difference;
}
@media (max-width: 760px) {
  .app.editing { right: 0; bottom: 45%; }
  .editor { top: 55%; width: 100%; border-left: 0; border-top: 1px solid #2c333d; }
}
