/* Paleta da marca HODIE Jiu-Jitsu: preto, vermelho e branco.
   O tema é sempre escuro, como a logo. Para ajustar o vermelho, mude só --brand.
   Pensado primeiro para celular (375 px): alvos de toque de 44 px, texto de 16 px nos campos
   (o iPhone dá zoom abaixo disso) e áreas seguras do aparelho respeitadas. */
:root {
  color-scheme: dark;
  --brand: #e1242c;
  --brand-strong: #ff3b43;
  --bg: #000000;
  --panel: #121212;
  --text: #ffffff;
  --muted: #a3a3a3;
  --line: #2e2e2e;
  --field-line: #7a7a7a;
  --work: var(--brand);
  --rest: #ffffff;
  --rest-text: #000000;
  --prep: #2e2e2e;
  --done: #000000;
  --accent: var(--brand);
  --alert: var(--brand-strong);
  --tap: 44px;
  --display: Impact, "Haettenschweiler", "Arial Narrow Bold", "Arial Black", system-ui, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding-block: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-bottom));
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible { outline: 3px solid #ffffff; outline-offset: 3px; }

/* ---------- Cabeçalho ---------- */

.top {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-logo {
  height: clamp(56px, 16vw, 96px);
  width: auto;
  border-radius: 6px;
}

h1 {
  margin: 0;
  min-width: 0;
  font-family: var(--display);
  font-weight: 400;
  line-height: .9;
  text-transform: uppercase;
  color: var(--text);
}
.brand-name { display: block; font-size: clamp(2rem, 9vw, 2.6rem); letter-spacing: .02em; }
.brand-sub { display: block; font-size: clamp(.85rem, 3.4vw, 1.05rem); letter-spacing: .12em; color: var(--brand-strong); }

h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.1rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin: 20px 0 4px;
  padding-left: 8px;
  border-left: 3px solid var(--brand);
}

/* Logo do topo do timer: a da academia, se enviada; senão a marca, só no modo parede. */
.logo {
  max-width: 200px;
  max-height: 90px;
  object-fit: contain;
}
.logo.brand-only { display: none; }

.panel {
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}
.timer-panel { border-top: 4px solid var(--brand); }

/* ---------- Timer ---------- */

/* Fases: luta = vermelho; descanso = branco; preparação = cinza; fim = preto com borda. */
.phase {
  text-align: center;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.35rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 8px;
  border-radius: 8px;
  color: var(--text);
  background: var(--line);
  border: 2px solid transparent;
  overflow-wrap: anywhere;
}
.phase.work { background: var(--work); }
.phase.rest { background: var(--rest); color: var(--rest-text); }
.phase.prep { background: var(--prep); border-color: var(--brand); }
.phase.done { background: var(--done); border-color: var(--brand); color: var(--brand-strong); }
/* Contagem final: branco com texto vermelho, piscando só 3 vezes (não pisca sem parar). */
.phase.warn { background: #ffffff; color: var(--brand); animation: blink 1s steps(2, start) 3; }

@keyframes blink {
  to { background: var(--brand); color: #ffffff; }
}

@media (prefers-reduced-motion: reduce) {
  .phase.warn { animation: none; }
}

.clock {
  text-align: center;
  font-size: clamp(4.5rem, 22vw, 8rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  margin: 12px 0 4px;
}
.clock.paused { opacity: .45; }

.meta {
  text-align: center;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 4px 0;
}
.total, .hint {
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
  margin: 4px 0;
}

.admin .hint { text-align: left; }

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}
.controls button { min-height: 52px; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

/* ---------- Botões e campos ---------- */

button, .button {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 14px;
  min-height: var(--tap);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
}
.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--muted);
}
.danger { color: var(--alert); border-color: var(--alert); }
/* Primeiro toque em ação destrutiva: o botão fica branco e pede confirmação. */
button.armed { background: #ffffff; color: var(--brand); border-color: #ffffff; }
button:disabled { opacity: .4; cursor: default; }

.stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .9rem;
  color: var(--muted);
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  font-size: .95rem;
  color: var(--text);
}

input, select {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--field-line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  touch-action: manipulation;
}
.check input {
  width: 24px;
  height: 24px;
  min-height: 0;
  accent-color: var(--brand);
}

input:invalid { border-color: var(--alert); }

.row input { flex: 1; width: auto; }

/* ---------- Editor ---------- */

.editor {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-margin-top: 12px;
}

.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.apply-all {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.beep-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.cycles { display: flex; flex-direction: column; gap: 14px; }

.cycle {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cycle > .small { align-self: flex-start; margin-top: 4px; }

.cycle-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.cycle-head h3 { margin: 0; font-size: 1rem; }
.cycle-actions { display: flex; gap: 8px; }

button.small { padding: 8px 12px; font-size: .9rem; }
button.icon { padding: 8px 0; min-width: var(--tap); justify-self: end; background: transparent; border-color: transparent; }
button.icon.danger { color: var(--alert); }

/* Cada tempo ocupa três linhas: nome | preparação, duração, descanso | contagem.
   Funciona igual no celular e no desktop (o painel nunca passa de 560 px). */
.round-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-areas:
    "name name name name name del"
    "prep prep dur  dur  rest rest"
    "up   up   up   up   up   up";
  gap: 8px 6px;
  align-items: end;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.cycle .round-row:last-of-type { border-bottom: 0; padding-bottom: 0; }
.c-name { grid-area: name; }
.c-prep { grid-area: prep; }
.c-dur { grid-area: dur; }
.c-rest { grid-area: rest; }
.c-up { grid-area: up; }
.c-del { grid-area: del; align-self: end; }
.no-rest .rest-field { display: none; }

/* Legenda de cada campo, sempre visível: sem cabeçalho de colunas. */
.f { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cap { font-size: .8rem; color: var(--muted); }

/* ---------- Configurações ---------- */

.settings-toggle { margin-top: 16px; }
.settings-panel { margin-top: 4px; }

.sync-status { font-size: .9rem; margin: 6px 0; color: var(--muted); }
.sync-status[data-status="ok"] { color: var(--text); }
.sync-status[data-status="offline"],
.sync-status[data-status="unauthorized"],
.sync-status[data-status="error"] { color: var(--alert); }

.code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .05em;
  color: var(--text);
  user-select: all;
}

/* Aviso rápido no topo: fica visível mesmo com o teclado aberto ou a tela rolada. */
.notice {
  position: fixed;
  z-index: 30;
  top: max(12px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  max-width: 560px;
  margin-inline: auto;
  padding: 12px 14px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--brand-strong);
  border-radius: 10px;
  font-size: .95rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .6);
}
.notice:empty { display: none; }

/* Fica no fluxo, abaixo dos controles: um botão fixo no canto cobria o "Zerar treino". */
.exit {
  align-self: center;
  background: var(--panel);
  color: var(--text);
  border: 2px solid #ffffff;
}

/* ---------- Modo parede (display do coach) ---------- */

body.wall {
  justify-content: center;
  gap: 1.5vh;
  padding-block: max(2vh, env(safe-area-inset-top)) max(2vh, env(safe-area-inset-bottom));
  padding-inline: max(2vw, env(safe-area-inset-left)) max(2vw, env(safe-area-inset-right));
}
.wall .top, .wall .admin, .wall .hint { display: none; }
.wall .logo {
  max-width: 50vw;
  max-height: 16vh;
  max-height: 16dvh;
}
.wall .logo.brand-only { display: block; }
.wall .timer-panel {
  max-width: none;
  background: transparent;
  border-color: transparent;
  padding: 0;
}
.wall .phase { font-size: clamp(1.5rem, 5vw, 4rem); }
/* O relógio respeita a largura E a altura da tela, para os botões não saírem do visor. */
.wall .clock {
  font-size: min(30vw, 36vh);
  font-size: min(30vw, 36dvh);
  margin: 1vh 0;
}
.wall .meta, .wall .total { font-size: clamp(1rem, 2.5vw, 2rem); }
.wall .controls { max-width: 720px; margin: 1.5vh auto 0; }

/* ---------- Telas médias e celulares ---------- */

@media (pointer: coarse) {
  .timer-panel > .hint { display: none; }
}

@media (max-width: 480px) {
  .panel { padding: 16px; }
  .controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .controls button { font-size: .9rem; padding-inline: 6px; line-height: 1.15; }
  .controls #startBtn { grid-column: 1 / -1; min-height: 68px; font-size: 1.3rem; }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .apply-all { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .apply-all button { grid-column: 1 / -1; }
  .beep-row { grid-template-columns: minmax(0, 1fr); }
  .cycle { padding: 10px; }
}

/* Celular deitado: a tela é baixa, então o modo parede esconde a logo e o total
   e reduz o relógio, para o relógio, os botões e o "Sair" caberem sem rolar. */
@media (orientation: landscape) and (max-height: 480px) {
  .wall .logo, .wall .total { display: none; }
  .wall .phase { font-size: clamp(1rem, 4vw, 1.6rem); padding: 4px; }
  .wall .clock { font-size: min(24vw, 32vh); font-size: min(24vw, 32dvh); margin: 0; }
  .wall .controls { margin-top: 0; }
  .wall .controls button { min-height: 44px; }
}
