/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6C5CE7;
  --primary-dark: #5A4BD1;
  --secondary: #00B894;
  --secondary-dark: #00A381;
  --accent: #E17055;
  --bg: #F0F2F5;
  --card-bg: #FFFFFF;
  --text: #2D3436;
  --text-light: #636E72;
  --border: #DFE6E9;
  --danger: #D63031;
  --success: #00B894;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
}

/* ===== View System ===== */
.view { display: none; min-height: 100dvh; padding: 1rem; }
.view.active { display: block; }

.container { max-width: 640px; margin: 0 auto; }
.container.center { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: calc(100dvh - 2rem); }

/* ===== Typography ===== */
.logo { font-size: 2.5rem; font-weight: 800; color: var(--primary); margin-bottom: 0.5rem; letter-spacing: -0.02em; }
.subtitle { color: var(--text-light); font-size: 1.1rem; margin-bottom: 2rem; }
.section-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.5rem; text-align: center; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.625rem 1.25rem; border: none; border-radius: var(--radius-sm);
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s;
  text-decoration: none; gap: 0.5rem;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: var(--secondary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: #D35A3F; }
.btn-ghost { background: transparent; color: var(--text-light); }
.btn-ghost:hover { background: rgba(0,0,0,0.05); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; }
.btn-lg { padding: 0.875rem 1.75rem; font-size: 1.125rem; }
.btn-full { width: 100%; }

.btn-group { display: flex; gap: 1rem; }
.btn-group.vertical { flex-direction: column; width: 100%; max-width: 320px; }

/* ===== Cards ===== */
.card {
  background: var(--card-bg); border-radius: var(--radius); padding: 1.5rem;
  box-shadow: var(--shadow); margin-bottom: 1rem; width: 100%;
}
.card h3 { font-size: 1.1rem; margin-bottom: 1rem; color: var(--text); }

/* ===== Forms ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; font-size: 0.875rem; margin-bottom: 0.375rem; color: var(--text-light); }

input[type="text"], input[type="number"], textarea, select {
  width: 100%; padding: 0.625rem 0.875rem; border: 2px solid var(--border);
  border-radius: var(--radius-sm); font-size: 1rem; transition: border-color 0.2s;
  font-family: inherit; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }

.range-group { display: flex; align-items: center; gap: 1rem; }
.range-group input[type="range"] { flex: 1; }
.range-group span { font-weight: 700; font-size: 1.25rem; min-width: 2rem; text-align: center; }

.hint { font-size: 0.85rem; color: var(--text-light); padding: 0.5rem; background: #FFF3E0; border-radius: var(--radius-sm); margin-bottom: 1rem; }

/* ===== Options Edit (Host Setup) ===== */
.options-edit-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.option-edit-row { display: flex; align-items: center; gap: 0.5rem; }
.option-edit-row .option-label { font-weight: 700; font-size: 0.875rem; min-width: 1.5rem; color: var(--primary); }
.option-edit-row input { flex: 1; }

/* ===== Quiz List (Host Setup) ===== */
.quiz-list { display: flex; flex-direction: column; gap: 0.5rem; }
.quiz-list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; background: var(--bg); border-radius: var(--radius-sm);
  gap: 0.75rem;
}
.quiz-list-item .quiz-info { flex: 1; min-width: 0; }
.quiz-list-item .quiz-num { font-weight: 700; color: var(--primary); min-width: 2.5rem; }
.quiz-list-item .quiz-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.9rem; }
.quiz-list-item .quiz-meta { font-size: 0.75rem; color: var(--text-light); }
.quiz-list-actions { display: flex; gap: 0.25rem; }
.empty-msg { color: var(--text-light); text-align: center; padding: 1rem; font-size: 0.9rem; }

/* ===== Admin Link ===== */
.admin-link { margin-top: 2rem; font-size: 0.8rem; color: var(--text-light); opacity: 0.5; }
.admin-link:hover { opacity: 1; }

/* ===== Card Header Bar ===== */
.card-header-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-header-bar h3 { margin-bottom: 0; }

