/* SKYJO — thème "table de jeu" : nuit ardoise, cartes franches et colorées.
   Bandes officielles : négatif = marine, 0 = ciel, 1-4 = vert, 5-8 = jaune, 9-12 = rouge. */

:root {
  --bg: #12161f;
  --bg2: #191f2c;
  --panel: #1f2736;
  --line: #2e3a52;
  --ink: #eef1f6;
  --dim: #8b95a9;
  --accent: #38bdf8;
  --shadow: rgba(0, 0, 0, .45);
  --navy: #1e3a8a;
  --sky: #7dd3fc;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #dc2626;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body {
  background: radial-gradient(1200px 700px at 50% -10%, #1c2434 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.4;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}

.hidden { display: none !important; }

.screen {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  max-width: 620px; margin: 0 auto;
}

/* ---------- boutons ---------- */
.big-btn {
  display: block; width: 100%;
  padding: 15px 14px;
  font: 700 1rem var(--sans); letter-spacing: .06em;
  color: #08131c;
  background: var(--accent);
  border: 0; border-radius: 14px;
  box-shadow: 0 4px 14px var(--shadow);
  cursor: pointer;
  text-transform: uppercase;
}
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 6px var(--shadow); }
.big-btn:disabled { background: #33404f; color: #67707e; box-shadow: none; }
.big-btn.keep { background: var(--green); }
.big-btn.drop { background: #f87171; }
.big-btn.ghost-btn { background: transparent; color: var(--dim); box-shadow: none; border: 2px solid var(--line); }
.mid-btn {
  padding: 10px 14px; font: 600 .85rem var(--sans);
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--ink); cursor: pointer;
}
.mid-btn:active { transform: translateY(1px); }
.mid-btn.ghost { background: transparent; color: var(--dim); border-color: transparent; }
.mini-btn {
  padding: 4px 10px; font: 600 .75rem var(--sans);
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--dim); cursor: pointer; margin-left: 8px;
}

/* ---------- accueil ---------- */
#screen-home { justify-content: center; }
.home-box { text-align: center; }
.logo { font-size: 3.2rem; font-weight: 900; letter-spacing: .04em; margin-bottom: 2px; }
.logo span { display: inline-block; padding: 2px 6px; border-radius: 10px; margin: 0 1px; color: #08131c; }
.l-s { background: var(--navy); color: #fff; transform: rotate(-4deg); }
.l-k { background: var(--sky); transform: rotate(3deg); }
.l-y { background: var(--green); transform: rotate(-2deg); }
.l-j { background: var(--yellow); transform: rotate(4deg); }
.l-o { background: var(--red); color: #fff; transform: rotate(-3deg); }
.tagline { color: var(--dim); margin: 12px 0 28px; }
#joinForm input {
  display: block; width: 100%; margin-bottom: 12px;
  padding: 13px 16px; font: 1.05rem var(--sans);
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--line); border-radius: 12px; outline: none;
}
#joinForm input:focus { border-color: var(--accent); }
#joinForm input::placeholder { color: var(--dim); }
.hint { color: var(--dim); font-size: .9rem; margin-top: 14px; }
.error { color: #ff9c9c; font-size: .95rem; margin-top: 12px; }
.rules-btn { margin: 18px auto 0; display: block; }

/* ---------- lobby ---------- */
.room-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.room-label { font-size: .7rem; letter-spacing: .2em; color: var(--dim); }
.room-code { font-size: 1.6rem; font-weight: 800; color: var(--accent); }

.player-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px;
}
.player-list .dot { width: 9px; height: 9px; border-radius: 50%; background: #45d06c; flex: none; }
.player-list .off .dot { background: #666; }
.player-list .off { opacity: .55; }
.player-list .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list .tag { font-size: .8rem; color: var(--dim); }
.bot-x {
  border: 1px solid var(--line); background: transparent; color: var(--dim);
  border-radius: 8px; width: 30px; height: 30px; cursor: pointer; flex: none;
}
#addBotBtn { margin-top: 10px; align-self: flex-start; }
.lobby-foot { margin-top: auto; padding-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.lobby-foot .hint { text-align: center; margin: 0; }
.lobby-foot .rules-btn { margin: 0 auto; }

/* ---------- partie : entête ---------- */
.game-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.round-info { font-size: 1.05rem; }
.round-info .dim { color: var(--dim); font-size: .85rem; }
.score-chip { padding: 8px 12px; }

/* ---------- grilles / cartes ---------- */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); }
.cell {
  aspect-ratio: 3 / 4;
  display: flex; align-items: center; justify-content: center;
  border-radius: 16%/12%;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 2px 4px var(--shadow);
}
.cell.navy { background: var(--navy); }
.cell.sky { background: var(--sky); color: #0b2536; }
.cell.green { background: var(--green); color: #06240f; }
.cell.yellow { background: var(--yellow); color: #2b2103; }
.cell.red { background: var(--red); }
.cell.back {
  background:
    repeating-linear-gradient(135deg, #26324a 0 6px, #202a3f 6px 12px);
  border: 1px solid var(--line);
}
.cell.gone { background: transparent; border: 1px dashed #2a3348; box-shadow: none; }
.cell.empty { background: transparent; border: 1px dashed var(--line); box-shadow: none; }

.big-grid { gap: 7px; max-width: 340px; margin: 0 auto; width: 100%; }
.big-grid .cell { font-size: 1.5rem; }
.big-grid .cell.pick { outline: 3px solid var(--accent); outline-offset: 1px; cursor: pointer; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { outline-color: rgba(56, 189, 248, .35); } }

.mini-grid { gap: 3px; width: 104px; }
.mini-grid .cell { font-size: .72rem; border-radius: 22%/16%; }

/* ---------- adversaires ---------- */
.opponents {
  display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 8px;
  scrollbar-width: none;
}
.opponents::-webkit-scrollbar { display: none; }
.opp {
  flex: none; background: var(--panel); border: 2px solid var(--line);
  border-radius: 14px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.opp.turn { border-color: var(--accent); box-shadow: 0 0 12px rgba(56, 189, 248, .25); }
.opp.off { opacity: .5; }
.opp-head { display: flex; justify-content: space-between; align-items: baseline; width: 100%; gap: 8px; }
.oname { font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.osum { font-size: .85rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.obadge { font-size: .68rem; padding: 2px 8px; border-radius: 999px; background: var(--bg2); color: var(--dim); }
.obadge.end { background: #3b2b10; color: var(--yellow); }
.obadge.last { background: #33121a; color: #fda4af; }

/* ---------- piles centrales ---------- */
.table-mid {
  display: flex; justify-content: center; align-items: flex-start; gap: 22px;
  padding: 10px 0 6px;
}
.pile { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pile .cell.big { width: 64px; font-size: 1.5rem; }
.pile-lbl { font-size: .68rem; letter-spacing: .12em; color: var(--dim); }
.pile.clickable .cell { cursor: pointer; outline: 3px solid var(--accent); outline-offset: 1px; animation: pulse 1.2s ease-in-out infinite; }
.pile.armed .cell { outline: 3px solid var(--yellow); animation: none; }

/* ---------- barre d'action + ma grille ---------- */
.action-bar { min-height: 62px; display: flex; flex-direction: column; justify-content: center; padding: 4px 0; }
.bar-msg { text-align: center; color: var(--dim); }
.bar-title { text-align: center; font-size: 1.05rem; }
.btn-row { display: flex; gap: 12px; max-width: 380px; margin: 0 auto; width: 100%; }
.btn-row .big-btn { flex: 1; }

.my-area { margin-top: auto; padding-top: 8px; }
.my-head {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  max-width: 340px; margin: 0 auto 8px; width: 100%;
}
.my-head .osum { font-size: 1.05rem; color: var(--ink); font-weight: 700; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(6, 9, 15, .92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 22px; gap: 14px;
}
.overlay .big-btn { max-width: 380px; }

.rules-overlay { justify-content: flex-start; overflow: hidden; }
.rules-box {
  width: min(92vw, 500px); flex: 1; min-height: 0; overflow-y: auto;
  background: var(--panel); border: 2px solid var(--line); border-radius: 16px;
  padding: 22px 20px; text-align: left; -webkit-user-select: text; user-select: text;
  margin-top: max(6px, env(safe-area-inset-top));
}
.rules-box h2 { text-align: center; margin-bottom: 14px; font-size: 1.25rem; }
.rules-box h3 { color: var(--accent); font-size: .95rem; margin: 18px 0 6px; }
.rules-box p, .rules-box li { font-size: .95rem; color: var(--ink); }
.rules-box p { margin-bottom: 8px; }
.rules-box ol, .rules-box ul { padding-left: 20px; margin-bottom: 8px; }
.rules-box li { margin-bottom: 6px; }
.rules-box i { color: var(--dim); font-style: normal; }
.c-navy { color: #93b4ff; }
.c-red { color: #fda4af; }

/* ---------- scores ---------- */
.score-box {
  width: min(92vw, 460px); background: var(--panel);
  border: 2px solid var(--line); border-radius: 16px;
  padding: 20px 16px; text-align: center;
  max-height: 70dvh; overflow-y: auto;
}
.score-box h2 { font-size: 1.2rem; margin-bottom: 12px; }
#scoreTableWrap { overflow-x: auto; }
.score-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.score-table td, .score-table th { padding: 7px 8px; border-bottom: 1px solid var(--line); font-size: .92rem; }
.score-table th { color: var(--dim); font-weight: 600; }
.score-table td:first-child { color: var(--dim); text-align: left; }
.score-table .totals td { font-weight: 800; border-bottom: 0; font-size: 1.05rem; }
.score-table .win { color: var(--yellow); }
.x2 { color: #f87171; font-size: .72rem; font-weight: 800; margin-left: 3px; }
.fin { color: var(--yellow); font-size: .6rem; margin-left: 3px; vertical-align: super; }
.score-box .hint { margin-top: 10px; }
