/* デザイントークン: 白基調 + アクセント 1 色(青)。ここを変えれば全体に反映される */
:root {
  --accent: #2563eb;
  --accent-strong: #1e40af;
  --accent-weak: #dbeafe;
  --bg: #ffffff;
  --bg-subtle: #f5f7fa;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #d9dee5;
  --danger: #dc2626;
  --ok: #15803d;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "YuGothic",
    "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

/* display 指定を持つ要素(.image-preview 等)でも hidden 属性を必ず有効にする */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg-subtle);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
}

h1, h2, h3 {
  margin: 0 0 0.5em;
  line-height: 1.3;
}

h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }

a { color: var(--accent); }

.muted { color: var(--text-muted); }
.small { font-size: 0.8rem; }
.error { color: var(--danger); font-size: 0.9rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* レイアウト */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 12px;
}

.container-wide { max-width: 1080px; }

.container-narrow {
  max-width: 420px;
  padding-top: 10vh;
}

.stack > * + * { margin-top: 12px; }

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

/* ヘッダ */
.app-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-title { margin: 0; font-size: 1.1rem; }

.app-header-actions { display: flex; align-items: center; gap: 8px; }

/* 通知音トグル(絵文字ボタン) */
.sound-toggle { min-width: 44px; font-size: 1.1rem; line-height: 1; padding: 8px 10px; }

.conn-status {
  background: #fef3c7;
  color: #92400e;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* タブ */
.tabs {
  display: flex;
  gap: 4px;
  margin: 12px auto;
}

.tab {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.tab-panel { padding-bottom: 48px; }

/* フォーム部品 */
.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

.textarea { resize: vertical; }

.input:focus, .textarea:focus, .select:focus, .btn:focus-visible, .tab:focus-visible, .vote-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

label { font-size: 0.9rem; }

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.field { margin-bottom: 12px; }

/* ボタン(タップターゲット 44px 以上) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:not(:disabled):hover { background: var(--accent-strong); }

.btn-ghost { background: transparent; }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger-text { color: var(--danger); }

.btn-small { min-height: 36px; padding: 4px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }

.file-label input { display: none; }

/* バッジ(色 + ラベルで状態を表現) */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-answered { background: #dcfce7; color: var(--ok); }
.badge-mine { background: var(--accent-weak); color: var(--accent-strong); }
.badge-status-active { background: var(--accent-weak); color: var(--accent-strong); }
.badge-status-ended { background: #e5e7eb; color: var(--text-muted); }
.badge-status-draft { background: #fef3c7; color: #92400e; }
.badge-status-published { background: #dcfce7; color: var(--ok); }
.badge-status-closed { background: #e5e7eb; color: var(--text-muted); }

/* 質問カード */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0 8px;
}

.list-header h2 { margin: 0; }

.sort-toggle { display: flex; gap: 4px; }
.sort-btn.active { background: var(--accent-weak); color: var(--accent-strong); font-weight: 600; }

.question-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.question-body {
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 回答済み: グレーアウト + バッジ(色のみに依存しない) */
.question-card.answered { background: var(--bg-subtle); }
.question-card.answered .question-body { color: var(--text-muted); }
.question-card.pending { opacity: 0.6; }

.question-image {
  max-width: 100%;
  max-height: 240px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-top: 4px;
}

.question-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.vote-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  min-width: 72px;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
}

.vote-btn.voted {
  background: var(--accent-weak);
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 600;
}

.vote-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* 回答スレッド */
.answers { margin-top: 8px; }

.answer {
  border-left: 3px solid var(--accent);
  background: var(--bg-subtle);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 8px 12px;
  margin-top: 8px;
}

.answer p { margin: 2px 0; white-space: pre-wrap; word-break: break-word; }

.answer-image {
  display: block;
  max-width: 100%;
  max-height: 160px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 4px 0;
}

.answer-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-strong);
}

/* 参加者の返信は色 + ラベルで講師回答と区別する(色のみに依存しない) */
.answer-participant { border-left-color: var(--border); }
.answer-label-participant { color: var(--text-muted); }

/* 本文中の自動リンク */
.question-body a, .answer a, .material-body a { color: var(--accent); word-break: break-all; }

.answered-section { margin-top: 24px; }
.answered-section summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
.answered-section > .stack { margin-top: 8px; }

/* 画像プレビュー */
.image-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.image-preview img {
  max-height: 80px;
  max-width: 120px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* 参考情報 */
.module-title {
  margin: 20px 0 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 700;
}

.material-body { white-space: pre-wrap; word-break: break-word; margin: 4px 0 0; }

/* アンケート */
.survey-option-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.survey-option-row input { width: 20px; height: 20px; accent-color: var(--accent); }

.survey-result-row { margin-top: 8px; }

.survey-result-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.9rem;
}

.bar-track {
  background: var(--bg-subtle);
  border-radius: 999px;
  height: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
  min-width: 0;
}

/* 入室ページ */
.enter-card { text-align: center; }
.enter-card form { text-align: left; margin-top: 16px; }

.code-input {
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
  margin: 4px 0 12px;
}

.turnstile-widget { margin: 12px 0; min-height: 65px; }

/* admin */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.session-code {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent-strong);
}

.actions-inline { display: flex; gap: 6px; flex-wrap: wrap; }

.admin-item-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.hidden { display: none !important; }

/* 投影モード: 大文字・高コントラスト */
body.present {
  background: #ffffff;
  font-size: 28px;
}

.present .container { max-width: 1600px; }

.present-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 3px solid var(--accent);
  flex-wrap: wrap;
}

.present-header h1 { font-size: 1.4em; margin: 0; }

.present-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
}

.present-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  margin-top: 16px;
}

.present .question-card { border-width: 2px; padding: 20px; }
.present .question-body { font-size: 1.1em; font-weight: 600; color: #111827; }
.present .vote-display { font-size: 0.8em; color: var(--accent-strong); font-weight: 700; }
.present .answer { font-size: 0.75em; }
.present .answer-image { max-height: 320px; }
.present .bar-track { height: 1em; }
.present .survey-result-label { font-size: 0.9em; font-weight: 600; }

/* レスポンシブ: 768px 以上 */
@media (min-width: 768px) {
  .container { padding: 0 24px; }
  /* タブは本文と同じ中央コンテナ幅を保ち、左端を本文カードと揃える。
     ボタンは幅いっぱいに引き伸ばさず左寄せで並べる */
  .tabs { justify-content: flex-start; }
  .tab { flex: 0 0 auto; min-width: 128px; }
  .present-columns { grid-template-columns: 3fr 2fr; }
}
