/* ══════════════════════════════════════════════════════
   TABATA.CSS — PhysEdBoard
   Layout : le timer dicte sa taille (pleine largeur),
            la cellule timer s'adapte à sa hauteur.
   Desktop : col gauche (compteurs) | col droite (timer)
             barre du bas : boutons | phase cards
   Portrait : empilé verticalement
══════════════════════════════════════════════════════ */
:root {
  --bg:         #061428;
  --panel:      #0d2040;
  --panel2:     #112548;
  --panel-rgb:  13,32,64;
  --border:     #1a3a60;
  --border-hi:  rgba(255,255,255,0.08);
  --accent:     #ffd43b;
  --accent-rgb: 255,212,59;
  --red:        #ff3c3c;
  --text:       #ffffff;
  --text-dim:   rgba(255,255,255,0.42);
  --dim:        #3a608a;
  --input-rgb:  4,14,32;
  --tr:         0.22s cubic-bezier(0.4, 0, 0.2, 1);

  --bar-h:   clamp(60px, 10vh, 96px);
  --left-w:  clamp(130px, 17vw, 220px);
  --gap:     clamp(6px, 0.8vw, 12px);
  --cell-px: clamp(12px, 2vw, 28px);
  --cell-py: clamp(12px, 2vw, 28px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; touch-action: manipulation; }

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

/* ── 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; }
.bg-phase     { transition: background 0.9s ease; }
body[data-tabata-phase="work"]    .bg-phase { background: radial-gradient(ellipse 80% 55% at 50% 100%, rgba(0,200,83,0.09)        0%, transparent 70%); }
body[data-tabata-phase="rest"]    .bg-phase { background: radial-gradient(ellipse 80% 55% at 50% 100%, rgba(255,60,60,0.10)        0%, transparent 70%); }
body[data-tabata-phase="prepare"] .bg-phase { background: radial-gradient(ellipse 80% 55% at 50% 100%, rgba(var(--accent-rgb),0.07) 0%, transparent 70%); }

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

/* ── Stage ── */
.stage {
  flex: 1; min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap);
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════
   LAYOUT PRINCIPAL — desktop / tablette landscape
   Col gauche (compteurs) | Col droite (timer + phase)
   Hauteur auto — dictée par le timer.
═══════════════════════════════════════════════════════ */
.tabata-layout {
  width: min(92vw, 1100px);
  display: grid;
  grid-template-columns: var(--left-w) 1fr;
  grid-template-rows: auto var(--bar-h);
  gap: var(--gap);
}

/* ═══════════ COLONNE GAUCHE — compteurs ═══════════
   S'étend sur les 2 rows (timer + barre) grâce à
   grid-row: 1 / 3, pour garder la même hauteur totale.
═══════════════════════════════════════════════════════ */
.tabata-left {
  grid-column: 1;
  grid-row: 1 / 3;        /* couvre timer + barre du bas */
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 0;
}

/* Cartes compteurs — s'étirent pour remplir la colonne */
.tabata-ctr-card,
.tabata-total-card {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: clamp(2px, 0.4vh, 6px);
  border-radius: clamp(10px, 1.2vw, 18px);
  background: rgba(var(--panel-rgb), 0.90);
  border: 1px solid var(--border);
  border-top-color: var(--border-hi);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.03) inset;
  backdrop-filter: blur(12px);
  min-height: 0;
}
.tabata-ctr-val {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(28px, 5vw, 80px);
  line-height: 1; letter-spacing: 0.02em;
  color: var(--text);
}
.tabata-ctr-label,
.tabata-total-label {
  font-size: clamp(10px, 1.2vw, 14px);
  font-weight: 700; letter-spacing: 0.5em; text-transform: uppercase;
  color: var(--text-dim);
}
.tabata-total-val {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(28px, 5vw, 80px);
  line-height: 1; letter-spacing: 0.04em;
  color: var(--text);
}

