:root {
  --ink: #2a2466; --card: #ffffff; --key: #e9e7ff; --red: #e63946; --yellow: #ffd23f; --blue: #2f6fe0; --green: #22b573; --dimblue: #2b4c94;
  --kh: 54px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif; color: #fff;
  background: radial-gradient(120% 90% at 20% 0%, #4a2fb3 0%, #2b1b6b 45%, #0e6f86 100%);
  user-select: none; -webkit-user-select: none;
}
button { font: inherit; cursor: pointer; border: 0; touch-action: manipulation; }
#app { position: fixed; inset: 0; height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

#bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px; min-height: 52px; flex: none; }
#info { flex: 1; font-weight: 800; font-size: clamp(14px, 4vw, 20px); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#score { display: flex; gap: 8px; font-weight: 800; font-size: clamp(14px, 3.6vw, 18px); white-space: nowrap; }
.ibtn { width: 48px; height: 48px; border-radius: 14px; background: rgba(255,255,255,.16); color: #fff; font-size: 22px; flex: none; }
.ibtn:active { background: rgba(255,255,255,.3); }

#play { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: stretch; }
#stage { position: relative; flex: 1; min-height: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#toast { position: absolute; left: 50%; top: 10px; transform: translate(-50%, -20px); opacity: 0; pointer-events: none; transition: .25s;
  background: #fff; color: var(--ink); font-weight: 800; padding: 10px 16px; border-radius: 16px; font-size: clamp(14px, 4vw, 20px); text-align: center; max-width: 92%; box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 5; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#hintline { position: absolute; left: 6px; right: 6px; bottom: 4px; pointer-events: none; text-align: center; font-size: clamp(12px, 3.4vw, 16px); font-weight: 700;
  background: rgba(255,210,63,.95); color: var(--ink); border-radius: 12px; padding: 4px 10px; display: none; z-index: 4; }
#hintline.on { display: block; }

#kb { flex: none; width: 100%; max-width: 680px; margin: 0 auto; padding: 4px 4px calc(6px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; }
.krow { display: flex; gap: 3px; justify-content: center; }
.key { position: relative; flex: 1 1 0; min-width: 0; max-width: 60px; height: var(--kh); border-radius: 10px; background: var(--key); color: var(--ink); font-weight: 800; font-size: clamp(22px, 6.4vw, 26px); box-shadow: 0 3px 0 #aaa5ec; padding: 0; }
.key::after { content: ''; position: absolute; inset: -3px -1.5px; }
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 #aaa5ec; }
.key.correct { background: var(--red); color: #fff; box-shadow: 0 3px 0 #a81f2b; border-radius: 6px; }
.key.present { background: var(--yellow); color: var(--ink); box-shadow: 0 3px 0 #c9a21a; border-radius: 26px; }
.key.absent { background: var(--dimblue); color: #b9c9ee; box-shadow: 0 3px 0 rgba(26,50,106,.4); opacity: .4; }
.key.wide { flex: 1.5 1 0; max-width: 90px; font-size: clamp(20px, 5.4vw, 24px); background: #ffd9de; box-shadow: 0 3px 0 #e8a2ab; }
.arow { display: flex; gap: 8px; }
.act { height: calc(var(--kh) + 6px); border-radius: 14px; font-weight: 800; font-size: clamp(16px, 4.6vw, 22px); }
#btnValid { flex: 1; background: var(--green); color: #fff; box-shadow: 0 4px 0 #14804f; }
#btnHint { flex: none; padding: 0 14px; background: #ffd23f; color: var(--ink); box-shadow: 0 4px 0 #c9a21a; }
.act:active { transform: translateY(2px); }

.panel { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 10px; background: rgba(20,12,60,.82); max-height: 100dvh; overflow-y: auto; }
#home { background-image: url('../assets/img/titre.jpg'), radial-gradient(120% 90% at 20% 0%, #4a2fb3 0%, #2b1b6b 45%, #0e6f86 100%); background-size: cover, auto; background-position: center; }
.card { background: var(--card); color: var(--ink); border-radius: 24px; padding: clamp(12px, 3vmin, 24px); width: min(94vw, 560px); max-height: calc(100dvh - 20px); overflow-y: auto; text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.4); margin: auto; }
.card h1 { margin: 0 0 4px; display: flex; gap: 6px; justify-content: center; }
.card h2 { margin: 0 0 8px; font-size: clamp(20px, 5vw, 28px); }
.card p { margin: 6px 0; font-size: clamp(14px, 4vw, 18px); }
.ltile { width: clamp(42px, 12vmin, 64px); height: clamp(42px, 12vmin, 64px); display: grid; place-items: center; font-weight: 900; font-size: clamp(24px, 7vmin, 38px); border-radius: 12px; color: #fff; }
.ltile.c { background: var(--red); border-radius: 8px; }
.ltile.p { background: var(--blue); }
.ltile.p span { background: var(--yellow); color: var(--ink); width: 78%; height: 78%; border-radius: 50%; display: grid; place-items: center; }
.ltile.a { background: var(--dimblue); color: #b9c9ee; }
.tag { font-weight: 700; }
#homeStats { display: flex; gap: 14px; justify-content: center; font-weight: 800; font-size: clamp(15px, 4vw, 20px); margin: 4px 0 8px; flex-wrap: wrap; }
#modes { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.mode { min-height: 52px; padding: 0 14px; border-radius: 16px; background: var(--key); color: var(--ink); font-weight: 800; font-size: clamp(15px, 4vw, 19px); }
.mode.on { background: var(--ink); color: #fff; }
#paliers { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.pal { min-height: 64px; border-radius: 18px; color: #fff; font-weight: 800; font-size: clamp(17px, 4.6vw, 22px); display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; padding: 6px 12px; box-shadow: 0 5px 0 rgba(0,0,0,.22); }
.pal small { font-size: .7em; font-weight: 700; opacity: .95; }
.pal:active { transform: translateY(2px); }
.pal[data-l="1"] { background: #22b573; } .pal[data-l="2"] { background: #f08a24; } .pal[data-l="3"] { background: #8a4fe0; }
.btn { min-height: 52px; padding: 0 18px; border-radius: 16px; background: var(--key); color: var(--ink); font-weight: 800; font-size: clamp(15px, 4vw, 20px); box-shadow: 0 4px 0 #aaa5ec; }
.btn.go { background: var(--green); color: #fff; box-shadow: 0 4px 0 #14804f; }
.btn.ghost { background: transparent; box-shadow: none; text-decoration: underline; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.legend { list-style: none; padding: 0; margin: 0 0 8px; text-align: left; font-weight: 700; font-size: clamp(14px, 4vw, 18px); }
.legend li { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.mini { width: 40px; height: 40px; flex: none; display: grid; place-items: center; font-weight: 900; color: #fff; border-radius: 8px; }
.mini.c { background: var(--red); } .mini.a { background: var(--dimblue); color: #b9c9ee; border-radius: 10px; }
.mini.p { background: var(--yellow); color: var(--ink); border-radius: 50%; }
#endWord { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
#endWord .ltile { width: clamp(34px, 10vmin, 52px); height: clamp(34px, 10vmin, 52px); font-size: clamp(20px, 6vmin, 30px); }
#endStars { font-size: clamp(28px, 8vmin, 44px); min-height: 1.2em; }

#confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.cf { position: absolute; top: -20px; width: 10px; height: 14px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110dvh) rotate(720deg); } }

@media (orientation: landscape) and (max-height: 500px) {
  :root { --kh: 48px; }
  .key { font-size: 20px; }
  #bar { min-height: 50px; padding: 1px 8px; }
  #play { flex-direction: row; }
  #kb { width: 54%; max-width: none; margin: 0; padding: 2px 6px 4px 2px; justify-content: center; gap: 5px; }
  .key { max-width: none; }
  .card { padding: 8px 12px; }
  .card h1 { margin: 0; }
  .card h2 { margin: 0 0 4px; font-size: 20px; }
  .card p { margin: 2px 0; font-size: 14px; }
  .ltile { width: 38px; height: 38px; font-size: 22px; }
  #endWord .ltile { width: 34px; height: 34px; font-size: 20px; }
  #homeStats { margin: 0 0 4px; }
  #modes { margin-bottom: 6px; }
  #paliers { flex-direction: row; gap: 6px; margin-bottom: 4px; }
  .pal { flex: 1; min-height: 56px; flex-direction: column; gap: 0; font-size: 16px; padding: 4px 6px; }
  .btn { min-height: 48px; }
  .row { margin-top: 4px; }
  #endStars { font-size: 26px; }
}
@media (min-width: 900px) and (min-height: 501px) { :root { --kh: 56px; } }
