:root {
  --bg: #0a0e17;
  --bg2: #111827;
  --bg3: #1a2234;
  --border: #2a3548;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #e8c547;
  --danger: #c0392b;
  --wolf: #e74c3c;
  --villager: #27ae60;
  --cyan: #22d3ee;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Auth screens */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(192,57,43,0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(232,197,71,0.08) 0%, transparent 50%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.auth-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.auth-logo h1 {
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(135deg, #e8c547, #c0392b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0.5rem 0 0;
}
.auth-logo .moon {
  font-size: 2.5rem;
  filter: drop-shadow(0 0 12px rgba(232,197,71,0.5));
}
.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.auth-tabs button {
  flex: 1;
  padding: 0.6rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}
.auth-tabs button.active {
  background: rgba(232,197,71,0.15);
  border-color: var(--accent);
  color: var(--accent);
}
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--accent); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, #c0392b, #8e1b12);
  color: white;
  width: 100%;
  padding: 0.85rem;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.15); }
.btn-accent {
  background: linear-gradient(135deg, #e8c547, #b8962e);
  color: #1a1a1a;
}
.btn-accent:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg3); }
.btn-danger {
  background: rgba(192,57,43,0.2);
  border: 1px solid var(--danger);
  color: #f87171;
}
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.7rem; border-radius: 4px; }
.error-msg {
  background: rgba(192,57,43,0.15);
  border: 1px solid rgba(192,57,43,0.4);
  color: #f87171;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.success-msg {
  background: rgba(39,174,96,0.15);
  border: 1px solid rgba(39,174,96,0.4);
  color: #6ee7b7;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* Hidden master link */
.hidden-dot {
  position: fixed;
  bottom: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  background: #1a1a1a;
  border-radius: 50%;
  opacity: 0.15;
  cursor: default;
  z-index: 9999;
  border: none;
  padding: 0;
}
.hidden-dot:hover { opacity: 0.25; }

/* Lobby */
.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.75rem;
}
.lobby-header h1 {
  font-size: 1.25rem;
  margin: 0;
  background: linear-gradient(135deg, #e8c547, #c0392b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.lobby-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem;
}
.room-list { display: flex; flex-direction: column; gap: 0.75rem; }
.room-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  transition: border-color 0.2s;
}
.room-card:hover { border-color: var(--accent); }
.room-card .name { font-weight: 700; font-size: 1.05rem; }
.room-card .meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}
.badge-waiting { background: rgba(39,174,96,0.2); color: #6ee7b7; }
.badge-playing { background: rgba(232,197,71,0.2); color: #fcd34d; }
.badge-finished { background: rgba(156,163,175,0.2); color: #9ca3af; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
}
.modal h2 { margin: 0 0 1rem; font-size: 1.15rem; }

/* Game layout */
.game-layout {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.game-top {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.phase-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.phase-badge {
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.3rem 0.75rem;
  border-radius: 8px;
  background: var(--bg3);
}
.phase-badge.night { background: rgba(99,102,241,0.25); color: #a5b4fc; }
.phase-badge.day { background: rgba(232,197,71,0.2); color: #fcd34d; }
.phase-badge.vote { background: rgba(192,57,43,0.25); color: #f87171; }
.phase-badge.finished { background: rgba(39,174,96,0.2); color: #6ee7b7; }
.timer {
  font-family: 'Courier New', monospace;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
}
.timer.urgent { color: #f87171; animation: pulse 1s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Role panel - always visible */
.role-panel {
  background: linear-gradient(90deg, var(--bg3), var(--bg2));
  border-bottom: 2px solid;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.role-panel .role-name {
  font-weight: 800;
  font-size: 1.05rem;
  white-space: nowrap;
}
.role-panel .role-desc {
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1;
  min-width: 150px;
}
.role-panel .role-team {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
}

.game-main {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  min-height: 0;
}
@media (min-width: 768px) {
  .game-main {
    grid-template-columns: 220px 1fr;
  }
}
@media (min-width: 1100px) {
  .game-main {
    grid-template-columns: 260px 1fr 280px;
  }
}

/* Players grid - compact for 30 */
.players-panel {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.75rem;
  min-height: 0;
}
.players-panel h3 {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(95px, 1fr));
  gap: 0.4rem;
}
@media (min-width: 768px) {
  .players-grid {
    grid-template-columns: 1fr;
  }
}
.player-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  font-size: 0.8rem;
  cursor: default;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}
.player-chip.clickable { cursor: pointer; }
.player-chip.clickable:hover {
  border-color: var(--accent);
  background: rgba(232,197,71,0.1);
}
.player-chip.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  background: rgba(232,197,71,0.15);
}
.player-chip.dead {
  opacity: 0.45;
  text-decoration: line-through;
}
.player-chip.me {
  border-color: rgba(34,211,238,0.5);
}
.player-chip .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #27ae60;
}
.player-chip .status-dot.off { background: #6b7280; }
.player-chip .status-dot.dead-dot { background: #c0392b; }
.player-chip .pname {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  font-weight: 600;
}
.player-chip .prole {
  font-size: 0.65rem;
  color: var(--wolf);
  flex-shrink: 0;
}
.player-chip .acted {
  font-size: 0.6rem;
  color: var(--accent);
}

/* Chat */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}
.chat-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.chat-tabs button {
  flex: 1;
  padding: 0.55rem 0.5rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.chat-tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.chat-tabs button.wolf-tab.active {
  color: var(--wolf);
  border-bottom-color: var(--wolf);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-height: 0;
}
.chat-msg {
  font-size: 0.85rem;
  line-height: 1.4;
  word-break: break-word;
}
.chat-msg .cname {
  font-weight: 700;
  margin-right: 0.4rem;
  color: #93c5fd;
}
.chat-msg.system .cname { color: var(--accent); }
.chat-msg.system { color: var(--muted); font-style: italic; font-size: 0.8rem; }
.chat-msg.werewolf .cname { color: var(--wolf); }
.chat-msg.werewolf {
  background: rgba(231,76,60,0.08);
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border-left: 2px solid var(--wolf);
}
.chat-msg.dead .cname { color: #a78bfa; }
.chat-msg .ctime {
  font-size: 0.65rem;
  color: #4b5563;
  margin-left: 0.35rem;
}
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  display: flex;
  gap: 0.5rem;
  background: var(--bg2);
  flex-shrink: 0;
}
.chat-input-area input {
  flex: 1;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.chat-input-area input:focus { border-color: var(--accent); }

/* Action panel */
.action-panel {
  background: var(--bg2);
  border-left: 1px solid var(--border);
  padding: 0.75rem;
  overflow-y: auto;
  min-height: 0;
}
.action-panel h3 {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.action-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}
.action-results {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.action-result-item {
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
  background: var(--bg3);
  border-radius: 6px;
  margin-bottom: 0.35rem;
}
.gm-controls {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.gm-controls h3 { color: var(--accent); }

/* Mobile action bar */
.mobile-action-bar {
  display: none;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  padding: 0.5rem 0.75rem;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
@media (max-width: 1099px) {
  .action-panel { display: none; }
  .mobile-action-bar { display: flex; }
}
@media (max-width: 767px) {
  .players-panel {
    max-height: 140px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .game-main {
    grid-template-rows: auto 1fr;
  }
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--muted);
  font-size: 1.1rem;
}
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  z-index: 2000;
  font-size: 0.9rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
