:root {
  --felt: #0b3d2e;
  --felt-2: #062a20;
  --felt-3: #041c15;
  --gold: #e0b84c;
  --gold-2: #f4d77d;
  --cream: #f6f1e3;
  --muted: #9fb8ac;
  --card: rgba(255, 255, 255, .06);
  --line: rgba(255, 255, 255, .13);
  --danger: #e5484d;
  --warn: #f5a524;
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--cream);
  background: radial-gradient(ellipse at 50% 0%, var(--felt) 0%, var(--felt-2) 55%, var(--felt-3) 100%) fixed;
  min-height: 100dvh;
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Barre du haut ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 10px; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); }
.brand-name {
  font-size: 1.4rem; font-weight: 800; letter-spacing: .02em;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  border: 1px solid var(--line); background: rgba(255, 255, 255, .1);
  padding: .55em 1em; border-radius: 999px; font-weight: 600;
  transition: background .15s, transform .05s;
}
.btn:hover { background: rgba(255, 255, 255, .18); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.small { font-size: .85rem; padding: .4em .85em; }
.btn.primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #1b2a12; border-color: transparent; }
.btn.danger { border-color: rgba(229, 72, 77, .6); color: #ff9a9d; background: transparent; }
.btn.danger:hover { background: rgba(229, 72, 77, .15); }
:focus-visible { outline: 3px solid var(--gold-2); outline-offset: 2px; }

/* ---------- Mise en page ---------- */
.layout {
  display: grid; gap: 18px;
  grid-template-columns: 1fr;
  padding: 0 clamp(12px, 3vw, 28px) 12px;
  max-width: 1400px; margin: 0 auto;
}
@media (min-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
}

.stage {
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .03));
  border: 1px solid var(--line); border-radius: 28px;
  padding: clamp(16px, 3vw, 34px) clamp(12px, 3vw, 30px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
  transition: box-shadow .3s, border-color .3s;
}
.t-name { margin: 0; color: var(--muted); font-size: clamp(.9rem, 1.6vw, 1.1rem); letter-spacing: .08em; text-transform: uppercase; }
.level-tag {
  display: inline-block; margin: 10px 0 0; padding: .3em 1.1em; border-radius: 999px;
  background: rgba(224, 184, 76, .16); color: var(--gold-2); font-weight: 800;
  font-size: clamp(1.1rem, 2.4vw, 1.7rem);
}
.is-break .level-tag { background: rgba(80, 200, 160, .18); color: #7be3c1; }
.caption { margin: 14px 0 0; color: var(--muted); font-size: clamp(.95rem, 1.8vw, 1.25rem); }

.clock {
  font-weight: 800; line-height: 1.05; letter-spacing: .01em;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
  font-size: clamp(4rem, min(21vw, 34vh), 15rem);
  margin: .05em 0 .1em;
  text-shadow: 0 6px 30px rgba(0, 0, 0, .45);
}
.clock.warn { color: var(--warn); }
.clock.danger { color: var(--danger); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.progress { height: 10px; border-radius: 999px; background: rgba(255, 255, 255, .1); overflow: hidden; margin: 6px auto 22px; max-width: 820px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--gold-2)); transition: width .3s linear; }
.is-break .progress > div { background: linear-gradient(90deg, #35b48f, #7be3c1); }

.blinds-label { margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: .85rem; }
.blinds { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.blind-box {
  min-width: min(190px, 42vw); padding: 12px 22px; border-radius: var(--radius);
  background: rgba(0, 0, 0, .28); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px;
}
.blind-box .k { color: var(--muted); font-size: .85rem; }
.blind-box .v { font-size: clamp(1.8rem, 5vw, 3.4rem); font-weight: 800; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.next-info { margin: 16px 0 0; color: var(--muted); font-size: clamp(1rem, 1.8vw, 1.3rem); min-height: 1.5em; }
.next-info b { color: var(--cream); }

.controls { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.round {
  min-width: 56px; height: 56px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .1);
  font-size: 1rem; font-weight: 700; transition: background .15s, transform .05s;
}
.round:hover { background: rgba(255, 255, 255, .2); }
.round:active { transform: scale(.96); }
.round.primary {
  width: 84px; height: 84px; font-size: 1.9rem;
  background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #1b2a12; border-color: transparent;
  box-shadow: 0 8px 24px rgba(224, 184, 76, .35);
}

.stage.flash { animation: flash 1.6s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 0 rgba(244, 215, 125, .9), 0 20px 50px rgba(0, 0, 0, .35); border-color: var(--gold-2); }
  100% { box-shadow: 0 0 0 40px rgba(244, 215, 125, 0), 0 20px 50px rgba(0, 0, 0, .35); }
}

/* ---------- Colonne de droite ---------- */
.side { display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 10px; font-size: .85rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.counter { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.counter + .counter { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; }
.c-val { text-align: center; }
.c-val b { display: block; font-size: 2.2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.c-val small { color: var(--muted); }
.mini { width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .1); font-size: 1.4rem; font-weight: 700; }
.mini:hover { background: rgba(255, 255, 255, .2); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats small { display: block; color: var(--muted); font-size: .75rem; margin-bottom: 4px; }
.stats b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.upcoming { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.upcoming li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 10px; background: rgba(0, 0, 0, .2); font-size: .95rem; }
.upcoming li b { color: var(--gold-2); font-variant-numeric: tabular-nums; }
.upcoming li small { color: var(--muted); font-weight: 400; }
.upcoming li span:last-child { color: var(--muted); }
.upcoming li.brk { background: rgba(80, 200, 160, .12); color: #7be3c1; grid-template-columns: 1fr auto; }
.upcoming li.muted { color: var(--muted); grid-template-columns: 1fr; }

/* ---------- Bannière de mise à jour ---------- */
.update-banner {
  position: sticky; top: 0; z-index: 50; display: flex; gap: 12px; align-items: center; justify-content: center;
  padding: 10px 14px; background: var(--gold); color: #1b2a12; font-weight: 600; text-align: center; flex-wrap: wrap;
}
.update-banner button { border: 0; background: #1b2a12; color: var(--gold-2); padding: .4em 1em; border-radius: 999px; font-weight: 700; }

/* ---------- Réglages (dialog) ---------- */
dialog {
  width: min(820px, calc(100% - 20px)); max-height: calc(100dvh - 20px);
  padding: 0; border: 1px solid var(--line); border-radius: 22px;
  background: #0d3226; color: var(--cream); box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(3px); }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 20px); }
.dlg-head, .dlg-foot { display: flex; align-items: center; gap: 10px; padding: 14px 18px; }
.dlg-head { justify-content: space-between; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 1.2rem; }
.dlg-foot { border-top: 1px solid var(--line); flex-wrap: wrap; }
.dlg-foot .spacer { flex: 1; }
.dlg-body { padding: 16px 18px; overflow: auto; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; padding: 6px 10px; border-radius: 8px; }
.icon-btn:hover { background: rgba(255, 255, 255, .1); color: var(--cream); }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; color: var(--muted); }
input[type="text"], input[type="number"], select {
  width: 100%; padding: .55em .7em; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, .3); color: var(--cream);
}
input:disabled { opacity: .35; }

.struct-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 20px 0 8px; flex-wrap: wrap; }
.struct-head h3 { margin: 0; font-size: 1rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table.struct { width: 100%; border-collapse: collapse; min-width: 560px; }
.struct th { text-align: left; font-size: .75rem; color: var(--muted); font-weight: 600; padding: 8px; background: rgba(0, 0, 0, .25); }
.struct td { padding: 4px 6px; border-top: 1px solid var(--line); }
.struct td.n { width: 40px; text-align: center; color: var(--muted); }
.struct input, .struct select { padding: .4em .5em; }
.struct tr.is-break td { background: rgba(80, 200, 160, .08); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- Pied de page (centré en bas de l'écran) ---------- */
.footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: center; text-align: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  font-size: .85rem; color: var(--muted);
  background: linear-gradient(0deg, rgba(4, 28, 21, .95), rgba(4, 28, 21, .6));
  pointer-events: none;
}
.noscript { text-align: center; padding: 20px; }

/* ---------- Petits écrans ---------- */
@media (max-width: 520px) {
  .tools .btn { font-size: .8rem; padding: .45em .8em; }
  .round { min-width: 48px; height: 48px; padding: 0 12px; }
  .round.primary { width: 72px; height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  .clock.danger, .stage.flash { animation: none; }
}
