/* Mölkky Live — mobile-first, no frameworks, no webfonts. */

:root {
  --bg: #f5efe4;
  --text: #4a3626;
  --text-soft: #8a7660;
  --card: #fffdf8;
  --card-2: #f8f2e6;
  --line: #e6dbc7;
  --accent: #3f7a4e;
  --accent-bg: #e6efe8;
  --amber: #e2a63d;
  --amber-bg: #f9ecd2;
  --danger: #c0492f;
  --gold: #d4a017;
  --silver: #9aa0a6;
  --bronze: #b06a3b;
  --shadow: 0 2px 12px rgba(74, 54, 38, 0.09);
  --header-bg: rgba(245, 239, 228, 0.92);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d2420;
    --text: #efe9dc;
    --text-soft: #a99f8d;
    --card: #262f28;
    --card-2: #2d372f;
    --line: #3b463d;
    --accent: #5fae70;
    --accent-bg: #2b3a2f;
    --amber: #e2a63d;
    --amber-bg: #3d3323;
    --danger: #e06a50;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    --header-bg: rgba(29, 36, 32, 0.92);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  line-height: 1.45;
  min-height: 100vh;
}

/* Only two keyframe animations in the whole site. */
@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.82); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- layout ---------- */

.content {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 14px 28px;
}

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.pin-logo { width: 30px; height: 30px; flex: none; }
.header-text { flex: 1; min-width: 0; }
.header-title {
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.updated {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--text-soft);
  animation: pulse 0.9s ease 1; /* fresh node each snapshot → pulses on every update */
}

.header-back {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 14px 8px;
}
.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.back-link:active { opacity: 0.7; }

/* ---------- badges ---------- */

.badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-sm { font-size: 0.62rem; padding: 3px 8px; }
.badge-live { background: var(--accent-bg); color: var(--accent); }
.badge-done { background: var(--amber-bg); color: var(--bronze); }
.badge-amber { background: var(--amber-bg); color: var(--bronze); }
.badge-muted { background: var(--card-2); color: var(--text-soft); border: 1px solid var(--line); }
.badge-upcoming { background: var(--card-2); color: var(--bronze); border: 1px solid var(--amber); }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}

/* ---------- banner ---------- */

.banner {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
}
.banner-muted { background: var(--card-2); color: var(--text-soft); border: 1px solid var(--line); }
.banner-finished { background: var(--amber-bg); color: var(--text); border: 1px solid var(--amber); }
.banner-upcoming { background: var(--amber-bg); color: var(--text); border: 1px solid var(--amber); }

/* ---------- chips ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-soft);
}

/* ---------- generic card ---------- */

.card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 14px;
}
.section-title {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-soft);
  margin-bottom: 10px;
}

/* ---------- player cards ---------- */

.player-cards { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.player-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  border-left: 4px solid transparent;
}
.player-card.is-current {
  border-left-color: var(--amber);
  box-shadow: 0 0 0 1px var(--amber), 0 3px 16px rgba(226, 166, 61, 0.35);
}
.player-card.is-eliminated { opacity: 0.62; }
.player-card.is-eliminated .pc-name { text-decoration: line-through; color: var(--text-soft); }
.player-card.is-won { border-left-color: var(--gold); }

