/* MotoKin Mobile — interface tactile (pensée pour l'horizontale, utilisable à la verticale) */
:root {
  --blue: #1b3a8c;
  --sky: #3aa0e8;
  --yellow: #ffd21a;
  --red: #d3242c;
  --green: #1fbf5a;
  --ink: #101418;
  --panel: rgba(12, 16, 24, 0.72);
  --panel-solid: #161c26;
  --text: #f4f4f4;
  --muted: #a9b2c0;
  --btn: clamp(52px, 13vmin, 92px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
body[data-ctl="small"] { --btn: clamp(44px, 10.5vmin, 74px); }
body[data-ctl="large"] { --btn: clamp(60px, 15.5vmin, 108px); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #hud .pad { pointer-events: auto; }
#topLeft { position: absolute; left: calc(10px + var(--safe-l)); top: calc(8px + var(--safe-t)); max-width: 46vw; }
#money { font-size: clamp(18px, 4.6vmin, 30px); font-weight: 800; color: var(--yellow); text-shadow: 0 2px 4px #000a; }
#debt { font-size: 13px; color: #ff8a8a; font-weight: 700; text-shadow: 0 1px 2px #000; }
#clock { font-size: clamp(12px, 3vmin, 16px); color: #fff; text-shadow: 0 1px 3px #000; margin-top: 2px; }
#mission { margin-top: 6px; font-size: clamp(11px, 2.7vmin, 14px); background: var(--panel); padding: 5px 9px; border-radius: 8px; border-left: 3px solid var(--yellow); max-width: 320px; }
#mission b { color: var(--yellow); display: block; font-size: 0.95em; }

#ride { position: absolute; left: 50%; top: calc(8px + var(--safe-t)); transform: translateX(-50%); background: var(--panel); border: 2px solid var(--yellow);
  border-radius: 12px; padding: 6px 14px; text-align: center; max-width: 42vw; }
#ride .dest { font-size: clamp(13px, 3.2vmin, 18px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ride .meta { font-size: 12px; color: var(--muted); }

#mapWrap { position: absolute; right: calc(10px + var(--safe-r)); top: calc(8px + var(--safe-t)); width: clamp(110px, 30vmin, 190px); aspect-ratio: 1; }
#minimap { width: 100%; height: 100%; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 10px #0008; background: #2a201a; pointer-events: auto; }
#zoneName { position: absolute; bottom: -18px; width: 100%; text-align: center; font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000; }

#warn { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); background: rgba(211, 36, 44, 0.9); padding: 6px 14px; border-radius: 10px; font-weight: 800; font-size: 14px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.55; } }

#dash { position: absolute; left: 50%; bottom: calc(8px + var(--safe-b)); transform: translateX(-50%); display: flex; gap: 10px; align-items: center; background: var(--panel); padding: 6px 12px; border-radius: 14px; }
#speed { text-align: center; min-width: 58px; }
#speed b { font-size: clamp(22px, 6vmin, 36px); display: block; line-height: 1; }
#speed small { font-size: 11px; color: var(--muted); }
.gauges { display: flex; flex-direction: column; gap: 5px; }
.gauge { display: flex; align-items: center; gap: 5px; font-size: 12px; }
.gauge small { min-width: 40px; color: var(--muted); font-size: 11px; }
.bar { width: clamp(70px, 16vmin, 120px); height: 9px; background: #ffffff22; border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 50%; background: var(--green); border-radius: 6px; transition: width 0.3s; }
.bar i.low { background: var(--red); }
.bar i.mid { background: #f0a020; }
#fps { position: absolute; left: 50%; bottom: calc(70px + var(--safe-b)); transform: translateX(-50%); font: 11px monospace; color: #8f8; }

#toasts { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; width: min(560px, 80vw); }
.toast { background: var(--panel-solid); border: 1px solid #ffffff22; padding: 8px 14px; border-radius: 10px; font-size: clamp(12px, 3vmin, 15px); text-align: center; box-shadow: 0 4px 14px #0008; animation: tin 0.25s ease-out; }
@keyframes tin { from { transform: translateY(-8px); opacity: 0; } }
#banner { position: absolute; left: 50%; top: 14%; transform: translateX(-50%); background: linear-gradient(90deg, var(--blue), #2b56c4); border: 2px solid var(--yellow); padding: 10px 22px; border-radius: 14px; text-align: center; box-shadow: 0 6px 20px #000a; }
#banner b { display: block; font-size: 18px; color: var(--yellow); }

/* Commandes */
.pad { position: absolute; bottom: calc(14px + var(--safe-b)); display: flex; gap: 10px; touch-action: none; }
#steerPad { left: calc(14px + var(--safe-l)); }
#pedalPad { right: calc(14px + var(--safe-r)); }
.pbtn { width: calc(var(--btn) * 1.15); height: calc(var(--btn) * 1.15); border-radius: 22px; border: 2px solid #ffffff66; background: rgba(20, 24, 32, 0.45);
  font-size: calc(var(--btn) * 0.38); font-weight: 900; color: #fff; touch-action: none; backdrop-filter: blur(2px); }
.pbtn.on { background: rgba(255, 255, 255, 0.35); border-color: #fff; transform: scale(0.96); }
.pbtn.gas { height: calc(var(--btn) * 1.5); background: rgba(31, 191, 90, 0.4); font-size: calc(var(--btn) * 0.24); }
.pbtn.brake { background: rgba(211, 36, 44, 0.4); font-size: calc(var(--btn) * 0.22); align-self: flex-end; }
#smallBtns { position: absolute; right: calc(clamp(110px, 30vmin, 190px) + 22px + var(--safe-r)); top: calc(8px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; }
#smallBtns button, #btnHorn { width: calc(var(--btn) * 0.62); height: calc(var(--btn) * 0.62); border-radius: 50%; border: 2px solid #ffffff55; background: var(--panel); font-size: calc(var(--btn) * 0.28); }
#smallBtns button.on { background: var(--yellow); color: #000; }
#btnHorn { position: absolute; left: calc(14px + var(--safe-l)); bottom: calc(var(--btn) * 1.15 + 28px + var(--safe-b)); width: calc(var(--btn) * 0.8); height: calc(var(--btn) * 0.8); }
#btnAct { position: absolute; right: calc(14px + var(--safe-r)); bottom: calc(var(--btn) * 1.5 + 30px + var(--safe-b)); min-height: calc(var(--btn) * 0.9); padding: 0 18px;
  border-radius: 18px; border: 3px solid var(--yellow); background: rgba(27, 58, 140, 0.92); font-weight: 800; font-size: clamp(13px, 3.4vmin, 18px); display: flex; align-items: center; gap: 8px;
  animation: pulse 1.2s infinite; max-width: 34vw; }

@keyframes pulse { 50% { box-shadow: 0 0 0 6px #ffd21a55; } }

/* Mise en page verticale : boutons plus compacts */
@media (orientation: portrait) {
  #btnAct { right: 50%; transform: translateX(50%); bottom: calc(var(--btn) * 1.7 + 30px + var(--safe-b)); max-width: 80vw; }
  #smallBtns { right: calc(10px + var(--safe-r)); top: calc(clamp(110px, 30vmin, 190px) + 30px + var(--safe-t)); }
  #dash { bottom: calc(var(--btn) * 1.7 + 30px + var(--safe-b)); }
  #dash.withAct { bottom: calc(var(--btn) * 2.7 + 40px + var(--safe-b)); }
  #ride { top: calc(clamp(110px, 30vmin, 190px) + 36px + var(--safe-t)); max-width: 90vw; }
  #topLeft { max-width: 52vw; }
}

/* ---------------- Écrans / menus ---------------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 30% 20%, #2b56c4cc, #0b1530ee); z-index: 20; }
#menu { background: linear-gradient(160deg, rgba(27,58,140,0.85), rgba(10,14,28,0.92)); }
.menuCard { width: min(420px, 90vw); max-height: 92vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; text-align: center; padding: 18px; }
.menuCard h1 { font-size: clamp(40px, 11vmin, 72px); margin: 0; letter-spacing: 1px; font-weight: 900; }
.menuCard h1 span, .logo span { color: var(--yellow); }
.menuCard h2 { margin: 0 0 6px; }
.menuCard .sub { margin: -6px 0 10px; color: var(--muted); }
.menuCard button { padding: 12px; border-radius: 12px; border: 2px solid #ffffff33; background: #ffffff14; font-size: 16px; font-weight: 700; }
.menuCard button.big { background: var(--yellow); color: #111; border-color: var(--yellow); font-size: 19px; }
.menuCard .ver { color: var(--muted); font-size: 12px; }

#modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: #0007; padding: 10px; }
#modal .card { width: min(520px, 94vw); max-height: 92vh; overflow: auto; background: var(--panel-solid); border: 2px solid #ffffff22; border-radius: 16px; padding: 14px 16px; box-shadow: 0 10px 40px #000c; }
#modal h3 { margin: 0 0 8px; color: var(--yellow); font-size: 19px; }
#modalBody { font-size: 14px; }
#modalBody h4 { margin: 12px 0 4px; color: var(--sky); }
#modalBody .quote { font-style: italic; color: #e8e2c8; }
#modalBody .hint { font-size: 12px; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid #ffffff10; }
.kv .big, b.big { font-size: 18px; color: var(--yellow); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid #ffffff12; }
.row small { display: block; color: var(--muted); font-size: 12px; }
.row button { padding: 7px 10px; border-radius: 10px; border: 0; background: var(--blue); font-weight: 700; white-space: nowrap; }
small.ok, .ok { color: #6fe39a; }
small.warn { color: #ffc35a; }
small.bad, .bad { color: #ff7a7a; }
.tag { padding: 3px 8px; border-radius: 8px; font-size: 12px; font-weight: 700; background: #ffffff18; }
.tag.ok { background: #1fbf5a33; } .tag.bad { background: #d3242c44; }
#modalButtons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#modalButtons button { flex: 1 1 120px; padding: 12px 10px; border-radius: 12px; border: 0; font-weight: 800; font-size: 15px; background: #ffffff1c; }
#modalButtons button.ok { background: var(--green); color: #062; color: #fff; }
#modalButtons button.alt { background: var(--blue); }
#modalButtons button.no { background: #ffffff18; }
#modalButtons button:disabled { opacity: 0.4; }
#modalBody .bar { width: 100%; height: 12px; margin: 4px 0; }
.qty { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 10px 0; }
.qty button { min-width: 48px; padding: 10px; border-radius: 10px; border: 0; background: var(--blue); font-weight: 800; font-size: 18px; }
.qty b { min-width: 70px; text-align: center; font-size: 18px; }
.opts { display: flex; gap: 6px; flex-wrap: wrap; }
.opts button { flex: 1; padding: 9px; border-radius: 10px; border: 2px solid #ffffff22; background: #ffffff10; font-weight: 700; }
.slider { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.slider span { flex: 0 0 132px; font-size: 13px; }
.slider input { flex: 1; accent-color: var(--yellow); height: 28px; }
.slider b { min-width: 38px; text-align: right; font-size: 13px; }
.opts button.sel { background: var(--yellow); color: #111; border-color: var(--yellow); }
.help li { margin: 4px 0; }

#fullmap { background: #0b0f16f2; flex-direction: column; }
#bigmap { width: min(92vmin, 92vw); height: min(92vmin, 92vw); max-height: 80vh; max-width: 80vh; border-radius: 12px; border: 2px solid #ffffff33; }
#fullmap .legend { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; font-size: 12px; margin-top: 8px; padding: 0 10px; }
#fullmap .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
#fullmap .close { position: absolute; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); width: 48px; height: 48px; border-radius: 50%; border: 0; background: #ffffff22; font-size: 22px; }

#loading { z-index: 40; background: linear-gradient(160deg, #1b3a8c, #0a0e1c); }
.loadBox { text-align: center; width: min(420px, 86vw); }
.loadBox .logo { font-size: 48px; font-weight: 900; margin-bottom: 10px; }
.loadBox .bar { width: 100%; height: 10px; margin: 12px 0; }
#loadTip { color: var(--muted); font-size: 13px; min-height: 2.6em; }

#rotate { position: fixed; inset: auto 0 0 0; padding: 6px; text-align: center; font-size: 12px; background: #000a; z-index: 5; pointer-events: none; }

/* Icônes SVG */
svg.ic { display: block; flex: none; }
#hud button svg.ic, .pbtn svg.ic, .close svg.ic { margin: auto; }
#smallBtns button, #btnHorn, .close { display: flex; align-items: center; justify-content: center; padding: 0; }
.pbtn { display: flex; align-items: center; justify-content: center; }
.pbtn svg.ic { width: 45%; height: 45%; stroke-width: 2.6; }
#smallBtns button svg.ic { width: 55%; height: 55%; }
#btnHorn svg.ic { width: 55%; height: 55%; }
.gauge span { display: flex; color: #dfe6ef; }
#ride .dest { display: flex; align-items: center; justify-content: center; gap: 6px; }
#ride .dest span { display: flex; color: var(--yellow); }
#btnAct .ico { display: flex; }
#btnAct .ico svg.ic { width: 1.5em; height: 1.5em; }
#rotate span { display: inline-flex; vertical-align: middle; }
.ico-inline { display: inline-flex; vertical-align: -0.2em; margin-right: 4px; }
.ico-inline svg.ic { width: 1.05em; height: 1.05em; }
small.ok .ico-inline, small.bad .ico-inline { margin-right: 3px; }
h3 .ico-inline svg.ic { width: 1em; height: 1em; }

/* Alerte police (ordre de s'arrêter, poursuite, moto signalée) */
#alert { position: absolute; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 12px; font-weight: 800; font-size: 14px; background: #1b3a8ce6; border: 2px solid #fff; }
#alert span { display: flex; }
#alert.stop { animation: blink 0.8s infinite; }
#alert.chase { background: #d3242ce6; animation: siren 0.5s infinite alternate; }
#alert.wanted { background: #3a3a3ae6; border-color: #ffd21a; }
@keyframes siren { from { background: #d3242ce6; } to { background: #1b3a8ce6; } }
@media (orientation: portrait) { #alert { top: calc(clamp(110px, 30vmin, 190px) + 90px + var(--safe-t)); } }

/* Procès-verbal de contrôle : petit papier sur le côté, la scène reste visible */
#ticket { position: fixed; left: calc(12px + var(--safe-l)); top: calc(70px + var(--safe-t)); width: min(330px, 46vw); max-height: calc(100vh - 160px);
  overflow: auto; z-index: 25; background: #f6f1e3; color: #1d1d1d; border-radius: 6px; box-shadow: 0 10px 30px #000a; font-size: 12.5px;
  border-top: 6px solid #1b3a8c; transform: rotate(-0.6deg); animation: tkin 0.35s ease-out; }
@keyframes tkin { from { transform: translateY(-20px) rotate(-3deg); opacity: 0; } }
#ticket .tk-head { padding: 8px 12px 6px; border-bottom: 1px dashed #9a927d; text-align: center; }
#ticket .tk-head span { display: block; font-size: 9px; letter-spacing: 1px; color: #555; }
#ticket .tk-head b { display: block; font-size: 15px; color: #1b3a8c; text-transform: uppercase; }
#ticket .tk-head small { color: #666; font-family: monospace; }
#ticket .tk-body { padding: 6px 12px; }
#ticket .quote { font-style: italic; color: #4a3f2a; margin: 4px 0; }
#ticket .row { padding: 3px 0; border-bottom: 1px dotted #c9c0a8; }
#ticket .row b { font-size: 12px; }
#ticket .row small { color: #555; }
#ticket small.ok, #ticket .ok { color: #1a7a3a; }
#ticket small.bad, #ticket .bad { color: #b3202a; }
#ticket .kv { border-bottom: 1px dotted #c9c0a8; padding: 3px 0; }
#ticket .big { color: #b3202a !important; font-size: 16px; }
#ticket h4 { margin: 8px 0 2px; color: #1b3a8c; font-size: 12px; text-transform: uppercase; }
#ticket .hint { font-size: 10.5px; color: #666; }
#ticket .tk-buttons { padding: 8px 12px 12px; display: flex; gap: 8px; position: sticky; bottom: 0; background: #f6f1e3; border-top: 1px dashed #9a927d; }
#ticket .tk-buttons button { flex: 1; padding: 10px; border: 0; border-radius: 8px; font-weight: 800; background: #1b3a8c; color: #fff; }
#ticket .tk-buttons button.ok { background: #1a7a3a; }
@media (orientation: portrait) { #ticket { width: calc(100vw - 24px); top: auto; bottom: calc(var(--btn) * 1.5 + 30px + var(--safe-b)); max-height: 42vh; } }
.menuCard .menuLink { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* Mise à jour disponible */
#updateBar { position: fixed; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); z-index: 45; display: flex; align-items: center; gap: 10px;
  background: var(--panel-solid); border: 2px solid var(--yellow); border-radius: 14px; padding: 8px 10px 8px 14px; box-shadow: 0 8px 30px #000a; font-size: 14px; max-width: 94vw; }
#updateBar button { border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 800; background: var(--yellow); color: #111; }
#updateBar button.ghost { background: #ffffff1a; color: #fff; }
.row.zone small.lvl { display: inline; color: var(--yellow); margin-left: 6px; }
.row button:disabled { opacity: .4; }

#warn.info { background: #1b3a8ce6; animation: none; font-weight: 700; }
/* Bulles de dialogue */
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 8; overflow: hidden; }
.bubble { position: absolute; left: 0; top: 0; max-width: min(260px, 60vw); background: #fffdf5; color: #1b1b1b; border-radius: 14px; padding: 6px 11px 7px;
  font-size: 14px; font-weight: 700; line-height: 1.25; box-shadow: 0 4px 14px #0007; border: 2px solid #1b1b1b; transform-origin: 50% 100%; will-change: transform; }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -10px; margin-left: -8px; border: 8px solid transparent; border-top-color: #1b1b1b; border-bottom: 0; }
.bubble .who { display: block; font-size: 10px; font-weight: 800; color: #6a6a6a; text-transform: uppercase; letter-spacing: .5px; }
.bubble .sub { display: block; font-size: 11.5px; font-weight: 500; font-style: italic; color: #555; margin-top: 2px; }
.bubble.angry { background: #ffe9e6; border-color: #b3202a; }
.bubble.angry::after { border-top-color: #b3202a; }
.bubble.angry .txt { color: #8a1018; }
.bubble.happy { background: #eefbe9; border-color: #1a7a3a; }
.bubble.happy::after { border-top-color: #1a7a3a; }
.bubble.police { background: #eaf0ff; border-color: #1b3a8c; }
.bubble.police::after { border-top-color: #1b3a8c; }

/* ---------------- Compte, connexion, classement, profil (0.7) ---------------- */
#login input { padding: 13px 14px; border-radius: 12px; border: 2px solid #ffffff33; background: #0b1530cc; color: #fff; font: inherit; font-size: 16px;
  user-select: text; -webkit-user-select: text; touch-action: manipulation; }
#login input:focus { outline: none; border-color: var(--yellow); }
#login .hint { font-size: 12px; color: var(--muted); margin: 2px 0; }
#login .err, .menuCard .err { background: #d3242c55; border: 1px solid #d3242c; border-radius: 10px; padding: 8px; margin: 0; font-size: 14px; }
#login button:disabled { opacity: 0.6; }
.account { font-size: 14px; color: var(--muted); margin: -4px 0 2px; }
.account b { color: #fff; }
.account .rk { color: var(--yellow); font-weight: 800; }
.annonce { margin: 0; background: #ffd21a22; border: 1px solid #ffd21a88; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.twin { display: flex; gap: 10px; } .twin button { flex: 1; }
.menuCard button.ghostBtn { background: transparent; border-color: #ffffff22; font-size: 14px; color: var(--muted); padding: 9px; }
.rank { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-bottom: 1px solid #ffffff10; }
.rank .pos { width: 30px; height: 30px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 13px; background: #ffffff14; }
.rank .pos.p1 { background: #e2b013; color: #111; } .rank .pos.p2 { background: #c9ced6; color: #111; } .rank .pos.p3 { background: #b8743a; color: #111; }
.rank .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .nm small { display: block; color: var(--muted); font-size: 11px; }
.rank .am { font-weight: 800; color: var(--yellow); white-space: nowrap; }
.rank.me { background: #3aa0e822; border-radius: 10px; }
.bigRank { text-align: center; padding: 8px; margin: 4px 0 8px; background: #ffffff0d; border-radius: 12px; }
.bigRank b { display: block; font-size: 30px; color: var(--yellow); line-height: 1.1; }
.bigRank small { color: var(--muted); }
