:root {
  --bg: #f4f4f7;
  --card: #ffffff;
  --text: #1d1d22;
  --muted: #6b6b75;
  --line: #e2e2e8;
  --key: #e9e9ef;
  --key-edge: #d4d4dc;
  --key-text: #2c2c33;
  --heat: #ff3b30;
  --accent: #5b5bd6;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --warn: #b35c00;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --card: #1b1b20;
    --text: #f0f0f4;
    --muted: #9b9ba6;
    --line: #2c2c34;
    --key: #2a2a31;
    --key-edge: #1e1e24;
    --key-text: #dcdce3;
    --heat: #ff453a;
    --accent: #8484ff;
    --accent-text: #0e0e14;
    --ok: #4ac26b;
    --warn: #f0a24a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; color: inherit; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: .95rem; margin: 1.2rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

/* ---------- Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.sync { margin-left: auto; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.sync.ok { color: var(--ok); }
.sync.warn { color: var(--warn); }
.account {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 4px 12px; min-height: 34px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.account img { width: 24px; height: 24px; border-radius: 50%; margin-left: -8px; }

main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 24px; }

/* ---------- Generic */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 8px 14px; min-height: 40px; cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--heat); }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 4px 0; min-height: 0; }
.icon {
  border: 0; background: none; cursor: pointer; font-size: 1.1rem; width: 36px; height: 36px;
  border-radius: 8px; color: var(--muted);
}
.icon:hover { background: var(--key); }

.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--accent) 12%, var(--card));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
}
.banner p { margin: 0; flex: 1 1 220px; }
.banner.warn {
  background: color-mix(in srgb, var(--warn) 12%, var(--card));
  border-color: color-mix(in srgb, var(--warn) 40%, var(--line));
}
.banner code { font-size: .85em; }

/* ---------- Keyboard selector */
.kb-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.kb-bar select {
  flex: 1; min-width: 0; min-height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); padding: 0 10px; font-weight: 600;
}

/* ---------- Board */
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.seg { display: inline-flex; background: var(--key); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: none; padding: 5px 12px; border-radius: 8px; cursor: pointer; font-size: .85rem;
}
.seg button.on { background: var(--card); box-shadow: 0 1px 2px rgb(0 0 0 / .15); font-weight: 600; }
.kb-wrap { overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.kb { position: relative; margin: 0 auto; }
.key {
  position: absolute;
  border: 0; border-radius: 6px; padding: 0;
  background: color-mix(in oklab, var(--heat) calc(var(--p, 0) * 100%), var(--key));
  box-shadow: inset 0 -3px 0 var(--key-edge);
  color: var(--key-text);
  cursor: pointer; touch-action: manipulation;
  display: flex; align-items: center; justify-content: center;
  line-height: 1.05; text-align: center; white-space: pre-line;
  transition: background .2s;
}
.key.hot { color: #fff; box-shadow: inset 0 -3px 0 rgb(0 0 0 / .2); }
.key.iso {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 18% 100%, 18% calc(50% - 2px), 0 calc(50% - 2px));
  border-radius: 6px;
}
.key.iso .lbl { padding-left: 18%; }
.key .lbl.long { font-size: .78em; }
.key .cnt {
  position: absolute; top: 2px; right: 3px; font-size: .62em; font-weight: 700; opacity: .9;
}
.key:hover { filter: brightness(1.06); }
.key.sel { outline: 3px solid var(--accent); outline-offset: 1px; z-index: 1; animation: pulse 1s infinite alternate; }
.key.flash { animation: flash .6s; }
@keyframes pulse { to { outline-color: transparent; } }
@keyframes flash { 30% { transform: scale(1.12); } }
.hint { margin: 10px 0 0; font-size: .85rem; color: var(--muted); }
.legend { display: flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--muted); }
.legend i {
  width: 70px; height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, var(--key), color-mix(in oklab, var(--heat) 25%, var(--key)), var(--heat));
}

/* ---------- Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--muted); }
.grid2 { display: grid; gap: 12px; }
@media (min-width: 820px) { .grid2 { grid-template-columns: 1fr 1fr; align-items: start; } }

.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.rank li:first-child { border-top: 0; }
.rank .bar { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: var(--key); overflow: hidden; }
.rank .bar i { display: block; height: 100%; background: var(--heat); border-radius: 3px; }
.rank .n { font-weight: 700; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; margin: 4px 0 12px; }
th, td { text-align: left; padding: 5px 4px; border-top: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: .78rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 999px; background: var(--key); margin-left: 6px; vertical-align: 1px; }
.tag.red { background: color-mix(in srgb, var(--heat) 18%, var(--card)); color: var(--heat); }
.tag.blue { background: color-mix(in srgb, var(--accent) 18%, var(--card)); color: var(--accent); }
.explain { font-size: .85rem; color: var(--muted); margin: 0 0 10px; }

.events { list-style: none; margin: 0; padding: 0; }
.events li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.events li:first-child { border-top: 0; }
.events .ico { width: 22px; text-align: center; }
.events .txt { flex: 1; min-width: 0; }
.events time { display: block; font-size: .75rem; color: var(--muted); }
.events .icon { width: 30px; height: 30px; font-size: .9rem; }

.empty { text-align: center; padding: 40px 16px; }
.empty .big-ico { font-size: 3rem; }

/* ---------- Dialogs (bottom sheet sur mobile) */
dialog.sheet {
  border: 0; padding: 0; color: var(--text); background: var(--card);
  width: 100%; max-width: 560px; max-height: 88vh;
  margin: auto auto 0; border-radius: 18px 18px 0 0;
}
dialog.sheet::backdrop { background: rgb(0 0 0 / .45); }
dialog.sheet[open] { animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 18px; } }
.sheet-body { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-head > div { flex: 1; min-width: 0; }
.sheet-head p { margin: 2px 0 0; }
.keycap {
  min-width: 52px; height: 52px; padding: 0 8px; border-radius: 10px; background: var(--key);
  box-shadow: inset 0 -3px 0 var(--key-edge); display: grid; place-items: center;
  font-weight: 700; white-space: pre-line; line-height: 1; text-align: center;
}
.mini { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mini div { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.mini b { font-size: 1.3rem; display: block; }
.mini span { font-size: .78rem; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label input, label select {
  min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px;
  background: var(--bg); color: var(--text); font-size: 1rem;
}

/* ---------- Swap bar & toast */
.swap-bar, .toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(560px, calc(100% - 32px));
  display: flex; align-items: center; gap: 10px;
  border-radius: 14px; padding: 10px 12px 10px 16px;
  box-shadow: 0 8px 30px rgb(0 0 0 / .25);
}
.swap-bar { background: var(--accent); color: var(--accent-text); }
.swap-bar span { flex: 1; }
.swap-bar button { background: rgb(255 255 255 / .2); border: 0; color: inherit; border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.toast { background: var(--text); color: var(--bg); bottom: calc(80px + env(safe-area-inset-bottom)); }
.toast span { flex: 1; }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; padding: 6px 8px; }
@media (prefers-color-scheme: dark) { .toast button { color: #4b4bc8; } }
[hidden] { display: none !important; }

/* ---------- Pages légales et pied de page */
.legal { max-width: 720px; padding-top: 24px; }
.legal h1 { font-size: 1.6rem; margin: 8px 0 4px; }
.legal h2 { margin: 24px 0 6px; }
.legal a, .footer a { color: var(--accent); }
.footer { text-align: center; font-size: .8rem; color: var(--muted); padding: 0 16px 90px; }