.pc-top { display: flex; align-items: center; gap: 12px; }
.pc-order {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pc-rank { background: var(--amber-bg); border-color: var(--amber); color: var(--bronze); }
.pc-nameblock { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pc-turn {
  font-size: 0.64rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--amber);
}
.pc-name {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pc-note { font-size: 0.7rem; font-weight: 700; color: var(--text-soft); letter-spacing: 0.05em; }
.pc-legs {
  margin-left: 8px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-soft);
  white-space: nowrap;
}
.pc-move {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  animation: slide-in 0.35s ease;
}
.pc-move.up { color: var(--accent); }
.pc-move.down { color: var(--danger); }
.pc-note-won { color: var(--gold); }
.pc-score {
  flex: none;
  font-size: 1.9rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.pc-members { display: flex; flex-direction: column; gap: 2px; }
.pc-member { font-size: 0.8rem; color: var(--text-soft); display: flex; align-items: center; gap: 6px; }
.pc-member.is-current-member { color: var(--amber); font-weight: 700; }
.pc-member.is-eliminated { text-decoration: line-through; opacity: 0.7; }

.err-dots { display: inline-flex; gap: 4px; margin-top: 2px; }
.err-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
}
.err-dot.filled { background: var(--danger); border-color: var(--danger); }

.pc-bar {
  margin-top: 10px;
  height: 6px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.pc-bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.5s ease;
}
.pc-bar-fill.danger { background: var(--amber); }

/* ---------- podium ---------- */

.podium-wrap { margin: 18px 0; }
.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
}
.podium-col {
  flex: 1;
  max-width: 170px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  min-width: 0;
}
.podium-col .p-name {
  font-weight: 800;
  font-size: 0.92rem;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.podium-col .p-score { font-size: 0.8rem; color: var(--text-soft); font-weight: 700; }
.podium-col .p-stats { font-size: 0.68rem; color: var(--text-soft); }
.p-block {
  width: 100%;
  border-radius: 10px 10px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8px;
  font-weight: 900;
  font-size: 1.05rem;
  color: rgba(0, 0, 0, 0.55);
  box-shadow: var(--shadow);
}
.podium-col.first .p-block { height: 96px; background: linear-gradient(180deg, #f3c94f, var(--gold)); }
.podium-col.second .p-block { height: 72px; background: linear-gradient(180deg, #c9cdd2, var(--silver)); }
.podium-col.third .p-block { height: 56px; background: linear-gradient(180deg, #cd8a55, var(--bronze)); }
.podium-col.empty { visibility: hidden; }

.ranking { list-style: none; }
.ranking-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.ranking-row:last-child { border-bottom: none; }
.ranking-row.is-eliminated .rk-name { text-decoration: line-through; color: var(--text-soft); }
.rk-rank { flex: none; width: 22px; font-weight: 800; color: var(--text-soft); text-align: center; }
.rk-name { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-stats { flex: none; font-size: 0.74rem; color: var(--text-soft); }

/* ---------- live feed ---------- */

.feed { list-style: none; }
.feed-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.feed-row:last-child { border-bottom: none; }
.feed-row.slide-in { animation: slide-in 0.35s ease; }
.feed-icon { flex: none; width: 22px; text-align: center; }
.feed-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.feed-text b { font-weight: 800; }

/* ---------- casual tournament ---------- */

.round-section { margin-bottom: 20px; }
.match-list { display: flex; flex-direction: column; gap: 10px; }
.match-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px 14px 12px;
  border: 1px solid transparent;
}
.match-card.is-live {
  border-color: var(--accent);
  cursor: pointer;
}
.match-card.is-live:active { background: var(--card-2); }
.mc-badges { display: flex; gap: 6px; margin-bottom: 6px; }
.mc-body { display: flex; align-items: center; gap: 10px; }
.mc-player {
  flex: 1;
  min-width: 0;
  font-size: 0.94rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mc-player.right { text-align: right; }
.mc-player.is-winner { font-weight: 800; }
.mc-trophy { margin: 0 4px; }
.mc-score {
  flex: none;
  font-weight: 900;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.mc-vs { flex: none; font-size: 0.78rem; font-weight: 700; color: var(--text-soft); }
.mc-live-pts {
  margin-top: 2px;
  text-align: center;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.mc-live-pts:empty { display: none; }
.mc-watch {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.84rem;
}

/* ---------- official tournament ---------- */

.phase-crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-soft);
}
.crumb { padding: 4px 12px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); }
.crumb.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.crumb-sep { color: var(--text-soft); }

.pool-card { padding: 14px; }
.pool-title {
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.table-scroll { overflow-x: auto; }
.standings { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.standings th {
  text-align: right;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-soft);
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
}
.standings th.st-name { text-align: left; }
.standings td { padding: 7px 8px; border-bottom: 1px solid var(--line); }
.standings tbody tr:last-child td { border-bottom: none; }
.st-rank { text-align: right; font-weight: 800; color: var(--text-soft); width: 26px; }
.st-name { text-align: left; font-weight: 700; }
.st-num { text-align: right; font-variant-numeric: tabular-nums; }
tr.tier-gold td { background: var(--amber-bg); }
tr.tier-gold td:first-child { border-radius: 8px 0 0 8px; }
tr.tier-gold td:last-child { border-radius: 0 8px 8px 0; }
tr.tier-silver td { color: var(--text-soft); }
.tier-mark {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: 1px;
}
.tier-mark.tier-gold { background: var(--gold); color: #fff; }
.tier-mark.tier-silver { background: var(--silver); color: #fff; }

.pool-legend {
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-soft);
  margin: -4px 0 16px;
}

.pool-matches { margin-top: 10px; }
.pool-matches summary,
.pools-collapsed summary {
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.06em;
}
.pools-collapsed { margin-top: 6px; }
.pools-collapsed > summary { padding: 10px 2px; }
.gm-list { list-style: none; margin-top: 8px; }
.gm {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.84rem;
}
.gm:last-child { border-bottom: none; }
.gm.upcoming { color: var(--text-soft); }
.gm-p { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gm-p.right { text-align: right; }
.gm-sets { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.8rem; }

/* ---------- bracket ---------- */

.bracket-section { margin-bottom: 22px; }
.bracket-outer { position: relative; }
/* edge fade hints */
.bracket-outer::before,
.bracket-outer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22px;
  pointer-events: none;
  z-index: 2;
}
.bracket-outer::before { left: 0; background: linear-gradient(to right, var(--bg), transparent); }
.bracket-outer::after { right: 0; background: linear-gradient(to left, var(--bg), transparent); }

.bracket-scroll {
  overflow-x: auto;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  padding: 4px 2px 12px;
}
.bracket { display: flex; min-width: max-content; }
.b-col {
  display: flex;
  flex-direction: column;
  width: 190px;
  flex: none;
  scroll-snap-align: start;
}
.b-round-title {
  height: 26px;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-soft);
  text-align: center;
}
.b-matches { flex: 1; display: flex; flex-direction: column; }
.b-slot {
  flex: 1;
  display: flex;
  align-items: center;
  position: relative;
  padding: 8px 16px;
  min-height: 86px;
}
/* connectors: classic elbows drawn with borders */
.b-col + .b-col .b-slot::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 16px;
  height: 2px;
  background: var(--line);
}
.b-col:not(:last-child) .b-slot:nth-child(odd)::after {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  width: 16px;
  height: 50%;
  border-top: 2px solid var(--line);
  border-right: 2px solid var(--line);
}
.b-col:not(:last-child) .b-slot:nth-child(even)::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 50%;
  width: 16px;
  height: 50%;
  border-bottom: 2px solid var(--line);
  border-right: 2px solid var(--line);
}

.b-match {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.b-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  font-size: 0.84rem;
}
.b-row + .b-row { border-top: 1px solid var(--line); }
.b-row.is-winner { color: var(--accent); font-weight: 800; background: var(--accent-bg); }
.b-row.is-empty { color: var(--text-soft); }
.b-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-sets { display: flex; gap: 8px; flex: none; font-variant-numeric: tabular-nums; }
.b-set { min-width: 14px; text-align: right; font-weight: 700; }

.small-final-block { max-width: 240px; margin: 6px auto 0; }
.b-small-title {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-soft);
  text-align: center;
  margin-bottom: 6px;
}
.b-match.detached { margin-bottom: 8px; }

/* ---------- states ---------- */

.center-state {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.state-card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 34px 26px;
  text-align: center;
  max-width: 420px;
}
.state-logo .pin-logo { width: 56px; height: 56px; }
.state-title { font-size: 1.15rem; font-weight: 900; margin: 12px 0 8px; }
.state-body { color: var(--text-soft); font-size: 0.92rem; }

.skeleton-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 18px 14px;
  margin-bottom: 12px;
  animation: pulse 1.5s ease-in-out infinite;
}
.sk-line {
  height: 12px;
  border-radius: 6px;
  background: var(--line);
  margin-bottom: 10px;
}
.sk-line:last-child { margin-bottom: 0; }
.sk-line.thin { height: 8px; }
.sk-line.w40 { width: 40%; }
.sk-line.w70 { width: 70%; }

/* ---------- footer ---------- */

.site-footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 14px 30px;
  text-align: center;
  color: var(--text-soft);
}
.footer-brand { font-weight: 800; font-size: 0.82rem; letter-spacing: 0.04em; }
.footer-note { font-size: 0.72rem; margin-top: 4px; }

/* Badge d'acquisition : lien vers la fiche Play Store de l'app */
.store-badge {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.store-badge:active { transform: scale(0.97); }

/* Barre superieure : n'accueille que le selecteur de langue, aligne a droite.
   Non collante — le header du contenu passe par-dessus au defilement. */
.topbar {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 14px 0;
  display: flex;
  justify-content: flex-end;
}

/* Selecteur de langue. Le choix du spectateur est memorise et prime sur le
   `?lang` du QR (cf. js/i18n.js). */
.lang-picker {
  appearance: none;
  padding: 5px 22px 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-soft) 50%),
    linear-gradient(135deg, var(--text-soft) 50%, transparent 50%);
  background-position: calc(100% - 12px) 52%, calc(100% - 8px) 52%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
}
.lang-picker:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- noscript ---------- */

.noscript {
  max-width: 640px;
  margin: 40px auto;
  padding: 20px;
  text-align: center;
  font-weight: 600;
}

/* respect users who prefer no motion */
@media (prefers-reduced-motion: reduce) {
  .dot, .updated, .skeleton-card, .feed-row.slide-in { animation: none; }
  .pc-bar-fill { transition: none; }
}
