/* =========================================================
   白書マフィア  style.css
   ダークネイビー基調 / スマホ縦画面・片手操作優先
   ========================================================= */
:root {
  --bg: #0b1120;
  --panel: #131d31;
  --panel2: #1e293b;
  --accent: #2563eb;
  --accent-hi: #3b82f6;
  --danger: #ef4444;
  --ok: #10b981;
  --gold: #fbbf24;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: #2a3854;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  background-image:
    linear-gradient(rgba(37, 99, 235, .06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, .06) 1px, transparent 1px);
  background-size: 24px 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

button, input, select { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(11, 17, 32, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--accent);
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, .35);
}
.brand-text { font-weight: 800; letter-spacing: .08em; font-size: 15px; white-space: nowrap; }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me-name {
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  color: var(--muted);
}
.coins {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--panel2);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 15px;
  white-space: nowrap;
}
.coins.bump { animation: bump .6s ease; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
.net { width: 10px; height: 10px; border-radius: 50%; background: #475569; flex: none; }
.net.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.net.connecting { background: var(--gold); animation: blink 1s infinite; }
.net.offline { background: var(--danger); }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}
@media (min-width: 900px) {
  .container { max-width: 980px; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
}

.loading { text-align: center; color: var(--muted); padding: 60px 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.panel h2, .panel h3 { margin: 0 0 12px; font-size: 16px; letter-spacing: .04em; }
.panel h2 small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.center { text-align: center; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.7; margin: 8px 0 0; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 10px; }

/* ---------- Hero (entry) ---------- */
.hero { text-align: center; padding: 26px 8px 10px; }
.hero .seal {
  display: inline-grid;
  place-items: center;
  width: 84px; height: 84px;
  border-radius: 50%;
  border: 3px double var(--danger);
  color: var(--danger);
  font-weight: 900;
  font-size: 22px;
  transform: rotate(-12deg);
  margin-bottom: 10px;
  letter-spacing: .1em;
}
.hero h1 { margin: 6px 0 4px; font-size: 30px; letter-spacing: .14em; }
.hero p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }

/* ---------- Form ---------- */
label.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input.text {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 17px;
  outline: none;
}
input.text:focus { border-color: var(--accent-hi); box-shadow: 0 0 0 3px rgba(37, 99, 235, .25); }
input.text.upper { text-transform: uppercase; letter-spacing: .2em; font-weight: 700; text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel2);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, opacity .15s ease;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent-hi); }
.btn.primary:not(:disabled):hover { background: var(--accent-hi); }
.btn.danger { background: var(--danger); border-color: #f87171; }
.btn.ok { background: var(--ok); border-color: #34d399; color: #04241a; }
.btn.ghost { background: transparent; }
.btn.big { min-height: 60px; font-size: 18px; }
.btn.sm { min-height: 40px; font-size: 14px; padding: 8px 12px; width: auto; }
.btn-gap { margin-top: 10px; }

/* segmented control */
.seg {
  display: flex;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.seg button {
  flex: 1;
  min-height: 46px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 700;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
}
.seg button.on { background: var(--accent); color: #fff; }
.seg button.on.red { background: var(--danger); }
.seg button:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Room info ---------- */
.room-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.room-id {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: .18em;
  font-variant-numeric: tabular-nums;
}
.label { font-size: 12px; color: var(--muted); letter-spacing: .1em; }
.qr {
  background: #fff;
  padding: 8px;
  border-radius: 10px;
  line-height: 0;
  flex: none;
}
.qr img, .qr canvas { display: block; width: 132px; height: 132px; }

/* ---------- Players ---------- */
.players { list-style: none; margin: 0; padding: 0; }
.players li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px dashed var(--line);
}
.players li:last-child { border-bottom: 0; }
.pdot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.pname .tag { font-size: 11px; font-weight: 600; color: var(--muted); margin-left: 6px; }
.pname.off { opacity: .45; }
.pcoins { font-variant-numeric: tabular-nums; font-weight: 800; }
.pcheck { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); }
.pcheck.done { background: rgba(16, 185, 129, .2); color: var(--ok); }
.kick {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 8px;
  width: 32px; height: 32px;
  color: var(--muted);
  cursor: pointer;
}

/* ---------- Phase bar ---------- */
.phase-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: .08em;
  margin-bottom: 10px;
}
.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel2);
  border: 1px solid var(--line);
  font-weight: 700;
  color: var(--text);
}
.pill.red { border-color: var(--danger); color: #fecaca; }

/* ---------- Timer ---------- */
.timer-box { text-align: center; margin-bottom: 14px; }
.timer {
  font-size: 56px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  line-height: 1.1;
}
.timer.warn { color: var(--danger); animation: blink 1s infinite; }
.tbar { height: 6px; background: var(--panel2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.tbar > div { height: 100%; width: 100%; background: var(--accent); transition: width .25s linear; }

/* ---------- Card flip ---------- */
.flip {
  perspective: 1400px;
  margin-bottom: 14px;
  cursor: pointer;
  user-select: none;
}
.flip-inner {
  display: grid;
  transition: transform .75s cubic-bezier(.2, .8, .2, 1);
  transform-style: preserve-3d;
}
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.face {
  grid-area: 1 / 1;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 18px;
  padding: 22px 20px;
  min-height: 300px;
  box-shadow: var(--shadow);
}
.face.front {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .025) 0 10px, transparent 10px 20px),
    linear-gradient(160deg, #1e3a8a, #0f172a);
  border: 2px solid #1d4ed8;
  position: relative;
  overflow: hidden;
}
.stamp {
  position: absolute;
  top: 18px; right: 16px;
  border: 3px solid var(--danger);
  color: var(--danger);
  padding: 2px 10px;
  font-weight: 900;
  letter-spacing: .3em;
  transform: rotate(12deg);
  opacity: .85;
}
.front-title { font-size: 28px; font-weight: 900; letter-spacing: .3em; }
.front-theme { margin-top: 10px; color: #bfdbfe; font-weight: 700; }
.front-tap { margin-top: 26px; font-size: 13px; color: var(--muted); animation: blink 1.6s infinite; }
.face.back {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #f8fafc, #e2e8f0);
  color: #0f172a;
  border: 2px solid #cbd5e1;
}
.card-static {
  background: linear-gradient(180deg, #f8fafc, #e2e8f0);
  color: #0f172a;
  border-radius: 14px;
  padding: 16px;
  border: 2px solid #cbd5e1;
}
.doc-src {
  font-size: 12px;
  font-weight: 800;
  color: #1e3a8a;
  border-bottom: 2px solid #1e3a8a;
  padding-bottom: 6px;
  letter-spacing: .06em;
}
.doc-metric { margin-top: 12px; font-size: 15px; font-weight: 700; line-height: 1.5; }
.doc-value {
  margin: 10px 0;
  font-size: 34px;
  font-weight: 900;
  color: #1d4ed8;
  line-height: 1.2;
  word-break: break-word;
}
.doc-desc { margin: 0; font-size: 14px; line-height: 1.8; color: #334155; }
.doc-close { margin-top: 14px; font-size: 12px; color: #64748b; text-align: center; }

.badge {
  display: block;
  text-align: center;
  font-weight: 900;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
  font-size: 15px;
}
.badge.mafia { background: var(--danger); color: #fff; box-shadow: 0 0 0 3px rgba(239, 68, 68, .3); }
.badge.citizen { background: var(--ok); color: #04241a; }
.badge-note { font-size: 12px; color: #7f1d1d; text-align: center; margin: -6px 0 10px; font-weight: 700; }

/* ---------- Tips ---------- */
.tips { margin: 0; padding-left: 1.2em; font-size: 14px; line-height: 1.8; color: #cbd5e1; }

/* ---------- Bet ---------- */
.target-list { display: grid; gap: 8px; }
.target {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--panel2);
  border: 2px solid var(--line);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.target.on { border-color: var(--danger); background: rgba(239, 68, 68, .15); }
.target .tname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bet-done {
  text-align: center;
  padding: 18px;
  border-radius: 14px;
  border: 2px dashed var(--ok);
  background: rgba(16, 185, 129, .08);
}
.bet-done .big { font-size: 22px; font-weight: 900; margin: 6px 0; }
details.mycard summary {
  cursor: pointer;
  font-weight: 700;
  padding: 4px 0;
  list-style: none;
}
details.mycard summary::-webkit-details-marker { display: none; }
details.mycard summary::before { content: "▶ "; color: var(--muted); }
details.mycard[open] summary::before { content: "▼ "; }
details.mycard .card-static { margin-top: 10px; }

/* ---------- Result ---------- */
.banner {
  text-align: center;
  border-radius: 16px;
  padding: 20px 14px;
  margin-bottom: 14px;
  font-weight: 900;
  font-size: 20px;
  line-height: 1.5;
  animation: pop .5s ease;
}
.banner small { display: block; font-size: 13px; font-weight: 600; opacity: .85; margin-top: 4px; }
.banner.c { background: linear-gradient(135deg, #065f46, #10b981); }
.banner.m { background: linear-gradient(135deg, #7f1d1d, #ef4444); }
@keyframes pop { 0% { transform: scale(.85); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.vote-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 14px; }
.vote-row .vn { width: 30%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.vote-row .vb { flex: 1; height: 16px; background: var(--panel2); border-radius: 999px; overflow: hidden; }
.vote-row .vb > div { height: 100%; background: var(--accent); }
.vote-row.mafia .vb > div { background: var(--danger); }
.vote-row .vc { width: 36px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.ledger { width: 100%; border-collapse: collapse; font-size: 13px; }
table.ledger th, table.ledger td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.ledger th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
table.ledger td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; white-space: nowrap; }
.plus { color: var(--ok); }
.minus { color: var(--danger); }
.role-m { color: var(--danger); font-weight: 900; }
.note { color: var(--muted); font-size: 12px; line-height: 1.6; }

.compare { display: grid; gap: 12px; }
@media (min-width: 640px) { .compare { grid-template-columns: 1fr 1fr; } }
.cmp {
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, #f8fafc, #e2e8f0);
  color: #0f172a;
  border: 3px solid var(--ok);
  position: relative;
}
.cmp.fake { border-color: var(--danger); }
.cmp .cmp-tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 900;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--ok);
  color: #04241a;
  margin-bottom: 8px;
}
.cmp.fake .cmp-tag { background: var(--danger); color: #fff; }
.cmp .doc-value { font-size: 26px; }
.cmp.fake .doc-value { color: #b91c1c; text-decoration: line-through; text-decoration-thickness: 2px; }

/* ---------- Chart ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }

/* ---------- Ranking ---------- */
.rank { list-style: none; margin: 0; padding: 0; }
.rank li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--panel2);
  margin-bottom: 8px;
  border: 1px solid var(--line);
}
.rank li.first { border-color: var(--gold); background: rgba(251, 191, 36, .12); }
.rank .rk { width: 40px; text-align: center; font-size: 22px; font-weight: 900; }
.rank .rn { flex: 1; font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .rc { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }

/* ---------- Rules ---------- */
details.rules summary { cursor: pointer; font-weight: 700; }
details.rules ol, details.rules ul { padding-left: 1.3em; line-height: 1.85; font-size: 14px; color: #cbd5e1; }
details.rules h4 { margin: 14px 0 4px; font-size: 14px; color: var(--text); }

/* ---------- Fatal / toast ---------- */
.fatal {
  border: 2px solid var(--danger);
  background: rgba(239, 68, 68, .1);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  line-height: 1.8;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 140%);
  max-width: min(92vw, 480px);
  background: #0f172a;
  border: 1px solid var(--accent-hi);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: var(--shadow);
  transition: transform .3s ease;
  z-index: 100;
  text-align: center;
}
.toast.show { transform: translate(-50%, 0); }

.waiting { color: var(--muted); text-align: center; padding: 8px; font-size: 14px; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }

/* ---------- ver.2：報告順・答え合わせ・出世 ---------- */
.report-order { margin: 0 0 12px; padding-left: 1.6em; line-height: 2; font-weight: 700; }
.report-order li .pdot { display: inline-block; margin-right: 8px; vertical-align: middle; }
.report-order li.is-me { color: #93c5fd; }
.report-tpl {
  background: var(--panel2);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
}
.report-tpl p { margin: 4px 0 0; font-size: 14px; line-height: 1.8; }

.reveal { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
@media (min-width: 640px) { .reveal { grid-template-columns: 1fr 1fr; } }
.reveal li {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  border-radius: 10px;
  padding: 10px 12px;
}
.reveal li.fake { border-left-color: var(--danger); background: rgba(239, 68, 68, .1); }
.rv-head { display: flex; align-items: center; gap: 8px; }
.rv-tag {
  margin-left: auto;
  font-size: 11px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(16, 185, 129, .2);
  color: var(--ok);
}
.reveal li.fake .rv-tag { background: var(--danger); color: #fff; }
.rv-src { font-size: 12px; color: var(--muted); margin-top: 6px; }
.rv-body { font-size: 14px; margin-top: 2px; line-height: 1.6; }
.reveal li.fake .rv-body b { color: #fca5a5; text-decoration: line-through; }

.promo { list-style: none; margin: 0; padding: 0; }
.promo li { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 15px; }
.promo li:last-child { border-bottom: 0; }
.promo li.up b:last-of-type { color: var(--gold); }
.promo li.down b:last-of-type { color: var(--muted); }

.rank .rt {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  margin-top: 2px;
}
.banner.pm {
  background: linear-gradient(135deg, #78350f, #f59e0b);
  color: #fff;
  font-size: 22px;
}

/* ---------- ver.3：物語・解説・振り返り ---------- */
.hero .subtitle {
  font-size: 18px;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: .2em;
  margin: 2px 0 14px;
}
.hero .story {
  font-size: 14px;
  line-height: 2;
  color: #cbd5e1;
  max-width: 30em;
  margin: 0 auto;
}
.hero .story b { color: var(--gold); }

.explain {
  margin-top: 12px;
  background: var(--panel2);
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  padding: 10px 12px;
}
.explain p { margin: 4px 0 0; font-size: 14px; line-height: 1.85; color: #e2e8f0; }

.review { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 10px; }
.review li {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.rv-round { font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rv-round .ok, .rv-round .ng { font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.rv-round .ok { background: rgba(16, 185, 129, .2); color: var(--ok); }
.rv-round .ng { background: rgba(239, 68, 68, .2); color: #fca5a5; }
.rv-vals { margin-top: 6px; font-size: 15px; font-weight: 800; }
.rv-vals .fakeval { color: #fca5a5; text-decoration: line-through; }
.rv-vals .realval { color: var(--ok); }
.rv-exp { margin: 8px 0 0; font-size: 13px; line-height: 1.85; color: #cbd5e1; }

/* ---------- スパイ潜入編 ---------- */
.memo summary { cursor: pointer; font-weight: 700; list-style: none; }
.memo summary::-webkit-details-marker { display: none; }
.memo .memo-body p { margin: 8px 0; font-size: 14px; line-height: 1.75; }
.memo .spy-head { font-weight: 900; color: #fca5a5; }
.spy-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 900;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  vertical-align: middle;
}
table.evidence th, table.evidence td { white-space: nowrap; font-size: 12px; }
