:root{
  --bg:#0f1115;
  --card:#171a21;
  --card2:#1f2430;
  --text:#e9eef7;
  --muted:#a9b3c7;
  --border:#2a3140;
  --accent:#ff9500;
  --accent2:#ffb84d;
  --danger:#ff4d4d;
  --ok:#3ddc84;
  --warn:#ffd54a;
}

*{box-sizing:border-box}
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1000px 500px at 50% -100px, #222a3a, var(--bg));
  color:var(--text);
}

.hero{
  padding:28px 16px;
  text-align:center;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #0b0d12, #101522);
}

.hero h1{
  margin:0;
  letter-spacing:0.5px;
}

.hero p{
  margin:8px 0 0;
  color:var(--muted);
}

.container{
  max-width:1100px;
  margin:18px auto 60px;
  padding:0 16px;
}

.card{
  background: linear-gradient(180deg, var(--card), var(--card2));
  border:1px solid var(--border);
  border-radius:14px;
  padding:16px;
  margin:14px 0;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
}

.control-row{
  display:flex;
  gap:14px;
  flex-wrap:wrap;
  align-items:flex-end;
}

.control{
  display:flex;
  flex-direction:column;
  gap:6px;
  min-width: 180px;
}

label{color:var(--muted); font-size:0.92rem}

input, select{
  background:#0f131c;
  color:var(--text);
  border:1px solid var(--border);
  border-radius:10px;
  padding:10px 12px;
  outline:none;
}

input:focus, select:focus{
  border-color: rgba(255,149,0,0.65);
  box-shadow: 0 0 0 3px rgba(255,149,0,0.15);
}

.primary{
  background: linear-gradient(180deg, var(--accent), #e57f00);
  color:#111;
  border:none;
  border-radius:10px;
  padding:10px 14px;
  font-weight:800;
  cursor:pointer;
}

.primary:hover{filter:brightness(1.05)}
.primary.inline{display:inline-block; text-decoration:none}

.status{margin-top:6px; color:var(--muted); font-size:0.9rem}

.toggles-row{
  display:flex;
  gap:18px;
  align-items:center;
  margin-top:10px;
  flex-wrap:wrap;
}

.toggle{
  display:flex;
  align-items:center;
  gap:8px;
  user-select:none;
  cursor:pointer;
}

.stat-options{
  margin-top:12px;
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  align-items:center;
  color:var(--muted);
}

.game-area{
  display:flex;
  flex-direction:column;
  gap:16px;
}

.participant{
  border:1px solid var(--border);
  border-radius:14px;
  padding:14px;
  background: rgba(0,0,0,0.12);
}

.participant h3{
  margin:0 0 10px;
}

.muted{color:var(--muted)}

.rows{
  display:flex;
  flex-direction:column;
  gap:10px;
  margin-top:10px;
}

.attr-row{
  display:grid;
  grid-template-columns: 160px 1fr 92px;
  gap:10px;
  align-items:center;
}

.attr-label{
  font-weight:700;
}

.attr-value input{
  width:100%;
}

.dice-btn{
  justify-self:end;
  padding:9px 12px;
  border-radius:10px;
  background: #222a3a;
  border:1px solid var(--border);
  color:var(--accent2);
  font-weight:800;
  cursor:pointer;
}

.dice-btn:hover{filter:brightness(1.08)}

.sim-output{
  margin-top:12px;
  white-space:pre-wrap;
  background:#0d1119;
  border:1px solid var(--border);
  padding:12px;
  border-radius:12px;
  min-height:60px;
}

/* Modal */
.modal-overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.65);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
  z-index:100;
}

.hidden{display:none}

.modal{
  width:min(1100px, 95vw);
  max-height: 85vh;
  background: linear-gradient(180deg, var(--card), var(--card2));
  border:1px solid var(--border);
  border-radius:14px;
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

.modal-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 14px;
  border-bottom:1px solid var(--border);
}

.icon-btn{
  background:transparent;
  border:none;
  color:var(--text);
  font-size:18px;
  cursor:pointer;
}

.modal-body{
  padding:12px;
  overflow:auto;
}

.pick-table{
  width:100%;
  border-collapse:collapse;
  font-size:0.92rem;
}

.pick-table th, .pick-table td{
  padding:10px 8px;
  border-bottom:1px solid rgba(255,255,255,0.06);
  text-align:left;
}

.pick-table th{
  position:sticky;
  top:0;
  background:#0f141f;
  z-index:1;
  color:var(--muted);
}

