/* ============================================================
   Thème : les couleurs viennent des paramètres (voir applyTheme()).
   [data-theme="light"] est posé automatiquement quand le fond est clair.
   ============================================================ */
:root {
  --bg: #1e1b2e;
  --accent: #ffcc00;
  --accent-text: #222;
  --pointer: #ffffff;
  --center: #ffffff;
  --center-text: #222;
  --border: #2b2540;

  --text: #f4f2ff;
  --muted: #b9b4d6;
  --panel-bg: color-mix(in srgb, var(--bg) 88%, #fff);
  --line: rgba(255, 255, 255, 0.14);
  --field-bg: rgba(0, 0, 0, 0.25);
  --field-border: rgba(255, 255, 255, 0.2);
  --soft: rgba(255, 255, 255, 0.12);
  --row-bg: rgba(0, 0, 0, 0.2);
  --panel-w: 380px;
}

[data-theme="light"] {
  --text: #1d1d1f;
  --muted: #5f5f66;
  --panel-bg: color-mix(in srgb, var(--bg) 92%, #000);
  --line: rgba(0, 0, 0, 0.12);
  --field-bg: rgba(255, 255, 255, 0.85);
  --field-border: rgba(0, 0, 0, 0.18);
  --soft: rgba(0, 0, 0, 0.07);
  --row-bg: rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
  overflow-x: hidden;
}

/* ---------- Mise en page : roue centrée ---------- */
.layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  transition: padding-right 0.3s ease;
}

/* Sur grand écran, le panneau ouvert pousse la roue (qui reste centrée dans l'espace restant) */
@media (min-width: 1100px) {
  body.panel-open .layout { padding-right: calc(var(--panel-w) + 16px); }
}

.wheel-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

h1 { margin: 0 0 24px; font-size: 2rem; text-align: center; overflow-wrap: anywhere; }

.wheel-wrapper {
  position: relative;
  width: min(560px, 90vw, calc(100vh - 190px));
  min-width: 260px;
  aspect-ratio: 1;
}

#wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  will-change: transform;
}

.pointer {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 42px solid var(--pointer);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.45));
  z-index: 2;
}

.spin-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 5px solid var(--border);
  background: var(--center);
  color: var(--center-text);
  font-weight: 800;
  font-size: clamp(0.62rem, 2.2vw, 1.05rem);
  line-height: 1.1;
  padding: 6px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s, filter 0.15s;
  z-index: 3;
}
.spin-btn:hover:not(:disabled) { transform: translate(-50%, -50%) scale(1.07); }
.spin-btn:active:not(:disabled) { transform: translate(-50%, -50%) scale(0.96); }
.spin-btn:disabled { cursor: not-allowed; filter: grayscale(0.4) brightness(0.9); }

.last-result { min-height: 1.5em; margin: 20px 0 0; color: var(--muted); font-size: 1.1rem; }

/* ---------- Bouton afficher / cacher ---------- */
.panel-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
.panel-toggle .icon { font-size: 1.1rem; line-height: 1; transition: transform 0.3s; }
body.panel-open .panel-toggle .icon { transform: rotate(90deg); }
@media (max-width: 600px) { .panel-toggle .txt { display: none; } }

/* ---------- Panneau (tiroir à droite) ---------- */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 12;
  width: min(var(--panel-w), 100vw);
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  padding: 72px 20px 24px;
  background: var(--panel-bg);
  border-left: 1px solid var(--line);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.25);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.3s ease, visibility 0s linear 0.3s, background 0.3s;
}
body.panel-open .panel {
  transform: none;
  visibility: visible;
  transition: transform 0.3s ease, visibility 0s, background 0.3s;
}

.panel h3 { margin: 22px 0 10px; font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.panel h3 .hint { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 0.8rem; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }

input[type="text"], textarea {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--text);
  font-size: 0.95rem;
  width: 100%;
}
input[type="color"] {
  width: 38px;
  height: 30px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}
input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }

button {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.danger { background: #e5484d; color: #fff; margin-top: 22px; width: 100%; }

/* ---------- Palettes ---------- */
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.preset {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: var(--soft);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 600;
}
.preset:hover { border-color: var(--accent); filter: none; }
.preset.active { border-color: var(--text); }
.preset .swatches {
  display: flex;
  height: 22px;
  border-radius: 4px;
  overflow: hidden;
  outline: 1px solid var(--line);
}
.preset .swatches span { width: 12px; height: 100%; }
.preset .swatches .bg-swatch { width: 18px; border-left: 2px solid var(--line); }

.color-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.color-grid label { display: flex; align-items: center; justify-content: space-between; font-size: 0.9rem; gap: 6px; }

.badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 1px 8px; font-size: 0.8rem; }
.badge:empty { display: none; }

/* ---------- Lots ---------- */
.lot-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.lot-list li { display: flex; align-items: center; gap: 6px; }
.lot-list .remove { background: transparent; color: var(--muted); font-size: 1.1rem; padding: 4px 8px; }
.lot-list .remove:hover { color: #e5484d; }

.add-form { display: flex; gap: 6px; margin-top: 10px; }

.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 0.95rem; cursor: pointer; }

/* ---------- Onglets ---------- */
.tabs { display: flex; gap: 2px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1 1 auto;
  background: transparent;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  padding: 8px 4px;
  border-bottom: 3px solid transparent;
  font-size: 0.85rem;
  white-space: nowrap;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-panel > h3:first-child { margin-top: 0; }

/* ---------- Divers ---------- */
.muted { color: var(--muted); }
.small { font-size: 0.85rem; line-height: 1.4; }
code { background: var(--soft); padding: 1px 5px; border-radius: 4px; }

textarea {
  margin: 8px 0;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.78rem;
  resize: vertical;
  word-break: break-all;
}

.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.checks-inline { display: flex; flex-wrap: wrap; gap: 4px 14px; }

button.secondary, .file-btn {
  background: var(--soft);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
button.danger-outline { background: transparent; border: 1px solid #e5484d; color: #e5484d; font-size: 0.85rem; }
button:disabled, .file-btn.disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Historique ---------- */
.history-list { list-style: none; padding: 0; margin: 0 0 10px; max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.history-list li {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--row-bg);
  border-radius: 8px;
}
.history-list .num { color: var(--muted); font-size: 0.8rem; min-width: 2ch; text-align: right; }
.history-list .dot { width: 12px; height: 12px; border-radius: 50%; outline: 1px solid var(--line); }
.history-list .label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-list time { grid-column: 3; font-size: 0.8rem; color: var(--muted); }

/* ---------- Modale ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-content {
  background: #fff;
  color: #222;
  border-radius: 18px;
  padding: 28px 36px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  animation: pop 0.35s cubic-bezier(.2, 1.4, .4, 1);
}
.modal-label { margin: 0; color: #777; text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.85rem; }
.modal-result { font-size: 2rem; font-weight: 800; margin: 10px 0 22px; word-break: break-word; }
.modal-date { margin: -12px 0 18px; color: #777; font-size: 0.9rem; }

@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: #222;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 40;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b4232a; }

@media (prefers-reduced-motion: reduce) {
  .panel, .layout, .panel-toggle .icon { transition: none !important; }
}