/* ═══════════ TIMER CELL (col 2, row 1) ═══════════
   Hauteur auto — enveloppe le timer + phase + progress + status.
═══════════════════════════════════════════════════ */
.tabata-timer-cell {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: clamp(10px, 1.2vw, 18px);
  background: rgba(var(--panel-rgb), 0.60);
  border: 1px solid var(--border);
  border-top-color: var(--border-hi);
  backdrop-filter: blur(12px);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.03) inset;
  padding: var(--cell-py) var(--cell-px);
  gap: clamp(4px, 0.8vh, 10px);
  overflow: hidden;
}

/* Label de phase — au-dessus du timer */
.tabata-phase-label {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(11px, 1.2vw, 20px);
  letter-spacing: 0.55em; text-transform: uppercase;
  color: var(--text-dim);
  transition: color 0.3s;
  flex-shrink: 0;
}
body[data-tabata-phase="work"]    .tabata-phase-label { color: #00c853; }
body[data-tabata-phase="rest"]    .tabata-phase-label { color: var(--red); }
body[data-tabata-phase="prepare"] .tabata-phase-label { color: var(--accent); }

/* ── Wrap : pleine largeur, hauteur auto ── */
.tabata-timer-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ══════════════════════════════════════════════
   LE GRAND TIMER
   font-size piloté par scaleTimer() (binary search)
   pour remplir ~96 % de la largeur du wrap.
══════════════════════════════════════════════ */
#tabataTime {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 20vw;           /* remplacé immédiatement par JS */
  line-height: 0.88;
  letter-spacing: 0.04em;
  color: #ffffff;
  user-select: none;
  white-space: nowrap;
  display: block;
  text-align: center;
  text-shadow: 0 3px 0 rgba(0,0,0,0.70);
  transition: color 0.25s;
}
body[data-tabata-phase="work"]    #tabataTime { color: #00e85c; text-shadow: 0 3px 0 rgba(0,0,0,0.65); }
body[data-tabata-phase="rest"]    #tabataTime { color: var(--red);    text-shadow: 0 3px 0 rgba(0,0,0,0.65); }
body[data-tabata-phase="prepare"] #tabataTime { color: var(--accent); text-shadow: 0 3px 0 rgba(0,0,0,0.65); }
body[data-tabata-phase="done"]    #tabataTime { color: var(--dim);    text-shadow: 0 3px 0 rgba(0,0,0,0.5); }

