:root {
  --ink: #eaf0ff;
  --panel: #ffffff;
  --accent: #6c5ce7;
  --accent2: #00d2ff;
  --gold: #ffd54a;
  --frame: #14131f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(108, 92, 231, 0.35), transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, rgba(0, 210, 255, 0.25), transparent 55%),
    linear-gradient(160deg, #0f1020 0%, #171533 45%, #0c0b1a 100%);
  background-attachment: fixed;
}

/* motif hexagonal décoratif animé en fond */
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.06;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='56' height='100' viewBox='0 0 56 100'><path d='M28 0L56 16v34L28 66 0 50V16z M28 66l28 16v18M28 66L0 82v18' fill='none' stroke='white' stroke-width='2'/></svg>");
  background-size: 56px 100px;
  animation: drift 40s linear infinite;
}
@keyframes drift {
  from { transform: translateY(0); }
  to   { transform: translateY(-100px); }
}

header, main { position: relative; z-index: 1; }

header {
  padding: 26px 24px 8px;
  text-align: center;
}
header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(90deg, var(--accent2), #fff 40%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 12px rgba(0, 210, 255, 0.35));
}
header .hint {
  margin: 8px auto 0;
  max-width: 640px;
  color: #b9c0e0;
  font-size: 0.9rem;
}

main {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  align-items: flex-start;
  justify-content: center;
  padding: 18px 24px 48px;
}

/* ----- Plateau : cadre noir type "boîte" physique ----- */
#board-area {
  position: relative;
  background: linear-gradient(145deg, #23212f, #0c0b14);
  border: 3px solid rgba(255, 255, 255, 0.06);
  border-radius: 20px;
  box-shadow: var(--shadow), inset 0 0 0 10px rgba(0, 0, 0, 0.35);
  padding: 22px;
}
#board {
  width: min(72vw, 560px);
  height: auto;
  display: block;
  touch-action: none;
  background: #f7f5ee;
  border-radius: 10px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* surbrillance de la case ciblée pendant le glisser */
#drop-highlight {
  fill: rgba(255, 213, 74, 0.28);
  stroke: var(--gold);
  stroke-width: 4;
  filter: drop-shadow(0 0 6px rgba(255, 213, 74, 0.8));
  pointer-events: none;
}

.placed-piece { cursor: grab; transition: transform 0.08s ease; }
.placed-piece:hover { transform: none; }

#win-banner {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #1f8a4c, #38c172);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 6px 20px rgba(56, 193, 114, 0.55);
  animation: pop 0.4s ease, glow 1.6s ease-in-out infinite alternate;
}
@keyframes pop {
  0% { transform: translateX(-50%) scale(0.6); opacity: 0; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}
@keyframes glow {
  from { box-shadow: 0 6px 20px rgba(56, 193, 114, 0.45); }
  to   { box-shadow: 0 6px 30px rgba(56, 193, 114, 0.95); }
}

/* ----- Réserve ----- */
#tray-area {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 250px;
}
.tray-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.tray-header h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.btn {
  border: none;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #fff;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(108, 92, 231, 0.5);
  transition: transform 0.1s ease, filter 0.1s ease;
}
.btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
#hint-btn { background: linear-gradient(90deg, #f7971e, var(--gold)); box-shadow: 0 4px 14px rgba(247, 151, 30, 0.5); }
#solve-btn { background: linear-gradient(90deg, #1f8a4c, #38c172); box-shadow: 0 4px 14px rgba(56, 193, 114, 0.5); }

#tray {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 14px;
}
.piece-card {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 14px;
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: grab;
  touch-action: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.piece-card:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
  border-color: rgba(0, 210, 255, 0.6);
}
.piece-card:active { cursor: grabbing; }
.piece-card svg { display: block; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35)); }

/* ----- Fantôme de glisser ----- */
#drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  pointer-events: none;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.5));
  transform: translate(-50%, -50%) scale(1.05);
}

/* ----- Chrono (HUD) ----- */
#timer {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}
.timer-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 19, 31, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 6px 14px;
  color: #fff;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.timer-chip.running {
  border-color: var(--accent2);
  animation: timerpulse 1.4s ease-in-out infinite;
}
@keyframes timerpulse {
  0%, 100% { box-shadow: 0 0 8px rgba(0, 210, 255, 0.35); }
  50% { box-shadow: 0 0 18px rgba(0, 210, 255, 0.75); }
}
.timer-chip .ico { font-size: 0.95rem; }
.best-chip {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(20, 19, 31, 0.8);
  border-radius: 999px;
  padding: 3px 12px;
  font-variant-numeric: tabular-nums;
}

/* ----- Message / toast ----- */
#message {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 88%;
  text-align: center;
  background: rgba(20, 19, 31, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow);
  animation: pop 0.25s ease;
}

/* ----- Pièce signalée comme mal placée ----- */
.placed-piece.flash { animation: badpulse 0.6s ease-in-out 3; transform-box: fill-box; transform-origin: center; }
@keyframes badpulse {
  0%, 100% { filter: none; }
  50% { filter: drop-shadow(0 0 10px #ff2d55) drop-shadow(0 0 18px #ff2d55); }
}

/* ----- Confettis ----- */
#confetti {
  position: fixed;
  inset: 0;
  z-index: 900;
  pointer-events: none;
  overflow: hidden;
}
.confetti-bit {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  will-change: transform, opacity;
  animation: fall linear forwards;
}
@keyframes fall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0.9; }
}

.hidden { display: none !important; }
