/* ============================================================
   Library Quest（クエストメーカー） 共通スタイル
   デザイン方針: 「本を探す冒険」の楽しさ × 整理された清潔な見た目
   トークンは仕様書1.1章に準拠。他アプリの配色（青・紫・ネイビー）は踏襲しない。
============================================================ */

:root {
  --bg: #FBFAF6;
  --main: #FF7A50;
  --main-hover: #F0653A;
  --main-light: #FFE9E0;
  --sub: #1FB8A6;
  --sub-light: #E3FBF7;
  --reward: #FFC93C;
  --reward-light: #FFF6DC;
  --text: #2B2620;
  --text-sub: #8A8378;
  --card: #FFFFFF;
  --border: #EDE8DD;
  --danger: #E85D5D;
  --shadow: 0 4px 16px rgba(43, 38, 32, 0.06);
  --shadow-lg: 0 8px 28px rgba(43, 38, 32, 0.10);
  --radius: 20px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans JP', sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3, .qm-heading {
  font-family: 'M PLUS Rounded 1c', 'Noto Sans JP', sans-serif;
  font-weight: 800;
  color: var(--text);
  margin: 0;
}

a { color: inherit; text-decoration: none; }

/* ---- レイアウト共通 ---- */
.qm-page {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.qm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.qm-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
}

.qm-header-title .qm-logo-badge {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--main);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow);
}

.qm-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.qm-card-title {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- クエスト作成画面: セクション見出し・進捗レール（情報設計の整理） ---- */
.qm-section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 800;
  margin: 32px 0 14px;
}

.qm-section:first-of-type .qm-section-heading { margin-top: 0; }

.qm-section-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--main);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  flex-shrink: 0;
}

.qm-progress-rail {
  display: flex;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px;
  margin-bottom: 24px;
  position: sticky;
  top: 12px;
  z-index: 50;
  box-shadow: var(--shadow);
}

.qm-rail-step {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  min-height: 44px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  transition: all 0.2s ease;
  cursor: pointer;
}

.qm-rail-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #F1EFE9;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.qm-rail-step.active { background: var(--main-light); color: var(--main-hover); }
.qm-rail-step.active .qm-rail-num { background: var(--main); color: #fff; }

/* ---- ボタン ---- */
.qm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.qm-btn:active { transform: scale(0.97); }
.qm-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.qm-btn-main {
  background: var(--main);
  color: #fff;
  box-shadow: 0 4px 14px rgba(255, 122, 80, 0.35);
}
.qm-btn-main:hover:not(:disabled) { background: var(--main-hover); }

.qm-btn-sub {
  background: var(--sub-light);
  color: var(--sub);
}
.qm-btn-sub:hover:not(:disabled) { background: #d3f6f1; }

.qm-btn-ghost {
  background: transparent;
  color: var(--text-sub);
  border: 1.5px solid var(--border);
}
.qm-btn-ghost:hover:not(:disabled) { border-color: var(--text-sub); color: var(--text); }

.qm-btn-danger {
  background: #FDEDED;
  color: var(--danger);
}

.qm-btn-block { width: 100%; }
.qm-btn-lg { padding: 15px 24px; font-size: 16px; }

/* ---- フォーム ---- */
.qm-field { margin-bottom: 16px; }

.qm-label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 6px;
}

.qm-input, .qm-textarea, .qm-select {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 14.5px;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s ease;
}

.qm-input:focus, .qm-textarea:focus, .qm-select:focus {
  outline: none;
  border-color: var(--main);
}

.qm-textarea { resize: vertical; min-height: 70px; font-family: inherit; }

/* ---- バッジ・タグ ---- */
.qm-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}

.qm-badge-main { background: var(--main-light); color: var(--main-hover); }
.qm-badge-sub { background: var(--sub-light); color: var(--sub); }
.qm-badge-reward { background: var(--reward-light); color: #9A6B00; }
.qm-badge-gray { background: #F1EFE9; color: var(--text-sub); }

/* ---- プログレスバー ---- */
.qm-progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #F1EFE9;
  overflow: hidden;
}

.qm-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--main), var(--reward));
  transition: width 0.5s cubic-bezier(0.34, 1.2, 0.64, 1);
}

/* ---- スタンプ演出（シグネチャー要素） ----
   ステップクリア時に共通で使う。play.html / monitor.html 双方で流用。 */
