:root {
  --bg: #12151c;
  --panel: #1c212b;
  --panel-2: #252b37;
  --text: #f2f4f8;
  --muted: #9aa3b2;
  --accent: #3ddc84;
  --danger: #ff5a5f;
  --felt: #0f7a4a;
  --felt-dark: #0b5e39;
  --wood: #6b3f1f;
  --wood-light: #8a5a2f;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Espace pour l'encoche et la barre d'état quand l'appli est installée */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button { font: inherit; cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
}
.topbar h1 { font-size: 1.2rem; margin: 0; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.layout {
  display: grid;
  gap: 16px;
  padding: 0 16px 24px;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas:
    "players players"
    "table controls";
  max-width: 1100px;
  margin: 0 auto;
}

.players { grid-area: players; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.table-wrap { grid-area: table; display: flex; justify-content: center; }
.controls { grid-area: controls; }

.player {
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
  transition: border-color .2s, box-shadow .2s;
}
.player.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(61, 220, 132, .15);
}
.player .name {
  width: 100%;
  background: transparent;
  border: 1px dashed transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  padding: 4px;
}
.player .name:hover, .player .name:focus { border-color: var(--muted); outline: none; }
.player .score { font-size: 2.6rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.player .pending { min-height: 1.2em; color: var(--accent); font-weight: 600; }
.player .turn-badge { visibility: hidden; font-size: .8rem; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.player.active .turn-badge { visibility: visible; }

#table { width: 100%; max-width: 460px; max-height: 86vh; height: auto; }
.hole { cursor: pointer; }
.hole:focus { outline: none; }
.hole .ring { transition: stroke .15s, stroke-width .15s; }
.hole:hover .ring, .hole:focus-visible .ring { stroke: #ffd54a; stroke-width: 5; }
.hole text { pointer-events: none; }

.float-text { font-weight: 800; font-size: 34px; pointer-events: none; animation: floatUp 900ms ease-out forwards; }
@keyframes floatUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-60px); } }
.drop-ball { animation: drop 450ms ease-in forwards; transform-box: fill-box; transform-origin: center; }
@keyframes drop { from { transform: scale(1.4); opacity: 1; } to { transform: scale(.2); opacity: 0; } }

.controls { display: flex; flex-direction: column; gap: 12px; }

.timer {
  background: var(--panel);
  border: 2px solid var(--panel-2);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}
.timer-main { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.timer-label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.timer-display { font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.warning .timer-display { color: #ffd54a; }
.timer.finished { border-color: var(--danger); }
.timer.finished.ringing { animation: pulse 1s ease-in-out infinite; }
.timer.finished .timer-display { color: var(--danger); }
.timer.finished .timer-label { color: var(--danger); font-weight: 700; }
.timer-buttons { display: grid; grid-template-columns: 1fr; gap: 8px; }
.timer-buttons button { padding: 10px; border-radius: var(--radius); border: none; font-weight: 700; }
.timer-extras { display: grid; gap: 4px; }
.timer-note { margin: 0; color: var(--muted); font-size: .82rem; }
.timer-note:empty { display: none; }
.timer-note.ok { color: var(--accent); }
.link-btn {
  background: var(--panel-2); color: var(--text);
  border: 1px dashed var(--muted); border-radius: 10px;
  padding: 8px 10px; font-size: .9rem; font-weight: 600; text-align: left;
}
.timer-alert { margin: 0; color: #ffb3b5; font-weight: 600; font-size: .9rem; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 90, 95, .25); } }

.turn-info { margin: 0; background: var(--panel); padding: 12px 14px; border-radius: var(--radius); }
#turnPoints { color: var(--accent); font-size: 1.3rem; }

.ball-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ball-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 10px;
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--panel-2);
  border-radius: var(--radius);
  font-weight: 600;
}
.ball-btn small { color: var(--muted); }
.ball-btn[aria-checked="true"] { border-color: #ffd54a; background: var(--panel-2); }
.ball { width: 22px; height: 22px; border-radius: 50%; display: inline-block; box-shadow: inset -3px -3px 5px rgba(0,0,0,.35); }
.ball.white { background: #f5f5f0; }
.ball.red { background: #d32f2f; }

.turn-log {
  list-style: none; margin: 0; padding: 8px;
  min-height: 48px;
  display: flex; flex-wrap: wrap; gap: 6px;
  background: var(--panel); border-radius: var(--radius);
}
.turn-log:empty::before { content: "Aucune bille ce tour"; color: var(--muted); padding: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); padding: 4px 10px; border-radius: 999px; font-size: .9rem; }
.chip .ball { width: 14px; height: 14px; }

.actions { display: grid; gap: 8px; }
.actions button { padding: 14px; border-radius: var(--radius); border: none; font-weight: 700; font-size: 1rem; }
.primary { background: var(--accent); color: #062b16; }
.danger { background: var(--danger); color: #fff; }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--panel-2) !important; }
button:disabled { opacity: .45; cursor: not-allowed; }
#newGame, #projector { padding: 8px 12px; border-radius: 10px; }
#newGame.confirming { background: var(--danger); color: #fff; border-color: var(--danger) !important; }
#projector.live { background: var(--accent); color: #062b16; border-color: var(--accent) !important; }

/* Fenêtre « Projecteur » */
.projector-dialog {
  width: min(520px, calc(100vw - 32px));
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-2);
  border-radius: 18px;
  padding: 20px;
}
.projector-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.projector-dialog h2 { margin: 0 0 12px; font-size: 1.2rem; }
.projector-dialog h3 { margin: 16px 0 6px; font-size: 1rem; color: var(--accent); }
.projector-dialog p { margin: 0 0 10px; color: #d5dae3; line-height: 1.45; }
.projector-dialog button { width: 100%; padding: 12px; border-radius: var(--radius); border: none; font-weight: 700; margin-top: 6px; }
.projector-dialog .hint { color: var(--muted); font-size: .9rem; }
.projector-status { background: var(--panel-2); padding: 10px 12px; border-radius: 10px; font-weight: 600; }

.history-title { font-size: .9rem; color: var(--muted); margin: 4px 0 0; text-transform: uppercase; letter-spacing: .05em; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .9rem; max-height: 220px; overflow-y: auto; }
.history li { background: var(--panel); padding: 6px 10px; border-radius: 8px; display: flex; justify-content: space-between; gap: 8px; }
.history .foul { color: var(--danger); }
.history .gain { color: var(--accent); }

@media (max-width: 800px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "players" "table" "controls";
  }
  .player .score { font-size: 2rem; }
  #table { max-height: 70vh; }
}

/* Téléphone à l'horizontale (recopie d'écran / HDMI vers un projecteur 16:9) :
   scores à gauche, billard au centre, boutons à droite, le tout sur un seul écran. */
@media (orientation: landscape) and (max-height: 600px) {
  .topbar { padding: 4px 12px; }
  .topbar h1 { font-size: 1rem; }
  .layout {
    max-width: none;
    height: calc(100vh - 44px);
    padding: 0 12px 8px;
    gap: 10px;
    grid-template-columns: minmax(150px, 1fr) auto minmax(220px, 1.2fr);
    grid-template-areas: "players table controls";
  }
  .players { grid-template-columns: 1fr; align-content: start; }
  .player { padding: 6px 8px; }
  .player .score { font-size: 2.4rem; }
  .table-wrap { height: 100%; }
  #table { width: auto; height: 100%; max-height: none; }
  .controls { overflow-y: auto; gap: 8px; }
  .timer { padding: 6px 10px; }
  .timer-display { font-size: 1.6rem; }
  .actions button, .ball-btn { padding: 10px; }
}
