/* ============================================================
   偉人戦略会議AI — スマホ最適化スタイル
   ============================================================ */
:root {
  /* 和紙（生成り）を基調にした明るい和風の配色 */
  --bg: #f2ead9;        /* 和紙の地 */
  --bg2: #e9dec8;       /* やや深い生成り（吹き出し・入力欄） */
  --card: #fcf8ef;      /* パネル（最も明るい） */
  --card2: #f4ecdb;     /* 入れ子の行 */
  --ink: #2d2518;       /* 墨色の文字 */
  --muted: #877a62;     /* 枯色 */
  --line: #ddd0b6;      /* 淡い境界 */
  --pro: #2f8050;       /* 緑青（濃いめ） */
  --pro-d: #246b41;
  --neutral: #9a7320;   /* 山吹（濃いめ） */
  --neutral-d: #7a5a18;
  --con: #b0463c;       /* 臙脂・朱 */
  --con-d: #8f3a33;
  --accent: #9a7322;    /* 金茶（濃いめ） */
  --gold: #9a7322;
  --serif: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", "Songti SC", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--ink);
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

/* ---- トップバー ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(248,243,233,0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-weight: 700; font-size: 18px; letter-spacing: 0.08em; color: var(--gold); }
.brand-icon { font-size: 22px; }
.icon-btn {
  background: none; border: 1px solid var(--line); color: var(--ink);
  width: 40px; height: 40px; border-radius: 10px; font-size: 18px; cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

.container { max-width: 640px; margin: 0 auto; padding: 16px 14px 40px; }
.lead { color: var(--muted); text-align: center; font-size: 14px; margin: 8px 0 18px; }
.lead b { color: var(--ink); }

/* ---- ヒーロー ---- */
.hero { text-align: center; padding: 22px 0 6px; }
.seal {
  width: 48px; height: 48px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: #a8423a; color: #f3e7d2;
  font-family: var(--serif); font-weight: 700; font-size: 26px; line-height: 1;
  border-radius: 5px; box-shadow: inset 0 0 0 2px rgba(243,231,210,0.25);
}
.hero-title {
  margin: 0; font-family: var(--serif); font-size: 33px; font-weight: 700;
  letter-spacing: 0.18em; color: var(--gold);
}
.hero-sub {
  font-family: var(--serif); font-size: 13px; color: var(--muted);
  margin: 14px 8px 0; line-height: 1.8; letter-spacing: 0.02em;
}
.hero-sub b { color: var(--ink); font-weight: 700; }

/* ---- 評議員一覧 ---- */
.council { margin: 18px 0 20px; }
.council-title { text-align: center; font-family: var(--serif); font-size: 14px; color: var(--ink); font-weight: 700; letter-spacing: 0.12em; margin-bottom: 14px; }
.council-title span { color: var(--gold); font-size: 12px; }
.council-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px 4px; }
.council-member {
  background: none; border: none; padding: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  animation: memberIn 0.45s ease both;
}
.council-member:active { transform: scale(0.93); }
.member-name { font-size: 10px; color: var(--muted); line-height: 1.25; text-align: center; }
.council-member.active .member-name { color: var(--gold); font-weight: 700; }
.council-member.active .avatar { box-shadow: 0 0 0 2px var(--gold), 0 0 12px rgba(200,162,74,0.5); }
.council-caption {
  margin-top: 14px; text-align: center; font-size: 12px; color: var(--muted);
  min-height: 32px; line-height: 1.5; padding: 0 6px;
}
.council-caption b { color: var(--ink); }
@keyframes memberIn { from { opacity: 0; transform: translateY(10px) scale(0.9); } to { opacity: 1; transform: none; } }

