/* ==========================================================================
   KENKEN V4 — BASE & COMPOSANTS COMMUNS
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  box-shadow: none !important;
  text-shadow: none !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  filter: none !important;
}

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  font-size: 1.125rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink); font-weight: 600; line-height: 1.2; letter-spacing: -.005em; }
h1 { font-size: clamp(1.9rem, 3.4vw, 2.7rem); }
h2 { font-size: clamp(1.45rem, 2.4vw, 1.95rem); }
h3 { font-size: 1.3rem; }
h4 { font-size: 1.1rem; }
p { max-width: 62ch; }
a { color: var(--act-text); font-weight: 700; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 4px; }
em, .ex { font-style: italic; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
img, svg { display: block; max-width: 100%; }
ul, ol { list-style: none; }
table { border-collapse: separate; border-spacing: 0; }

[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hide { display: none !important; }
.skip { position: fixed; top: -80px; left: 16px; z-index: 9999; background: var(--act); color: var(--act-ink); padding: 10px 20px; border-radius: var(--r-pill); }
.skip:focus { top: 16px; }

/* ---------- Focus : contour indigo épais toujours visible ---------- */
:focus { outline: none; }
:focus-visible,
[data-tv='1'] :focus,
.nav-focus {
  outline: 4px solid var(--act) !important;
  outline-offset: 3px !important;
}
[data-tv='1'] :focus { outline-width: 6px !important; outline-offset: 4px !important; }

/* ---------- Boutons : coins arrondis sobres ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; padding: 0 22px;
  border: 1.5px solid transparent;
  border-radius: var(--r-btn);
  font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; line-height: 1; letter-spacing: .005em;
  background: var(--act); color: var(--act-ink);
  text-decoration: none; white-space: nowrap; user-select: none;
  transition: transform var(--dur) var(--ease), background-color 120ms ease, border-color 120ms ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(0) !important; background: var(--act-press); }
.btn-soft { background: var(--act-soft); color: var(--act-text); }
.btn-soft:active { background: var(--act-soft); filter: none; }
.btn-line { background: var(--paper); color: var(--ink); border-color: var(--line-strong); }
.btn-line svg { color: var(--act-text); }
.btn-ok { background: var(--ok-strong); color: var(--ok-bg); }
.btn-lg { min-height: 56px; padding: 0 30px; font-size: 1.15rem; border-radius: 14px; }
.btn-sm { min-height: 40px; padding: 0 16px; font-size: .95rem; border-radius: 10px; gap: 8px; }
.btn-sm svg { width: 1.1em; height: 1.1em; }
.btn[disabled], .btn[aria-disabled='true'] { background: var(--sunk); color: var(--muted); border-color: var(--line); cursor: not-allowed; transform: none !important; }
.btn svg { width: 1.25em; height: 1.25em; }
[data-tv='1'] .btn { min-height: 64px; padding: 0 36px; }
[data-tv='1'] .btn-lg { min-height: 80px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: var(--r-m);
  background: transparent; color: var(--text); border: 1px solid transparent;
  transition: transform var(--dur) var(--ease), background-color 120ms ease;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn[aria-pressed='true'], .icon-btn.on { background: var(--act); color: var(--act-ink); }
[data-tv='1'] .icon-btn { width: 64px; height: 64px; }

@media (hover: hover) {
  .btn:not([disabled]):hover, .icon-btn:hover, .chip:hover, .tile:hover, .card-link:hover, .lift:hover { transform: translateY(var(--lift)); }
  .btn-primary:hover, .btn:not(.btn-soft):not(.btn-line):not([disabled]):hover { background: var(--act-hover); }
  .btn-soft:hover { background: var(--act-soft); border-color: var(--act); }
  .btn-line:hover { border-color: var(--act); }
  .icon-btn:hover { background: var(--sunk); color: var(--act-text); transform: none; }
}

/* ---------- Pastilles d'icône ---------- */
.iconpill {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--u-bg, var(--act-soft)); color: var(--u-strong, var(--act-text));
}
.iconpill svg { width: 24px; height: 24px; }
.iconpill.lg { width: 56px; height: 56px; }
.iconpill.lg svg { width: 30px; height: 30px; }
.iconpill.sm { width: 32px; height: 32px; }
.iconpill.sm svg { width: 18px; height: 18px; }

