/* ============================================================================
   BOLTZ — PASSE ESTHÉTIQUE PREMIUM. Langage visuel harmonisé sur
   _kit/kit-design.css (glassmorphism, ombres bokeh, radii 8px-grid), thème
   local « atelier mécanique » (rouille, laiton, néon d'établi). Mobile-first,
   safe-areas iPhone, RTL arabe, light/dark via prefers-color-scheme.
   ========================================================================== */

:root {
  --bg-0: #241a12;
  --bg-1: #120d09;
  --bg-2: #0a0705;
  --bg-glow: rgba(255, 148, 72, 0.20);
  --bg-glow-2: rgba(255, 193, 7, 0.06);

  --panel-0: #1c140d;
  --panel-1: #130e09;
  --slot-0: #241a12;
  --slot-1: #150f0a;

  --ink: #f4efe6;
  --muted: #c9b69a;
  --muted-dark: #a3906f;

  --accent: #ffc107;
  --accent-hi: #ffd54f;
  --accent-dk: #d4a500;
  --accent-glow: rgba(255, 193, 7, 0.4);

  --border-light: rgba(255, 220, 180, 0.10);
  --border-medium: rgba(255, 220, 180, 0.16);
  --border-strong: rgba(255, 220, 180, 0.22);

  --shadow-xs: 0 2px 6px rgba(0, 0, 0, 0.24);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.36);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.46);
  --shadow-2xl: 0 32px 80px rgba(0, 0, 0, 0.60);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.10);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 999px;

  --duration-instant: 0.08s;
  --duration-fast: 0.14s;
  --duration-normal: 0.20s;
  --duration-slow: 0.35s;
  --duration-deliberate: 0.45s;

  --easing-bounce: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --easing-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --easing-in-out: cubic-bezier(0.38, 0.1, 0.2, 1);

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-0: #fff6ea;
    --bg-1: #fffdfa;
    --bg-2: #ffffff;
    --bg-glow: rgba(255, 148, 72, 0.10);
    --bg-glow-2: rgba(255, 193, 7, 0.05);
    --panel-0: #ffffff;
    --panel-1: #fff8ee;
    --slot-0: #fbeedb;
    --slot-1: #f4e4c9;
    --ink: #241a12;
    --muted: #6b5638;
    --muted-dark: #4a3a24;
    --border-light: rgba(120, 80, 30, 0.10);
    --border-medium: rgba(120, 80, 30, 0.16);
    --border-strong: rgba(120, 80, 30, 0.24);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; accent-color: var(--accent); }

html, body {
  margin: 0; height: 100%;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px; line-height: 1.35;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}

body {
  background:
    radial-gradient(900px 520px at 50% -12%, var(--bg-glow) 0%, rgba(255, 148, 72, 0) 60%),
    radial-gradient(1100px 700px at 50% 0%, var(--bg-0) 0%, var(--bg-1) 45%, var(--bg-2) 100%);
  background-attachment: fixed;
  background-color: var(--bg-1);
}

#wrap {
  position: relative; z-index: 1;
  width: 100%; max-width: 520px; margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  min-height: 100vh;
}

@media (max-width: 380px) {
  #wrap { padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); gap: 7px; }
}

header { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 2px 0; }

.back-hub {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-full);
  color: var(--ink); text-decoration: none; font-size: 18px; font-weight: 800;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border-light);
  transition: all var(--duration-fast) var(--easing-ease-out);
}
.back-hub:hover { background: rgba(255, 255, 255, 0.12); transform: translateX(-2px); }

.brand {
  font-weight: 800; letter-spacing: 2px; font-size: 22px; line-height: 1;
  background: linear-gradient(135deg, var(--ink) 0%, var(--muted) 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.brand b { color: var(--accent); -webkit-text-fill-color: var(--accent); }

.hchips { display: flex; gap: 6px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 10px; border-radius: var(--radius-full);
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.03));
  border: 1px solid var(--border-medium);
  backdrop-filter: blur(10px) saturate(1.2); -webkit-backdrop-filter: blur(10px) saturate(1.2);
  box-shadow: var(--shadow-sm), var(--shadow-inset);
}
.lives-chip { color: #ff8a8a; }
.wchip.earn { color: var(--accent-hi); border-color: rgba(255, 193, 7, 0.30); background: linear-gradient(180deg, rgba(255, 193, 7, 0.16), rgba(255, 193, 7, 0.05)); }

.hud { width: 100%; display: flex; gap: 6px; align-items: center; padding: 0 2px; flex-wrap: wrap; }

.chip-btn {
  font-family: inherit; width: auto; margin: 0; padding: 6px 10px; font-size: 13px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.03));
  color: var(--ink); border: 1px solid var(--border-medium); border-radius: var(--radius-full);
  cursor: pointer; transition: all var(--duration-fast) var(--easing-ease-out);
}
.chip-btn:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 193, 7, 0.30); transform: translateY(-1px); }
.chip-btn:active { transform: translateY(0) scale(0.96); }
.hud .chip-btn:last-child { margin-inline-start: auto; }

