/* ══════════════════════════════════════════════════════════════
   STANDARD SCOREBOARD — PhysEdBoard
   Layout : les scores et le timer remplissent tout l'espace.
            scaleNumbers() en JS dicte les font-size.
══════════════════════════════════════════════════════════════ */

:root {
  --home:     #ffd43b;
  --home-rgb: 255,212,59;
  --away:     #00b4d8;
  --away-rgb: 0,180,216;

  --neutral:      #b8b8cc;
  --neutral-glow: rgba(184,184,204,0.30);
  --neutral-dim:  rgba(184,184,204,0.12);

  --danger:  #ff2255;
  --warning: #ffd43b;

  --bg:        #061428;
  --text:      #ffffff;
  --text-mid:  rgba(255,255,255,0.55);
  --text-dim:  rgba(255,255,255,0.22);
  --border:    rgba(255,255,255,0.08);
  --border-hi: rgba(255,255,255,0.14);
  --accent:    #ffd43b;

  --ring-c: 552.9;
  --r:      8px;
  --tr:     0.15s cubic-bezier(0.4,0,0.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; touch-action: manipulation; }
button { font-family: inherit; cursor: pointer; }
input  { font-family: inherit; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Oswald', sans-serif;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Background layers ── */
.bg-layer    { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.bg-main     {
  background:
    radial-gradient(ellipse 130% 70% at 50% 115%, rgba(0,80,200,0.18) 0%, transparent 65%),
    radial-gradient(ellipse 60% 50% at 10% 0%,    rgba(0,50,130,0.12) 0%, transparent 55%),
    radial-gradient(ellipse 60% 50% at 90% 0%,    rgba(0,50,130,0.12) 0%, transparent 55%),
    linear-gradient(180deg, #04101e 0%, #061428 40%, #091a34 100%);
}
.bg-vignette  { background: radial-gradient(ellipse 100% 100% at 50% 50%, transparent 35%, rgba(0,0,0,0.55) 100%); }
.bg-scanlines { background-image: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.05) 2px, rgba(0,0,0,0.05) 4px); opacity: 0.4; }

/* ── App shell ── */
.app {
  position: relative; z-index: 2;
  width: 100%; height: 100dvh;
  display: flex; flex-direction: column;
}

settings-panel {
  display: block; flex-shrink: 0;
  margin: 0 !important; padding: 0 !important;
}

/* ══════════════════════════════════════════════════════════════
   BOARD — remplit tout l'espace sous le header
══════════════════════════════════════════════════════════════ */
.board {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.board-main {
  width: 100%;
  height: 100%;
  display: grid;
  /* Timer colonne centrale, scores prennent le reste */
  grid-template-columns: 1fr clamp(200px, 28vw, 460px) 1fr;
  overflow: hidden;
}

body.booting .board-main {
  visibility: hidden;
}

/* ══════════════════════════════════════════════════════════════
   SCORE PANELS
   Hauteur = toute la colonne (100%).
   font-size des scores dicté par scaleNumbers() en JS.
══════════════════════════════════════════════════════════════ */
.score-panel {
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: clamp(2px, 0.4vh, 6px);
  padding: clamp(12px, 2vh, 28px) clamp(8px, 1.5vw, 20px);
  min-height: 0; overflow: hidden;
}
.home-panel { border-left:  4px solid var(--home); }
.away-panel { border-right: 4px solid var(--away); }

/* ── Nom d'équipe ── */
.team-name {
  font-family: 'Teko', sans-serif;
  font-weight: 600;
  /* Taille calculée par scaleNumbers() — valeur initiale raisonnable */
  font-size: clamp(22px, 3.5vw, 58px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  flex-shrink: 0;
  margin-bottom: clamp(8px, 1.4vh, 18px);
}
.home-panel .team-name { color: var(--home); }
.away-panel .team-name { color: var(--away); }

/* ── Score row ── */
.score-row {
  display: flex; flex-direction: row; align-items: center; justify-content: center;
  width: 100%;
  gap: clamp(8px, 1.2vw, 18px);
  flex: 0 0 auto;
  min-height: 0;
}

/* Score value — BIG, JS override font-size */
.score-value {
  font-family: 'Teko', sans-serif;
  font-weight: 700;
  /* font-size définie par scaleNumbers() */
  font-size: clamp(48px, 14vw, 300px);
  line-height: 0.84;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: default;
  flex: 1 1 0; min-width: 0;
  overflow: visible; white-space: nowrap;
  transition: none;
  user-select: none;
  color: var(--text);
  text-shadow: 0 2px 14px rgba(0,0,0,0.72);
}
body.ui-ready .score-value { transition: color 0.18s; }

.score-value.flash-home { animation: flashHome 0.55s cubic-bezier(0.34,1.56,0.64,1) forwards; }
.score-value.flash-away { animation: flashAway 0.55s cubic-bezier(0.34,1.56,0.64,1) forwards; }

/* ── Boutons score ── */
.score-btn {
  flex-shrink: 0;
  align-self: center;
  transform: translateY(-8%);
  width:  clamp(64px, 8.5vw, 118px);
  height: clamp(64px, 8.5vw, 118px);
  border-radius: 50%;
  background: transparent;
  border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(40px, 5.4vw, 74px);
  transition: none;
}
body.ui-ready .score-btn { transition: transform var(--tr), filter var(--tr); }
.score-btn:active { transform: translateY(-8%) scale(0.88); }

.home-panel .score-btn { color: var(--home); }
.home-panel .score-btn:hover { filter: drop-shadow(0 0 10px rgba(var(--home-rgb),0.6)); }
.away-panel .score-btn { color: var(--away); }
.away-panel .score-btn:hover { filter: drop-shadow(0 0 10px rgba(var(--away-rgb),0.6)); }

/* ══════════════════════════════════════════════════════════════
   TIMER PANEL
   Remplit toute la hauteur de la colonne centrale.
   Le SVG ring + le texte s'ajustent via scaleNumbers().
══════════════════════════════════════════════════════════════ */
.timer-panel {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: clamp(6px, 1.2vh, 14px) clamp(4px, 1vw, 10px);
  min-height: 0;
  position: relative;
}

/* Clock face — carré, remplit la colonne */
.timer-face {
  position: relative;
  /* Carré : le plus petit des deux dimensions disponibles */
  aspect-ratio: 1;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  flex: 1 1 0;
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: visible;
}

/* SVG ring — remplit le timer-face */
.timer-ring-svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
}
.ring-track {
  fill: none;
  stroke: var(--neutral-dim);
  stroke-width: 6;
}
#ringFill {
  fill: none;
  stroke: var(--neutral);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: var(--ring-c);
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.12s linear, stroke 0.3s;
  filter: drop-shadow(0 0 6px var(--neutral-glow));
}
#ringFill.warning { stroke: #ffd43b; filter: drop-shadow(0 0 8px rgba(255,212,59,0.5)); }
#ringFill.danger  { stroke: #ff2255; filter: drop-shadow(0 0 10px rgba(255,34,85,0.6)); }

/* Timer display */
.timer-inner {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: clamp(4px, 0.8vh, 10px);
}

#time {
  font-family: 'Teko', sans-serif;
  font-weight: 700;
  /* font-size définie par scaleNumbers() — valeur initiale */
  font-size: clamp(36px, 7vw, 110px);
  line-height: 1;
  letter-spacing: 0.04em;
  color: var(--text);
  white-space: nowrap;
  text-shadow: 0 2px 20px rgba(0,0,0,0.9);
  transition: color 0.3s;
}
#time.warning { color: #ffd43b; }
#time.danger  { color: #ff2255; animation: dangerPulse 0.5s infinite alternate; }
#time.done    { color: var(--text-dim); }

/* Timer controls */
.timer-controls {
  display: flex; align-items: center; justify-content: center;
  gap: clamp(6px, 1vw, 16px);
  flex-shrink: 0;
}
.ctrl-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  width:  clamp(32px, 3.2vw, 50px);
  height: clamp(32px, 3.2vw, 50px);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(12px, 1.4vw, 18px);
  transition: all var(--tr);
}
.ctrl-btn:hover { color: var(--text-mid); border-color: rgba(255,255,255,0.22); }
.ctrl-btn:active { transform: scale(0.88); }