/* ---- 入力エリア ---- */
.input-area { margin-bottom: 18px; }
.input-label { display: block; font-family: var(--serif); font-size: 14px; font-weight: 700; color: var(--ink); letter-spacing: 0.08em; margin-bottom: 10px; }
#consult-input {
  width: 100%; min-height: 110px; resize: vertical;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 14px; font-size: 16px; font-family: inherit; line-height: 1.6;
}
#consult-input:focus { outline: none; border-color: var(--accent); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.example {
  background: var(--card2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.example:active { transform: scale(0.96); }
.run-btn {
  width: 100%; margin-top: 8px;
  background: #a8423a; /* 朱・臙脂の単色 */
  color: #f3e7d2; border: 1px solid #c2554c; border-radius: 8px;
  padding: 16px; font-family: var(--serif); font-size: 18px; font-weight: 700;
  letter-spacing: 0.1em; cursor: pointer;
}
.run-btn span { position: relative; }
.run-btn:hover { background: #b14a40; }
.run-btn:disabled { opacity: 0.5; }
.run-btn:active { transform: scale(0.99); }

/* ---- フォーカスモード（相談後は評議員一覧・例題・ヒーロー説明を畳む） ---- */
body.consulted .council,
body.consulted .examples,
body.consulted .seal,
body.consulted .hero-sub { display: none; }
body.consulted .hero { padding: 8px 0 0; }
body.consulted .hero-title { font-size: 22px; }
body.consulted .input-label { display: none; }
.status { min-height: 18px; margin-top: 8px; font-size: 13px; color: var(--muted); text-align: center; }
.status.err { color: var(--con); }

/* ---- ローディング ---- */
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 0; color: var(--muted); }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- カード共通 ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px; margin-bottom: 14px;
}
.card-title {
  font-family: var(--serif); font-size: 17px; margin: 0 0 14px;
  padding-left: 11px; border-left: 3px solid var(--gold);
  line-height: 1.35; letter-spacing: 0.06em;
}

/* ---- 最終結論 ---- */
.conclusion { text-align: center; border-width: 2px; }
.conclusion.pro { border-color: var(--pro-d); }
.conclusion.neutral { border-color: var(--neutral-d); }
.conclusion.con { border-color: var(--con-d); }
.verdict-badge {
  display: inline-block; font-family: var(--serif); font-size: 20px; font-weight: 700;
  letter-spacing: 0.06em; padding: 8px 22px; border-radius: 6px; margin-bottom: 10px;
}
.verdict-badge.pro { background: rgba(46,204,113,0.16); color: var(--pro); }
.verdict-badge.neutral { background: rgba(241,177,59,0.16); color: var(--neutral); }
.verdict-badge.con { background: rgba(231,76,60,0.16); color: var(--con); }
.conclusion-text { font-size: 15px; margin: 6px 0 14px; }
.tally { display: flex; justify-content: center; gap: 8px; }
.chip { font-family: var(--serif); font-size: 13px; font-weight: 700; padding: 4px 13px; border-radius: 4px; }
.chip.pro { background: rgba(46,204,113,0.18); color: var(--pro); }
.chip.neutral { background: rgba(241,177,59,0.18); color: var(--neutral); }
.chip.con { background: rgba(231,76,60,0.18); color: var(--con); }

/* ---- 投票グリッド ---- */
.card-hint { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 8px; }

/* 派閥グルーピング */
.faction-group { margin-bottom: 16px; }
.faction-group:last-child { margin-bottom: 0; }
.faction-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 2px 0 8px; }
.faction-badge { font-family: var(--serif); font-weight: 700; font-size: 14px; letter-spacing: 0.08em; padding: 3px 13px; border-radius: 4px; }
.faction-badge.pro { background: rgba(46,204,113,0.18); color: var(--pro); }
.faction-badge.neutral { background: rgba(241,177,59,0.18); color: var(--neutral); }
.faction-badge.con { background: rgba(231,76,60,0.18); color: var(--con); }
.faction-count { font-size: 12px; color: var(--muted); font-weight: 700; }
.faction-sum { flex: 1 1 100%; font-size: 12px; color: var(--muted); line-height: 1.5; }

.vote-grid { display: flex; flex-direction: column; gap: 8px; }
.giant-card {
  background: var(--card2); border: 1px solid var(--line);
  border-left-width: 4px; border-radius: 8px; overflow: hidden;
}
.giant-card.pro { border-left-color: var(--pro); }
.giant-card.neutral { border-left-color: var(--neutral); }
.giant-card.con { border-left-color: var(--con); }
.giant-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; cursor: pointer; list-style: none;
}
.giant-row::-webkit-details-marker { display: none; }
.row-caret { flex: 0 0 auto; color: var(--muted); font-size: 13px; transition: transform 0.2s; }
.giant-card[open] .row-caret { transform: rotate(180deg); }
.giant-card[open] { background: var(--card); }
.giant-detail { padding: 6px 12px 14px; }