.qm-stamp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 4px solid var(--main);
  color: var(--main);
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-weight: 900;
  font-size: 13px;
  transform: rotate(-8deg) scale(0);
  opacity: 0;
}

.qm-stamp.qm-stamp-show {
  animation: qmStampPop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes qmStampPop {
  0% { transform: rotate(-8deg) scale(0); opacity: 0; }
  60% { transform: rotate(-8deg) scale(1.15); opacity: 1; }
  100% { transform: rotate(-8deg) scale(1); opacity: 1; }
}

/* ---- ログイン画面専用 ---- */
.qm-login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.qm-login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.qm-login-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--main);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  margin: 0 auto 16px;
  box-shadow: 0 6px 18px rgba(255, 122, 80, 0.4);
}

.qm-error-text {
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  margin-top: 10px;
  min-height: 18px;
}

/* ---- スキャナー共通 ---- */
.qm-scanner-box {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #1a1814;
}

.qm-scanner-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qm-scan-frame {
  position: absolute;
  inset: 14%;
  border: 3px solid var(--reward);
  border-radius: 16px;
  pointer-events: none;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35);
}

/* ---- 過去のクエスト管理（複製・リセット・削除） ---- */
.qm-quest-mgmt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.qm-quest-mgmt-row:last-child { border-bottom: none; }

.qm-quest-mgmt-info { min-width: 0; flex: 1; }
.qm-quest-mgmt-title { font-weight: 800; font-size: 14px; }
.qm-quest-mgmt-meta { font-size: 11.5px; color: var(--text-sub); margin-top: 2px; }

.qm-quest-mgmt-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.qm-quest-mgmt-actions .qm-btn {
  padding: 8px 12px;
  font-size: 12.5px;
}

/* ---- テンプレート選択カード ---- */
.qm-template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.qm-template-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: left;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.qm-template-card:hover { border-color: var(--main); transform: translateY(-2px); }

.qm-template-card-emoji { font-size: 22px; margin-bottom: 6px; }
.qm-template-card-title { font-size: 13.5px; font-weight: 800; margin-bottom: 3px; }
.qm-template-card-desc { font-size: 11.5px; color: var(--text-sub); line-height: 1.4; }

/* ---- ステップ編集カード ---- */
.qm-step-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  margin-bottom: 14px;
  background: #FFFDF9;
  position: relative;
}

.qm-step-num {
  position: absolute;
  top: -12px;
  left: 16px;
  background: var(--main);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.qm-step-remove {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-sub);
  cursor: pointer;
  font-size: 16px;
  /* 見た目の位置・サイズは変えず、パディング+負のマージンでタップ領域だけ約40px四方に拡大 */
  padding: 12px;
  margin: -12px;
}

.qm-book-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--sub-light);
  margin-top: 8px;
}

.qm-book-preview img {
  width: 36px;
  height: 50px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.qm-book-preview-text { font-size: 12.5px; line-height: 1.4; }
.qm-book-preview-title { font-weight: 800; }
.qm-book-preview-author { color: var(--text-sub); }

/* ---- 参加者プレイ画面: 冒険の道のり風プログレス ---- */
.qm-map-progress {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  /* ステップ数が多いクエストでは28px固定のノードが画面幅を超えうるため、
     溢れる場合は横スクロールに逃がして崩れを防ぐ */
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
}

.qm-map-node {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 900;
  flex-shrink: 0;
  background: #F1EFE9;
  color: var(--text-sub);
  border: 3px solid #F1EFE9;
  transition: all 0.3s ease;
}

.qm-map-node.qm-map-done { background: var(--sub); color: #fff; border-color: var(--sub); }

.qm-map-node.qm-map-current {
  background: #fff;
  color: var(--main);
  border-color: var(--main);
  box-shadow: 0 0 0 4px var(--main-light);
  animation: qmMapPulse 1.6s ease-in-out infinite;
}

@keyframes qmMapPulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--main-light); }
  50% { box-shadow: 0 0 0 8px var(--main-light); }
}

.qm-map-node.qm-map-goal { font-size: 14px; }

.qm-map-line {
  flex: 1;
  height: 4px;
  background: #F1EFE9;
  margin: 0 2px;
  border-radius: 2px;
}

.qm-map-line.qm-map-line-filled { background: var(--sub); }

.qm-play-wrap {
  max-width: 440px;
  margin: 0 auto;
  padding: 24px 18px 50px;
  text-align: center;
}