/* ===== Filter Bar ===== */
.filter-bar { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.filter-bar input { flex: 1; }

/* ===== Filter Chips (Type Multi-Select) ===== */
.filter-chips { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-bottom: 0.75rem; }
.type-chip {
  display: inline-flex; align-items: center; padding: 0.3rem 0.75rem;
  background: var(--bg); border: 2px solid var(--border); border-radius: 2rem;
  font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: all 0.2s;
  user-select: none;
}
.type-chip:hover { border-color: var(--secondary); }
.type-chip.active { background: var(--secondary); color: #fff; border-color: var(--secondary); }

/* ===== Tag List ===== */
.tag-list { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-bottom: 0.75rem; }
.tag-chip {
  display: inline-flex; align-items: center; padding: 0.25rem 0.75rem;
  background: var(--bg); border: 2px solid var(--border); border-radius: 2rem;
  font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: all 0.2s;
  user-select: none;
}
.tag-chip:hover { border-color: var(--primary); }
.tag-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tag-chip .tag-count { margin-left: 0.25rem; opacity: 0.7; font-size: 0.75rem; }

/* ===== Quiz Select List (Room Create) ===== */
.quiz-select-item {
  display: flex; align-items: center; padding: 0.75rem 1rem;
  background: var(--bg); border-radius: var(--radius-sm); gap: 0.75rem;
  cursor: pointer; transition: all 0.2s; border: 2px solid transparent;
}
.quiz-select-item:hover { border-color: var(--primary); }
.quiz-select-item.selected { border-color: var(--primary); background: #EBF5FB; }
.quiz-select-item .quiz-check {
  width: 1.5rem; height: 1.5rem; border: 2px solid var(--border); border-radius: 4px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-size: 0.9rem; color: #fff; transition: all 0.2s;
}
.quiz-select-item.selected .quiz-check { background: var(--primary); border-color: var(--primary); }

/* ===== Quiz Tags Display ===== */
.quiz-tags { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.25rem; }
.quiz-tag {
  display: inline-block; padding: 0.125rem 0.5rem; border-radius: 2rem;
  font-size: 0.7rem; font-weight: 600; background: var(--primary); color: #fff; opacity: 0.8;
}

/* ===== Stock Quiz Checkbox ===== */
.stock-checkbox {
  width: 1.25rem; height: 1.25rem; accent-color: var(--primary);
  cursor: pointer; flex-shrink: 0;
}

/* ===== Bulk Actions ===== */
.bulk-actions { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }

/* ===== Order Controls ===== */
.order-controls { display: flex; align-items: center; gap: 0.5rem; }
.order-label { font-size: 0.8rem; font-weight: 600; color: var(--text-light); white-space: nowrap; }
.order-controls select { padding: 0.3rem 0.5rem; font-size: 0.85rem; min-width: auto; width: auto; }

/* ===== Selected Quiz Reorder ===== */
.selected-quiz-item {
  display: flex; align-items: center; padding: 0.75rem 1rem;
  background: var(--bg); border-radius: var(--radius-sm); gap: 0.75rem;
}
.selected-quiz-item .reorder-actions { display: flex; flex-direction: column; gap: 0.125rem; }
.selected-quiz-item .reorder-actions button {
  background: var(--border); border: none; border-radius: 4px; width: 1.75rem; height: 1.5rem;
  font-size: 0.75rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.selected-quiz-item .reorder-actions button:hover { background: var(--primary); color: #fff; }
.selected-quiz-item .reorder-actions button:disabled { opacity: 0.3; cursor: not-allowed; }
.selected-quiz-item .reorder-actions button:disabled:hover { background: var(--border); color: inherit; }

/* ===== Room Code Display ===== */
.room-code-display {
  display: flex; flex-direction: column; align-items: center;
  margin: 1.5rem 0; padding: 1.5rem 2rem; background: var(--card-bg);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.room-code-display .label { font-size: 0.875rem; color: var(--text-light); font-weight: 600; }
.room-code-display .code { font-size: 3.5rem; font-weight: 800; letter-spacing: 0.75rem; color: var(--primary); }

/* ===== Participant List ===== */
.participant-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.participant-chip {
  display: inline-flex; align-items: center; padding: 0.5rem 1rem;
  background: var(--bg); border-radius: 2rem; font-weight: 600; font-size: 0.9rem;
}

/* ===== Game Header ===== */
.game-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 1rem; font-weight: 700;
}
.timer {
  font-size: 1.75rem; font-weight: 800; color: var(--accent);
  min-width: 3rem; text-align: center;
}
.timer.urgent { color: var(--danger); animation: pulse 0.5s infinite; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ===== Quiz Display ===== */
.quiz-type-badge {
  display: inline-block; padding: 0.25rem 0.75rem; border-radius: 2rem;
  font-size: 0.8rem; font-weight: 700; background: var(--primary); color: #fff;
  margin-bottom: 0.75rem;
}
.quiz-question {
  font-size: 1.5rem; font-weight: 700; text-align: center;
  margin-bottom: 1.5rem; line-height: 1.4; word-break: break-word;
}

/* ===== Options Display (Host) ===== */
.options-display { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.option-card {
  padding: 1rem; border-radius: var(--radius-sm); color: #fff;
  font-weight: 700; font-size: 1.1rem; text-align: center;
  min-height: 3.5rem; display: flex; align-items: center; justify-content: center;
  word-break: break-word;
}

/* ===== Options Grid (Participant) ===== */
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.option-btn {
  padding: 1rem; border: none; border-radius: var(--radius-sm); color: #fff;
  font-weight: 700; font-size: 1.1rem; cursor: pointer; text-align: center;
  min-height: 3.5rem; transition: all 0.2s; display: flex; align-items: center; justify-content: center;
  word-break: break-word;
}
.option-btn:hover { transform: scale(1.03); filter: brightness(1.1); }
.option-btn:active { transform: scale(0.97); }
.option-btn.selected { box-shadow: 0 0 0 4px #fff, 0 0 0 6px var(--primary); }

/* Option Colors */
.opt-color-0 { background: #E74C3C; }
.opt-color-1 { background: #3498DB; }
.opt-color-2 { background: #2ECC71; }
.opt-color-3 { background: #F39C12; }
.opt-color-4 { background: #9B59B6; }
.opt-color-5 { background: #1ABC9C; }
.opt-color-6 { background: #E67E22; }
.opt-color-7 { background: #E84393; }

/* ===== Sort List ===== */
.sort-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.sort-item {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem;
  background: var(--card-bg); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-weight: 600; cursor: grab; user-select: none;
}
.sort-item .sort-handle { color: var(--text-light); font-size: 1.25rem; }
.sort-item .sort-num { color: var(--primary); font-weight: 800; min-width: 1.5rem; }
.sort-item .sort-text { flex: 1; }
.sort-item .sort-actions { display: flex; gap: 0.25rem; }
.sort-item .sort-actions button {
  background: var(--bg); border: none; border-radius: 4px; width: 2rem; height: 2rem;
  font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.sort-item .sort-actions button:hover { background: var(--border); }

/* ===== Tally Chart ===== */
.tally-chart { margin-bottom: 1.5rem; }
.tally-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.tally-label { min-width: 80px; font-weight: 600; font-size: 0.9rem; text-align: right; word-break: break-word; }
.tally-bar-wrap { flex: 1; background: var(--border); border-radius: 4px; height: 2rem; overflow: hidden; position: relative; }
.tally-bar { height: 100%; border-radius: 4px; transition: width 0.6s ease-out; display: flex; align-items: center; justify-content: flex-end; padding-right: 0.5rem; }
.tally-bar span { color: #fff; font-weight: 700; font-size: 0.85rem; }
.tally-count { min-width: 2.5rem; font-weight: 700; text-align: center; }

/* ===== Correct Answer Display ===== */
.correct-answer-display {
  text-align: center; padding: 1.5rem; margin-bottom: 1.5rem;
  background: linear-gradient(135deg, #00B894, #00CEC9); color: #fff;
  border-radius: var(--radius); font-size: 1.5rem; font-weight: 700;
}

/* ===== Scoreboard ===== */
.scoreboard { margin-bottom: 1.5rem; }
.score-row {
  display: flex; align-items: center; padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border); gap: 0.75rem;
}
.score-row:last-child { border-bottom: none; }
.score-rank { font-weight: 800; min-width: 2rem; color: var(--primary); }
.score-name { flex: 1; font-weight: 600; }
.score-pts { font-weight: 700; color: var(--accent); }

/* ===== Answered Message ===== */
.answered-message { text-align: center; padding: 3rem 1rem; }
.check-icon { font-size: 4rem; color: var(--success); margin-bottom: 0.5rem; }
.answered-message p { font-size: 1.25rem; font-weight: 700; color: var(--text-light); }
.answered-detail { margin-top: 1rem; font-size: 0.95rem; color: var(--text); }
.answered-detail .detail-answer { font-weight: 600; margin-bottom: 0.25rem; }
.answered-detail .detail-time { color: var(--text-light); font-size: 0.85rem; }

/* ===== Result Display ===== */
.result-display { text-align: center; padding: 2rem 1rem; }
.result-display .result-icon { font-size: 4rem; margin-bottom: 0.5rem; }
.result-display .result-text { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
.result-display .result-answer { font-size: 1.1rem; color: var(--text-light); }

/* ===== Podium ===== */
.podium {
  display: flex; align-items: flex-end; justify-content: center;
  gap: 0.5rem; margin-bottom: 2rem;
}
.podium-item { display: flex; flex-direction: column; align-items: center; width: 100px; }
.podium-name { font-weight: 700; font-size: 0.9rem; margin-bottom: 0.25rem; text-align: center; word-break: break-all; }
.podium-score { font-weight: 600; font-size: 0.8rem; color: var(--text-light); margin-bottom: 0.5rem; }
.podium-bar {
  width: 100%; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 0.75rem;
  font-size: 2rem; font-weight: 800; color: #fff;
}
.podium-bar.gold { background: linear-gradient(180deg, #F1C40F, #F39C12); height: 160px; }
.podium-bar.silver { background: linear-gradient(180deg, #BDC3C7, #95A5A6); height: 120px; }
.podium-bar.bronze { background: linear-gradient(180deg, #E67E22, #D35400); height: 80px; }

/* ===== Ranking List ===== */
.ranking-list { width: 100%; margin-bottom: 1.5rem; }
.rank-row {
  display: flex; align-items: center; padding: 0.75rem 1rem;
  background: var(--card-bg); border-radius: var(--radius-sm); margin-bottom: 0.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05); gap: 0.75rem;
}
.rank-num { font-weight: 800; font-size: 1.1rem; min-width: 2rem; color: var(--primary); }
.rank-name { flex: 1; font-weight: 600; }
.rank-score { font-weight: 700; color: var(--accent); }
.rank-time { font-size: 0.8rem; color: var(--text-light); }

/* ===== Final Result Personal ===== */
.final-result-personal {
  text-align: center; padding: 2rem; margin-bottom: 1.5rem;
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
}
.final-result-personal .place { font-size: 3rem; font-weight: 800; color: var(--primary); }
.final-result-personal .place-label { font-size: 1.25rem; font-weight: 600; }
.final-result-personal .stats { margin-top: 1rem; color: var(--text-light); }

/* ===== Waiting Animation ===== */
.waiting-animation { margin-top: 2rem; }
.dot-pulse { display: flex; gap: 0.5rem; justify-content: center; }
.dot-pulse::before, .dot-pulse::after, .dot-pulse {
  content: ''; width: 12px; height: 12px; border-radius: 50%;
  background: var(--primary); animation: dotPulse 1.4s infinite ease-in-out;
}
.dot-pulse::before { animation-delay: -0.32s; }
.dot-pulse::after { animation-delay: 0.32s; }
@keyframes dotPulse { 0%,80%,100% { transform: scale(0.4); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }

/* ===== Overlay & Toast ===== */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.spinner {
  width: 48px; height: 48px; border: 4px solid #fff;
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
  padding: 0.75rem 1.5rem; background: var(--text); color: #fff;
  border-radius: var(--radius-sm); font-weight: 600; z-index: 200;
  animation: toastIn 0.3s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(1rem); } }

.header-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.header-bar h2 { font-size: 1.25rem; }

/* ===== Abort Modal ===== */
.abort-modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
  max-width: 360px;
  width: 90%;
  box-shadow: var(--shadow);
}
.abort-modal-content .abort-icon { font-size: 3rem; margin-bottom: 1rem; }
.abort-modal-content h2 { font-size: 1.4rem; margin-bottom: 0.5rem; color: var(--danger); }
.abort-modal-content p { color: var(--text-light); margin-bottom: 1.5rem; }

/* ===== Responsive: Small ===== */
@media (max-width: 480px) {
  .logo { font-size: 2rem; }
  .quiz-question { font-size: 1.2rem; }
  .room-code-display .code { font-size: 2.5rem; letter-spacing: 0.5rem; }
  .options-display, .options-grid { grid-template-columns: 1fr; }
  .podium-item { width: 80px; }
}

/* ===== Responsive: Host Wide (PC / Tablet / Projector) ===== */
@media (min-width: 768px) {
  /* 主催者画面はコンテナを広く */
  [id^="view-host-game"] .container,
  [id^="view-host-lobby"] .container,
  [id^="view-host-final"] .container {
    max-width: 960px;
  }
  [id^="view-host-quiz-manage"] .container,
  [id^="view-host-room-create"] .container {
    max-width: 800px;
  }

  /* ゲーム画面: 問題・タイマーを大きく */
  .game-header {
    padding: 1rem 1.5rem;
    font-size: 1.2rem;
  }
  .timer {
    font-size: 3rem;
    min-width: 4.5rem;
  }
  .quiz-question {
    font-size: 2.2rem;
    margin-bottom: 2rem;
  }
  .quiz-type-badge {
    font-size: 1rem;
    padding: 0.375rem 1rem;
  }

  /* 選択肢を大きく */
  .options-display {
    gap: 1rem;
  }
  .option-display-item {
    font-size: 1.4rem;
    min-height: 4.5rem;
    padding: 1.25rem;
  }

  /* 集計チャート */
  .tally-label { font-size: 1.1rem; min-width: 120px; }
  .tally-bar-wrap { height: 2.5rem; }
  .tally-bar span { font-size: 1rem; }
  .tally-count { font-size: 1.1rem; }

  /* 正解発表 */
  .correct-answer-display {
    font-size: 2.2rem;
    padding: 2rem;
  }

  /* スコアボード */
  .score-row {
    padding: 0.75rem 1rem;
    font-size: 1.1rem;
  }

  /* ロビー: 部屋コードを大きく */
  .room-code-display .code {
    font-size: 5rem;
    letter-spacing: 1rem;
  }
  .room-code-display .label {
    font-size: 1.1rem;
  }

  /* 最終結果: 表彰台を大きく */
  .podium-item { width: 140px; }
  .podium-name { font-size: 1.1rem; }
  .podium-score { font-size: 1rem; }
  .podium-bar { font-size: 2.5rem; }
  .podium-bar.gold { height: 220px; }
  .podium-bar.silver { height: 160px; }
  .podium-bar.bronze { height: 110px; }

  .rank-row { padding: 0.75rem 1rem; font-size: 1.1rem; }
  .rank-num { font-size: 1.3rem; }

  .section-title { font-size: 1.8rem; }
}

/* ===== Responsive: Host Extra Wide (Large Screen / Projector) ===== */
@media (min-width: 1200px) {
  [id^="view-host-game"] .container,
  [id^="view-host-lobby"] .container,
  [id^="view-host-final"] .container {
    max-width: 1200px;
  }

  .timer { font-size: 4rem; }
  .quiz-question { font-size: 2.8rem; }
  .option-display-item { font-size: 1.6rem; min-height: 5rem; }
  .correct-answer-display { font-size: 2.8rem; }
  .room-code-display .code { font-size: 6rem; letter-spacing: 1.5rem; }

  .podium-item { width: 180px; }
  .podium-bar.gold { height: 280px; }
  .podium-bar.silver { height: 200px; }
  .podium-bar.bronze { height: 140px; }
}
