:root {
  --sky: #3f6fc4;
  --sand: #e8b468;
  --ink: #1a1010;
  --sun: #f7a823;
  --cream: #fff6e3;
  --title: "Luckiest Guy", "Arial Black", Impact, sans-serif;
  --s: 1;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #1d2a4a; color: var(--ink); overflow: hidden; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button { font: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: radial-gradient(ellipse at top, #2f4f8f, #121a30); }
#stage { position: relative; flex: none; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.5); background: var(--sky); }
#cv { display: block; }

/* ------------------------------------------------------------------ HUD */
#hud { position: absolute; inset: 0; pointer-events: none; font-family: var(--title); }
.hud-side { position: absolute; top: calc(var(--s) * 10px); left: calc(var(--s) * 12px); width: calc(var(--s) * 300px); }
.hud-side.right { left: auto; right: calc(var(--s) * 60px); text-align: right; }
.hud-name { display: flex; align-items: center; gap: calc(var(--s) * 8px); color: #fff; font-size: max(11px, calc(var(--s) * 20px));
  text-shadow: 0 2px 0 #000, 0 0 6px rgba(0,0,0,.5); }
.hud-side.right .hud-name { justify-content: flex-end; }
.hud-name .dot { width: calc(var(--s) * 16px); height: calc(var(--s) * 16px); min-width: 8px; min-height: 8px; border-radius: 50%; border: 2px solid #000; }
.hud-name .pips { letter-spacing: 2px; font-size: .85em; }
.tanbar { position: relative; margin-top: calc(var(--s) * 4px); height: max(8px, calc(var(--s) * 18px)); background: rgba(0,0,0,.45);
  border: 2px solid #fff; border-radius: 99px; overflow: hidden; }
.tanbar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; transition: width .15s; }
.hud-side.right .tanbar i { left: auto; right: 0; }
.tanbar .pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff;
  font-size: max(8px, calc(var(--s) * 13px)); text-shadow: 0 1px 0 #000; }
.hud-side.king .hud-name::after { content: '👑'; }
.hud-side.right.king .hud-name::after { content: none; }
.hud-side.right.king .hud-name::before { content: '👑'; }
.hud-mid { position: absolute; top: calc(var(--s) * 10px); left: 50%; transform: translateX(-50%); width: calc(var(--s) * 220px); text-align: center; color: #fff; }
.hud-mode { font-size: max(10px, calc(var(--s) * 16px)); text-shadow: 0 2px 0 #000; }
.daybar { position: relative; margin-top: calc(var(--s) * 6px); height: max(6px, calc(var(--s) * 10px)); background: rgba(0,0,0,.4); border-radius: 99px; border: 2px solid rgba(255,255,255,.8); }
.daybar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 99px; background: linear-gradient(90deg, #ffd23f, #ff8a3d); }
.daybar .sunicon { position: absolute; top: 50%; transform: translate(-50%, -50%); font-size: max(12px, calc(var(--s) * 20px)); }
.daybar.late .sunicon { animation: blink .5s infinite alternate; }
@keyframes blink { to { opacity: .4; } }
.hud-surv { position: absolute; top: calc(var(--s) * 10px); left: calc(var(--s) * 12px); display: flex; gap: calc(var(--s) * 22px); color: #fff;
  font-size: max(12px, calc(var(--s) * 24px)); text-shadow: 0 2px 0 #000; }
.hud-surv .hearts.flash { animation: shake .5s; }
@keyframes shake { 20% { transform: translateX(-6px) scale(1.2); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
.hud-btns { position: absolute; top: calc(var(--s) * 8px); right: calc(var(--s) * 8px); pointer-events: auto; }
.ibtn { width: max(32px, calc(var(--s) * 44px)); height: max(32px, calc(var(--s) * 44px)); border-radius: 50%; border: 3px solid #000;
  background: #fff6e3; font-size: max(14px, calc(var(--s) * 20px)); box-shadow: 0 3px 0 #000; }

#banner { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; width: 90%; }
#banner .b-title { font-family: var(--title); color: #fff; font-size: max(22px, calc(var(--s) * 56px));
  text-shadow: 0 4px 0 #2a4fa0, 0 6px 0 #000, 0 0 20px rgba(0,0,0,.4); letter-spacing: 1px; }
#banner .b-sub { margin-top: 6px; display: inline-block; background: rgba(0,0,0,.55); color: #fff; padding: 4px 12px; border-radius: 8px; font-size: max(11px, calc(var(--s) * 18px)); }
.pop { animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.2); opacity: 0; } }
#evbanner { position: absolute; top: calc(var(--s) * 74px); left: 50%; transform: translateX(-50%); font-family: var(--title); background: #ff5a3a; color: #fff;
  padding: calc(var(--s) * 6px) calc(var(--s) * 18px); border: 3px solid #000; border-radius: 10px; font-size: max(13px, calc(var(--s) * 26px));
  box-shadow: 0 4px 0 #000; pointer-events: none; white-space: nowrap; }
#evbanner.pop { animation: evpop .5s cubic-bezier(.2,1.6,.4,1); }
@keyframes evpop { from { transform: translateX(-50%) scale(.2) rotate(-10deg); } }

/* --------------------------------------------------------------- ÉCRANS */
.screen { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) 16px max(12px, env(safe-area-inset-bottom, 0px)); overflow-y: auto;
  background: linear-gradient(180deg, rgba(20,40,90,.25), rgba(20,20,40,.55)); }
#scr-title { justify-content: space-evenly; background: linear-gradient(180deg, rgba(20,40,90,.05), rgba(20,20,40,.45)); }
.logo { text-align: center; }
.cocotitle { margin: 0; font-family: var(--title); font-weight: normal; color: #fff; letter-spacing: 2px;
  font-size: clamp(44px, 11vw, 120px); line-height: .95;
  text-shadow: 0 4px 0 #2a55b8, 0 8px 0 #1a3478, 0 10px 18px rgba(0,0,0,.45);
  animation: wobble 3s ease-in-out infinite; }
@keyframes wobble { 0%,100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg) translateY(-4px); } }
.subtitle { font-family: var(--title); color: #ffd23f; font-size: clamp(16px, 3.6vw, 34px); text-shadow: 0 3px 0 #000; margin-top: 6px; }
.menu { display: grid; grid-template-columns: repeat(4, minmax(0, 190px)); gap: 12px; width: 100%; justify-content: center; }
.big { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 8px; border: 4px solid #000; border-radius: 18px;
  background: var(--cream); font-family: var(--title); font-size: clamp(18px, 2.6vw, 26px); box-shadow: 0 6px 0 #000; transition: transform .1s; }
.big span { font-size: 1.6em; }
.big small { font-family: system-ui, sans-serif; font-size: 12px; color: #6a4a2a; }
.big:hover, .big:focus-visible { transform: translateY(-3px) rotate(-1deg); background: #fff; }
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #000; }
.big[data-mode="histoire"] { background: #ffe08a; }
.big[data-mode="duel"] { background: #ffb3bd; }
.big[data-mode="chaos"] { background: #c8b6ff; }
.big[data-mode="survie"] { background: #b6f0c0; }
.menu-small { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.menu-small button, .ghost { border: 3px solid #000; background: rgba(255,246,227,.92); border-radius: 12px; padding: 8px 14px; font-weight: 700; box-shadow: 0 3px 0 #000; }
.credit { color: #fff; opacity: .85; font-size: 12px; text-align: center; max-width: 640px; margin: 0; text-shadow: 0 1px 2px #000; }

.scr-h { font-family: var(--title); font-weight: normal; color: #fff; font-size: clamp(22px, 4vw, 40px); text-shadow: 0 3px 0 #000; margin: 4px 0 10px; text-align: center; }
.scr-h3 { font-family: var(--title); font-weight: normal; color: #5ad1ff; text-shadow: 0 2px 0 #000; margin: 8px 0; text-align: center; }
.sel-row { display: grid; grid-template-columns: repeat(4, minmax(0, 200px)); gap: 10px; justify-content: center; width: 100%; }
.char { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px; border: 4px solid #000; border-radius: 16px; background: var(--cream);
  box-shadow: 0 5px 0 #000; text-align: center; transition: transform .1s; }
.char canvas { background: radial-gradient(circle at 50% 70%, var(--c), transparent 70%); border-radius: 50%; }
.char b { font-family: var(--title); font-weight: normal; font-size: 22px; }
.char small { font-size: 11.5px; color: #5a4a3a; line-height: 1.25; min-height: 3.6em; }
.char .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; font-size: 10.5px; color: #3a2a1a; margin-top: 4px; }
.char.on { background: #fff; outline: 4px solid var(--c); transform: translateY(-4px) scale(1.03); box-shadow: 0 9px 0 #000; }
#sel-opts { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin: 14px 0 4px; }
.seg { display: flex; border: 3px solid #000; border-radius: 12px; overflow: hidden; box-shadow: 0 3px 0 #000; }
.seg button { border: 0; background: #e8dcc4; padding: 8px 12px; font-weight: 700; }
.seg button + button { border-left: 2px solid #000; }
.seg button.on { background: #ffd23f; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.actions.col { flex-direction: column; align-items: stretch; }
.go { border: 4px solid #000; background: #4cd964; color: #000; font-family: var(--title); font-size: 22px; padding: 10px 26px; border-radius: 14px; box-shadow: 0 5px 0 #000; }
.go:active, .ghost:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }

.howto { display: grid; grid-template-columns: repeat(2, minmax(0, 360px)); gap: 12px; }
.hcard { background: var(--cream); border: 3px solid #000; border-radius: 14px; padding: 12px 14px; box-shadow: 0 4px 0 #000; font-size: 14px; }
.hcard .hicon { font-size: 28px; float: left; margin-right: 10px; }
.hcard b:first-of-type { font-family: var(--title); font-weight: normal; font-size: 20px; }
.hcard p { margin: 6px 0 0; line-height: 1.35; }

.card { background: var(--cream); border: 4px solid #000; border-radius: 20px; padding: 18px 22px; max-width: 620px; width: 100%; text-align: center;
  box-shadow: 0 8px 0 #000; animation: cardin .45s cubic-bezier(.2,1.5,.4,1); }
@keyframes cardin { from { transform: scale(.6) rotate(-4deg); opacity: 0; } }
.card.night { background: #24305e; color: #fff; }
.ep-num { font-weight: 800; text-transform: uppercase; letter-spacing: 2px; font-size: 13px; color: #b0602a; }
.night .ep-num { color: #ffd23f; }
.ep-title { font-family: var(--title); font-weight: normal; font-size: clamp(26px, 5vw, 44px); margin: 6px 0; line-height: 1.05; }
.ep-desc { font-size: 16px; margin: 6px 0; }
.ep-vs { font-size: 13px; color: #6a4a2a; margin: 4px 0; }
.choices { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.choice { display: flex; gap: 12px; align-items: center; text-align: left; border: 3px solid #000; border-radius: 14px; background: #fff6e3; padding: 10px 14px; box-shadow: 0 4px 0 #000; }
.choice:hover { background: #ffe08a; }
.choice .ci { font-size: 30px; }
.choice b { display: block; font-size: 16px; }
.choice small { color: #6a4a2a; }

#rotate { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.7); color: #fff; padding: 6px 10px; border-radius: 8px; font-size: 12px; white-space: nowrap; z-index: 5; pointer-events: none; }

/* -------------------------------------------------------- BOUTONS D'ACTION */
#pad { flex: none; width: 100%; display: flex; gap: 10px; justify-content: center; align-items: stretch; padding: 6px 8px; }
.hand { position: relative; flex: 1; max-width: 760px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#pad.two .hand { max-width: 50%; }
.act { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 3px solid #000; border-radius: 14px; background: var(--cream); box-shadow: 0 4px 0 #000, inset 0 -6px 0 color-mix(in srgb, var(--c) 60%, transparent);
  padding: 4px 4px 6px; min-height: 0; transition: transform .08s, filter .2s; }
.act:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.act .ic { font-size: clamp(22px, 4.2vh, 36px); line-height: 1; }
.act .lb { font-weight: 800; font-size: clamp(10px, 1.7vh, 14px); line-height: 1.1; text-align: center; }
.act kbd { position: absolute; top: 3px; left: 5px; font: 700 11px/1 system-ui; background: #000; color: #fff; padding: 2px 4px; border-radius: 4px; opacity: .7; }
.act .badge { position: absolute; top: 3px; right: 5px; font: 800 12px/1 system-ui; background: #5b3518; color: #fff; padding: 2px 5px; border-radius: 6px; }
.act .cd { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(0,0,0,.35); pointer-events: none; }
.act.off { filter: grayscale(.85) brightness(.85); }
.act.new { animation: flip .35s; }
@keyframes flip { from { transform: rotateY(90deg); } }
.hand.ontop .act { background: #fff2b0; }
.hand.busy .act { filter: grayscale(.6) brightness(.9); }
.hand-ov { position: absolute; inset: -4px; display: none; align-items: center; justify-content: center; border-radius: 16px;
  font-family: var(--title); font-size: clamp(20px, 4vh, 34px); color: #fff; text-shadow: 0 3px 0 #000; border: 4px solid #000; z-index: 2; }
.hand.gauge .hand-ov { display: flex; background: #22b14c; animation: pulse .4s infinite alternate; }
.hand.mash .hand-ov { display: flex; background: #ff3b3b; animation: pulse .15s infinite alternate; }
@keyframes pulse { to { filter: brightness(1.2); transform: scale(1.02); } }
.hand-tag { position: absolute; top: -12px; left: 50%; transform: translateX(-50%); font: 800 11px/1 system-ui; background: var(--c); border: 2px solid #000; padding: 2px 6px; border-radius: 6px; z-index: 3; }

/* téléphone en portrait : boutons en 2×2 */
body.portrait .hand { grid-template-columns: repeat(2, 1fr); }
body.portrait #pad.two .hand { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 760px) {
  .menu { grid-template-columns: repeat(2, minmax(0, 220px)); }
  .sel-row { grid-template-columns: repeat(2, minmax(0, 220px)); }
  .howto { grid-template-columns: 1fr; }
  .char small { display: none; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .cocotitle { font-size: 52px; }
  .subtitle { font-size: 18px; }
  .big { padding: 6px; font-size: 17px; }
  .big small { display: none; }
  .char small, .char .stats { display: none; }
  .char canvas { width: 56px !important; height: 56px !important; }
  .char b { font-size: 16px; }
  .card { padding: 10px 14px; }
  .ep-desc { font-size: 14px; }
  .credit { display: none; }
}
