:root {
  --ink: #1b2a49;
  --card: rgba(255,255,255,.14);
  --gold: #f6c343;
  --cell: #fff7e3;
  --cell-text: #2b2b3a;
  --accent: #34c38f;
  --sky1: #2b5876; --sky2: #4e4376;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: #fff;
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif; user-select: none; -webkit-user-select: none; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.screen.active { display: flex; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }

/* ---------- parties ---------- */
#screen-saves, #screen-auth { background: linear-gradient(160deg, #f2994a 0%, #c0392b 45%, #4e2a6e 100%); overflow-y: auto; }
.saves-hero { padding: 36px 24px 8px; text-align: center; }
.logo { font-size: clamp(34px, 9vw, 52px); font-weight: 900; line-height: 1.02; letter-spacing: .5px; text-shadow: 0 4px 0 rgba(0,0,0,.25); }
.logo span { color: var(--gold); }
.tagline { opacity: .9; margin: 10px auto 0; max-width: 360px; font-size: 15px; }
.saves-panel { width: min(520px, 100%); margin: 14px auto 0; padding: 12px 18px 32px; }
.saves-panel h2 { margin: 6px 0 10px; font-size: 18px; opacity: .9; }
.save-card { display: flex; align-items: center; gap: 12px; background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.25);
  border-radius: 16px; padding: 12px 14px; margin-bottom: 10px; backdrop-filter: blur(4px); }
.save-card .avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; font-weight: 900;
  background: var(--gold); color: #5a3b00; flex: none; }
