:root {
  --ink: #15130f;
  --ink-2: #26221b;
  --paper: #f3ecd9;
  --muted: #b5ac96;
  --acid: #d7f03c;
  --danger: #ff5a3c;
  --line: rgba(243, 236, 217, .2);
  --display: "Arial Black", "Helvetica Neue", Impact, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font: 16px/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  transition: filter .25s;
}
#view.dragging { cursor: grabbing; }
body[data-mode="place"] #view,
body[data-mode="seek"] #view { cursor: crosshair; }
body[data-mode="paint"] #view { cursor: cell; }
body[data-mode="home"] #view,
body[data-mode="share"] #view { filter: brightness(.55) blur(3px); }
/* Empêche de repérer le décor avant le départ du chrono. */
body[data-mode="seek-intro"] #view { filter: brightness(.45) blur(22px); }

h1, h2 { font-family: var(--display); line-height: 1.05; margin: 0; letter-spacing: -.01em; }
h1 { font-size: clamp(44px, 9vw, 72px); color: var(--acid); }
h2 { font-size: clamp(24px, 4vw, 32px); }
p { margin: 0; }

button, .button {
  font: 600 15px/1 var(--body);
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--paper);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}
button:hover:not(:disabled), .button:hover { border-color: var(--paper); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--acid); outline-offset: 2px; }
button.primary {
  background: var(--acid);
  border-color: var(--acid);
  color: var(--ink);
  font-weight: 800;
}
button.primary:disabled { opacity: .35; cursor: not-allowed; }
button.active { background: var(--paper); color: var(--ink); border-color: var(--paper); }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }

/* Barre du haut */
#top {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}
#phase {
  background: var(--ink);
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
}
#timer {
  background: var(--ink);
  color: var(--acid);
  font: 28px/1 var(--display);
  padding: 8px 14px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
#timer.low { color: var(--danger); }
#timer.hit { animation: hit .35s; }
@keyframes hit {
  30% { transform: scale(1.25); background: var(--danger); color: var(--ink); }
}

/* Cartes centrées */
.card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  align-items: stretch;
}
#logo {
  width: 160px;
  height: 100px;
  margin: 0 auto -8px;
  image-rendering: pixelated;
}
.lead { font-size: 17px; }
.label { color: var(--muted); font-size: 14px; margin-top: 6px; }
.tip { color: var(--muted); font-size: 14px; }
.warn { color: var(--danger); font-size: 14px; }

#places { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.place {
  position: relative;
  height: 92px;
  padding: 0;
  overflow: hidden;
  background-size: cover;
  background-position: center 42%;
  border: 1px solid var(--line);
  align-items: flex-end;
  justify-content: flex-start;
}
.place span {
  width: 100%;
  text-align: left;
  padding: 24px 12px 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .85));
  font-family: var(--display);
  font-weight: 400;
  font-size: 18px;
}

#link {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  background: var(--ink-2);
  color: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: 14px ui-monospace, Consolas, monospace;
}

/* Panneaux du bas */
.dock {
  position: fixed;
  left: 50%;
  bottom: max(26px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 32px));
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hint { font-size: 15px; }
.size { display: flex; gap: 10px; align-items: center; flex: 1 1 180px; font-size: 14px; }
.size input { flex: 1; accent-color: var(--acid); min-width: 80px; }
.dock .primary { margin-left: auto; }
.dock.result { text-align: center; }
.dock.result .primary { margin-left: 0; }
.brushes { display: flex; gap: 4px; }

#palette { display: grid; grid-template-columns: repeat(16, 1fr); gap: 4px; }
.swatch {
  min-height: 0;
  height: 30px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 4px;
}
.swatch:hover:not(:disabled) { border-color: rgba(255, 255, 255, .5); }
.swatch.active { border-color: var(--acid); box-shadow: 0 0 0 2px var(--ink) inset; }

#ring {
  position: fixed;
  left: 0;
  top: 0;
  border: 3px solid var(--acid);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .55);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; } }

.miss {
  position: fixed;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  border: 3px solid var(--danger);
  pointer-events: none;
  animation: miss .55s ease-out forwards;
}
@keyframes miss { from { transform: scale(.4); } to { transform: scale(1.5); opacity: 0; } }

#loading, #toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 16px;
  max-width: calc(100vw - 32px);
}
#loading { top: 16px; }
#toast { top: 76px; font-weight: 600; }

#credit {
  position: fixed;
  left: 8px;
  bottom: 4px;
  font-size: 11px;
  color: var(--paper);
  text-shadow: 0 1px 2px #000;
  text-decoration: none;
}
#credit:hover { text-decoration: underline; }

@media (max-width: 560px) {
  #palette { grid-template-columns: repeat(8, 1fr); }
  .swatch { height: 26px; }
  .card { padding: 20px; }
  button, .button { padding: 0 11px; font-size: 14px; }
  .place { height: 76px; }
  .dock .primary { flex: 1 1 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #ring, .miss, #timer.hit { animation: none; }
}
