/* Mölkky : un tableau d'affichage lumineux, lisible de loin en plein air.
   Fond noir mat, points LED francs ; la couleur de l'équipe qui joue
   (--c) éclaire le tableau et les quilles. */

@font-face {
  font-family: "Doto";
  src: url("Doto-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: block;
}
@font-face {
  font-family: "Lexend";
  src: url("../Lexend-Variable.woff2") format("woff2");
  font-weight: 100 900;
}

:root {
  --bg: #050607;
  --panel: #0d1013;
  --line: #1c2127;
  --text: #f4f1e8;
  --dim: #8a929c;
  --amber: #ffb21a;
  --red: #ff4040;
  --c: var(--amber);
}

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

html,
body {
  height: 100%;
}

body {
  font-family: "Lexend", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle, #ffffff0b 1.2px, transparent 1.7px) 0 0 / 9px 9px,
    var(--bg);
  display: flex;
  flex-direction: column;
  /* Une colonne de téléphone, centrée sur un grand écran. */
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

input {
  -webkit-user-select: text;
  user-select: text;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
svg .fill {
  fill: currentColor;
  stroke: none;
}

.hidden {
  display: none !important;
}

/* --- La barre du haut : 1fr auto 1fr, le titre reste centré ------------- */

.bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 6px 8px 2px;
  flex: none;
}
.bar-right {
  display: flex;
  justify-content: flex-end;
}

.icon-btn {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--dim);
}
.icon-btn svg {
  width: 26px;
  height: 26px;
}
.icon-btn:active {
  color: var(--text);
}
#soundBtn .off,
#soundBtn.muted .on {
  display: none;
}
#soundBtn.muted .off {
  display: inline;
}

.title {
  font-family: "Doto", monospace;
  font-weight: 900;
  font-size: 28px;
  letter-spacing: 1px;
  color: var(--amber);
  text-shadow: 0 0 10px #ffb21a88;
  display: flex;
  align-items: center;
  gap: 10px;
}
.target {
  font-size: 18px;
  color: var(--bg);
  background: var(--amber);
  border-radius: 8px;
  padding: 1px 6px;
  text-shadow: none;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* --- Avant la partie ---------------------------------------------------- */

.setup {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 10px 16px 16px;
  min-height: 0;
}

.board-title {
  font-family: "Doto", monospace;
  font-weight: 900;
  font-size: 30px;
  text-align: center;
  color: var(--text);
  text-shadow: 0 0 10px #ffffff55;
}

.chips {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}
.chip {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--bg);
  font-weight: 800;
  font-size: 15px;
  display: grid;
  place-items: center;
  transition: transform 0.15s;
}
.chip.used {
  background: var(--c);
}
.chip[aria-checked="true"] {
  transform: scale(1.12);
  box-shadow:
    0 0 0 3px var(--bg),
    0 0 0 6px var(--text),
    0 0 18px var(--c);
}

.add-form {
  display: flex;
  gap: 10px;
}
.name-input {
  flex: 1;
  min-width: 0;
  height: 58px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font:
    600 22px "Lexend",
    Arial,
    sans-serif;
  padding: 0 16px;
  outline: none;
}
.name-input:focus {
  border-color: var(--amber);
}
.name-input::placeholder {
  color: #4c535c;
}
.add-btn {
  width: 58px;
  height: 58px;
  flex: none;
  border-radius: 14px;
  background: var(--amber);
  color: var(--bg);
  display: grid;
  place-items: center;
}
.add-btn svg {
  width: 30px;
  height: 30px;
  stroke-width: 3;
}

.roster {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.team-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 10px 10px 18px;
  border-radius: 14px;
  background: var(--panel);
  position: relative;
  min-height: 62px;
  align-items: center;
}
.team-line::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 6px;
  border-radius: 0 4px 4px 0;
  background: var(--c);
  box-shadow: 0 0 10px var(--c);
}
.team-line.ghost {
  background: none;
  border: 2px dashed var(--line);
}
.team-line.ghost::before {
  display: none;
}
.player-tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding-left: 14px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--c) 18%, transparent);
  border: 2px solid var(--c);
  font-weight: 600;
  font-size: 19px;
  height: 42px;
}
.del-btn {
  width: 40px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--dim);
}
.del-btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.6;
}

