:root {
  --rouge: #ff2a2a;
  --rouge-hover: #e02424;
  --bg: #111;
  --bg-card: #1c1c1c;
  --bg-elev: #252525;
  --text: #fff;
  --muted: #9a9a9a;
  --line: #333;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
}

html {
  font-size: 18px;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: rgba(255, 42, 42, 0.35);
  touch-action: manipulation;
}

.credits {
  margin-top: 1.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: calc(0.75rem + var(--safe-t)) 1rem 0.75rem;
  background: var(--rouge);
}

.topbar svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.topbar h1 {
  flex: 1;
  min-width: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.topbar-link {
  flex-shrink: 0;
  color: #fff;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.55);
  white-space: nowrap;
}

.topbar-link:active {
  background: rgba(0, 0, 0, 0.15);
}

.page {
  padding: 1rem 1rem calc(1rem + var(--safe-b));
}

.page-title {
  font-size: 1.35rem;
  margin-bottom: 0.85rem;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.search-field {
  display: block;
  margin-bottom: 0.75rem;
}

.search-field input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  padding: 0.6rem 0.7rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

.chip.is-on {
  background: var(--rouge);
  border-color: var(--rouge);
  color: #fff;
}

.card-list {
  display: grid;
  gap: 0.65rem;
}

.card {
  display: grid;
  grid-template-columns: 4.4rem 1fr;
  gap: 0.75rem;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--line);
  padding: 0.65rem 0.75rem;
  text-align: left;
  width: 100%;
  color: inherit;
  text-decoration: none;
}

.card:active { background: #2a1818; }

.illu {
  width: 4.4rem;
  height: 4.4rem;
  background: #141414;
  display: grid;
  place-items: center;
}

.illu img {
  width: 4.2rem;
  height: 4.2rem;
  object-fit: contain;
}

.card h2, .card .nom {
  font-size: 1.05rem;
  font-weight: 700;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--rouge);
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  background: transparent;
  text-decoration: none;
  color: inherit;
  margin-top: 0.5rem;
}

.btn-primary {
  background: var(--rouge);
  border-color: var(--rouge);
  color: #fff;
  font-weight: 700;
}

.btn-primary:active { background: var(--rouge-hover); }

.btn-ghost { color: var(--muted); }

.field {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.85rem;
}

.field label {
  font-size: 0.8rem;
  color: var(--muted);
}

.field input, .field select, .field textarea {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  padding: 0.6rem 0.7rem;
  width: 100%;
}

.field textarea { resize: vertical; min-height: 3.2rem; }

.field-inline {
  grid-template-columns: auto 5rem;
  align-items: center;
}

.canvas {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 12rem;
  margin: 0.4rem 0 0.75rem;
}

.canvas-item {
  background: var(--bg-card);
  border: 1px solid var(--line);
  padding: 0.55rem;
}

.canvas-item.is-on { border-color: var(--rouge); }

.canvas-item.is-dragging {
  opacity: 0.55;
  border-color: var(--rouge);
}

.canvas-head {
  display: grid;
  grid-template-columns: 1.6rem 1.2rem 1fr;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.45rem;
}

.drag-handle {
  width: 2.6rem;
  height: 2.6rem;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  display: grid;
  gap: 4px;
  place-content: center;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.drag-handle i {
  display: block;
  width: 16px;
  height: 2px;
  background: #777;
}

.drag-placeholder {
  border: 1px dashed var(--rouge);
  background: rgba(255, 42, 42, 0.12);
  min-height: 3rem;
}

.edit-block.is-dragging {
  opacity: 0.92;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.dur-wrap {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.dur-wrap .dur {
  width: auto;
  min-width: 6.8rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  padding: 0.35rem 0.4rem;
}

.dur-wrap [data-reps] { min-width: 4rem; }

.canvas-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.fin-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.5rem;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.fin-row select {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  padding: 0.35rem 0.4rem;
}

.dur-wrap.is-off,
.approx-wrap.is-off { display: none; }

.approx-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.canvas-item [data-titre],
.canvas-item [data-groupe-nom] {
  display: block;
  margin-top: 0.45rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  padding: 0.45rem 0.55rem;
  width: 100%;
}

.canvas-group {
  border-left: 3px solid var(--rouge);
}

.canvas-group > .canvas-head {
  grid-template-columns: 1.6rem 1.2rem 1fr auto;
}

.fold-btn {
  width: 1.85rem;
  height: 1.85rem;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: inherit;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0;
}

.fold-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.group-preview {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.4rem 0 0;
}

.canvas-group.is-min .canvas-group-items,
.canvas-group.is-min [data-ungroup] { display: none; }

.canvas-group:not(.is-min) .group-preview { display: none; }

.canvas-group-items {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0.5rem 0;
  padding-left: 0.35rem;
}

.step-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-left: 0.55rem;
  border-left: 3px solid var(--rouge);
}

.step.is-group {
  grid-template-columns: 1fr auto;
}

.canvas-head select {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  padding: 0.35rem 0.4rem;
  width: 100%;
}

.canvas-pick { margin: 0; }

.perso-grid {
  display: grid;
  grid-template-columns: 4.4rem 1fr;
  gap: 0.55rem;
  align-items: start;
}

.perso-fields { display: grid; gap: 0.35rem; }

.perso-fields input,
.perso-fields textarea {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  padding: 0.45rem 0.55rem;
  width: 100%;
}

.icon-pick {
  border: 0;
  padding: 0;
  background: transparent;
}

.illu-empty {
  border: 1px dashed #444;
  background: #101010;
}

.sel-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.65rem;
  padding: 0.45rem 0.55rem;
  background: #1a1a1a;
  border: 1px solid var(--rouge);
  color: var(--muted);
  font-size: 0.85rem;
}

.btn-compact {
  width: auto;
  margin-top: 0;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.icon-opt {
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  padding: 0.4rem;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
}

.icon-opt .illu {
  width: 3.4rem;
  height: 3.4rem;
}

.icon-opt .illu img {
  width: 3.2rem;
  height: 3.2rem;
}

.step-list { display: grid; gap: 0.5rem; }

.step {
  display: grid;
  grid-template-columns: 3.2rem 1fr auto;
  gap: 0.55rem;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--line);
  padding: 0.5rem;
}

.page-edit .step {
  grid-template-columns: auto 3.2rem 1fr auto;
}

.page-edit .step.is-group {
  grid-template-columns: auto 1fr auto;
}

.step-tools {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: center;
}

.step-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  text-align: right;
  color: var(--muted);
  font-size: 0.8rem;
}

.step-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.3rem;
}

