/* Thème clair par défaut, thème sombre automatique ou forcé (data-theme). */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #667085;
  --border: #d9d6cc;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --board-bg: #ece8dc;
  --board: #e9c46a;
  --grid: rgba(80, 60, 20, 0.35);
  --grid-strong: rgba(80, 60, 20, 0.7);
  --line-black: #d9480f;
  --line-white: #1971c2;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #14161a;
    --surface: #1d2025;
    --text: #e6e6e6;
    --muted: #9aa3b2;
    --border: #343a42;
    --accent: #ff8a4c;
    --accent-text: #14161a;
    --danger: #ff6b6b;
    --ok: #69db7c;
    --board-bg: #101215;
    --board: #b58d3a;
    --grid: rgba(0, 0, 0, 0.45);
    --grid-strong: rgba(0, 0, 0, 0.8);
    --line-black: #ff8a4c;
    --line-white: #74c0fc;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #14161a;
  --surface: #1d2025;
  --text: #e6e6e6;
  --muted: #9aa3b2;
  --border: #343a42;
  --accent: #ff8a4c;
  --accent-text: #14161a;
  --danger: #ff6b6b;
  --ok: #69db7c;
  --board-bg: #101215;
  --board: #b58d3a;
  --grid: rgba(0, 0, 0, 0.45);
  --grid-strong: rgba(0, 0, 0, 0.8);
  --line-black: #ff8a4c;
  --line-white: #74c0fc;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
h3 { font-size: 1rem; margin: .75rem 0 .25rem; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }

