/* ============================================================
   一発逆転！悪代官 オンライン  スタイル（和風テーマ）
   ============================================================ */
:root {
  --bg: #1d2417;
  --bg2: #2a3320;
  --panel: #e9dfc3;          /* 和紙色 */
  --panel-line: #4a5d2f;
  --ink: #2c2417;
  --gold: #d9b44a;
  --aku: #7c5cbf;            /* 悪代官側 紫 */
  --kami: #d9607a;           /* 上様側 紅 */
  --shomin: #5a9e5a;         /* 庶民 緑 */
  --danger: #c0392b;
  --shadow: 0 4px 14px rgba(0,0,0,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background:
    radial-gradient(circle at 50% -10%, #34401f 0%, var(--bg) 60%) fixed;
  color: #f3eede;
  min-height: 100vh;
  line-height: 1.6;
}
#app { max-width: 680px; margin: 0 auto; padding: 0 14px 120px; position: relative; }

/* ---- 画面切替 ---- */
.screen { display: none; animation: fade .35s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px);} to {opacity:1; transform:none;} }

/* ---- ヒーロー ---- */
.hero { text-align: center; margin: 18px 0 10px; }
.hero-img { width: 100%; max-width: 560px; border-radius: 12px; box-shadow: var(--shadow); }

/* ---- パネル（和紙） ---- */
.panel {
  background: var(--panel);
  color: var(--ink);
  border: 3px solid var(--panel-line);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: var(--shadow);
  margin: 14px 0;
}
.lead { text-align: center; font-weight: 600; margin: 0 0 18px; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 5px; color: #5a4a2a; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 2px solid #b9a878; border-radius: 9px; background: #fffdf6; color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(217,180,74,.35); }
.code-input { text-transform: uppercase; letter-spacing: .18em; font-weight: 800; }

.network-consent {
  margin: 16px 0; padding: 12px 14px; border: 1px solid #c3b487; border-radius: 9px; background: #fffaf0;
}
.network-consent label { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; font-weight: 800; cursor: pointer; }
.network-consent input { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 2px; accent-color: #4a5d2f; }
.network-consent p { margin: 8px 0 0 27px; color: #6a5a36; font-size: 12px; line-height: 1.65; }
.noscript { max-width: 680px; margin: 12px auto; padding: 12px; background: #fff3cd; color: #4a3510; }

.divider { text-align: center; margin: 16px 0; position: relative; color: #8a7a55; font-size: 13px; }
.divider::before { content:""; position:absolute; top:50%; left:0; right:0; height:1px; background:#c3b487; z-index:0; }
.divider span { background: var(--panel); padding: 0 12px; position: relative; z-index: 1; }

/* ---- ボタン ---- */
.btn {
  display: block; width: 100%; padding: 13px 16px; margin: 8px 0;
  font-size: 16px; font-weight: 800; letter-spacing: .04em;
  border: none; border-radius: 10px; cursor: pointer;
  background: #4a5d2f; color: #fff; transition: transform .08s, filter .15s;
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, #e0b94f, #c89a2c); color: #3a2c08; }
.btn-danger { background: linear-gradient(180deg, #d9534f, #b73229); }
.btn-ghost { background: transparent; color: #e9dfc3; box-shadow: none; border: 2px solid #6c7d4d; }
.btn-tiny { width: auto; padding: 7px 12px; font-size: 13px; margin: 0; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin: 8px 0; }

.error { color: var(--danger); font-weight: 700; text-align: center; min-height: 1.2em; margin: 8px 0 0; }

/* ---- トップバー ---- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  position: sticky; top: 0; z-index: 20;
  background: rgba(29,36,23,.96); backdrop-filter: blur(4px);
  padding: 10px 4px; margin: 0 -4px 8px; border-bottom: 1px solid #3c4a28;
}
.room-code { font-size: 13px; color: #c8bd98; }
.room-code strong { font-size: 18px; color: var(--gold); letter-spacing: .15em; }
.phase-badge { flex: 1; text-align: center; font-weight: 800; }
.phase-badge .pno {
  display: inline-block; background: var(--gold); color: #3a2c08;
  border-radius: 6px; padding: 1px 8px; margin-right: 6px; font-size: 14px;
}

/* ---- ステージ（フェーズ操作） ---- */
.stage {
  background: var(--panel); color: var(--ink);
  border: 3px solid var(--panel-line); border-radius: 14px;
  padding: 18px 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.stage h2 { margin: 0 0 6px; font-size: 20px; }
.stage .hint { color: #6a5a36; font-size: 14px; margin: 0 0 14px; }
.stage .big-note { text-align:center; font-size: 15px; font-weight: 700; margin: 10px 0; }
.waiting { text-align: center; color: #7a6a44; font-style: italic; padding: 10px; }

.lobby-tip { font-size: 13px; color: #6a5a36; text-align: center; }
.copy-code {
  display:flex; align-items:center; justify-content:center; gap:10px;
  background:#fffdf6; border:2px dashed #b9a878; border-radius:10px;
  padding:12px; margin:10px 0; font-size: 26px; font-weight: 900; letter-spacing:.2em; color:#4a5d2f;
}

/* ---- プレイヤー一覧 ---- */
.section-title { font-size: 15px; color: #ccc09a; margin: 6px 2px; }
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px,1fr)); gap: 10px; }
.pcard {
  background: var(--panel); color: var(--ink); border-radius: 11px; padding: 10px 8px;
  text-align: center; border: 2px solid #b9a878; position: relative; box-shadow: var(--shadow);
}
.pcard.me { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.pcard.dead { filter: grayscale(.8) brightness(.8); }
.pcard .pname { font-weight: 800; font-size: 14px; word-break: break-all; }
.pcard .ptag {
  display:inline-block; margin-top:5px; font-size:11px; font-weight:800; color:#fff;
  border-radius: 20px; padding: 2px 9px; background:#9a8c66;
}
.ptag.aku { background: var(--aku); }
.ptag.kami { background: var(--kami); }
.ptag.shomin { background: var(--shomin); }
.pcard .badge {
  position:absolute; top:-8px; right:-6px; font-size:18px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.4));
}
.pcard .pmini { font-size: 11px; color:#8a7a55; margin-top:3px; min-height: 14px; }
.host-dot { color: var(--gold); }
.offline { opacity: .5; }

/* ---- 役職カード（自分用・大） ---- */
.role-card-big {
  border-radius: 16px; padding: 22px 18px; margin: 8px auto; max-width: 320px;
  color: #fff; box-shadow: var(--shadow); border: 3px solid rgba(255,255,255,.25);
}
.role-card-big .rc-name { font-size: 34px; font-weight: 900; letter-spacing: .08em; }
.role-card-big .rc-team { font-size: 14px; opacity: .9; margin: 4px 0 12px; }
.role-card-big .rc-desc { font-size: 14px; line-height: 1.7; text-align: left; background: rgba(0,0,0,.18); border-radius: 10px; padding: 10px 12px; }
.side-aku { background: linear-gradient(160deg,#8e6fd4,#5e3fa0); }
.side-kami { background: linear-gradient(160deg,#e2748d,#b03e5c); }
.side-shomin { background: linear-gradient(160deg,#6cb56c,#3f8a3f); }

/* 自分の役職ミニ表示（ステージ上部固定） */
.myrole-bar {
  display:flex; align-items:center; gap:10px; border-radius:10px;
  padding:8px 12px; margin-bottom:14px; color:#fff; font-weight:800;
}
.myrole-bar small { font-weight:600; opacity:.85; }
.myrole-name { font-size: 20px; }

/* ---- 選択ボタン群 ---- */
.choice-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(120px,1fr)); gap:10px; margin:12px 0; }
.choice {
  padding: 12px; border-radius: 10px; border: 2px solid #b9a878; background:#fffdf6;
  font-weight: 800; cursor:pointer; color: var(--ink); font-size:15px;
}
.choice.selected { border-color: var(--danger); background:#ffe9e4; box-shadow: 0 0 0 2px var(--danger); }

/* 伏せ役職カード */
.hidden-cards { display:flex; gap:14px; justify-content:center; margin:14px 0; }
.hcard {
  width: 92px; height: 132px; border-radius: 10px; cursor: pointer;
  background: repeating-linear-gradient(45deg,#3a4a26,#3a4a26 8px,#445530 8px,#445530 16px);
  border:3px solid var(--gold); display:flex; align-items:center; justify-content:center;
  color: var(--gold); font-size: 40px; font-weight:900; box-shadow: var(--shadow);
  transition: transform .15s;
}
.hcard:hover { transform: translateY(-4px); }
.hcard.flipped {
  background: var(--panel); color: var(--ink); cursor: default; flex-direction: column; font-size: 14px;
}
.hcard.flipped .hc-name { font-size: 22px; font-weight: 900; }

/* ---- 進行ログ ---- */
.log-box { background: rgba(0,0,0,.25); border-radius: 10px; margin-top: 14px; padding: 4px 12px; }
.log-box summary { cursor: pointer; font-weight: 700; padding: 6px 0; color: #ccc09a; }
.log { max-height: 160px; overflow-y: auto; font-size: 13px; }
.log div { padding: 3px 0; border-bottom: 1px dashed #3c4a28; color: #d8d0b6; }

/* ---- チャット ---- */
.chat {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  max-width: 680px; margin: 0 auto; background: rgba(20,26,15,.97);
  border-top: 2px solid #4a5d2f; padding: 8px 12px; display:none;
}
.chat.show { display: block; }
.chat-log { max-height: 110px; overflow-y: auto; font-size: 13px; margin-bottom: 6px; }
.chat-log .c { padding: 2px 0; }
.chat-log .c b { color: var(--gold); }
.chat-form { display: flex; gap: 6px; }
.chat-form input { flex: 1; padding: 9px 12px; border-radius: 8px; border: 2px solid #4a5d2f; background:#fffdf6; color: var(--ink); font-size: 15px; }

/* ---- 結果 ---- */
.result-banner { text-align:center; border-radius:14px; padding:18px; margin-bottom:14px; color:#fff; }
.result-banner.aku { background: linear-gradient(160deg,#8e6fd4,#5e3fa0); }
.result-banner.kami { background: linear-gradient(160deg,#e2748d,#b03e5c); }
.result-banner h2 { font-size: 28px; margin: 0; }
.result-banner .win-you { font-size: 18px; font-weight: 900; margin-top: 8px; }
.result-table { width:100%; border-collapse: collapse; margin: 10px 0; }
.result-table td { padding: 8px 6px; border-bottom: 1px solid #cdbf96; font-size: 14px; }
.result-table .rrole { font-weight: 800; }

/* ---- モーダル ---- */
.modal { display:none; position: fixed; inset:0; background: rgba(0,0,0,.7); z-index: 100; overflow-y:auto; padding: 24px 12px; }
.modal.show { display: block; }
.modal-inner { max-width: 600px; margin: 0 auto; background: var(--panel); color: var(--ink); border-radius: 14px; padding: 24px 20px; position: relative; }
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: none; font-size: 30px; cursor: pointer; color: #6a5a36; }
.modal h2 { border-bottom: 3px solid var(--panel-line); padding-bottom: 6px; }
.flow-list { padding-left: 22px; }
.flow-list li { margin: 8px 0; }
.rules-roles { display: grid; gap: 10px; }
.rrole-card { border-radius: 10px; padding: 12px 14px; color: #fff; }
.rrole-card h4 { margin: 0 0 4px; font-size: 18px; }
.rrole-card p { margin: 0; font-size: 13px; }
.terms { margin-top: 18px; font-size: 13px; background: #fffaf0; border:1px solid #d8c89a; border-radius:8px; padding: 10px 14px; }
.rogo { text-align: center; margin-top: 18px; }
.rogo img { width: 120px; }
.rogo p { font-size: 12px; color: #6a5a36; }

/* 役職お披露目オーバーレイ */
.role-reveal { display:none; position: fixed; inset:0; z-index: 200; background: rgba(0,0,0,.85);
  align-items:center; justify-content:center; padding: 20px; }
.role-reveal.show { display: flex; }
.role-reveal-inner { text-align:center; max-width: 360px; width:100%; animation: pop .4s ease; }
@keyframes pop { from { transform: scale(.7); opacity:0;} to {transform:none; opacity:1;} }
.rr-label { color: var(--gold); font-size: 18px; font-weight: 800; }

/* タヌキ */
.tanuki { display:block; width: 120px; margin: 30px auto 10px; opacity:.9; }

@media (max-width: 420px) {
  .role-card-big .rc-name { font-size: 28px; }
  .players { grid-template-columns: repeat(auto-fill, minmax(84px,1fr)); }
}