.ctrl-main { border-color: var(--neutral); color: var(--neutral); }
.ctrl-main:hover { border-color: var(--text); color: var(--text); }
.ctrl-main.is-running { border-color: var(--text-mid); color: var(--text-mid); }
.ctrl-main.is-paused  { border-color: var(--neutral); color: var(--neutral); animation: breathe 2s ease-in-out infinite; }

/* ══════════════════════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════════════════════ */
.modal-veil {
  display: none;
  position: fixed; inset: 0; z-index: 800;
  background: rgba(8,8,8,0.88);
  align-items: center; justify-content: center;
  backdrop-filter: blur(16px);
}
.modal-veil.visible { display: flex; animation: fadeIn 0.18s; }

.modal-box {
  background: #141414;
  border: 1px solid var(--border-hi);
  border-top-color: rgba(255,212,59,0.4);
  border-radius: 10px;
  width: min(520px, 96vw);
  max-height: 92dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.03) inset, 0 40px 80px rgba(0,0,0,0.9);
  animation: modalIn 0.22s cubic-bezier(0.34,1.4,0.64,1);
  position: relative;
}
.modal-box::before {
  content: '';
  position: absolute; top: 0; left: 10%; right: 10%; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,212,59,0.55), transparent);
}

.modal-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-heading {
  font-family: 'Oswald', sans-serif;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.28em; color: var(--text-mid);
}
.modal-heading i { color: var(--accent); margin-right: 2px; }