/* セリフ吹き出し（本人が語りかけている感／アイコンはヘッダー行にあるため非重複） */
.quote-block { margin: 2px 0 12px; }
.speech-tag { display: block; font-size: 10px; color: var(--muted); margin: 0 0 6px 4px; }
.speech-bubble {
  position: relative; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 4px 12px 12px 12px; padding: 11px 13px;
  font-family: var(--serif); font-size: 15px; line-height: 1.75; color: var(--ink);
}
/* 吹き出しの尾（上向き＝ヘッダーの顔から発話している印象） */
.speech-bubble::before {
  content: ""; position: absolute; top: -7px; left: 16px;
  border: 6px solid transparent; border-bottom-color: var(--line); border-top: 0;
}
.speech-bubble::after {
  content: ""; position: absolute; top: -6px; left: 16px;
  border: 6px solid transparent; border-bottom-color: var(--bg2); border-top: 0;
}

/* 個別偉人への追問（フォローアップ） */
.followup { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.followup-thread { display: flex; flex-direction: column; gap: 9px; }
.followup-thread:not(:empty) { margin-bottom: 11px; }
.fu-q {
  align-self: flex-end; max-width: 85%;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px 10px 2px 10px; padding: 7px 11px; font-size: 13px; color: var(--ink);
}
.fu-a { align-self: flex-start; max-width: 92%; }
.fu-bubble {
  background: var(--bg2); border: 1px solid var(--line); border-left: 3px solid var(--gold);
  border-radius: 2px 11px 11px 11px; padding: 8px 12px;
  font-family: var(--serif); font-size: 14px; line-height: 1.75; color: var(--ink);
}
.fu-a.pending .fu-bubble { color: var(--muted); }
.fu-a.error .fu-bubble { color: var(--con); font-family: inherit; font-size: 12px; }
.followup-form { display: flex; gap: 8px; }
.followup-input {
  flex: 1; min-width: 0; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  font-size: 14px; font-family: inherit;
}
.followup-input:focus { outline: none; border-color: var(--gold); }
.followup-send {
  flex: 0 0 auto; background: #a8423a; color: #f3e7d2;
  border: 1px solid #c2554c; border-radius: 8px; padding: 0 16px;
  font-family: var(--serif); font-weight: 700; font-size: 14px; cursor: pointer;
}
.followup-send:disabled { opacity: 0.5; }

/* 現代の教訓 */
.lesson {
  display: flex; align-items: stretch; gap: 9px;
  background: rgba(154,115,34,0.10); border: 1px solid rgba(154,115,34,0.34);
  border-radius: 6px; padding: 9px 12px; margin: 0 0 12px;
}
.lesson-label {
  flex: 0 0 auto; white-space: nowrap; align-self: center;
  font-family: var(--serif); font-size: 11px; font-weight: 700; color: var(--gold);
  border-right: 1px solid rgba(200,162,74,0.32); padding-right: 9px;
}
.lesson-text { font-size: 13px; color: var(--ink); line-height: 1.65; }

.detail-row { font-size: 13px; margin: 7px 0; }
.detail-row b { display: block; color: var(--accent); font-size: 12px; margin-bottom: 1px; }
.detail-row.advice b { color: var(--pro); }
.avatar {
  position: relative; overflow: hidden;
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.15);
}
.avatar.sm { width: 34px; height: 34px; font-size: 18px; }
.avatar.lg { width: 56px; height: 56px; font-size: 28px; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.18); transition: box-shadow 0.2s; }
.ava-emoji { position: relative; z-index: 1; line-height: 1; }
.ava-img {
  position: absolute; inset: 0; z-index: 2;
  width: 100%; height: 100%; object-fit: cover; object-position: center;
}
.giant-body { flex: 1; min-width: 0; }
.giant-name { font-family: var(--serif); font-weight: 700; font-size: 15px; letter-spacing: 0.04em; }
.giant-comment { font-size: 12px; color: var(--muted); }
.vote-badge { flex: 0 0 auto; font-family: var(--serif); font-weight: 700; font-size: 13px; padding: 4px 11px; border-radius: 4px; }
.vote-badge.pro { background: rgba(46,204,113,0.2); color: var(--pro); }
.vote-badge.neutral { background: rgba(241,177,59,0.2); color: var(--neutral); }
.vote-badge.con { background: rgba(231,76,60,0.2); color: var(--con); }