/* ---------- Pilules statiques & filtres ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 12px; border-radius: var(--r-pill);
  font-weight: 800; font-size: .84rem; line-height: 1.4;
  background: var(--u-bg, var(--sunk)); color: var(--u-strong, var(--text));
  white-space: nowrap;
}
.pill svg { width: 16px; height: 16px; }
.pill-act { background: var(--act-soft); color: var(--act-text); }
.pill-yellow { background: var(--yellow-bg); color: var(--yellow-strong); }
.pill-hero { background: var(--hero-chip); color: var(--hero-ink); }
.pill-ok { background: var(--ok-bg); color: var(--ok-strong); }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  background: var(--paper); color: var(--ink);
  font-weight: 700; font-size: .97rem; white-space: nowrap;
  transition: transform var(--dur) var(--ease), background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.chip svg { width: 18px; height: 18px; color: var(--u-strong, var(--act-text)); }
.chip[aria-pressed='true'] svg { color: currentColor; }
@media (hover: hover) { .chip:hover { border-color: var(--act); } }
.chip small { font-weight: 800; font-size: .8rem; opacity: .85; }
.chip[aria-pressed='true'] { background: var(--act); color: var(--act-ink); border-color: var(--act); }
.chip.is-empty { opacity: .5; }
[data-tv='1'] .chip { min-height: 60px; padding: 0 28px; }

/* ---------- Cartes & zones ---------- */
.card { background: var(--paper); border: var(--line-w) solid var(--line); border-radius: var(--r-l); padding: var(--s3); }
.panel { background: var(--sunk); border-radius: var(--r-l); padding: var(--s3); }
.band-yellow { background: var(--yellow-bg); color: var(--yellow-strong); border-radius: var(--r-l); }

/* ---------- Champs ---------- */
.field {
  width: 100%; min-height: 52px; padding: 0 20px;
  border: 1.5px solid var(--line-strong); border-radius: var(--r-m);
  background: var(--paper); color: var(--ink); font-weight: 700; font-size: 1.05rem;
  transition: border-color 120ms ease;
}
.field::placeholder { color: var(--muted); font-weight: 600; }
/* Champ actif : contour adouci et halo très léger (le gros contour indigo reste réservé aux boutons et au mode TV) */
.field:focus { border-color: var(--act-line); background-color: var(--paper); outline: none; }
:root:not([data-tv='1']) .field:focus-visible { outline: 3px solid var(--act-ring) !important; outline-offset: 0 !important; }
textarea.field { border-radius: var(--r-m); padding: 16px 24px; min-height: 120px; resize: vertical; }
select.field { appearance: none; padding-right: 48px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23586380' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6.4 9.4 5.6 5.6 5.6-5.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 18px center; }
[data-theme='dark'] select.field { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%239ba5cc' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6.4 9.4 5.6 5.6 5.6-5.6'/%3E%3C/svg%3E"); }
.label { display: block; font-weight: 800; color: var(--ink); margin: 0 0 6px 12px; font-size: .95rem; }

/* ---------- Interrupteur & segmenté ---------- */
.switch {
  position: relative; width: 64px; height: 36px; flex: none;
  border-radius: var(--r-pill); background: var(--line-strong);
  transition: background-color 120ms ease;
}
.switch::after {
  content: ''; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px;
  border-radius: 50%; background: var(--paper);
  transition: transform var(--dur) var(--ease);
}
.switch[aria-checked='true'] { background: var(--act); }
.switch[aria-checked='true']::after { transform: translateX(28px); }

.seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--sunk); border-radius: var(--r-pill); }
.seg button {
  min-height: 42px; padding: 0 18px; border-radius: var(--r-pill);
  font-weight: 800; font-size: .95rem; color: var(--text);
  display: inline-flex; align-items: center; gap: 8px;
  transition: background-color 120ms ease;
}
.seg button svg { width: 18px; height: 18px; }
.seg button[aria-pressed='true'] { background: var(--act); color: var(--act-ink); }
.seg button[disabled] { color: var(--muted); cursor: not-allowed; }
[data-tv='1'] .seg button { min-height: 56px; padding: 0 26px; }

/* ---------- Jauges & étoiles ---------- */
.meter { height: 12px; border-radius: var(--r-pill); background: var(--sunk); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: var(--r-pill); background: var(--act); transition: width 400ms var(--ease); }
.meter.ok > i { background: var(--ok-strong); }
.meter.u > i { background: var(--u-strong); }
.meter.thin { height: 8px; }

.stars { display: inline-flex; gap: 2px; }
.stars svg { width: 22px; height: 22px; color: var(--gold); }
.stars .off { color: var(--line-strong); }
.star-fill { fill: currentColor; stroke: var(--gold-deep); stroke-width: 1.6; stroke-linejoin: round; }

/* ---------- Bandeaux & toasts ---------- */
.notice { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-radius: var(--r-l); font-weight: 700; }
.notice-ok { background: var(--ok-bg); color: var(--ok-strong); border: var(--line-w) solid var(--ok-line); }
.notice-rev { background: var(--rev-bg); color: var(--rev-strong); border: var(--line-w) solid var(--rev-line); }
.notice-hint { background: var(--yellow-bg); color: var(--yellow-strong); border: var(--line-w) solid var(--yellow-line); }
.notice-act { background: var(--act-soft); color: var(--act-text); }

#layer-toast { position: fixed; left: 0; right: 0; bottom: 96px; z-index: 9000; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--ink); color: var(--bg); padding: 12px 24px; border-radius: var(--r-pill);
  font-weight: 800; animation: pop 240ms var(--ease) both; max-width: 90vw;
}
[data-theme='dark'] .toast { background: var(--ink); color: var(--paper); }
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity 200ms, transform 200ms; }