.modal-x {
  background: transparent;
  border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-dim); font-size: 11px; padding: 4px 11px;
  font-family: 'Oswald', sans-serif; letter-spacing: 0.06em;
  transition: all var(--tr);
}
.modal-x:hover { border-color: var(--danger); color: var(--danger); }

.modal-body { padding: 4px 20px; overflow-y: auto; flex: 1; }

.m-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 54px;
}
.m-row-team { align-items: flex-start; padding: 10px 0; min-height: 0; }

.m-info { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; }
.m-label { font-size: 11px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(255,255,255,0.75); }
.m-sub   { font-size: 10px; color: var(--text-dim); letter-spacing: 0.04em; }
.m-divider { height: 1px; background: var(--border); flex-shrink: 0; }

/* Time inputs */
.time-inputs { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.spin-wrap { position: relative; width: 72px; }
.spin-input {
  font-family: 'Teko', sans-serif; font-size: 26px; font-weight: 600; width: 100%;
  background: rgba(0,0,0,0.5); border: 1px solid var(--border-hi); border-radius: 6px;
  color: #fff; text-align: center; padding: 4px 26px 4px 4px; outline: none;
  -moz-appearance: textfield; appearance: textfield; transition: border-color 0.2s;
}
.spin-input:focus { border-color: rgba(255,212,59,0.5); }
.spin-input::-webkit-outer-spin-button,
.spin-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.time-sep { font-family: 'Teko', sans-serif; font-size: 20px; color: var(--text-dim); }
.spin-col {
  position: absolute; top: 2px; right: 2px; bottom: 2px; width: 24px;
  display: flex; flex-direction: column; gap: 1px;
}
.spin-btn {
  flex: 1; background: transparent; border: none;
  color: var(--text-dim); font-size: 10px; border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.14s;
}
.spin-btn:hover { color: var(--accent); }

/* Team config */
.team-config {
  display: flex; align-items: center;
  gap: 10px; flex-shrink: 0; position: relative;
}
.m-text {
  width: min(155px, 32vw);
  font-family: 'Oswald', sans-serif; font-size: 13px; font-weight: 500;
  letter-spacing: 0.08em; text-transform: uppercase;
  background: rgba(0,0,0,0.5); border: 1px solid var(--border-hi); border-radius: 6px;
  color: #fff; padding: 8px 10px; outline: none; transition: border-color 0.2s;
}
.m-text:focus { border-color: rgba(255,212,59,0.5); }

/* Toggle */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.tog-track {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.08); border: 1px solid var(--border-hi); border-radius: 24px;
  cursor: pointer; transition: background 0.2s, border-color 0.2s;
}
.tog-track::before {
  content: ''; position: absolute;
  width: 18px; height: 18px; left: 3px; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.35); border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.toggle input:checked + .tog-track { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .tog-track::before { transform: translateX(20px) translateY(-50%); background: #111; }

/* Modal footer */
.modal-foot {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center;
}
.m-reset {
  background: transparent; border: 1px solid rgba(255,34,85,0.25); border-radius: 6px;
  color: rgba(255,34,85,0.65);
  font-family: 'Oswald', sans-serif; font-size: 10px; font-weight: 600;
  letter-spacing: 0.15em; padding: 8px 14px; transition: all var(--tr);
}
.m-reset:hover { border-color: var(--danger); color: var(--danger); }
.modal-spacer { flex: 1; }
.m-cancel {
  background: transparent; border: 1px solid var(--border-hi); border-radius: 6px;
  color: var(--text-dim);
  font-family: 'Oswald', sans-serif; font-size: 11px; font-weight: 600;
  letter-spacing: 0.2em; padding: 9px 18px; transition: all var(--tr);
}
.m-cancel:hover { color: var(--text-mid); border-color: rgba(255,255,255,0.3); }
.m-apply {
  background: var(--accent); border: none; border-radius: 6px; color: #111;
  font-family: 'Oswald', sans-serif; font-size: 11px; font-weight: 700;
  letter-spacing: 0.22em; padding: 9px 24px; transition: all var(--tr);
}
.m-apply:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* Color trigger */
.color-trigger {
  width: 22px; height: 22px; border-radius: 4px;
  border: 2px solid rgba(255,255,255,0.25); cursor: pointer; flex-shrink: 0;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.color-trigger:hover { transform: scale(1.12); border-color: rgba(255,255,255,0.55); box-shadow: 0 0 8px rgba(255,255,255,0.2); }

/* Dropdown palette */
.color-palette {
  display: none; position: absolute; top: 100%; left: 0; margin-top: 6px;
  background: #1c1c1c; border: 1px solid var(--border-hi); border-radius: 8px;
  padding: 8px; gap: 6px; flex-wrap: wrap; width: 130px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.7); animation: fadeIn 0.12s;
}
.color-palette.open { display: flex; }
.swatch {
  width: 22px; height: 22px; border-radius: 4px;
  border: 2px solid transparent; cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  flex-shrink: 0; padding: 0;
}
.swatch:hover { transform: scale(1.18); }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.25), 0 0 10px rgba(255,255,255,0.3); transform: scale(1.12); }