.primary-btn {
  height: 64px;
  border-radius: 16px;
  background: var(--amber);
  color: var(--bg);
  font-weight: 800;
  font-size: 22px;
  box-shadow: 0 0 24px -6px var(--amber);
  flex: none;
}
.primary-btn:disabled {
  background: var(--panel);
  color: #4c535c;
  box-shadow: none;
}

/* --- Pendant la partie -------------------------------------------------- */

.game {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 4px 10px 10px;
  --d: min(64px, 16vw, 8.6dvh);
  --g: min(12px, 2.6vw);
}

.board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.row {
  flex: 1 1 0;
  min-height: 0;
  max-height: 128px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 20px;
  border-radius: 16px;
  background: var(--panel);
  border: 2px solid var(--line);
  position: relative;
  transition: opacity 0.4s;
}
.row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 7px;
  border-radius: 0 4px 4px 0;
  background: var(--c);
  box-shadow: 0 0 12px var(--c);
}
.row.active {
  border-color: var(--c);
  box-shadow:
    0 0 22px -6px var(--c),
    inset 0 0 30px -18px var(--c);
}
.row.out {
  opacity: 0.45;
}

.info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.names {
  display: flex;
  flex-wrap: wrap;
  column-gap: 10px;
  font-weight: 600;
  font-size: 18px;
  line-height: 1.15;
  color: var(--dim);
  overflow: hidden;
  max-height: 2.3em;
}
.names span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.names .current {
  color: var(--text);
  font-weight: 800;
}
.row:not(.active) .names span:first-child:last-child {
  color: var(--text);
}

/* Jauge vers 50 : dix segments de 5 points. */
.gauge {
  height: 8px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--c) 16%, transparent);
  position: relative;
  overflow: hidden;
}
.gauge-fill {
  position: absolute;
  inset: 0;
  background: var(--c);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 0.7s cubic-bezier(0.3, 0.9, 0.3, 1);
}
.gauge::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0 calc(10% - 3px),
    var(--panel) calc(10% - 3px) 10%
  );
}

.history {
  font-weight: 600;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  display: flex;
  gap: 8px;
  height: 1.1em;
  overflow: hidden;
}
.history .zero {
  color: var(--red);
}

/* Trois ratés de suite et l'équipe sort : trois voyants. */
.misses {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: none;
}
.misses i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #ff404066;
}
.misses i.on {
  background: var(--red);
  border-color: var(--red);
  box-shadow: 0 0 10px var(--red);
}

.led {
  display: block;
  flex: none;
}

.board.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: minmax(0, 1fr);
}
.board.tiles .row {
  max-height: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  gap: 4px 6px;
  padding: 6px 8px 6px 16px;
}
.board.tiles .info {
  justify-self: stretch;
  gap: 4px;
}
.board.tiles .names {
  font-size: 16px;
  max-height: 1.2em;
}
.board.tiles .history,
.board.tiles .gauge {
  display: none;
}
.board.tiles .misses {
  flex-direction: row;
  gap: 4px;
  align-self: start;
  margin-top: 4px;
}
.board.tiles .misses i {
  width: 10px;
  height: 10px;
}
.board.tiles .led {
  grid-column: 1 / -1;
}

/* À qui le tour */
.turn {
  flex: none;
  text-align: center;
  padding: 8px 0 4px;
  min-height: 46px;
}
.turn-name {
  font-family: "Doto", monospace;
  font-weight: 900;
  font-size: 32px;
  line-height: 1;
  color: var(--c);
  text-shadow: 0 0 12px var(--c);
}

/* Le pavé des points, de 1 à 12. */
.pins {
  flex: none;
  align-self: center;
  display: grid;
  grid-template-columns: repeat(4, var(--d));
  gap: var(--g);
  margin: 4px 0 10px;
}
.pin {
  width: var(--d);
  height: var(--d);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: "Doto", monospace;
  font-weight: 900;
  font-size: calc(var(--d) * 0.46);
  color: var(--c);
  background: radial-gradient(
    circle at 50% 40%,
    color-mix(in srgb, var(--c) 18%, var(--bg)),
    var(--bg) 70%
  );
  border: 3px solid color-mix(in srgb, var(--c) 55%, transparent);
  transition: transform 0.12s;
}
.pin[aria-pressed="true"] {
  background: var(--c);
  color: var(--bg);
  border-color: #fff;
  box-shadow: 0 0 22px var(--c);
  transform: scale(1.08);
}
.pin:active {
  transform: scale(0.94);
}

