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

:root {
  --bg: #0f0e17;
  --surface: #1c1b29;
  --surface2: #252438;
  --accent: #e94560;
  --accent2: #ff6b6b;
  --success: #2ecc71;
  --warning: #f39c12;
  --text: #fffffe;
  --text-muted: #a7a9be;
  --border: #2e2d40;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* ─── Screens ────────────────────────────────────────────────── */
.screen { display: none; min-height: 100vh; padding: 20px; }
.screen.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
}
.join-card { max-width: 560px; }
.lobby-card { max-width: 500px; }
.result-card { max-width: 600px; }

/* ─── Typography ─────────────────────────────────────────────── */
.game-title {
  font-size: 2.2rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--accent), #ff9a3c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle { text-align: center; color: var(--text-muted); margin-bottom: 28px; font-size: 0.95rem; }
h2 { font-size: 1.4rem; margin-bottom: 16px; }
h3 { font-size: 1.1rem; margin-bottom: 12px; color: var(--text-muted); }

/* ─── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; }
input[type="text"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--accent); }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--accent2); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:not(:disabled):hover { filter: brightness(1.1); }
.btn-full { width: 100%; margin-top: 8px; }
.btn-small { padding: 4px 10px; font-size: 0.8rem; background: var(--surface2); color: var(--text-muted); }

/* ─── Error / Hint ───────────────────────────────────────────── */
.error-msg { color: var(--accent); font-size: 0.9rem; margin-top: 10px; min-height: 1.2em; text-align: center; }
.hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 12px; text-align: center; }

/* ─── Utility ────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Icon selector ──────────────────────────────────────────── */
.icon-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
}
.icon-btn {
  width: 100px;
  height: 100px;
  padding: 4px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.1s;
}
.icon-btn:hover { border-color: var(--text-muted); transform: scale(1.08); }
.icon-btn.selected {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.15);
  transform: scale(1.12);
}

/* 共通アイコン画像スタイル */
.icon-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 4px;
}
/* 画像読み込み失敗時のフォールバック */
.icon-missing { background: var(--surface2); }