/* ══════════════════════════════════════════════════════════════
   INTRO OVERLAY
══════════════════════════════════════════════════════════════ */
#introOverlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(10,10,10,0.95);
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(24px);
}
#introOverlay.visible { display: flex; animation: fadeIn 0.15s; }

#introRing {
  position: absolute;
  width: clamp(200px, 32vw, 460px); height: clamp(200px, 32vw, 460px);
  border-radius: 50%; border: 2px solid rgba(255,255,255,0.10);
}
#introRing.spin { animation: ringExpandFade 0.9s ease-out; }

#introNumber {
  font-family: 'Teko', sans-serif; font-weight: 700;
  font-size: clamp(180px, 30vw, 440px); line-height: 1;
  color: var(--accent); position: relative; z-index: 1;
}
#introNumber.pop { animation: numPop 0.38s cubic-bezier(0.34,1.56,0.64,1) both; }
#introNumber.go  { color: #fff; animation: numGo 0.44s cubic-bezier(0.34,1.3,0.64,1) both; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — portrait
   3 sections empilées verticalement :
   [Timer] [Score domicile] [Score visiteur]
══════════════════════════════════════════════════════════════ */
@media (orientation: portrait), (max-aspect-ratio: 3/4) {
  .board-main {
    /* 3 rows égales — chaque section prend 1/3 de la hauteur */
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr 1fr;
  }

  /* ── Timer — ligne du haut ── */
  .timer-panel {
    grid-column: 1;
    grid-row: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(8px, 1.5vh, 18px) clamp(8px, 3vw, 24px);
    gap: clamp(4px, 1vh, 10px);
    border-bottom: 1px solid var(--border);
  }

  .timer-face {
    /* Carré contraint par la hauteur disponible dans la row */
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    aspect-ratio: 1;
    max-width: min(100%, 46dvh);
  }

  .timer-controls {
    flex-direction: row;
    gap: clamp(6px, 2vw, 14px);
    flex-shrink: 0;
  }

  /* ── Score domicile — ligne du milieu ── */
  .home-panel {
    grid-column: 1;
    grid-row: 2;
    border-left:   4px solid var(--home);
    border-right:  none;
    border-bottom: 1px solid var(--border);
  }

  /* ── Score visiteur — ligne du bas ── */
  .away-panel {
    grid-column: 1;
    grid-row: 3;
    border-right: 4px solid var(--away);
    border-left:  none;
  }

  /* Score panels — restent centrés verticalement dans leur tiers d'ecran */
  .score-panel {
    justify-content: center;
    padding-top: clamp(12px, 2vh, 28px);
    padding-bottom: clamp(12px, 2vh, 28px);
  }
  .score-row { flex: 0 0 auto; }

  /* Les boutons de score restent horizontaux, taille adaptée */
  .score-btn {
    width:  clamp(62px, 15vw, 94px);
    height: clamp(62px, 15vw, 94px);
    font-size: clamp(34px, 8.4vw, 54px);
  }
}