/* Barre de progression */
.tabata-progress-track {
  width: 100%; height: 5px; flex-shrink: 0;
  background: rgba(255,255,255,0.06);
  border-radius: 4px; overflow: visible; position: relative;
}
.tabata-progress-fill {
  height: 100%; background: var(--accent); border-radius: 4px;
  transition: width 0.12s linear, background 0.3s;
  position: relative;
  box-shadow: 0 0 10px rgba(var(--accent-rgb),0.5);
}
.tabata-progress-fill::after {
  content: ''; position: absolute; right: -4px; top: 50%;
  transform: translateY(-50%);
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent), 0 0 22px rgba(var(--accent-rgb),0.4);
}
body[data-tabata-phase="work"]    .tabata-progress-fill        { background: #00c853; box-shadow: 0 0 8px rgba(0,200,83,0.6); }
body[data-tabata-phase="work"]    .tabata-progress-fill::after { background: #00c853; box-shadow: 0 0 12px #00c853; }
body[data-tabata-phase="rest"]    .tabata-progress-fill        { background: var(--red);  box-shadow: 0 0 8px rgba(255,60,60,0.6); }
body[data-tabata-phase="rest"]    .tabata-progress-fill::after { background: var(--red);  box-shadow: 0 0 12px var(--red); }
body[data-tabata-phase="prepare"] .tabata-progress-fill        { background: #ffcc00; box-shadow: 0 0 8px rgba(255,204,0,0.6); }
body[data-tabata-phase="prepare"] .tabata-progress-fill::after { background: #ffcc00; box-shadow: 0 0 12px #ffcc00; }

/* Status */
.tabata-status-row {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  width: 100%;
}
.status-bar {
  display: flex; align-items: center; gap: 7px;
  font-size: clamp(11px, 1.4vw, 15px); font-weight: 700;
  letter-spacing: 0.32em; text-transform: uppercase; color: var(--text-dim);
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--border); flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.status-dot.running {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent), 0 0 16px rgba(var(--accent-rgb),0.4);
  animation: blink 1.1s infinite;
}
.status-dot.done { background: var(--red); box-shadow: 0 0 8px var(--red); }

/* ═══════════ BARRE DU BAS — col 2, row 2 ═══════════ */

/* Boutons — col 2 row 2, flex partagé avec phase bar */
.tabata-set-cell {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  gap: var(--gap);
  /* Les boutons prennent ~30 % de la largeur, les phase cards le reste */
}

.tabata-btns {
  display: flex;
  gap: var(--gap);
  flex: none;
  width: clamp(120px, 25%, 260px);
}

.tabata-phase-bar {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--gap);
}

/* On fusionne set-cell + phase-bar dans un seul conteneur flex */
.tabata-bottom-row {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: stretch;
  gap: var(--gap);
  height: var(--bar-h);
}

/* Boutons */
.btn {
  flex: 1;
  font-size: clamp(14px, 1.8vw, 24px);
  border-radius: clamp(7px, 0.8vw, 12px);
  padding: 0; height: 100%;
  cursor: pointer; transition: var(--tr); border: 1px solid transparent;
  display: flex; align-items: center; justify-content: center;
}
.btn:active { transform: scale(0.97) translateY(1px) !important; }

.btn-main {
  background: var(--accent); color: #000;
  box-shadow: 0 3px 18px rgba(var(--accent-rgb),0.35), 0 1px 0 rgba(255,255,255,0.3) inset;
}
.btn-main:hover { filter: brightness(1.08); transform: translateY(-2px); }
.btn-main.is-running { background: rgba(18,34,66,0.95); color: rgba(255,255,255,0.78); border-color: rgba(255,255,255,0.12); box-shadow: none; }
.btn-main.is-running:hover { background: rgba(28,50,90,0.95); color: #fff; border-color: rgba(255,255,255,0.22); filter: none; transform: translateY(-2px); }
.btn-main.is-paused { background: transparent; color: var(--accent); border-color: rgba(var(--accent-rgb),0.48); }
.btn-main.is-paused:hover { background: rgba(var(--accent-rgb),0.07); border-color: rgba(var(--accent-rgb),0.7); transform: translateY(-2px); }
.btn-reset { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-reset:hover { background: rgba(255,60,60,0.08); color: var(--red); border-color: rgba(255,60,60,0.35); transform: translateY(-2px); }

/* Phase cards */
.tabata-phase-card {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: clamp(2px, 0.4vh, 5px);
  border-radius: clamp(8px, 1vw, 14px);
  border: 1px solid transparent;
  opacity: 0.42;
  transition: opacity 0.3s, box-shadow 0.3s, border-color 0.3s;
  user-select: none;
}
.tabata-phase-card--prepare { background: linear-gradient(145deg, #ffcc00, #e6a800); color: #000; }
.tabata-phase-card--work    { background: linear-gradient(145deg, #00c853, #009940); color: #000; }
.tabata-phase-card--rest    { background: linear-gradient(145deg, #ff3c3c, #c42828); color: #fff; }

body[data-tabata-phase="prepare"] .tabata-phase-card--prepare { opacity: 1; border-color: rgba(255,220,0,0.55);  box-shadow: 0 4px 24px rgba(255,204,0,0.55); }
body[data-tabata-phase="work"]    .tabata-phase-card--work    { opacity: 1; border-color: rgba(0,200,83,0.55);   box-shadow: 0 4px 24px rgba(0,200,83,0.55); }
body[data-tabata-phase="rest"]    .tabata-phase-card--rest    { opacity: 1; border-color: rgba(255,60,60,0.55);  box-shadow: 0 4px 24px rgba(255,60,60,0.55); }

.phase-card-time {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(18px, 2.8vw, 42px);
  line-height: 1; letter-spacing: 0.06em;
}
.phase-card-label {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: clamp(10px, 1.2vw, 14px);
  font-weight: 700; letter-spacing: 0.35em; text-transform: uppercase;
  opacity: 0.72;
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE — portrait / mobile
══════════════════════════════════════════════════════ */
@media (orientation: portrait), (max-aspect-ratio: 1/1) {
  .tabata-layout {
    width: min(96vw, 700px);
    /* Compteurs en ligne en haut | timer | barre du bas */
    grid-template-columns: 1fr;
    grid-template-rows: auto auto var(--bar-h);
    gap: clamp(8px, 1.2vh, 12px);
  }

  :root { --bar-h: clamp(54px, 9vh, 80px); }

  /* Compteurs : ligne horizontale en haut */
  .tabata-left {
    grid-column: 1;
    grid-row: 1;
    flex-direction: row;
    min-height: clamp(70px, 12dvh, 110px);
    max-height: clamp(80px, 14dvh, 120px);
  }

  .tabata-ctr-val,
  .tabata-total-val {
    font-size: clamp(24px, 7vw, 52px);
  }
  .tabata-ctr-label,
  .tabata-total-label {
    font-size: clamp(9px, 2.2vw, 13px);
  }

  /* Timer cell */
  .tabata-timer-cell {
    grid-column: 1;
    grid-row: 2;
  }

  /* Barre du bas */
  .tabata-bottom-row {
    grid-column: 1;
    grid-row: 3;
  }

  .btn { font-size: clamp(16px, 4.5vw, 26px); }

  .phase-card-time  { font-size: clamp(14px, 4.5vw, 28px); }
  .phase-card-label { font-size: clamp(8px, 2vw, 12px); letter-spacing: 0.2em; }
}

@media (max-width: 380px) { .tabata-layout { width: 98vw; } }

/* Paysage très serré */
@media (max-height: 460px) and (orientation: landscape) {
  :root { --bar-h: clamp(44px, 8vh, 58px); --left-w: clamp(100px, 14vw, 160px); --gap: 5px; }
  .tabata-phase-label { display: none; }
}

/* ══════════════════════════════════════════════════════
   MODAL SETUP
══════════════════════════════════════════════════════ */
.tabata-setup-overlay {
  display: none; position: fixed; inset: 0; z-index: 400;
  background: rgba(2,2,8,0.92); align-items: center; justify-content: center;
  backdrop-filter: blur(18px);
}
.tabata-setup-overlay.visible { display: flex; animation: tabataFadeIn 0.18s ease; }
.tabata-setup-modal {
  background: #061428;
  border: 1px solid rgba(255,255,255,0.07);
  border-top: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  width: min(520px, 94vw); 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: tabataModalIn 0.2s cubic-bezier(0.34,1.4,0.64,1);
  position: relative;
}
.tabata-setup-modal::before {
  content: ''; position: absolute; top: 0; left: 10%; right: 10%; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(var(--accent-rgb),0.35) 40%, rgba(var(--accent-rgb),0.35) 60%, transparent);
}
.tm-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding: clamp(12px,2vw,15px) clamp(14px,2.5vw,18px); border-bottom: 1px solid rgba(255,255,255,0.06); background: rgba(255,255,255,0.02); flex-shrink: 0; }
.tm-title  { flex: 1; font-size: clamp(12px, 2vw, 15px); font-weight: 700; letter-spacing: 0.3em; text-transform: uppercase; color: var(--text); display: flex; align-items: center; gap: 8px; }
.tm-title i { color: var(--accent); opacity: 0.8; font-size: clamp(12px, 2vw, 15px); }
.tm-close  { font-family: 'Barlow Condensed', sans-serif; font-size: 11px; font-weight: 700; letter-spacing: 0.12em; background: transparent; border: 1px solid var(--border); border-radius: 6px; color: rgba(255,255,255,0.22); padding: 4px 10px; cursor: pointer; transition: all 0.15s; min-height: 32px; }
.tm-close:hover { border-color: var(--red); color: var(--red); }
.tm-body   { overflow-y: auto; }
.tm-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; padding: clamp(10px,1.8vh,13px) clamp(14px,2.5vw,18px); border-top: 1px solid rgba(255,255,255,0.05); flex-shrink: 0; }
.tm-btn-next { font-family: 'Barlow Condensed', sans-serif; font-size: clamp(12px, 2vw, 15px); font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; padding: 10px 22px; border-radius: 8px; cursor: pointer; background: var(--accent); color: #000; border: none; box-shadow: 0 4px 16px rgba(var(--accent-rgb),0.25); transition: all 0.15s; min-height: 40px; }
.tm-btn-next:hover { filter: brightness(1.08); transform: translateY(-1px); }
.co-toggle-row   { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 52px; padding: clamp(8px, 1.5vh, 10px) clamp(14px, 2.5vw, 18px); }
.co-toggle-info  { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.co-toggle-label { font-size: clamp(12px, 2vw, 15px); font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text) !important; }
.co-toggle-sub   { font-size: 11px; letter-spacing: 0.06em; color: rgba(255,255,255,0.4); }
.co-divider      { height: 1px; background: var(--border-hi); margin: 10px 0; }
.tabata-label--prepare { color: #ffcc00; }
.tabata-label--work    { color: #00c853; }
.tabata-label--rest    { color: #ff4440; }
.tabata-time-inputs { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.tabata-time-inputs .input-spin { position: relative; width: 76px; }
.tabata-time-inputs input { font-family: 'Bebas Neue', sans-serif; font-size: 26px; width: 100%; background: rgba(4,14,32,0.88); border: 1px solid var(--border); border-radius: 10px; color: var(--text); text-align: center; padding: 4px 30px 4px 4px; outline: none; line-height: 1; -moz-appearance: textfield; appearance: textfield; transition: border-color 0.2s; }
.tabata-time-inputs input:focus { border-color: rgba(var(--accent-rgb),0.35); }
.tabata-time-inputs input::-webkit-outer-spin-button, .tabata-time-inputs input::-webkit-inner-spin-button { -webkit-appearance: none; }
.tabata-time-inputs .spin-btns { position: absolute; top: 2px; right: 3px; bottom: 2px; display: flex; flex-direction: column; justify-content: center; gap: 1px; }
.tabata-time-inputs .spin-btn { background: none; border: none; cursor: pointer; color: rgba(255,255,255,0.3); font-size: 11px; padding: 0; width: 22px; height: 18px; display: flex; align-items: center; justify-content: center; border-radius: 4px; transition: color 0.15s, background 0.15s; }
.tabata-time-inputs .spin-btn:hover { color: var(--accent); }
.tabata-time-sep { font-family: 'Bebas Neue', sans-serif; font-size: 20px; color: rgba(255,255,255,0.2); padding: 0 2px; }
.tabata-stepper { display: flex; align-items: center; gap: 3px; background: transparent; border: none; border-radius: 10px; padding: 3px 7px; flex-shrink: 0; }
.tabata-stepper input { font-family: 'Bebas Neue', sans-serif; font-size: 28px; width: 40px; background: transparent; border: none; color: var(--text); text-align: center; padding: 0; outline: none; line-height: 1; pointer-events: none; -moz-appearance: textfield; appearance: textfield; }
.tabata-stepper input::-webkit-outer-spin-button, .tabata-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.tabata-stepper-btn { background: transparent; border: none; color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 10px; transition: color 0.15s; border-radius: 5px; min-width: 28px; min-height: 28px; }
.tabata-stepper-btn:hover { color: var(--accent); }
.tabata-setup-cancel { font-family: 'Barlow Condensed', sans-serif; font-size: clamp(12px, 2vw, 15px); font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; padding: 10px 16px; border-radius: 8px; background: transparent; border: 1px solid rgba(255,255,255,0.12); color: rgba(255,255,255,0.45); cursor: pointer; transition: all 0.15s; min-height: 40px; }
.tabata-setup-cancel:hover { border-color: rgba(255,255,255,0.3); color: rgba(255,255,255,0.8); }

/* ── Keyframes ── */
@keyframes blink         { 0%, 100% { opacity: 1; } 50% { opacity: 0.1; } }
@keyframes tabataFadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes tabataModalIn { from { opacity: 0; transform: scale(0.95) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }