* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #0d1a3d 0%, #2c3e80 100%);
  color: #e8eefa;
  min-height: 100vh;
  padding: 20px;
}
.container {
  max-width: 1300px;
  margin: 0 auto;
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  backdrop-filter: blur(8px);
}
.hidden { display: none !important; }
.login { max-width: 420px; text-align: center; margin-top: 60px; }
.login h1 { margin-bottom: 8px; }
.login p { color: #b8c5ff; margin-bottom: 20px; }
.login input { width: 100%; }
.login .btn { width: 100%; margin-top: 12px; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.95rem;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  background: rgba(0,0,0,0.25);
  color: #fff;
  margin-top: 4px;
  outline: none;
  font-family: inherit;
}
input[type="color"] { padding: 4px; height: 42px; cursor: pointer; }
input:focus, select:focus, textarea:focus { border-color: #5a78e0; box-shadow: 0 0 0 3px rgba(90,120,224,0.25); }
textarea { font-family: "Courier New", monospace; font-size: 0.85rem; }
label { display: block; margin-top: 12px; font-size: 0.9rem; color: #b8c5ff; font-weight: 600; }

.btn {
  padding: 10px 16px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.2s, transform 0.1s;
}
.btn:hover { background: rgba(255,255,255,0.15); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, #3a5fcd 0%, #5a78e0 100%);
  border-color: transparent;
  font-weight: 700;
}
.btn.primary:hover { background: linear-gradient(135deg, #4a6fdd 0%, #6a88f0 100%); }
.btn.danger { background: rgba(192, 57, 43, 0.3); border-color: rgba(192, 57, 43, 0.6); }
.btn.danger:hover { background: rgba(192, 57, 43, 0.5); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.topbar h1 { font-size: 1.3rem; }
.topbar h1 small { font-size: 0.85rem; color: #b8c5ff; font-weight: normal; }

.instances-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 0.92rem; }
.instances-table th, .instances-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.1); }
.instances-table th { background: rgba(0,0,0,0.25); font-size: 0.8rem; text-transform: uppercase; color: #b8c5ff; }
.instances-table tr:hover { background: rgba(255,255,255,0.03); }
.instances-table code { background: rgba(0,0,0,0.3); padding: 2px 6px; border-radius: 4px; font-size: 0.85rem; }
.instances-table a { color: #aed6ff; text-decoration: none; }
.instances-table a:hover { text-decoration: underline; }

.status-online { color: #66bb6a; font-weight: 700; }
.status-offline { color: #ef5350; font-weight: 700; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.78rem; font-weight: 700; }
.badge.lobby { background: #ffeb3b40; color: #fdd835; }
.badge.playing { background: #66bb6a40; color: #66bb6a; }
.badge.finished { background: #ce93d840; color: #ce93d8; }

.actions-cell { display: flex; gap: 4px; flex-wrap: wrap; }

.empty {
  text-align: center; padding: 40px; color: #b8c5ff; font-size: 1.1rem;
  border: 2px dashed rgba(255,255,255,0.15); border-radius: 12px; margin-top: 20px;
}

/* Modales */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  overflow-y: auto;
}
.modal.hidden { display: none; }
.modal-content {
  background: #1a2960; border-radius: 14px; padding: 24px;
  max-width: 500px; width: 100%; max-height: 95vh; overflow: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.modal-content.wide { max-width: 1000px; }
.modal-content.xwide { max-width: 1200px; }
.modal-content h2 { margin-bottom: 12px; }
.modal-content h3 { margin: 10px 0 8px; }
.modal-content h4 { margin: 10px 0 6px; color: #b8c5ff; }
.modal-content code { background: rgba(0,0,0,0.3); padding: 2px 6px; border-radius: 4px; }

.row { display: flex; gap: 20px; flex-wrap: wrap; }
.col { flex: 1; min-width: 280px; }

.actions { margin-top: 18px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.err { color: #ff8888; margin-top: 8px; min-height: 18px; }
.small { font-size: 0.82rem; color: #b8c5ff; margin-top: 6px; }
.logs { background: #000; color: #0f0; padding: 14px; border-radius: 8px; max-height: 60vh; overflow: auto; font-size: 0.78rem; white-space: pre-wrap; }
hr { border: none; border-top: 1px solid rgba(255,255,255,0.15); margin: 16px 0; }

/* ---- Galerie de templates ---- */
.preset-gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px; margin: 16px 0;
}
.preset-card {
  border-radius: 12px; padding: 14px; cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative; overflow: hidden;
  min-height: 200px;
  display: flex; flex-direction: column; gap: 8px;
  color: #1a1a1a;
}
.preset-card:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
.preset-card .pc-emoji { font-size: 2.2rem; }
.preset-card .pc-title { font-size: 1.15rem; font-weight: 800; }
.preset-card .pc-subtitle { font-size: 0.88rem; opacity: 0.85; font-style: italic; }
.preset-card .pc-count {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0,0,0,0.15); padding: 3px 8px;
  border-radius: 12px; font-size: 0.75rem; font-weight: 700;
}
.preset-card .pc-sample {
  background: rgba(255,255,255,0.7); border-radius: 8px;
  padding: 8px 10px; font-size: 0.82rem; margin-top: auto;
  border-left: 3px solid currentColor;
  font-style: italic;
}
.preset-card .pc-actions { display: flex; gap: 6px; margin-top: 8px; }
.preset-card .pc-actions button {
  flex: 1; padding: 6px 10px; font-size: 0.85rem;
  border: 1px solid rgba(0,0,0,0.2); background: rgba(255,255,255,0.75);
  color: #1a1a1a; border-radius: 6px; cursor: pointer; font-weight: 700;
}
.preset-card .pc-actions button:hover { background: rgba(255,255,255,0.95); }
.preset-card .pc-actions button.choose { background: rgba(0,0,0,0.75); color: #fff; border-color: transparent; }

.selected-preset {
  background: rgba(255,255,255,0.08); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 14px;
  display: flex; gap: 12px; align-items: center;
}
.selected-preset .sp-emoji { font-size: 2rem; }
.selected-preset .sp-text { flex: 1; }
.selected-preset .sp-text strong { display: block; }
.selected-preset .sp-text small { color: #b8c5ff; }

/* ---- Aperçu visuel (mini-jeu) ---- */
.preview-frame {
  border-radius: 12px; padding: 18px;
  min-height: 240px;
  display: flex; flex-direction: column; gap: 10px;
}
.preview-frame.compact { min-height: 160px; padding: 14px; }
.preview-frame .pf-title { font-size: 1.3rem; font-weight: 800; text-align: center; }
.preview-frame .pf-subtitle { font-size: 0.95rem; text-align: center; font-style: italic; }
.preview-frame .pf-card {
  border-radius: 10px; padding: 14px;
  background: rgba(255,255,255,0.92); color: #1a1a1a;
}
.preview-frame .pf-q { font-size: 0.95rem; margin-bottom: 8px; }
.preview-frame .pf-input {
  background: #fff; border-radius: 6px; padding: 8px 10px;
  font-size: 0.85rem; color: #888; border: 1px solid #ddd;
}
.preview-frame .pf-btn {
  background: linear-gradient(135deg, currentColor 0%, currentColor 100%);
  filter: brightness(0.85);
  color: #fff !important;
  padding: 10px; border-radius: 8px; text-align: center;
  font-weight: 700; margin-top: 8px;
}

.preview-questions {
  max-height: 400px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
}
.preview-questions .pq {
  background: rgba(255,255,255,0.05); border-radius: 8px;
  padding: 10px 12px; font-size: 0.88rem;
  border-left: 3px solid #5a78e0;
}
.preview-questions .pq-num { color: #b8c5ff; font-weight: 700; margin-right: 6px; }
.preview-questions .pq-ans {
  font-size: 0.78rem; color: #aed6ff; margin-top: 4px; font-style: italic;
}

/* ---- Onglets ---- */
.tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  margin-bottom: 16px; padding-bottom: 0;
}
.tab {
  background: transparent; color: #b8c5ff;
  padding: 10px 14px; border: none; border-radius: 6px 6px 0 0;
  cursor: pointer; font-size: 0.92rem; font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { background: rgba(255,255,255,0.06); color: #fff; }
.tab.active {
  background: rgba(90,120,224,0.25);
  color: #fff;
  border-bottom: 2px solid #5a78e0;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.theme-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 12px;
}
.theme-grid > div { min-width: 0; }

/* ---- Questions editor ---- */
.questions-editor {
  display: flex; flex-direction: column; gap: 12px;
  max-height: 60vh; overflow-y: auto;
  margin-bottom: 14px; padding: 4px;
}
.qcard {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.qcard-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; flex-wrap: wrap;
}
.qcard-num { font-weight: 800; color: #aed6ff; font-size: 0.92rem; }
.qcard-buttons { display: flex; gap: 4px; }
.qcard-buttons button {
  padding: 4px 8px; font-size: 0.85rem;
  background: rgba(255,255,255,0.1); color: #fff;
  border: 1px solid rgba(255,255,255,0.15); border-radius: 5px;
  cursor: pointer;
}
.qcard-buttons button:hover { background: rgba(255,255,255,0.2); }
.qcard-buttons button.del { background: rgba(192,57,43,0.3); }
.qcard textarea { font-family: inherit; font-size: 0.92rem; min-height: 50px; }
.qcard .qrow {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.qcard .qrow-small {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
}
.qcard label { font-size: 0.82rem; margin-top: 2px; }
.qcard input, .qcard textarea { font-size: 0.88rem; padding: 7px 9px; }

.current-logo {
  background: rgba(255,255,255,0.06);
  border: 1px dashed rgba(255,255,255,0.2);
  padding: 14px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; min-height: 80px;
  color: #b8c5ff; font-style: italic;
}
.current-logo img { max-height: 100px; max-width: 200px; border-radius: 6px; }