/* En-tête */
.nav {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .5rem max(16px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.nav a { text-decoration: none; }
.nav .brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.nav .links { display: flex; gap: .25rem; flex: 1; }
.nav .links a { color: var(--text); padding: .5rem .6rem; border-radius: 8px; min-height: 44px; display: inline-flex; align-items: center; }
.nav .links a.current { background: var(--bg); font-weight: 600; }
.nav .right { display: flex; align-items: center; gap: .5rem; }
.nav .user { font-weight: 600; }

/* Boutons et champs */
.btn, .icon-btn, button.link {
  font: inherit; cursor: pointer; border-radius: 8px; text-decoration: none;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .4rem 1rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.icon { min-width: 44px; padding: .4rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  min-width: 44px; min-height: 44px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 1.1rem;
}
button.link { background: none; border: 0; color: var(--accent); padding: .5rem; min-height: 44px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input[type='text'], input[type='password'], input[type='number'], input[type='email'], input[type='search'], select {
  font: inherit; min-height: 44px; padding: .4rem .6rem; width: 100%;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
}
.form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field .label { font-size: .9rem; color: var(--muted); }
.radios { display: flex; gap: .5rem; flex-wrap: wrap; }
.radio, .check { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; padding: 0 .75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.check { border: 0; padding: 0; background: none; }
details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
details .field { margin-top: .75rem; }

/* Pages */
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page { padding: 1rem max(16px, env(safe-area-inset-left)); width: 100%; max-width: 920px; margin: 0 auto; }
.page.narrow { max-width: 520px; }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 60ch; }
.cta { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0; }

.game-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.game-row a {
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .75rem; justify-content: space-between;
  padding: .75rem 1rem; text-decoration: none; color: var(--text); min-height: 44px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.game-row a:hover { border-color: var(--accent); }
.game-row.mine a { border-left: 4px solid var(--accent); }
.row-main { flex: 1 1 60%; }
.row-sub { color: var(--muted); font-size: .9rem; flex-basis: 100%; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0 .6rem; font-size: .85rem; font-weight: 600; }
.table-wrap { overflow-x: auto; }
table.stats { border-collapse: collapse; width: 100%; background: var(--surface); }
table.stats th, table.stats td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); text-align: right; }
table.stats th:first-child, table.stats thead th { text-align: left; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.row label { display: flex; align-items: center; gap: .5rem; }
.row input, .row select { width: auto; }

/* Partie : barre d'état, plateau, panneau. */
.game { flex: 1; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.game-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: center;
  padding: .5rem max(12px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--border);
}
.chip { display: flex; align-items: center; gap: .5rem; padding: .25rem .5rem; border-radius: var(--radius); border: 2px solid transparent; min-width: 0; }
.chip:last-child { flex-direction: row-reverse; text-align: right; }
.chip.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.chip .who { display: flex; align-items: center; gap: .35rem; min-width: 0; }
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chip .score { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stone { width: 26px; height: 26px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; line-height: 1; border: 2px solid #495057; }
.stone.black { background: #15171a; color: #f8f9fa; border-color: #000; }
.stone.white { background: #f8f9fa; color: #212529; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--border); }
.center { text-align: center; font-size: .9rem; display: flex; flex-direction: column; align-items: center; }
.info.mine { color: var(--accent); font-weight: 700; }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; }
.clock.urgent { color: var(--danger); }

.board-wrap { position: relative; min-height: 240px; overflow: hidden; background: var(--board-bg); }
canvas.board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
canvas.board:focus-visible { outline-offset: -3px; }
canvas.minimap {
  position: absolute; left: 8px; bottom: 8px; width: 140px; height: 110px;
  background: color-mix(in srgb, var(--surface) 85%, transparent); border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.minimap.empty { display: none; }
.board-tools { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; }
.coords { position: absolute; right: 8px; bottom: 8px; padding: 2px 8px; border-radius: 6px; font-size: .85rem; background: color-mix(in srgb, var(--surface) 85%, transparent); }
.coords:empty { display: none; }
.confirm {
  position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: .5rem .75rem; background: var(--surface); border: 2px solid var(--accent); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}
.confirm-btns { display: flex; gap: .5rem; }

.panel { background: var(--surface); border-top: 1px solid var(--border); padding: 0 max(12px, env(safe-area-inset-left)); max-height: 42vh; overflow: auto; }
.panel > summary { font-weight: 600; }
.banner { padding: .5rem .75rem; margin-bottom: .5rem; border-radius: 8px; background: color-mix(in srgb, var(--accent) 15%, transparent); font-weight: 600; }
.actions, .replay { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .75rem; }
.replay-n { min-width: 4.5rem; text-align: center; font-variant-numeric: tabular-nums; }
.copy-row { display: flex; gap: .5rem; }
.chat { margin-bottom: .75rem; }
.chat-log { height: 7rem; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: .25rem .5rem; background: var(--bg); }
.chat-log p { margin: .15rem 0; overflow-wrap: anywhere; }
.chat-form { display: flex; gap: .5rem; margin-top: .5rem; }

/* Réglages et messages */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(440px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog .field, dialog .check { margin-bottom: .75rem; }
#toasts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 20; width: min(92vw, 420px); }
.toast { padding: .6rem .9rem; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: 0 4px 16px rgba(0, 0, 0, .3); }
.toast.error { background: var(--danger); color: #fff; }

/* Administration */
.page.admin { max-width: 1100px; }
.admin-tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.admin-tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--text); border-radius: 8px 8px 0 0; min-height: 44px; display: inline-flex; align-items: center; }
.admin-tabs a.current { background: var(--surface); border: 1px solid var(--border); border-bottom-color: var(--surface); margin-bottom: -1px; font-weight: 600; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { display: flex; flex-direction: column; gap: .15rem; padding: .75rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.stat strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .9rem; }
a.stat:hover { border-color: var(--accent); }
.report { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin: .75rem 0; }
.report blockquote { margin: .5rem 0; padding: .4rem .75rem; border-left: 3px solid var(--accent); background: var(--bg); overflow-wrap: anywhere; }
.report-form { margin-top: .5rem; }
.report-form input[type='text'] { flex: 1 1 14rem; width: auto; }
.report-form select { width: auto; }
label.inline { display: inline-flex; align-items: center; gap: .35rem; }
.error { color: var(--danger); }
.chat-report { background: none; border: 0; color: var(--muted); cursor: pointer; min-width: 32px; min-height: 28px; font-size: 1rem; }
.chat-report:hover { color: var(--danger); }
@media (min-width: 900px) {
  /* Ordinateur : le panneau passe à droite du plateau. */
  .game { grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto minmax(0, 1fr); }
  .game-bar { grid-column: 1 / -1; }
  .panel { border-top: 0; border-left: 1px solid var(--border); max-height: none; padding: 0 16px; }
  .panel > summary { pointer-events: none; list-style: none; }
  .panel > summary::-webkit-details-marker { display: none; }
}

@media (max-width: 560px) {
  .chip .score { font-size: 1.15rem; }
  .stone { width: 22px; height: 22px; }
  canvas.minimap { width: 100px; height: 80px; }
  .nav { gap: .25rem; }
  .nav .right { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

@media (max-width: 560px) {
  .nav .links { order: 3; flex-basis: 100%; justify-content: space-between; }
  .game-bar { grid-template-columns: 1fr 1fr; row-gap: 0; }
  .game-bar .center { grid-column: 1 / -1; grid-row: 2; flex-direction: row; gap: .75rem; justify-content: center; }
}

/* Mode intégré au chat : barre de navigation compacte, sans marque ni compte. */
.embed .nav { padding-top: .25rem; padding-bottom: .25rem; gap: .5rem; }
.embed .nav .links { flex: 1; }

/* Réglages : installation, notifications et e-mail */
.app-section { display: flex; flex-direction: column; gap: .75rem; margin-bottom: .75rem; }
.email-block { display: flex; flex-direction: column; gap: .5rem; padding: .75rem; border: 1px solid var(--border); border-radius: var(--radius); }