.save-card .info { flex: 1; min-width: 0; }
.save-card .name { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-card .meta { font-size: 13px; opacity: .85; margin-top: 2px; }
.save-card .actions { display: flex; gap: 6px; }
.empty { text-align: center; opacity: .85; padding: 18px 8px 22px; }

.btn { border-radius: 14px; padding: 10px 16px; font-weight: 800; transition: transform .08s; }
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--accent); color: #053b28; box-shadow: 0 4px 0 #1d8e66; }
.btn-secondary { background: #fff; color: var(--ink); box-shadow: 0 4px 0 rgba(0,0,0,.2); }
.btn-danger { background: #e74c3c; color: #fff; box-shadow: 0 4px 0 #a52a1d; }
.btn-ghost { background: rgba(255,255,255,.16); }
.btn-block { display: block; width: 100%; padding: 14px; font-size: 17px; }
.btn-small { padding: 8px 12px; font-size: 14px; border-radius: 12px; }
.saves-tools { display: flex; gap: 8px; margin-top: 14px; }
.saves-tools .btn { flex: 1; font-size: 14px; }
.warning { background: rgba(0,0,0,.35); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-top: 12px; }

/* ---------- jeu ---------- */
#screen-game { background: linear-gradient(180deg, var(--sky1), var(--sky2)); overflow: hidden; }
#scene { position: absolute; inset: -14px; pointer-events: none; filter: blur(2px) saturate(.9);
  background: linear-gradient(rgba(50,110,190,.38), rgba(26,56,120,.58)), var(--bg-img, url(guide-montagnes-atlas.jpg)) 58% center / cover no-repeat; }
.topbar { position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; background: var(--card); font-size: 20px; }
.topbar .title { flex: 1; text-align: center; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
#world-name { font-weight: 900; font-size: 16px; }
#level-label { font-size: 13px; opacity: .9; }
.coins { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,.3); border-radius: 20px; padding: 6px 12px; font-size: 16px; min-width: 76px; justify-content: center; }
.coin { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe58a, #e1a50f); border: 2px solid #b97d00; display: inline-block; }

#grid-area { position: relative; z-index: 1; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px 14px; }
#grid { display: grid; gap: 3px; }
.cell { display: grid; place-items: center; border-radius: 8px; font-weight: 900; text-transform: uppercase;
  background: rgba(255,255,255,.2); border: 2px solid rgba(255,255,255,.55); color: transparent; transition: background .2s; }
.cell.filled { background: var(--cell); color: var(--cell-text); border-color: #e2c98a; box-shadow: 0 2px 0 #c9ae6a; animation: pop .35s ease; }
.cell.targetable { animation: blink 1s infinite; cursor: pointer; }
.cell.flash { animation: flash .6s; }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes blink { 50% { background: rgba(246,195,67,.55); } }
@keyframes flash { 30% { background: var(--gold); } }

#preview-wrap { position: relative; z-index: 2; height: 46px; display: flex; align-items: center; justify-content: center; }
#preview { min-width: 24px; padding: 6px 18px; border-radius: 20px; background: rgba(255,255,255,.95); color: var(--ink); font-weight: 900; font-size: 22px; letter-spacing: 3px; visibility: hidden; }
#preview.show { visibility: visible; }
#preview.bad { animation: shake .35s; background: #ff8a80; }
#preview.good { background: #b9f6ca; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

#wheel-area { position: relative; z-index: 2; display: flex; align-items: center; justify-content: center; padding: 6px 0 18px; }
#wheel { position: relative; border-radius: 50%; background: rgba(255,255,255,.9); box-shadow: 0 8px 24px rgba(0,0,0,.35); touch-action: none; }
#wheel-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#wheel-line { stroke: var(--ink); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: .55; }
.letter { position: absolute; display: grid; place-items: center; border-radius: 50%; font-weight: 900; color: var(--ink); text-transform: uppercase; pointer-events: none; transition: background .12s, color .12s, transform .12s; }
.letter.sel { background: var(--ink); color: #fff; transform: scale(1.08); }
#btn-shuffle { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%; background: #e8ecf5; color: var(--ink); font-size: 26px; font-weight: 900; box-shadow: 0 2px 0 #b9c1d6; }
#btn-shuffle:active { transform: rotate(180deg); transition: transform .25s; }

.side-btn { position: absolute; width: 58px; height: 58px; border-radius: 50%; background: var(--card); border: 2px solid rgba(255,255,255,.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.side-btn .ico { font-size: 22px; }
.side-btn small { font-size: 12px; font-weight: 800; margin-top: 3px; background: rgba(0,0,0,.35); border-radius: 8px; padding: 1px 6px; }
.side-btn.left { left: 12px; top: 10%; }
.side-btn.left2 { left: 12px; top: 52%; }
.side-btn.right { right: 12px; top: 30%; }
.side-btn.active { background: var(--gold); border-color: #fff; }
.side-btn:disabled { opacity: .45; }

/* ---------- toast & modal ---------- */
#toast { position: fixed; left: 50%; top: 14%; transform: translate(-50%, -20px); background: rgba(0,0,0,.8); padding: 10px 18px; border-radius: 22px; font-weight: 800; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 86vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.modal { position: fixed; inset: 0; background: rgba(8,12,28,.7); display: grid; place-items: center; padding: 20px; z-index: 40; }
.modal[hidden] { display: none; }
.modal-card { width: min(380px, 100%); max-height: 86vh; overflow: auto; background: #fff; color: var(--ink); border-radius: 22px; padding: 22px 20px 18px; text-align: center; animation: pop .3s ease; }
.modal-card h3 { margin: 0 0 8px; font-size: 22px; }
.modal-card p { margin: 6px 0 14px; line-height: 1.4; }
.modal-card input[type=text] { width: 100%; padding: 12px 14px; font-size: 18px; border-radius: 12px; border: 2px solid #cfd6e6; outline: none; margin: 6px 0 14px; color: var(--ink); }
.modal-card input[type=text]:focus { border-color: var(--accent); }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-actions.row { flex-direction: row; }
.modal-actions.row .btn { flex: 1; }
.modal .btn-ghost { background: #eef1f8; color: var(--ink); }
.bonus-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 4px 0 14px; }
.bonus-list span { background: #eef1f8; border-radius: 10px; padding: 4px 10px; font-weight: 800; }
.stars { font-size: 38px; letter-spacing: 6px; margin: 4px 0; }

@media (max-height: 640px) { #preview-wrap { height: 38px; } #preview { font-size: 18px; } }

/* ---------- choix de difficulté ---------- */
.diff-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 8px; }
.diff { padding: 12px 0; border-radius: 12px; background: #eef1f8; color: var(--ink); font-weight: 900; font-size: 18px; border: 2px solid transparent; }
.diff.on { background: var(--accent); color: #053b28; border-color: #1d8e66; box-shadow: 0 3px 0 #1d8e66; }
.diff-desc { font-size: 14px; min-height: 40px; opacity: .85; }

#credit { position: absolute; z-index: 1; left: 0; right: 0; bottom: calc(2px + env(safe-area-inset-bottom)); text-align: center; font-size: 9px; opacity: .65; pointer-events: none; text-shadow: 0 1px 2px rgba(0,0,0,.6); padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.side-btn.right2 { right: 12px; top: 56%; }

/* ---------- aide ---------- */
.help-corner { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 14px; font-weight: 900; font-size: 20px; }
.modal-card .help { text-align: left; }
.modal-card .help h3 { text-align: center; }
.modal-card .help h4 { margin: 14px 0 4px; font-size: 16px; }
.modal-card .help p { margin: 4px 0 6px; font-size: 14.5px; }
.modal-card .help ul { margin: 4px 0 6px; padding-left: 20px; font-size: 14.5px; line-height: 1.45; }
.modal-card .help .modal-actions { margin-top: 16px; }
#screen-saves { position: absolute; }
.saves-hero { position: relative; }
#tip { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); width: min(420px, calc(100vw - 28px)); display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center;
  background: #fff; color: var(--ink); border-radius: 18px; padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.35); animation: pop .3s ease; }
#tip[hidden] { display: none; }
#tip-ico { font-size: 28px; grid-row: 1 / 3; }
#tip p { margin: 0; font-size: 14px; line-height: 1.35; }
#tip .btn { justify-self: end; }
#tip .tip-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
#tip #tip-off { background: #eef1f8; color: var(--ink); box-shadow: none; }

/* ---------- compte ---------- */
.account-bar { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.25); border-radius: 14px; padding: 8px 10px 8px 12px; font-size: 14px; margin-bottom: 12px; }
.account-bar .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.account-bar small { opacity: .8; font-size: 12px; }
.auth-card { width: min(440px, 100%); margin: 10px auto 0; padding: 4px 18px 32px; }
.auth-box { background: rgba(255,255,255,.96); color: var(--ink); border-radius: 22px; padding: 14px 16px 12px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #eef1f8; border-radius: 14px; padding: 4px; margin-bottom: 12px; }
.auth-tabs button { padding: 10px 4px; border-radius: 11px; background: transparent; color: var(--ink); font-weight: 800; }
.auth-tabs button.on { background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.auth-box label { display: block; font-weight: 800; font-size: 14px; margin-bottom: 10px; }
.auth-box input, .modal-card input[type=password] { display: block; width: 100%; margin-top: 4px; padding: 12px 14px; font-size: 17px; border-radius: 12px; border: 2px solid #cfd6e6; outline: none; color: var(--ink); background: #fff; font-weight: 400; }
.modal-card input[type=password] { margin: 6px 0 8px; }
.auth-box input:focus, .modal-card input[type=password]:focus { border-color: var(--accent); }
.auth-error { background: #fdecea; color: #a52a1d; border-radius: 10px; padding: 8px 10px; font-size: 14px; margin: 0 0 10px; text-align: left; }
.auth-info { background: #eef6ff; color: #1f4b7a; border-radius: 10px; padding: 8px 10px; font-size: 13.5px; margin: 0 0 10px; text-align: left; }
.auth-error[hidden], .auth-info[hidden] { display: none; }
.link { display: block; width: 100%; background: none; color: var(--ink); text-decoration: underline; padding: 12px 6px 4px; font-size: 14px; text-align: center; }
.link.light { color: #fff; opacity: .92; padding-top: 18px; }