.qm-mission-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px 24px;
  margin-bottom: 20px;
  text-align: left;
}

.qm-mission-step-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--sub);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- ミッションのテーマアイコン（判定方法に応じて自動表示） ---- */
.qm-mission-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--main-light);
  font-size: 16px;
  flex-shrink: 0;
}

.qm-mission-text {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.5;
  margin-bottom: 16px;
}

/* ---- ヒント開示: display切替ではなくスライドダウン+フェードインで開く ---- */
.qm-hint-box {
  background: var(--reward-light);
  border-radius: var(--radius-sm);
  padding: 0 16px;
  font-size: 13.5px;
  color: #7A5600;
  line-height: 1.6;
  margin-top: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.3s ease, padding 0.35s ease, margin-top 0.35s ease;
}

.qm-hint-box.qm-hint-open {
  padding: 14px 16px;
  margin-top: 12px;
  max-height: 300px;
  opacity: 1;
}

.qm-feedback {
  font-size: 14px;
  font-weight: 700;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
  display: none;
}

.qm-feedback.show { display: block; }
.qm-feedback.correct { background: var(--sub-light); color: var(--sub); }
.qm-feedback.wrong { background: #FDEDED; color: var(--danger); }

/* ---- 不正解時のやさしい揺れ演出（ミッションカードに一時的に付与） ---- */
.qm-mission-card.qm-shake {
  animation: qmShake 0.4s ease;
}

@keyframes qmShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* ---- クリア画面のトロフィー・バウンスイン演出 ---- */
#complete-trophy.qm-trophy-bounce {
  animation: qmTrophyBounce 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes qmTrophyBounce {
  0% { transform: scale(0) rotate(-15deg); opacity: 0; }
  60% { transform: scale(1.25) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ---- 紙吹雪演出（正解時・クリア時共通。DOM+CSSのみでライブラリ不使用） ---- */
.qm-confetti-piece {
  position: fixed;
  top: -20px;
  width: 9px;
  height: 14px;
  z-index: 10000;
  pointer-events: none;
  opacity: 0.95;
  animation-name: qmConfettiFall;
  animation-timing-function: cubic-bezier(0.4, 0.1, 0.6, 0.9);
  animation-fill-mode: forwards;
}

@keyframes qmConfettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(540deg); opacity: 0; }
}

/* ---- モニター・振り返り 共通の参加者リスト ---- */
.qm-participant-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.qm-participant-row:last-child { border-bottom: none; }

.qm-participant-name { font-weight: 800; font-size: 14px; flex-shrink: 0; width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.qm-participant-bar-wrap { flex: 1; min-width: 0; }

.qm-participant-meta { font-size: 11px; color: var(--text-sub); margin-top: 4px; }

.qm-rank-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--reward-light);
  color: #9A6B00;
  font-size: 12px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.qm-rank-num.qm-rank-1 { background: var(--reward); color: #fff; }
.qm-rank-num.qm-rank-2 { background: #D8DCE3; color: #475569; }
.qm-rank-num.qm-rank-3 { background: #E3B583; color: #7C4A1E; }

/* ---- 実況モニター: クリア済み/挑戦中グループ分け・カード形式の参加者行 ---- */
.qm-participant-group-title {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-sub);
  margin: 18px 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.qm-participant-group-title:first-child { margin-top: 0; }

.qm-participant-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: #FFFDF9;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.qm-participant-card.qm-participant-done {
  background: var(--reward-light);
  border-color: #FFE29A;
}

.qm-participant-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--sub);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}

.qm-participant-card.qm-participant-done .qm-participant-avatar { background: var(--reward); }

.qm-participant-card-info { flex: 1; min-width: 0; }

.qm-participant-card-name {
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- 空状態・ローディング ---- */
.qm-empty-msg {
  text-align: center;
  color: var(--text-sub);
  font-size: 13.5px;
  padding: 30px 0;
}

.qm-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--main);
  border-radius: 50%;
  animation: qmSpin 0.7s linear infinite;
  margin: 0 auto;
}

@keyframes qmSpin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .qm-template-grid { grid-template-columns: 1fr; }
  .qm-header { flex-direction: column; align-items: stretch; }
  .qm-rail-label { display: none; }

  .qm-map-node { width: 24px; height: 24px; font-size: 11px; }
  .qm-map-node.qm-map-goal { font-size: 13px; }
}