.stat-gold{color:#111; background:#f5c542}
.stat-green{color:#0b2; background:#1c3a2a}
.stat-yellow{color:#f5d000; background:#3a3418}
.stat-orange{color:#ffb347; background:#3a2a12}
.stat-red{color:#ff6b6b; background:#3a1a1a}

.pick-table td.stat-gold,
.pick-table td.stat-green,
.pick-table td.stat-yellow,
.pick-table td.stat-orange,
.pick-table td.stat-red{
  border-radius:8px;
  padding:8px;
}

.pill{
  display:inline-block;
  padding:4px 8px;
  border-radius:999px;
  border:1px solid var(--border);
  color:var(--muted);
}

.legend{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
  margin-top:10px;
  color:var(--muted);
  font-size:0.9rem;
}

.legend .pill{
  color:#111;
  font-weight:700;
}

.legend .stat-gold{color:#111}
.legend .stat-green{color:#b7ffd9}
.legend .stat-yellow{color:#ffe57a}
.legend .stat-orange{color:#ffd1a6}
.legend .stat-red{color:#ffc0c0}
/* ========================================
   AI BIOGRAPHY MODAL & CONTROLS
   ======================================== */

.ai-button-group{
  display:flex;
  gap:10px;
  margin-top:12px;
  flex-wrap:wrap;
}

.ai-button{
  padding:9px 12px;
  border-radius:10px;
  border:1px solid var(--border);
  background: #222a3a;
  color:var(--accent2);
  font-weight:700;
  cursor:pointer;
  font-size:0.92rem;
}

.ai-button:hover:not(:disabled){
  filter:brightness(1.1);
  background: #2a3240;
}

.ai-button:disabled{
  opacity:0.5;
  cursor:not-allowed;
  color:var(--muted);
}

.ai-button.disabled-gemini:disabled::after{
  content:" (quota exhausted)";
  font-size:0.8rem;
}

.ai-modal{
  display:flex;
  flex-direction:column;
  height:100%;
}

.ai-modal-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:14px 16px;
  border-bottom:1px solid var(--border);
  flex-shrink:0;
}

.ai-modal-header h3{
  margin:0;
}

.ai-modal-body{
  flex:1;
  overflow:auto;
  padding:16px;
  background: #0d111c;
}

.ai-bio-text{
  line-height:1.6;
  color:var(--text);
  margin:0;
  white-space:pre-wrap;
  word-wrap:break-word;
}

.ai-modal-controls{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin-top:14px;
  padding-top:14px;
  border-top:1px solid var(--border);
}

.ai-control-btn{
  padding:8px 12px;
  border-radius:8px;
  border:1px solid var(--border);
  background: #222a3a;
  color:var(--text);
  cursor:pointer;
  font-weight:600;
  font-size:0.9rem;
}

.ai-control-btn:hover{
  background: #2a3240;
  filter:brightness(1.05);
}

.ai-control-btn.active{
  background: var(--accent);
  color:#111;
  border-color:var(--accent);
}

.ai-loading{
  display:flex;
  align-items:center;
  justify-content:center;
  min-height:200px;
  gap:12px;
  color:var(--muted);
}

.ai-spinner{
  width:24px;
  height:24px;
  border:2px solid rgba(255,149,0,0.2);
  border-top-color:var(--accent);
  border-radius:50%;
  animation:spin 0.8s linear infinite;
}

@keyframes spin{
  to { transform:rotate(360deg); }
}

.ai-error-box{
  background: rgba(255,77,77,0.1);
  border:1px solid rgba(255,77,77,0.3);
  border-radius:10px;
  padding:12px;
  color:#ff6b6b;
  margin-bottom:12px;
}

.ai-success-note{
  font-size:0.85rem;
  color:var(--muted);
  margin-top:10px;
  padding-top:10px;
  border-top:1px solid var(--border);
}

.ai-copy-btn{
  padding:8px 10px;
  border-radius:8px;
  border:1px solid var(--border);
  background: transparent;
  color:var(--accent2);
  cursor:pointer;
  font-size:0.9rem;
  font-weight:600;
}

.ai-copy-btn:hover{
  background: #222a3a;
}

.ai-copy-btn.copied{
  color:#3ddc84;
}

@media (max-width: 768px) {
  .ai-button-group{
    flex-direction:column;
  }

  .ai-button{
    width:100%;
  }

  .ai-modal-controls{
    justify-content:center;
  }

  .ai-control-btn{
    flex:1;
    min-width:100px;
  }
}