:root {
  --blue: #00A3E0;
  --blue-dark: #0080B0;
  --green: #73C92D;
  --green-dark: #5EA824;
  --gray: #91999F;
  --gray-light: #F2F4F5;
  --gray-dark: #4A4F53;
  --white: #FFFFFF;
  --text: #2C3033;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  --font: "Trebuchet MS", "Trebuchet MS Bold", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--gray-light);
}

a { color: inherit; }

button {
  font-family: var(--font);
  cursor: pointer;
}

.hidden { display: none !important; }

/* ---------- Bandeau ---------- */

.top-bar {
  background: var(--blue);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-bar__title {
  font-size: 1.4rem;
  font-weight: bold;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.top-bar__gear {
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 1.5rem;
  padding: 0.4rem;
  border-radius: 50%;
  transition: transform 0.4s ease, background 0.2s ease;
}

.top-bar__gear:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: rotate(70deg);
}

/* ---------- Conteneur principal ---------- */

.main-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.2rem 4rem;
}

/* ---------- Bulle compteur ---------- */

.stories-bubble {
  background: var(--white);
  border: 2px solid var(--green);
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: bold;
  color: var(--green-dark);
  margin: 0 auto 1.4rem;
  box-shadow: var(--shadow);
  width: fit-content;
}

.stories-bubble i { color: var(--green); }

.bubble-wrap { display: flex; justify-content: center; }

/* ---------- Formulaire ---------- */

.story-form {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.8rem;
}

.story-form h2 {
  margin-top: 0;
  font-size: 1.2rem;
  color: var(--blue);
}

.field {
  margin-bottom: 1.4rem;
}

.field label {
  display: block;
  font-weight: bold;
  margin-bottom: 0.5rem;
  color: var(--gray-dark);
}

.field input[type="text"] {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--gray-light);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 1rem;
  background: var(--gray-light);
  transition: border-color 0.2s ease;
}

.field input[type="text"]:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--white);
}

.world-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.world-chip {
  background: var(--gray-light);
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  color: var(--gray-dark);
  transition: background 0.2s ease, color 0.2s ease;
}

.world-chip:hover {
  background: var(--blue);
  color: var(--white);
}

/* ---------- Sélecteur d'âge PEGI ---------- */

.age-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.age-square {
  flex: 1 1 0;
  min-width: 70px;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 3px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-weight: bold;
  font-size: 1rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.age-square span.age-num { font-size: 1.3rem; }
.age-square span.age-txt { font-size: 0.7rem; font-weight: normal; }

.age-square:hover { transform: translateY(-3px); }

.age-square.selected {
  border-color: var(--blue);
  transform: translateY(-3px);
}

.age-square.selected::after {
  content: "\f00c";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.8rem;
}

.age-square[data-age="18"] { color: var(--white); }

/* ---------- Boutons ---------- */

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.8rem 1.6rem;
  font-size: 1rem;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--green);
  color: var(--white);
  width: 100%;
  justify-content: center;
  padding: 1rem;
  margin-top: 0.6rem;
}

.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { background: var(--gray); cursor: not-allowed; }

.btn-secondary {
  background: var(--gray-light);
  color: var(--gray-dark);
}

.btn-secondary:hover { background: #e4e7e9; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--blue);
  color: var(--blue);
}

.btn-outline:hover { background: var(--blue); color: var(--white); }

.btn-danger { background: #E5322D; color: var(--white); }
.btn-danger:hover { filter: brightness(1.08); }

/* ---------- Bouton "voir les histoires" ---------- */

.browse-btn-wrap { text-align: center; margin-top: 1.4rem; }

/* ---------- Modal générique ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 27, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  background: var(--white);
  border-radius: var(--radius);
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal--wide { max-width: 960px; }

.modal__header {
  background: var(--blue);
  color: var(--white);
  padding: 1rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__header h3 { margin: 0; font-size: 1.15rem; }

.modal__close {
  background: transparent;
  border: none;
  color: var(--white);
  font-size: 1.3rem;
}

.modal__body {
  padding: 1.4rem;
  overflow-y: auto;
}

.modal__filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-pill {
  border: 2px solid var(--gray-light);
  background: var(--white);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  color: var(--gray-dark);
}

.filter-pill.active {
  border-color: var(--blue);
  color: var(--blue);
  background: #E6F7FD;
}

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

.stories-table th {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 2px solid var(--gray-light);
  color: var(--gray-dark);
}

.stories-table td {
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--gray-light);
  vertical-align: middle;
}

.pegi-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: bold;
  color: var(--white);
  padding: 0.15rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

.status-tag {
  font-size: 0.78rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-weight: bold;
}

.status-in_progress { background: #FFF3D6; color: #B9790A; }
.status-ended_good { background: #E4F7DC; color: var(--green-dark); }
.status-ended_bad { background: #FBE1E0; color: #C22B26; }

.table-actions { display: flex; gap: 0.4rem; }

.icon-btn {
  background: var(--gray-light);
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-dark);
}

.icon-btn:hover { background: var(--blue); color: var(--white); }
.icon-btn.danger:hover { background: #E5322D; color: var(--white); }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--gray);
}

/* ---------- Page d'attente ---------- */

.waiting-screen {
  position: fixed;
  inset: 0;
  background: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  text-align: center;
  gap: 1.6rem;
}

.waiting-screen__game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
}