.step.is-on { border-color: var(--rouge); }

.picker-sheet .canvas-head {
  grid-template-columns: 1fr;
}

.step.is-rest {
  color: var(--muted);
}

.step .dur {
  width: 4.2rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  padding: 0.35rem 0.4rem;
  text-align: center;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.25rem 0.4rem;
  font-size: 1.1rem;
}

.detail-illu {
  width: 100%;
  max-width: 14rem;
  margin: 0 auto 1rem;
  background: #141414;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.detail-illu .illu,
.player-illu .illu {
  width: 100%;
  height: 100%;
  background: transparent;
}

.detail-illu img,
.player-illu img {
  width: 90%;
  height: 90%;
  object-fit: contain;
}

.player {
  min-height: 100dvh;
  padding: calc(1rem + var(--safe-t)) 1rem calc(1.25rem + var(--safe-b));
  display: flex;
  flex-direction: column;
  background: #0c0c0c;
}

.player.is-rest { background: #161616; }

.player-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
}

.player-illu {
  margin: 1.2rem auto 0.5rem;
  width: min(58vw, 16rem);
  aspect-ratio: 1;
  background: #141414;
  display: grid;
  place-items: center;
}

.step .illu {
  width: 3.2rem;
  height: 3.2rem;
}

.step .illu img {
  width: 3rem;
  height: 3rem;
}

.player h2 {
  text-align: center;
  font-size: 1.6rem;
  margin: 0.4rem 0 0.2rem;
}

.player .complement {
  text-align: center;
  color: var(--muted);
  margin: 0 0 0.15rem;
}

.player .desc {
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.35;
  color: #d8d8d8;
  margin: 0.35rem 0 0.2rem;
  max-height: 5.6em;
  overflow: auto;
  padding: 0 0.15rem;
}

.player.has-desc .player-illu {
  width: min(42vw, 12rem);
  margin-top: 0.55rem;
}

.player .cote {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--rouge);
  margin: 0.15rem 0 0.2rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.55rem 0 0.35rem;
  font-size: 0.9rem;
}

.check-row input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--rouge);
}

.player .next {
  text-align: center;
  color: var(--muted);
  min-height: 1.3em;
}

.timer {
  font-size: clamp(67px, 22vw, 104px);
  font-weight: 700;
  text-align: center;
  line-height: 1;
  margin: auto 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}

.progress {
  height: 6px;
  background: #2a2a2a;
  margin: 0.75rem 0 1.1rem;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--rouge);
  width: 0%;
}

.progress.is-manual {
  visibility: hidden;
}

.player-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 0.5rem;
}

.empty {
  color: var(--muted);
  padding: 1.5rem 0.25rem;
  text-align: center;
}

.picker {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: flex-end;
}

.picker.picker-center {
  align-items: center;
  justify-content: center;
  padding: calc(0.75rem + var(--safe-t)) 0.85rem calc(0.75rem + var(--safe-b));
}

.picker-sheet {
  width: 100%;
  max-height: 82dvh;
  overflow: auto;
  background: #171717;
  border-top: 1px solid var(--rouge);
  padding: 1rem 1rem calc(1rem + var(--safe-b));
}

.picker-center .picker-sheet {
  width: min(100%, 32rem);
  max-height: min(86dvh, calc(100dvh - var(--safe-t) - var(--safe-b) - 1.5rem));
  border: 1px solid var(--rouge);
  font-size: 20px;
  padding: 1rem;
}

.seance-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.step-time {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.85rem;
}

#app.player-mode { padding-bottom: 0; }