/* ---- 最大の争点 ---- */
.versus { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.vs-side { border-radius: 12px; padding: 10px 12px; }
.vs-side p { margin: 4px 0 0; font-size: 14px; }
.vs-side.pro { background: rgba(46,204,113,0.1); border: 1px solid var(--pro-d); }
.vs-side.con { background: rgba(231,76,60,0.1); border: 1px solid var(--con-d); }
.vs-label { font-weight: 700; font-size: 12px; }
.vs-side.pro .vs-label { color: var(--pro); }
.vs-side.con .vs-label { color: var(--con); }
.vs-mark { text-align: center; font-weight: 800; color: var(--muted); font-size: 13px; }

/* ---- 議長総括 / アクション ---- */
.summary-text { font-size: 14px; margin: 0; }
.actions { border-color: var(--accent); }
.action-list { margin: 0; padding-left: 22px; }
.action-list li { margin-bottom: 10px; font-size: 15px; font-weight: 600; }

/* ---- 折りたたみ ---- */
details.fold { padding: 0; }
details.fold > summary {
  list-style: none; cursor: pointer; padding: 14px 16px;
  font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; align-items: center;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "▾"; color: var(--muted); transition: transform 0.2s; }
details.fold[open] > summary::after { transform: rotate(180deg); }
.fold-body { padding: 0 16px 16px; }
.debate-fold > summary { font-family: var(--serif); letter-spacing: 0.04em; }

/* ---- 討論シミュレーション（賛成派＝左・緑／反対派＝右・朱の対決） ---- */
.debate { display: flex; flex-direction: column; gap: 12px; padding-top: 2px; }
.turn { display: flex; gap: 9px; align-items: flex-start; }
.turn .avatar.sm { margin-top: 2px; }
.chair-av { background: #a8423a; }
.chair-av .ava-emoji { font-family: var(--serif); color: #f3e7d2; font-size: 15px; font-weight: 700; }
.turn-body { flex: 1; min-width: 0; }
.turn-name { font-family: var(--serif); font-weight: 700; font-size: 13px; color: var(--ink); margin-bottom: 3px; }
.turn-text {
  display: inline-block; max-width: 90%;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 3px 12px 12px 12px; padding: 9px 12px;
  font-family: var(--serif); font-size: 14px; line-height: 1.75; color: var(--ink); text-align: left;
}

/* 賛成派：左・緑 */
.turn.side-pro .turn-name { color: var(--pro-d); }
.turn.side-pro .turn-text { border-left: 3px solid var(--pro); }

/* 反対派：右・朱（アバターを右に） */
.turn.side-con { flex-direction: row-reverse; }
.turn.side-con .turn-body { text-align: right; }
.turn.side-con .turn-name { color: var(--con); }
.turn.side-con .turn-text {
  border-radius: 12px 3px 12px 12px;
  border-right: 3px solid var(--con);
}

/* 議長：中央寄せの仕切り */
.turn.chair { justify-content: center; align-items: center; }
.turn.chair .turn-body { flex: 0 1 auto; text-align: center; }
.turn.chair .turn-name { color: var(--con); }
.turn.chair .turn-text { background: rgba(176,70,60,0.07); max-width: 100%; }

/* ---- 派閥 ---- */
.faction { border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.faction h3 { margin: 0 0 4px; font-size: 14px; }
.faction p { margin: 0; font-size: 13px; color: var(--muted); }
.faction.pro { background: rgba(46,204,113,0.08); }
.faction.pro h3 { color: var(--pro); }
.faction.neutral { background: rgba(241,177,59,0.08); }
.faction.neutral h3 { color: var(--neutral); }
.faction.con { background: rgba(231,76,60,0.08); }
.faction.con h3 { color: var(--con); }

/* ---- エラー ---- */
.card.error { border-color: var(--con-d); }
.card.error .hint { font-size: 12px; color: var(--muted); }

/* ---- モーダル ---- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; width: 100%; max-width: 420px;
}
.modal-box h2 { margin: 0 0 16px; font-size: 18px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; background: var(--bg2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px; font-size: 15px;
}
.modal-hint { font-size: 12px; color: var(--muted); line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.btn { border: none; border-radius: 10px; padding: 10px 18px; font-size: 15px; font-weight: 700; cursor: pointer; }
.btn.ghost { background: var(--card2); color: var(--ink); border: 1px solid var(--line); }
.btn.primary { background: var(--accent); color: #fff; }

.foot { text-align: center; color: var(--muted); font-size: 11px; padding: 0 16px 30px; }

/* ---- 広い画面 ---- */
@media (min-width: 520px) {
  .versus { flex-direction: row; align-items: center; }
  .vs-side { flex: 1; }
  .vs-mark { flex: 0 0 auto; }
}
