/* Run, Kash, Run! : téléphone en paysage et jeu */

:root { --bg: #140c24; --ink: #fff; --red: #ff3355; --gold: #ffd166; --desk: #0b0b0c; --u: 1; }
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
body {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  font-family: "Press Start 2P", ui-monospace, Consolas, monospace; color: var(--ink);
  background:
    radial-gradient(60% 50% at 50% 50%, rgba(227, 36, 43, 0.14) 0%, transparent 70%),
    var(--desk);
}

/* lien de retour (ordinateur) */
.run-back {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: Manrope, system-ui, sans-serif; font-size: 0.875rem; font-weight: 600;
  color: rgba(236, 236, 238, 0.72); text-decoration: none;
}
.run-back:hover { color: #fff; }
.run-back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* téléphone couché : même appareil que l'accueil, tourné d'un quart de tour */
.lphone {
  position: relative;
  width: min(calc(100vw - 48px), calc((100vh - 110px) * 2.08), 1500px);
  aspect-ratio: 2.08;
  padding: 11px;
  border-radius: 58px;
  background: linear-gradient(60deg, #34353a 0%, #18191c 40%, #0d0e10 100%);
  box-shadow:
    inset 0 0 0 2px #3c3d42,
    inset 0 2px 1px rgba(255, 255, 255, 0.1),
    0 40px 90px rgba(0, 0, 0, 0.75),
    0 0 140px rgba(227, 36, 43, 0.12);
}
/* boutons latéraux : en haut et en bas, du côté de l'îlot */
.lphone::before, .lphone::after { content: ""; position: absolute; height: 4px; border-radius: 2px; background: #2b2c30; }
.lphone::before { top: -3px; left: 190px; width: 92px; }
.lphone::after { bottom: -3px; left: 160px; width: 120px; background: linear-gradient(90deg, #2b2c30 0 44%, transparent 44% 56%, #2b2c30 56%); }

.lphone__screen {
  position: relative;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  border-radius: 47px;
  background: var(--bg);
  box-shadow: 0 0 0 1px #000;
  isolation: isolate;
}
.lphone__island {
  position: absolute; z-index: 6; left: 12px; top: 50%;
  width: 36px; height: 128px; margin-top: -64px;
  border-radius: 20px; background: #000; pointer-events: none;
}
/* barre d'accueil : retour au téléphone */
.lphone__home {
  position: absolute; z-index: 7; left: 50%; bottom: 0;
  width: 180px; height: 22px; margin-left: -90px;
}
.lphone__home::before {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: 7px;
  height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.6); transition: background-color 0.2s;
}
.lphone__home:hover::before { background: #fff; }

/* Vrai téléphone : le jeu prend tout l'écran */
@media (pointer: coarse) and (max-height: 600px), (max-width: 600px) {
  body { display: block; background: var(--bg); }
  .run-back { display: none; }
  .lphone { width: 100vw; height: 100vh; height: 100dvh; aspect-ratio: auto; padding: 0; border-radius: 0; box-shadow: none; background: none; }
  .lphone::before, .lphone::after, .lphone__island, .lphone__home { display: none; }
  .lphone__screen { border-radius: 0; box-shadow: none; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
}

/* téléphone tenu droit : demander de le tourner */
#rotate {
  display: none; position: fixed; inset: 0; z-index: 50;
  flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  padding: 24px; text-align: center; background: var(--bg);
  font-size: 11px; line-height: 1.9; color: #e8dcff;
}
#rotate a { font-size: 9px; color: #9c8cc4; }
#rotate .rotate__icon { font-size: 42px; animation: tilt 1.6s ease-in-out infinite; }
@keyframes tilt { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (max-width: 820px) {
  #rotate { display: flex; }
}

/* Jeu */
#wrap { position: relative; overflow: hidden; }
#game { display: block; }

.overlay {
  position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: calc(var(--u) * 10px); text-align: center; padding: calc(var(--u) * 16px);
  background: radial-gradient(ellipse at center, rgba(20, 12, 36, .55), rgba(20, 12, 36, .9));
  transition: opacity .25s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
#wrap h1 { font-size: calc(var(--u) * 34px); line-height: 1.25; color: var(--gold); letter-spacing: 2px; font-weight: 400;
  text-shadow: calc(var(--u) * 3px) calc(var(--u) * 3px) 0 var(--red), calc(var(--u) * 6px) calc(var(--u) * 6px) 0 #000; }
#wrap h1 .knife { display: inline-block; animation: wiggle .5s ease-in-out infinite alternate; }
@keyframes wiggle { from { transform: rotate(-14deg); } to { transform: rotate(14deg); } }
#wrap h2 { font-size: calc(var(--u) * 24px); color: var(--red); line-height: 1.3; font-weight: 400;
  text-shadow: calc(var(--u) * 3px) calc(var(--u) * 3px) 0 #000; }
#over h2 { animation: shake .35s ease-in-out 3; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px) rotate(-2deg); } 75% { transform: translateX(6px) rotate(2deg); } }
.sub, #quip { font-size: calc(var(--u) * 10px); line-height: 1.7; color: #e8dcff; max-width: calc(var(--u) * 600px); }
#quip { color: var(--gold); }
.btn { font-family: inherit; font-size: calc(var(--u) * 16px); color: #1a0f2e; background: var(--gold);
  border: calc(var(--u) * 4px) solid #000; padding: calc(var(--u) * 11px) calc(var(--u) * 26px); cursor: pointer;
  box-shadow: calc(var(--u) * 5px) calc(var(--u) * 5px) 0 var(--red); transition: transform .08s, box-shadow .08s; }
.btn:hover { transform: translate(-2px, -2px); box-shadow: calc(var(--u) * 7px) calc(var(--u) * 7px) 0 var(--red); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--red); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn--small { font-size: calc(var(--u) * 10px); padding: calc(var(--u) * 8px) calc(var(--u) * 14px); box-shadow: calc(var(--u) * 3px) calc(var(--u) * 3px) 0 var(--red); }
.btn--ghost { background: #2c1f4a; color: #fff; border-color: #000; }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: calc(var(--u) * 14px); }
.controls { font-size: calc(var(--u) * 8px); line-height: 2.1; color: #cdbfef; }
kbd { font-family: inherit; background: #2c1f4a; border: 2px solid #6c5a99; border-radius: 3px; padding: 1px 5px; color: #fff; }
.best, .scores { font-size: calc(var(--u) * 11px); color: #fff; }
.scores b { color: var(--gold); }
.badge { font-size: calc(var(--u) * 11px); color: #000; background: var(--gold); padding: 6px 10px;
  animation: pulse .6s ease-in-out infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.1); } }
.gone { display: none !important; }
.hint { font-size: calc(var(--u) * 8px); color: #9c8cc4; text-decoration: none; }
a.hint:hover { color: #fff; }
body.touch .no-touch, body:not(.touch) .only-touch { display: none; }

/* enregistrement du score */
.save { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: calc(var(--u) * 10px);
  font-size: calc(var(--u) * 9px); color: #e8dcff; min-height: calc(var(--u) * 34px); }
.save b { color: var(--gold); }
.save input { font-family: inherit; font-size: calc(var(--u) * 10px); width: calc(var(--u) * 190px);
  padding: calc(var(--u) * 8px); color: #fff; background: #1d1438; border: 2px solid #6c5a99; border-radius: 4px;
  user-select: text; -webkit-user-select: text; }
.save input:focus { outline: none; border-color: var(--gold); }
.save .note { line-height: 1.7; max-width: calc(var(--u) * 520px); color: #cdbfef; }
.save .note--top { color: var(--gold); }
.save .note--error { color: var(--red); }

/* classement */
#board { z-index: 6; justify-content: flex-start; padding-top: calc(var(--u) * 18px); background: rgba(20, 12, 36, .97); }
.tabs { display: flex; gap: 0; border: 2px solid #000; }
.tabs button { font-family: inherit; font-size: calc(var(--u) * 9px); padding: calc(var(--u) * 7px) calc(var(--u) * 12px);
  color: #cdbfef; background: #1d1438; border: 0; cursor: pointer; }
.tabs button[aria-selected="true"] { color: #1a0f2e; background: var(--gold); }
.board { list-style: none; width: min(100%, calc(var(--u) * 560px)); flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: calc(var(--u) * 4px); touch-action: pan-y; scrollbar-width: thin; }
.board li { display: grid; grid-template-columns: calc(var(--u) * 42px) 1fr auto; align-items: center; gap: calc(var(--u) * 10px);
  padding: calc(var(--u) * 7px) calc(var(--u) * 10px); background: rgba(44, 31, 74, .7); border: 2px solid #000;
  font-size: calc(var(--u) * 10px); text-align: left; }
.board li.is-me { background: rgba(255, 209, 102, .18); border-color: var(--gold); }
.board .rank { color: var(--gold); text-align: center; }
.board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .name small { display: block; margin-top: 4px; font-size: calc(var(--u) * 7px); color: #9c8cc4; }
.board .pts { color: var(--gold); }
.board .gap { display: block; text-align: center; background: none; border: 0; color: #9c8cc4; padding: 0; }
.board .empty { display: block; text-align: center; background: none; border: 0; color: #cdbfef; line-height: 1.8; }

.ui-btn { position: absolute; z-index: 5; width: calc(var(--u) * 40px); height: calc(var(--u) * 40px);
  font-size: calc(var(--u) * 18px); line-height: 1; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 12, 36, .75); color: #fff; border: 2px solid rgba(255, 255, 255, .5); border-radius: 8px;
  cursor: pointer; font-family: system-ui, sans-serif; }
.ui-btn:hover { border-color: #fff; }
#restartBtn { right: calc(var(--u) * 12px); bottom: calc(var(--u) * 10px); }
#duckBtn { left: calc(var(--u) * 12px); bottom: calc(var(--u) * 8px); width: calc(var(--u) * 76px);
  height: calc(var(--u) * 44px); font-size: calc(var(--u) * 11px); font-family: inherit; display: none; }
body.touch #duckBtn.live { display: flex; }
#duckBtn.on { background: rgba(255, 51, 85, .8); }