/* ---------- Fenêtres intégrées (jamais de boîtes natives) ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 8000;
  background: var(--scrim);
  display: flex; align-items: center; justify-content: center; padding: var(--s2);
  animation: fade 160ms ease both;
}
.modal {
  width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--paper); border-radius: var(--r-xl); padding: var(--s4);
  border: var(--line-w) solid var(--line);
  animation: pop 240ms var(--ease) both;
}
.modal.wide { width: min(980px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); }
.modal-actions { display: flex; flex-wrap: wrap; gap: var(--s1); justify-content: flex-end; margin-top: var(--s3); }
.modal.sheet-from-bottom { align-self: flex-end; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

/* ---------- Clavier et pavé à l'écran ---------- */
.osk { display: grid; gap: 8px; width: 100%; }
.osk-row { display: flex; gap: 8px; justify-content: center; }
.osk .key {
  flex: 1 1 0; max-width: 84px; min-height: 60px; padding: 0 6px;
  border-radius: var(--r-m); background: var(--sunk); color: var(--ink);
  font-family: var(--font-display); font-weight: 600; font-size: 1.35rem;
  display: inline-flex; align-items: center; justify-content: center;
  border: var(--line-w) solid transparent;
  transition: transform var(--dur) var(--ease), background-color 120ms ease;
}
.osk .key:active { background: var(--act-soft); }
.osk .key.wide { flex: 2 1 0; max-width: 170px; }
.osk .key.act { background: var(--act); color: var(--act-ink); }
.osk .key svg { width: 26px; height: 26px; }
.osk.pad { grid-template-columns: repeat(3, 1fr); max-width: 380px; margin: 0 auto; }
.osk.pad .key { max-width: none; min-height: 72px; font-size: 1.7rem; }
[data-tv='1'] .osk .key { min-height: 76px; font-size: 1.6rem; }
[data-tv='1'] .osk.pad .key { min-height: 92px; }

/* ---------- Tables aérées à lignes arrondies ---------- */
.rows { width: 100%; border-spacing: 0 8px; }
.rows th { text-align: left; padding: 4px 16px; font-size: .9rem; color: var(--muted); font-weight: 800; }
.rows td { padding: 12px 16px; background: var(--sunk); vertical-align: middle; }
.rows td:first-child { border-radius: var(--r-m) 0 0 var(--r-m); }
.rows td:last-child { border-radius: 0 var(--r-m) var(--r-m) 0; }

/* ---------- Utilitaires de mise en page ---------- */
.row { display: flex; align-items: center; gap: var(--s2); }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.row.center { justify-content: center; }
.stack { display: flex; flex-direction: column; gap: var(--s2); }
.stack-s { display: flex; flex-direction: column; gap: var(--s1); }
.grow { flex: 1 1 auto; min-width: 0; }
.center { text-align: center; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.muted { color: var(--muted); }
.ink { color: var(--ink); }
.b { font-weight: 800; }

/* ---------- Animations brèves, douces, jamais clignotantes ---------- */
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes burst {
  0% { opacity: 0; transform: translate(0, 0) scale(.3); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(var(--rot)); }
}
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

.burst { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.burst svg { position: absolute; left: 50%; top: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px; color: var(--gold); animation: burst 900ms var(--ease) both; }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: var(--r-pill); border: 3px solid transparent; background-clip: content-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
[data-motion='reduce'] *, [data-motion='reduce'] *::before, [data-motion='reduce'] *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }


/* ---------- Tuiles de reponse : gris ultra-clair, contour discret, contour indigo net a la selection ---------- */
.tile {
  display: flex; align-items: center; gap: 14px; min-height: 76px; padding: 14px 24px; width: 100%;
  border-radius: var(--r-l); background: var(--sunk); border: 3px solid var(--line); color: var(--ink);
  font-weight: 800; font-size: 1.15rem; text-align: left;
  transition: transform var(--dur) var(--ease), border-color 120ms ease, background-color 120ms ease;
}
.tile:hover:not([disabled]) { border-color: var(--act); }
.tile[aria-checked='true'], .tile.is-selected { border-color: var(--act); background: var(--act-soft); }
.tile.is-right { border-color: var(--ok-line); background: var(--ok-bg); color: var(--ok-strong); }
.tile.is-review { border-color: var(--rev-line); background: var(--rev-bg); color: var(--rev-strong); }
.tile[disabled] { cursor: default; }
.tile-key { flex: none; width: 42px; height: 42px; border-radius: 50%; background: var(--paper); color: var(--act-text); display: inline-flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; border: 2px solid var(--line); }
.tile[aria-checked='true'] .tile-key { background: var(--act); color: var(--act-ink); border-color: var(--act); }
.tile-text { flex: 1; min-width: 0; }
[data-tv='1'] .tile { min-height: 96px; font-size: 1.3rem; }
.pill-white { background: var(--paper); color: var(--u-strong, var(--text)); }
.pill-lvl { background: var(--sunk); color: var(--text); }
