/* Base : thème, typographie, boutons, champs, mise en page générale. */

:root,
[data-theme="dark"] {
  --bg: #16131c;
  --bg-2: #1d1925;
  --surface: #252030;
  --surface-2: #2f2939;
  --border: #3d3549;
  --text: #ece3d0;
  --muted: #a99f90;
  --gold: #d9b26a;
  --gold-2: #f0d595;
  --on-gold: #241c0e;
  --red: #d0574a;
  --green: #6fae7c;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font-title: "Cinzel", "Trajan Pro", Georgia, "Palatino Linotype", "Book Antiqua", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #efe6d3;
  --bg-2: #e7dcc5;
  --surface: #fbf6ea;
  --surface-2: #f3ead8;
  --border: #d4c4a3;
  --text: #2a2230;
  --muted: #6e6253;
  --gold: #9a6f22;
  --gold-2: #b9862d;
  --on-gold: #fffaf0;
  --red: #b23b2f;
  --green: #3f7f4e;
  --shadow: 0 6px 20px rgba(60, 40, 10, 0.18);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(ellipse at top, color-mix(in srgb, var(--gold) 9%, transparent), transparent 60%),
    var(--bg);
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: var(--gold); }
[hidden] { display: none !important; }

h1, h2, h3, .title { font-family: var(--font-title); font-weight: 600; letter-spacing: 0.02em; }

/* ---------- Écrans ---------- */

#app { height: 100%; }

.screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.center-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
}

.stack { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.lead { font-size: 1.1rem; }
.warn { color: var(--gold); }
.section-title { font-size: 1rem; color: var(--gold); margin: 22px 0 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.title { text-align: center; font-size: 1.6rem; margin: 8px 0 12px; }

/* ---------- Barre du haut ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(6px);
}
.topbar-title { font-size: 1.15rem; margin: 0; }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; }
.brand-small { font-family: var(--font-title); color: var(--gold); padding-left: 6px; }

.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: var(--font-title);
  letter-spacing: 0.15em;
}
.conn-text { font-family: var(--font-body); letter-spacing: 0; font-size: 0.8rem; color: var(--muted); }
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.conn-dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.conn-dot.offline, .conn-dot.connecting { background: var(--gold); animation: blink 1s infinite; }
.conn-dot.notfound, .conn-dot.expired { background: var(--red); }
.pending-badge { font-size: 0.85rem; font-weight: 700; color: var(--gold); white-space: nowrap; }
@media (max-width: 420px) {
  .conn-text { display: none; } /* la pastille de couleur suffit sur petit écran */
}

@keyframes blink { 50% { opacity: 0.3; } }

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

.btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  transition: transform 0.08s, background 0.15s;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn small { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.btn-primary {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: var(--on-gold);
  border-color: var(--gold);
}
.btn-primary small { color: color-mix(in srgb, var(--on-gold) 70%, transparent); }
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, var(--border)); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-lg { min-height: 60px; font-size: 1.1rem; }
.btn-small { min-height: 38px; padding: 6px 12px; font-size: 0.9rem; border-radius: 10px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.2rem;
  text-decoration: none;
}
.icon-btn.small { width: 36px; height: 36px; font-size: 1rem; }

/* ---------- Champs et sélecteurs ---------- */

.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
}
.input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.input-small { width: 96px; }
.input-code {
  max-width: 240px;
  text-align: center;
  font-family: var(--font-title);
  font-size: 2rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  min-height: 42px;
  min-width: 52px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
}
.chip.active { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }

.segmented { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg { flex: 1; min-height: 52px; border: 0; background: var(--surface); font-size: 1.2rem; font-weight: 700; }
.seg + .seg { border-left: 1px solid var(--border); }
.seg.active { background: var(--gold); color: var(--on-gold); }

.tabs { display: flex; gap: 4px; padding: 8px 12px 0; overflow-x: auto; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  white-space: nowrap;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--muted);
  font-weight: 600;
}
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ---------- Cartes, listes, tableaux ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 6px; font-size: 1.05rem; color: var(--gold); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-actions { display: flex; gap: 6px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:first-child td { color: var(--gold); font-weight: 700; }

.history, .profile-list { list-style: none; margin: 0; padding: 0; }
.history-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.history p { margin: 4px 0 0; }

.code-big {
  display: block;
  margin: 8px auto;
  border: 0;
  background: none;
  color: var(--gold);
  font-family: var(--font-title);
  font-size: 2.6rem;
  letter-spacing: 0.25em;
  text-align: center;
}

.footer-bar { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg); }

/* ---------- Accueil ---------- */

.hero { text-align: center; margin: 24px 0 20px; }
.hero h1 { margin: 10px 0 2px; font-size: 1.9rem; color: var(--gold); }
.hero-icon { filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.4)); }
.home-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.home-tools .btn { padding: 8px; font-size: 0.9rem; }

/* ---------- Création de partie ---------- */

.seats-form { display: flex; flex-direction: column; gap: 10px; }
.seat-form { display: flex; align-items: center; gap: 10px; }
.seat-num {
  flex: 0 0 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--gold);
  font-weight: 700;
}
.me-radio { display: flex; align-items: center; gap: 4px; font-size: 0.9rem; color: var(--muted); white-space: nowrap; }
.me-radio input { width: 20px; height: 20px; accent-color: var(--gold); }

/* ---------- Divers ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 30px);
  width: max-content;
  max-width: min(92vw, 480px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--gold);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
.big-icon { font-size: 3rem; color: var(--gold); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
