:root {
  --ink: #1d1b2b;
  --yellow: #ffcc33;
  --red: #e8423c;
  --green: #3ecf6a;
  --paper: #fff8e6;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #4fb3ff; color: var(--ink); font-family: var(--font);
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas#game { display: block; position: fixed; inset: 0; }

/* ---------- écrans ---------- */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: 16px; background: rgba(29, 27, 43, 0.45); z-index: 10;
  animation: fade 0.25s ease-out;
}
.overlay[hidden] { display: none; }
#result { animation: fade 0.3s ease-out 0.6s both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--paper); border: 4px solid var(--ink); border-radius: 22px;
  box-shadow: 0 8px 0 var(--ink); padding: 24px; text-align: center;
}
.card.small { width: min(320px, 100%); }
.card.win { background: #e9ffe9; }
.card.lose { background: #fff0ec; }

h1 {
  margin: 0; font-size: clamp(44px, 10vw, 72px); font-weight: 900; letter-spacing: 2px;
  color: var(--yellow); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
}
h2 { margin: 0 0 8px; font-size: 36px; font-weight: 900; }
.tag { margin: 6px 0 18px; font-weight: 700; opacity: 0.75; }
.hint { font-size: 13px; opacity: 0.75; margin: 14px 0 8px; }

button {
  font: inherit; font-weight: 800; cursor: pointer; color: var(--ink);
  background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  padding: 12px 16px; margin: 6px 0; width: 100%;
  box-shadow: 0 4px 0 var(--ink); transition: transform 0.05s;
}
button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
button:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
button.primary { background: var(--yellow); }
button.ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; }
button[hidden] { display: none; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choices button { display: flex; flex-direction: column; gap: 4px; padding: 16px 12px; margin: 0; }
.choices strong { font-size: 18px; }
.choices span { font-weight: 600; font-size: 13px; opacity: 0.8; }
.choices small { font-weight: 700; font-size: 12px; color: #2a7a3f; }

.seed { display: flex; gap: 8px; align-items: center; margin: 14px 0 4px; flex-wrap: wrap; justify-content: center; }
.seed label { font-weight: 700; font-size: 14px; }
.seed small { font-weight: 800; color: #2a7a3f; }
.pseudo { margin: 0 0 14px; }
.pseudo input { width: 190px; }
.seed input {
  font: inherit; font-weight: 700; width: 130px; padding: 8px 10px;
  border: 3px solid var(--ink); border-radius: 10px; background: #fff;
}
.seed button { width: auto; margin: 0; padding: 8px 14px; }

.help { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; text-align: left; font-size: 13px; font-weight: 600; margin-top: 14px; }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; margin-right: 2px;
  border: 2px solid var(--ink); border-bottom-width: 3px; border-radius: 6px;
  background: #fff; font: 800 12px var(--font); text-align: center;
}

.friends { margin: 0 auto 12px; width: min(320px, 100%); text-align: left; }
.friends h3 { margin: 0 0 6px; font-size: 16px; text-align: center; }
.friends ol { margin: 0; padding: 0 0 0 22px; }
.friends li { padding: 2px 0; }
.friends li span { display: inline-block; min-width: 60%; }
.friends li.me { font-weight: 900; color: #2a7a3f; }
#account-hint { margin: -6px 0 12px; }
.seed input:disabled { background: #eef7ee; }
dl { display: grid; grid-template-columns: auto auto; gap: 6px 16px; text-align: left; margin: 16px auto; width: fit-content; }
dt { font-weight: 600; opacity: 0.75; }
dd { margin: 0; font-weight: 900; }
#result-reason { font-weight: 700; }

/* ---------- commandes tactiles ---------- */
#touch { display: none; }
body.touch[data-state="running"] #touch,
body.touch[data-state="countdown"] #touch { display: block; }

.tc {
  position: fixed; z-index: 5; width: auto; margin: 0; padding: 0;
  display: grid; place-items: center; font-size: 26px; font-weight: 900;
  background: rgba(255, 255, 255, 0.55); border: 3px solid rgba(29, 27, 43, 0.8);
  box-shadow: none; border-radius: 50%; touch-action: none;
}
.tc.active { background: var(--yellow); transform: scale(0.94); }
.tc-pedal {
  left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom));
  width: 128px; height: 128px; font-size: 17px; border-radius: 50%;
}
.tc-rot { width: 76px; height: 76px; bottom: max(16px, env(safe-area-inset-bottom)); }
.tc-back { right: calc(max(16px, env(safe-area-inset-right)) + 88px); }
.tc-fwd { right: max(16px, env(safe-area-inset-right)); }
.tc-gear { width: 60px; height: 60px; border-radius: 16px; left: calc(max(16px, env(safe-area-inset-left)) + 140px); }
.tc-up { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 70px); }
.tc-down { bottom: max(16px, env(safe-area-inset-bottom)); }
.tc-pause { width: 48px; height: 48px; font-size: 16px; border-radius: 12px; top: 120px; right: max(16px, env(safe-area-inset-right)); }

@media (max-width: 560px) {
  .choices, .help { grid-template-columns: 1fr; }
  .card { padding: 18px 16px; }
  .tc-pedal { width: 104px; height: 104px; }
  .tc-gear { left: calc(max(16px, env(safe-area-inset-left)) + 116px); }
  .tc-rot { width: 66px; height: 66px; }
  .tc-back { right: calc(max(16px, env(safe-area-inset-right)) + 76px); }
}