.waiting-screen__score {
  font-weight: bold;
  color: var(--gray-dark);
  font-size: 0.95rem;
  letter-spacing: 0.3px;
}

.waiting-screen__score-value {
  color: var(--blue);
  font-size: 1.15rem;
}

.waiting-screen__canvas-wrap {
  line-height: 0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.waiting-screen__canvas-wrap canvas {
  display: block;
  touch-action: none;
}

.waiting-screen__controls {
  display: flex;
  gap: 0.5rem;
}

.waiting-screen__controls button {
  background: var(--white);
  border: 2px solid var(--gray-light);
  color: var(--blue);
  border-radius: 10px;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.waiting-screen__controls button:active {
  background: var(--blue);
  color: var(--white);
  transform: scale(0.94);
}

.waiting-screen__text {
  color: var(--gray-dark);
  font-size: 1.05rem;
  font-weight: bold;
}

.waiting-screen__sub {
  color: var(--gray);
  font-size: 0.85rem;
  max-width: 320px;
}

/* ---------- Page histoire ---------- */

.story-header {
  text-align: center;
  margin-bottom: 1.4rem;
}

.story-header h1 {
  color: var(--blue);
  font-size: 1.6rem;
  margin-bottom: 0.3rem;
}

.story-header .story-meta {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
}

.node-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.4rem;
}

.node-card__image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: var(--gray-light);
}

.node-card__body { padding: 1.6rem; }

.node-card__text {
  font-size: 1.08rem;
  line-height: 1.6;
  margin: 0;
}

.ending-banner {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.ending-banner.good { background: #E4F7DC; color: var(--green-dark); }
.ending-banner.bad { background: #FBE1E0; color: #C22B26; }

.choices-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 1.6rem;
}

.choice-btn {
  background: var(--white);
  border: 2px solid var(--blue);
  color: var(--blue);
  border-radius: 12px;
  padding: 0.9rem 1.1rem;
  text-align: left;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.choice-btn:hover { background: var(--blue); color: var(--white); }
.choice-btn i { flex-shrink: 0; }

.story-footer {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: 1rem 0 2rem;
}

.story-footer .btn { flex: 1 1 auto; justify-content: center; min-width: 140px; }

/* ---------- Admin ---------- */

.admin-tabs {
  display: flex;
  gap: 0.4rem;
  border-bottom: 2px solid var(--gray-light);
  margin-bottom: 1.2rem;
}

.admin-tab {
  background: transparent;
  border: none;
  padding: 0.7rem 1.1rem;
  font-weight: bold;
  color: var(--gray);
  border-bottom: 3px solid transparent;
}

.admin-tab.active { color: var(--blue); border-color: var(--blue); }

.admin-form .field select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--gray-light);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 1rem;
  background: var(--gray-light);
}

.admin-login {
  max-width: 380px;
  margin: 4rem auto;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  text-align: center;
}

.admin-login i { font-size: 2rem; color: var(--blue); margin-bottom: 0.8rem; }

.admin-login input {
  width: 100%;
  padding: 0.8rem;
  margin: 1rem 0;
  border-radius: 10px;
  border: 2px solid var(--gray-light);
  font-family: var(--font);
}

.admin-error { color: #C22B26; font-size: 0.85rem; min-height: 1.2em; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-dark);
  color: var(--white);
  padding: 0.8rem 1.3rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 3000;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.toast.success { background: var(--green-dark); }
.toast.error { background: #C22B26; }

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
  .top-bar__title { font-size: 1.1rem; }
  .main-container { padding: 1.4rem 0.8rem 3rem; }
  .age-square { min-width: 55px; font-size: 0.85rem; }
  .age-square span.age-num { font-size: 1.05rem; }
  .story-footer .btn { min-width: 100%; }
  .node-card__body { padding: 1.1rem; }
  .stories-table { font-size: 0.82rem; }
}