.actions {
  flex: none;
  display: flex;
  gap: 10px;
}
.undo-btn {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: 16px;
  border: 2px solid var(--line);
  color: var(--text);
  display: grid;
  place-items: center;
}
.undo-btn svg {
  width: 28px;
  height: 28px;
}
.undo-btn:disabled {
  color: #343a42;
}
.throw-btn {
  flex: 1;
  height: 64px;
  border-radius: 16px;
  border: 3px solid #ff404099;
  color: var(--red);
  font-family: "Doto", monospace;
  font-weight: 900;
  font-size: 34px;
  display: grid;
  place-items: center;
}
.throw-miss {
  font-family: "Lexend", Arial, sans-serif;
  font-weight: 800;
  font-size: 30px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.throw-miss svg {
  width: 30px;
  height: 30px;
  stroke-width: 2.6;
}
.throw-points {
  display: none;
}
.throw-btn.has-points {
  background: var(--c);
  border-color: var(--c);
  color: var(--bg);
  box-shadow: 0 0 24px -4px var(--c);
}
.throw-btn.has-points .throw-miss {
  display: none;
}
.throw-btn.has-points .throw-points {
  display: block;
}
.throw-btn:active {
  transform: scale(0.98);
}

/* --- Surcouches --------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: #050607e6;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
}
.panel {
  width: 100%;
  max-width: 400px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 22px;
  padding: 22px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel-title {
  font-family: "Doto", monospace;
  font-weight: 900;
  font-size: 30px;
  text-align: center;
  color: var(--amber);
  text-shadow: 0 0 10px #ffb21a88;
}
.panel-text {
  text-align: center;
  font-size: 18px;
  color: var(--dim);
}
.panel-actions {
  display: flex;
  gap: 10px;
}
.panel-actions .primary-btn,
.panel-actions .ghost-btn {
  flex: 1;
}
.ghost-btn {
  height: 64px;
  border-radius: 16px;
  border: 2px solid var(--line);
  font-weight: 700;
  font-size: 22px;
}

.winner-panel {
  border-color: var(--c);
  box-shadow: 0 0 40px -8px var(--c);
  align-items: stretch;
  text-align: center;
}
.winner-led {
  width: 100%;
  aspect-ratio: 3 / 2;
}
.winner-names {
  font-family: "Doto", monospace;
  font-weight: 900;
  font-size: 34px;
  line-height: 1.1;
  color: var(--c);
  text-shadow: 0 0 12px var(--c);
  overflow-wrap: anywhere;
}
.winner-text {
  font-size: 22px;
  font-weight: 700;
}

/* Dans les règles, les quilles placées comme sur le terrain. */
.rules-panel .pins-mini {
  --d: 40px;
  --g: 8px;
  --c: var(--amber);
  display: block;
  position: relative;
  width: calc(4 * var(--d) + 3 * var(--g));
  height: calc(var(--d) + 3 * 0.87 * (var(--d) + var(--g)));
  margin: 0;
}
.pins-mini .pin {
  position: absolute;
  left: calc(var(--x) * (var(--d) + var(--g)));
  top: calc(var(--y) * 0.87 * (var(--d) + var(--g)));
}
.rules-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 16px;
  line-height: 1.4;
}
.rules-list strong {
  color: var(--amber);
}

.sparks {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

/* --- Mouvements --------------------------------------------------------- */

.shake {
  animation: shake 0.4s;
}
@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}
.misses i.shake {
  animation: blink 0.5s 2;
}
@keyframes blink {
  50% {
    opacity: 0.15;
  }
}

@media (hover: hover) {
  .icon-btn:hover {
    color: var(--text);
  }
}

@media (prefers-reduced-motion: reduce) {
  .shake,
  .misses i.shake {
    animation: none;
  }
  .gauge-fill,
  .chip,
  .pin,
  .row {
    transition: none;
  }
}
