/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button { color: inherit; font-family: inherit; background: none; border: none; cursor: pointer; }

:root {
  --bg: #0d0d0f;
  --bg2: #161618;
  --bg3: #1e1e22;
  --border: #2a2a30;
  --text: #e8e8ec;
  --text-muted: #888;
  --accent: #c9a84c;
  --accent-dim: #8a6f2a;
  --danger: #c0392b;
  --success: #27ae60;
  --system: #4a9eff;
  --radius: 10px;
  --sidebar-w: 240px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .5rem 1.1rem; border-radius: 8px; border: none; cursor: pointer;
  font-size: 14px; font-weight: 600; transition: .15s; text-decoration: none;
  background: var(--bg3); color: var(--text);
}
.btn:hover { filter: brightness(1.2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #0d0d0f; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-outline  { background: transparent; border: 1px solid var(--border); }
.btn-large    { padding: .8rem 1.8rem; font-size: 16px; width: 100%; }
.btn-sm       { padding: .35rem .8rem; font-size: 13px; }

/* ── Forms ── */
input, textarea, select {
  width: 100%; padding: .6rem .9rem; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  font-size: 15px; outline: none; transition: border-color .15s;
  font-family: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
label { display: block; margin-bottom: .3rem; color: var(--text-muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.form-group { margin-bottom: 1.2rem; }

/* ── Landing Page ── */
.landing-page { display: flex; align-items: flex-start; justify-content: center; min-height: 100vh; padding: 2rem 1rem 4rem; }
.landing-container { width: 100%; max-width: 560px; }
.landing-hero { text-align: center; padding: 2rem 0 1.5rem; }
.logo { font-size: 3.5rem; margin-bottom: .5rem; }
.landing-hero h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -.02em; }
.tagline { color: var(--text-muted); margin-top: .4rem; font-size: 1rem; }

.landing-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.8rem; margin-bottom: 1.2rem;
}
.landing-card h2 { font-size: 1.2rem; margin-bottom: 1.2rem; }

/* Story selection */
.story-list { display: flex; flex-direction: column; gap: .6rem; }
.story-option input { display: none; }
.story-card {
  border: 1.5px solid var(--border); border-radius: 8px; padding: 1rem;
  cursor: pointer; transition: .15s;
}
.story-clickable { cursor: pointer; }
.story-clickable:hover .story-card { border-color: var(--accent); background: rgba(201,168,76,.07); }
.story-clickable:active .story-card { transform: scale(.98); }
.story-option input:checked + .story-card { border-color: var(--accent); background: rgba(201,168,76,.07); }
.story-title { font-weight: 700; margin-bottom: .3rem; }
.story-desc  { font-size: 13px; color: var(--text-muted); margin-bottom: .5rem; }
.story-meta  { display: flex; gap: 1rem; font-size: 12px; color: var(--text-muted); }

/* Invite links */
.invite-link-row { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.invite-label    { min-width: 70px; font-size: 13px; color: var(--text-muted); }
.invite-input    { flex: 1; font-size: 12px; font-family: monospace; }
.invite-sent .invite-input { color: var(--success); border-color: var(--success); opacity: .75; }
.invite-sent .btn { opacity: .6; }
.btn-whatsapp { background: #25d366; color: #fff; padding: .35rem .7rem; }
.btn-whatsapp:hover { filter: brightness(1.1); }

/* Lobby */
.player-row { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.player-avatar { font-size: 1.2rem; }
.player-count { text-align: center; margin-top: .8rem; color: var(--text-muted); font-size: 13px; }
.invite-section { margin: 1.2rem 0; }
.invite-section h3 { font-size: 14px; margin-bottom: .6rem; color: var(--text-muted); }
.waiting-msg { text-align: center; color: var(--text-muted); padding: 1.5rem 0; }
.badge { background: var(--accent-dim); color: var(--accent); padding: .1rem .5rem; border-radius: 4px; font-size: 11px; font-weight: 700; }

/* Spinner */
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto .5rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Chat Page ── */
.chat-page { height: 100vh; overflow: hidden; }
.chat-layout { display: flex; height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar-header { padding: 1rem; border-bottom: 1px solid var(--border); }
.game-title { font-weight: 700; font-size: 14px; }
.game-round { color: var(--accent); font-size: 12px; margin-top: .2rem; }

.player-info { padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.role-badge   { display: flex; align-items: center; gap: .6rem; }
.role-emoji   { font-size: 1.8rem; }
.role-name    { font-weight: 700; font-size: 14px; }
.player-name-small { font-size: 12px; color: var(--text-muted); }

.sidebar-section { padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.section-title   { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: .5rem; font-weight: 700; }

.sidebar-player { padding: .3rem 0; font-size: 13px; display: flex; align-items: center; justify-content: space-between; }
.sidebar-player.me { color: var(--accent); }
.badge-sm { background: var(--border); color: var(--text-muted); padding: .1rem .4rem; border-radius: 4px; font-size: 10px; }

/* Main chat */
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.chat-tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--bg2); }
.tab { background: none; border: none; color: var(--text-muted); padding: .75rem 1.2rem; cursor: pointer; font-size: 14px; font-weight: 600; transition: .15s; position: relative; }
.tab.active { color: var(--accent); border-bottom: 2px solid var(--accent); }
.tab:hover   { color: var(--text); }
.badge-new { color: var(--accent); font-size: 10px; position: absolute; top: 6px; right: 6px; }

.tab-content { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.tab-content.active { display: flex; }

.messages {
  flex: 1; overflow-y: auto; padding: 1rem;
  display: flex; flex-direction: column; gap: .5rem;
}

.message { padding: .5rem .8rem; border-radius: 8px; max-width: 90%; }
.message.chat    { background: var(--bg3); align-self: flex-start; }
.message.system, .message.ai { background: rgba(74,158,255,.1); border-left: 3px solid var(--system); align-self: stretch; max-width: 100%; }
.message.role    { background: rgba(201,168,76,.1); border-left: 3px solid var(--accent); align-self: stretch; max-width: 100%; }
.message.cards   { background: rgba(39,174,96,.1); border-left: 3px solid var(--success); align-self: stretch; max-width: 100%; }
.message.ability { background: rgba(155,89,182,.1); border-left: 3px solid #9b59b6; align-self: stretch; max-width: 100%; }

.msg-sender { font-size: 11px; font-weight: 700; color: var(--accent); display: block; margin-bottom: .2rem; }
.msg-content { font-size: 14px; }
.msg-time { font-size: 10px; color: var(--text-muted); margin-top: .2rem; }

.input-area { display: flex; gap: .5rem; padding: .8rem; border-top: 1px solid var(--border); background: var(--bg2); }
.input-area input { flex: 1; }

/* Ability panel */
.ability-panel { padding: 1rem; border-top: 1px solid var(--border); background: var(--bg2); }
.ability-card  { background: var(--bg3); border-radius: 8px; padding: .8rem; margin-bottom: .6rem; }
.ability-name  { font-weight: 700; font-size: 13px; margin-bottom: .2rem; }
.ability-desc  { font-size: 12px; color: var(--text-muted); margin-bottom: .5rem; }
.ability-hint  { color: var(--text-muted); font-size: 13px; }

/* Overlay */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 999; }
.overlay-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem; text-align: center; max-width: 400px; }
.overlay-icon  { font-size: 4rem; margin-bottom: .8rem; }
.overlay-card h2 { font-size: 1.6rem; margin-bottom: .8rem; }
.overlay-card p  { color: var(--text-muted); margin-bottom: 1.5rem; }

/* ── Admin ── */
.admin-page { height: 100vh; overflow: hidden; }
.admin-layout { display: flex; flex-direction: column; height: 100vh; }
.admin-header { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1.5rem; background: var(--bg2); border-bottom: 1px solid var(--border); }
.admin-header h1 { font-size: 1.2rem; }
.admin-status { display: flex; align-items: center; gap: .5rem; font-size: 13px; color: var(--text-muted); }
.status-dot   { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.online  { background: var(--success); }
.status-dot.offline { background: var(--danger); }

.admin-body { display: flex; flex: 1; overflow: hidden; }

.admin-sidebar { width: 280px; flex-shrink: 0; background: var(--bg2); border-right: 1px solid var(--border); overflow-y: auto; padding: 1rem; }
.admin-sidebar h2 { font-size: 14px; margin-bottom: .8rem; display: flex; align-items: center; gap: .5rem; }

.admin-game-card { border: 1px solid var(--border); border-radius: 8px; padding: .8rem; margin-bottom: .6rem; cursor: pointer; transition: .15s; }
.admin-game-card:hover  { border-color: var(--accent-dim); }
.admin-game-card.active { border-color: var(--accent); background: rgba(201,168,76,.07); }
.agc-title { font-weight: 700; font-size: 14px; margin-bottom: .3rem; }
.agc-meta  { display: flex; gap: .6rem; font-size: 12px; color: var(--text-muted); flex-wrap: wrap; margin-bottom: .4rem; }
.agc-players { display: flex; flex-wrap: wrap; gap: .3rem; }

.player-chip { background: var(--bg3); border-radius: 4px; padding: .1rem .5rem; font-size: 11px; }
.player-chip.murderer { background: rgba(192,57,43,.2); color: #e74c3c; }

.admin-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 1rem; min-width: 0; }
#game-detail { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.detail-header { display: flex; align-items: center; gap: 1rem; margin-bottom: .8rem; flex-wrap: wrap; }
.detail-header h2 { font-size: 1.1rem; flex: 1; }
.detail-tabs { display: flex; gap: .3rem; margin-bottom: .8rem; flex-wrap: wrap; max-height: 90px; overflow-y: auto; }
.player-tab { font-size: 12px; padding: .3rem .7rem; }
.admin-invite-links { font-size: 11px; padding: .6rem .8rem; background: var(--bg3); border-radius: 6px; margin-bottom: .6rem; }
.admin-invite-links summary { cursor: pointer; color: var(--text-muted); user-select: none; }
.invite-link-row { display: flex; align-items: center; gap: .4rem; padding: .2rem 0; }
.invite-link-row a { color: var(--accent-dim); text-overflow: ellipsis; overflow: hidden; white-space: nowrap; flex: 1; font-size: 10px; }
.invite-link-row .copy-btn { flex-shrink: 0; background: none; border: 1px solid var(--border); color: var(--text-muted); border-radius: 4px; padding: .1rem .4rem; cursor: pointer; font-size: 10px; }

.admin-messages { flex: 1; overflow-y: auto; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: .8rem; display: flex; flex-direction: column; gap: .4rem; }
.admin-msg { font-size: 13px; padding: .4rem .6rem; border-radius: 6px; background: var(--bg3); }
.admin-msg.system, .admin-msg.ai { background: rgba(74,158,255,.07); border-left: 2px solid var(--system); }
.admin-msg.role   { background: rgba(201,168,76,.07); border-left: 2px solid var(--accent); }
.msg-meta { font-size: 11px; color: var(--text-muted); margin-bottom: .2rem; display: block; }

.admin-events { width: 260px; flex-shrink: 0; background: var(--bg2); border-left: 1px solid var(--border); overflow-y: auto; padding: 1rem; }
.admin-events h2 { font-size: 14px; margin-bottom: .8rem; }
.event-entry { font-size: 12px; padding: .4rem 0; border-bottom: 1px solid var(--border); color: var(--text-muted); word-break: break-all; }
.event-time  { color: var(--accent-dim); margin-right: .3rem; }
.event-game  { color: var(--text-muted); }

.empty-state { text-align: center; color: var(--text-muted); padding: 2rem 1rem; font-size: 13px; }
.empty-state-main { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 1.1rem; }

.state-active  { color: var(--success); }
.state-lobby   { color: var(--accent); }
.state-ended   { color: var(--text-muted); }

/* Accuse select */
#accuse-select { margin-bottom: 0; }

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

/* Mobile */
@media (max-width: 600px) {
  .sidebar { display: none; }
  .admin-events { display: none; }
}
