:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e8eaed;
  --muted: #9aa0ab;
  --accent: #4f8cff;
  --danger: #ef4444;
  --pink: #3a1f2a;
  --pink-text: #ff9db3;
  --green: #123a24;
  --green-text: #5be08a;
  --border: #2a2e38;
  --role-p: #f5a623;
  --role-d: #2ecc71;
  --role-c: #29b6f6;
  --role-a: #e74c3c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; }
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 32px; max-width: 360px; width: 100%; text-align: center;
}
.login-box h1 { margin: 0 0 8px; font-size: 24px; }
.login-box p { color: var(--muted); margin: 0 0 20px; }
.login-box select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 15px; margin-bottom: 14px;
}
.who-enter-btn { width: 100%; }

.app { padding: 12px 12px 40px; max-width: 100%; }

.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 4px 14px;
  position: sticky; top: 0; background: var(--bg); z-index: 30;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; text-align: center; line-height: 1.15; font-weight: 800; }
.topbar-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  font-size: 18px; width: 38px; height: 38px; border-radius: 10px; cursor: pointer; flex-shrink: 0;
}
.me { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0; }

.players-updated-at { color: var(--muted); font-size: 11px; text-align: center; margin: 0 0 8px; }

.active-role-banner {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 12px; font-weight: 600; text-align: center;
}
.active-role-banner.done { background: var(--green); color: var(--green-text); }

.pick-form {
  display: grid; grid-template-columns: 1fr; gap: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; margin-bottom: 16px;
}
@media (min-width: 640px) {
  .pick-form { grid-template-columns: 1fr 2fr 1fr auto; align-items: end; }
}
.field { display: flex; flex-direction: column; gap: 4px; position: relative; }
.field label { font-size: 12px; color: var(--muted); }
.field select, .field input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 15px; width: 100%;
}
.field select:focus, .field input:focus { outline: 2px solid var(--accent); }
.submit-btn {
  background: var(--accent); color: white; border: none; border-radius: 10px;
  padding: 12px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.submit-btn:active { opacity: 0.85; }
.error-text { color: var(--danger); font-size: 13px; margin: 4px 0 0; min-height: 1em; }

.dropdown {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  max-height: 260px; overflow-y: auto; z-index: 40; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.dropdown-item { padding: 10px 12px; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dropdown-item:hover, .dropdown-item.active { background: var(--panel); }
.dropdown-item-left { display: flex; align-items: center; gap: 8px; }
.dropdown-empty { padding: 12px; color: var(--muted); font-size: 13px; }
.dropdown-add { padding: 10px 12px; cursor: pointer; font-size: 13px; color: var(--accent); border-top: 1px solid var(--border); }
.dropdown-add:hover { background: var(--panel); }

.team-badge { width: 18px; height: 18px; object-fit: contain; flex-shrink: 0; vertical-align: middle; }
.role-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%; font-size: 10px; font-weight: 700;
  color: white; flex-shrink: 0; margin-right: 4px;
}
.role-dot-p { background: var(--role-p); }
.role-dot-d { background: var(--role-d); }
.role-dot-c { background: var(--role-c); }
.role-dot-a { background: var(--role-a); }

.board-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 14px; max-height: 70vh; }
.board { border-collapse: collapse; width: 100%; min-width: 100%; }
.board th, .board td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 8px 10px; text-align: left; white-space: nowrap; vertical-align: top; }
.board thead th { position: sticky; top: 0; background: var(--panel); z-index: 10; }
.board thead tr.row-badges th { top: 44px; padding-top: 4px; padding-bottom: 8px; }
.owner-head { display: flex; flex-direction: column; gap: 2px; }
.owner-head .owner-name { font-weight: 700; font-size: 14px; }
.owner-head .owner-remaining { font-size: 13px; color: var(--accent); font-weight: 600; }
.role-badges { display: flex; gap: 4px; }
.role-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; padding: 3px 6px 3px 3px; border-radius: 6px;
  background: var(--pink); color: var(--pink-text); font-weight: 600;
}
.role-badge.done { background: var(--green); color: var(--green-text); }
.role-badge .role-dot { width: 15px; height: 15px; font-size: 8px; margin-right: 0; }
.player-cell { display: flex; align-items: center; gap: 8px; min-width: 190px; }
.player-cell .pname { font-size: 13px; display: inline-flex; align-items: center; flex: 1; min-width: 0; }
.player-cell .pname-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-cell .pcredits { font-size: 13px; color: var(--muted); font-weight: 600; min-width: 26px; text-align: right; flex-shrink: 0; }
.del-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; width: 22px; height: 22px; font-size: 12px; cursor: pointer; flex-shrink: 0;
}
.del-btn.confirm1 { border-color: var(--danger); color: var(--danger); }
.del-btn.confirm2 { background: var(--danger); color: white; border-color: var(--danger); }
.empty-cell { color: var(--border); }
.board td[colspan] { text-align: center; padding: 24px; color: var(--muted); }
.board td.role-sep { border-top: 2px solid var(--accent); }

.log-panel { position: fixed; top: 0; right: 0; height: 100vh; height: 100dvh; z-index: 100; }
.log-backdrop { position: fixed; top: 0; right: 0; left: 0; width: 100%; height: 100vh; height: 100dvh; z-index: 90; background: rgba(0,0,0,0.5); }
.log-panel { width: min(420px, 92vw); background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; }
.log-panel-header { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.log-panel-header h2 { font-size: 16px; margin: 0; }
.log-list { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 14px; flex: 1 1 auto; min-height: 0; }
.log-item { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.log-item .log-detail { margin: 0 0 3px; }
.log-item .log-meta { color: var(--muted); font-size: 11px; }

.confirm-modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.6); padding: 20px; }
.confirm-box { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px; max-width: 320px; width: 100%; text-align: center; }
.confirm-box p { margin: 0 0 16px; font-size: 15px; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
.danger-btn { background: var(--danger); color: white; border: none; border-radius: 10px; padding: 10px 18px; cursor: pointer; font-weight: 600; }

.add-player-box { text-align: left; max-width: 340px; }
.add-player-box h3 { margin: 0 0 4px; font-size: 17px; }
.add-player-hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.add-player-box .field { margin-bottom: 10px; }
.add-player-box .confirm-actions { justify-content: flex-start; margin-top: 4px; }
.danger-link-btn {
  background: none; border: none; color: var(--danger); cursor: pointer;
  font-size: 13px; padding: 0; margin-top: 14px; text-decoration: underline;
}

.rules-panel-footer { padding: 12px 14px; border-top: 1px solid var(--border); flex-shrink: 0; }
.rules-panel-footer .submit-btn { width: 100%; }

.rules-list { font-size: 14px; line-height: 1.5; }
.rules-note { color: var(--muted); font-size: 12px; margin: 0 0 16px; }
.rules-list h3 { font-size: 14px; margin: 18px 0 8px; color: var(--accent); }
.rules-list h3:first-of-type { margin-top: 0; }
.rules-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.rules-item-text { flex: 1; }
.rules-edit-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; width: 26px; height: 26px; font-size: 12px; cursor: pointer; flex-shrink: 0;
}
.rules-edit-btn:hover { color: var(--accent); border-color: var(--accent); }

.add-player-box textarea {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 15px; width: 100%; font-family: inherit; resize: vertical;
}