/* ─── Room ID badge ──────────────────────────────────────────── */
.room-id-wrap { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.room-id-label { color: var(--text-muted); font-size: 0.9rem; }
.room-id-badge {
  font-family: monospace;
  font-size: 1.1rem;
  font-weight: 700;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 10px;
  color: var(--warning);
  letter-spacing: 1px;
}
.player-count { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 16px; }

/* ─── Player list ────────────────────────────────────────────── */
.player-list { list-style: none; margin-bottom: 20px; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  margin-bottom: 6px;
}
.player-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.player-icon-sm {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid;
  overflow: hidden;
  flex-shrink: 0;
  padding: 2px;
  background: var(--surface2);
}
.player-name { font-weight: 600; }
.host-badge {
  margin-left: auto;
  font-size: 0.75rem;
  background: var(--warning);
  color: #000;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 700;
}
.me-badge {
  font-size: 0.75rem;
  background: var(--surface);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 4px;
}
.waiting-text { color: var(--text-muted); text-align: center; padding: 12px 0; }

/* ─── Round badge ────────────────────────────────────────────── */
.round-badge {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ─── Drawing screen ─────────────────────────────────────────── */
.drawing-layout {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawing-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.topic-display {
  flex: 1;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 6px 18px;
  border-radius: 8px;
  border: 2px solid currentColor;
  background: var(--surface);
}

.turn-indicator {
  font-size: 0.95rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.turn-indicator.my-turn {
  color: var(--success);
  font-weight: 700;
  animation: pulse-text 1.5s ease-in-out infinite;
}
@keyframes pulse-text {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.canvas-wrap {
  position: relative;
  width: 100%;
  background: #fff;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
#canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
}
#canvas.inactive { cursor: default; }

.drawing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drawing-dots { font-size: 1rem; color: var(--text-muted); }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
.dot-anim { animation: blink 1.2s infinite; }

.drawing-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.turn-order {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.turn-dot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.turn-dot {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 2px solid transparent;
  overflow: hidden;
  padding: 3px;
  background: var(--surface2);
  transition: transform 0.2s, box-shadow 0.2s;
}
.turn-dot.active {
  transform: scale(1.25);
  box-shadow: 0 0 8px rgba(255,255,255,0.5);
}
.turn-dot.done { opacity: 0.3; }
.turn-name { font-size: 0.65rem; color: var(--text-muted); max-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Voting screen ──────────────────────────────────────────── */
.voting-layout {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.voting-header {
  display: flex;
  align-items: center;
  gap: 12px;
}
.voting-header h2 { margin: 0; }

#canvas-voting {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border-radius: var(--radius-sm);
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.vote-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s;
}

.vote-section, .wolf-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.vote-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.vote-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
}
.vote-btn:hover { background: var(--surface); }
.vote-btn.selected {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.12);
}
.vote-btn .v-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.vote-btn .v-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 2px solid;
  overflow: hidden;
  flex-shrink: 0;
  padding: 2px;
  background: var(--surface2);
}

.voted-confirm { color: var(--success); font-weight: 600; margin-top: 10px; }

.wolf-hint { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 12px; }
.wolf-hint strong { color: var(--text); }

/* ─── Wolf guess screen ──────────────────────────────────────── */
.wolf-guess-card {
  max-width: 600px;
}
.wolf-guess-card > * + * { margin-top: 20px; }

.wg-caught-banner {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent);
  padding: 10px;
  border: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  background: rgba(233,69,96,0.1);
}

.wg-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  margin-top: 8px;
}

.wg-wait-text {
  font-size: 1rem;
}

/* ─── Result screen ──────────────────────────────────────────── */
.result-card { max-width: 600px; }
.result-card > * + * { margin-top: 20px; }

.wolf-reveal {
  text-align: center;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--accent);
  font-size: 1rem;
}
.wolf-reveal .wolf-name {
  font-size: 1.4rem;
  font-weight: 800;
  display: block;
  margin-top: 4px;
}

.topic-reveal {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.topic-pair {
  flex: 1;
  min-width: 120px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: center;
}
.topic-label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
.topic-value { display: block; font-size: 1.3rem; font-weight: 700; }
.wolf-topic { color: var(--warning); }

.vote-tally { }
.vote-tally h3 { margin-bottom: 10px; }
.tally-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.tally-row:last-child { border-bottom: none; }
.tally-dot {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 2px solid;
  overflow: hidden;
  flex-shrink: 0;
  padding: 2px;
  background: var(--surface2);
}
.tally-name { flex: 1; font-weight: 600; }
.tally-wolf-tag { font-size: 0.75rem; background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 4px; }
.tally-bar-wrap { width: 120px; height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.tally-bar { height: 100%; border-radius: 4px; transition: width 0.5s; }
.tally-count { font-size: 0.9rem; color: var(--text-muted); min-width: 40px; text-align: right; }

.wolf-guess-result {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.95rem;
}
.wolf-guess-result .label { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 4px; }
.wolf-guess-result .guess-text { font-size: 1.1rem; font-weight: 700; }
.correct-badge { color: var(--success); font-size: 1.1rem; margin-left: 8px; }
.wrong-badge { color: var(--accent); font-size: 1.1rem; margin-left: 8px; }

.win-banner {
  text-align: center;
  padding: 18px;
  border-radius: var(--radius);
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 2px;
  animation: slide-in 0.4s ease-out;
}
.win-banner.villagers { background: rgba(46,204,113,0.15); color: var(--success); border: 2px solid var(--success); }
.win-banner.wolf { background: rgba(233,69,96,0.15); color: var(--accent); border: 2px solid var(--accent); }
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-reason {
  text-align: center;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
}
.reason-villagers { background: rgba(46,204,113,0.12); color: var(--success); }
.reason-wolf      { background: rgba(233,69,96,0.12);  color: var(--accent); }
.reason-next      { background: rgba(167,169,190,0.12); color: var(--text-muted); }

.result-buttons { text-align: center; }
.result-buttons .btn { margin: 6px; }

/* ─── Rules accordion ───────────────────────────────────────── */
.rules-details {
  margin-top: 16px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.rules-summary {
  list-style: none;
  padding: 10px 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  background: var(--surface2);
}
.rules-summary::-webkit-details-marker { display: none; }
.rules-summary:hover { color: var(--text); }
.rules-details[open] .rules-summary { border-bottom: 1px solid var(--border); }
.rules-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface2);
}
.rules-section { }
.rules-heading {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.rules-body ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rules-body li {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding-left: 12px;
  position: relative;
}
.rules-body li::before {
  content: '・';
  position: absolute;
  left: 0;
}
.rules-body strong { color: var(--text); }

/* ─── Ad bar ─────────────────────────────────────────────────── */
#ad-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 12px;
  z-index: 100;
  min-height: 60px;
}
.ad-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  align-self: flex-start;
  padding-top: 2px;
}
#ad-content {
  flex: 1;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 広告バー分のスクロール余白 */
.screen { padding-bottom: 80px; }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .card { padding: 20px; }
  .drawing-header { flex-direction: column; align-items: flex-start; }
  .topic-display { width: 100%; }
  .vote-grid { grid-template-columns: 1fr 1fr; }
  .win-banner { font-size: 1.3rem; }
  .topic-reveal { flex-direction: column; }
}