.board-wrap { width: 100%; }
canvas#c {
  width: 100%; height: auto; display: block; border-radius: var(--radius-lg);
  touch-action: none;
  box-shadow: var(--shadow-xl), 0 0 40px rgba(255, 148, 72, 0.14);
  border: 1px solid var(--border-light);
}

.toolbar { width: 100%; display: flex; gap: 8px; }
.tool {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; margin: 0; border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border-light); color: var(--ink);
  font-size: 12px; font-weight: 700;
  transition: all var(--duration-fast) var(--easing-ease-out);
}
.tool .tool-ic { font-size: 18px; }
.tool small { color: var(--muted-dark); font-weight: 600; font-size: 10px; }
.tool:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); transform: translateY(-2px); }
.tool:disabled { opacity: 0.4; cursor: not-allowed; }

footer { color: var(--muted-dark); font-size: 11px; text-align: center; padding: 2px 8px 4px; letter-spacing: 0.3px; }

/* --- Overlays --- */
.overlay {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: linear-gradient(135deg, rgba(8, 6, 4, 0.78) 0%, rgba(18, 12, 8, 0.70) 50%, rgba(6, 4, 3, 0.82) 100%);
  backdrop-filter: blur(5px) saturate(1.1); -webkit-backdrop-filter: blur(5px) saturate(1.1);
  z-index: 5; padding: 14px; animation: overlay-in var(--duration-normal) var(--easing-ease-out);
}
.overlay.show { display: flex; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.overlay .card {
  background: linear-gradient(135deg, var(--panel-0) 0%, #17110a 50%, var(--panel-1) 100%);
  border: 1px solid var(--border-light); border-radius: var(--radius-xl);
  padding: 22px 18px; width: min(380px, 92vw); max-height: 94vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch; text-align: center;
  box-shadow: var(--shadow-2xl), 0 0 40px rgba(255, 148, 72, 0.12);
  animation: card-in var(--duration-normal) var(--easing-bounce);
}
.overlay .card.wide {
  width: min(440px, 94vw); text-align: start;
  background: linear-gradient(180deg, var(--panel-0) 0%, #17110a 55%, var(--panel-1) 100%);
}
@keyframes card-in {
  0% { opacity: 0; transform: scale(0.9) translateY(16px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.overlay h2 { margin: 0 0 10px; font-size: 24px; font-weight: 800; letter-spacing: -0.3px; text-align: center; }
.overlay .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; line-height: 1.4; text-align: center; }

/* --- Buttons --- */
button {
  border: 0; border-radius: var(--radius-md); padding: 12px 16px;
  font-size: 15px; font-weight: 800; width: 100%; cursor: pointer; margin-top: 9px;
  font-family: inherit; transition: all var(--duration-fast) var(--easing-ease-out);
  letter-spacing: 0.3px;
}
button:hover { transform: translateY(-2px); filter: brightness(1.08); }
button:active { transform: translateY(0) scale(0.96); filter: brightness(0.96); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.sm { width: auto; padding: 9px 14px; font-size: 13px; margin-top: 0; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #ff9448 100%);
  color: #1f1408; box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.btn-primary:hover { box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.4); }

.btn-ghost { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border-light); color: var(--ink); box-shadow: var(--shadow-sm), var(--shadow-inset); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 193, 7, 0.28); }

.btn-rewarded {
  background: linear-gradient(135deg, #5b8cff 0%, #8b5bff 100%); color: #fff;
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-rewarded small { display: block; font-weight: 600; opacity: 0.85; font-size: 11px; margin-top: 2px; }

/* --- Home screen --- */
.overlay .card.home { padding: 22px 20px 18px; }
.logo {
  font-weight: 900; letter-spacing: 3px; font-size: 38px; line-height: 1; margin-bottom: 4px;
  background: linear-gradient(135deg, var(--ink) 0%, var(--muted) 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  text-align: center;
}
.logo b { color: var(--accent); -webkit-text-fill-color: var(--accent); }
.overlay .card.home .sub { text-align: center; }

.stats { display: flex; gap: 8px; margin-bottom: 10px; }
.stat {
  flex: 1; background: linear-gradient(135deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.03) 100%);
  border: 1px solid var(--border-light); border-radius: var(--radius-md); padding: 10px 6px;
  box-shadow: var(--shadow-sm), var(--shadow-inset);
}
.stat .lbl { font-size: 9px; color: var(--muted-dark); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat .val { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }

/* --- Win / stuck --- */
.badge {
  display: inline-block; background: linear-gradient(135deg, var(--accent) 0%, #ffc20e 100%);
  color: #1a1426; font-weight: 900; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  border-radius: var(--radius-full); padding: 6px 14px; margin-bottom: 8px;
}
.badge.warn { background: linear-gradient(135deg, #ff8a8a, #ff5c57); color: #2a0808; display: block; width: fit-content; margin: 0 auto 10px; }

.overlay .big {
  font-size: 46px; font-weight: 900; color: var(--accent); margin: 8px 0 6px; letter-spacing: 4px;
  text-shadow: 0 0 32px rgba(255, 193, 7, 0.5); text-align: center;
}

/* --- Levels (world map) --- */
.levels-body { max-height: 60vh; overflow-y: auto; margin-bottom: 10px; }
.world-section h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  display: flex; justify-content: space-between; margin: 14px 0 6px;
}
.world-section h3 small { color: var(--muted-dark); font-weight: 600; }
.level-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.lv {
  width: auto; margin: 0; padding: 6px 2px; border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border-light); color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 12px; font-weight: 800;
}
.lv .lv-s { font-size: 11px; letter-spacing: 1px; }
.lv .lv-s .on { color: var(--accent); }
.lv .lv-s .off { color: var(--muted-dark); opacity: 0.5; }
.lv.current { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.25); }
.lv.locked { opacity: 0.4; }
.lv .lv-lock { font-size: 12px; }

/* --- Friends --- */
.field { display: block; text-align: start; margin-bottom: 10px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field-row input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-md); border: 1px solid var(--border-medium);
  background: rgba(255, 255, 255, 0.05); color: var(--ink); font-size: 14px; font-family: inherit;
}
.field-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.field-row input { flex: 1; }
.friend-groups { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.group-row {
  width: auto; margin: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: var(--radius-md); background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light); color: var(--ink); font-size: 13px;
}
.group-row.on { border-color: var(--accent); }
.group-row code { color: var(--accent); letter-spacing: 1px; }
.tabs { display: flex; gap: 4px; margin-inline-start: auto; }
.tabs button { width: auto; margin: 0; padding: 6px 10px; font-size: 11px; background: rgba(255,255,255,.05); border: 1px solid var(--border-light); color: var(--muted); }
.tabs button.on { background: var(--accent); color: #1a1426; border-color: var(--accent); }
table.friend-board { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
table.friend-board td { padding: 7px 6px; border-bottom: 1px solid var(--border-light); }

/* --- Toast --- */
.toast {
  position: fixed; inset-inline: 0; bottom: calc(16px + env(safe-area-inset-bottom));
  margin-inline: auto; width: max-content; max-width: 88vw;
  background: linear-gradient(135deg, rgba(26, 18, 10, 0.94) 0%, rgba(14, 10, 6, 0.94) 100%);
  color: var(--ink); border: 1px solid rgba(255, 193, 7, 0.2); border-radius: var(--radius-full);
  padding: 11px 16px; font-size: 13px; font-weight: 700; z-index: 9;
  box-shadow: var(--shadow-lg); backdrop-filter: blur(10px);
  animation: toast-in var(--duration-normal) var(--easing-ease-out);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* --- Accessibility --- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
@media (prefers-contrast: more) {
  .chip, .chip-btn, button, .overlay .card { border-width: 2px; border-color: var(--border-strong); }
}

/* --- RTL --- */
html[dir="rtl"] .back-hub { transform: scaleX(-1); }
html[dir="rtl"] .hud .chip-btn:last-child { margin-inline-start: auto; }