/* Très petite hauteur (paysage serré) */
@media (max-height: 420px) {
  .timer-controls { gap: 3px; }
  .ctrl-btn { width: 28px; height: 28px; font-size: 10px; }
}

/* ── Keyframes ── */
@keyframes fadeIn     { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn    { from { opacity: 0; transform: scale(0.94) translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes numPop     { from { transform: scale(0.38) rotate(-6deg); filter: blur(14px); opacity: 0; } to { transform: scale(1) rotate(0); filter: none; opacity: 1; } }
@keyframes numGo      { from { transform: scale(0.72); filter: blur(8px); opacity: 0; } to { transform: scale(1); filter: none; opacity: 1; } }
@keyframes ringExpandFade { from { transform: scale(0.6); opacity: 0.8; } to { transform: scale(1.6); opacity: 0; } }
@keyframes dangerPulse { from { opacity: 1; } to { opacity: 0.45; } }
@keyframes breathe    { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes flashHome  {
  0%   { color: var(--home); text-shadow: 0 0 50px var(--home), 0 0 100px rgba(var(--home-rgb),0.6); transform: scale(1.10); }
  100% { color: var(--text); text-shadow: none; transform: scale(1); }
}
@keyframes flashAway  {
  0%   { color: var(--away); text-shadow: 0 0 50px var(--away), 0 0 100px rgba(var(--away-rgb),0.6); transform: scale(1.10); }
  100% { color: var(--text); text-shadow: none; transform: scale(1); }
}