:root {
  --bg: #232323;
  --bg-2: #2c2c2c;
  --bg-3: #3d3d3d;
  --line: #3a3a3a;
  --text: #ffffff;
  --muted: #8a8a8a;
  --yellow: #fcff3c;
  --green: #9bff45;
  --red: #ff3b30;
  --blue: #3ea6e6;
  --ink: #000000;
  --font: "Bebas Neue", "Oswald", "Arial Narrow", Impact, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #111;
  color: var(--text);
  font-family: var(--font);
  letter-spacing: .02em;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; letter-spacing: inherit; touch-action: manipulation; }
ul { list-style: none; margin: 0; padding: 0; }
svg { display: block; }
.hidden { display: none !important; }

#app {
  position: relative;
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#screens { flex: 1; min-height: 0; display: flex; }
.screen { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------- cabeçalho do timer ---------- */
.timer-head {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  padding: calc(var(--safe-top) + 8px) 10px 4px;
  color: var(--yellow);
  flex: none;
}
.timer-title { text-align: center; font-size: 28px; line-height: 1.1; }
.timer-title > div:first-child { font-size: 25px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; color: var(--yellow); }
.icon-btn svg { width: 28px; height: 28px; }
.icon-btn.small { width: 36px; height: 36px; color: #6a6a6a; }
.icon-btn.small svg { width: 26px; height: 26px; }
.icon-btn.small.on { color: var(--green); }
.icon-btn:active { opacity: .6; }

/* ---------- painel da fase ---------- */
.phase-panel {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--panel, var(--yellow));
  color: var(--ink);
  transition: background-color .25s ease;
  width: 100%;
  padding: 0 0 10px;
  text-align: center;
  container-type: size; /* números escalam pelo tamanho real do painel */
}
.phase-label {
  font-size: min(19cqw, 22cqh, 100px);
  line-height: 1;
  margin-top: min(6cqh, 40px);
  white-space: nowrap;
}
.phase-time {
  font-size: min(52cqw, 62cqh, 270px);
  line-height: .86;
  font-variant-numeric: tabular-nums;
  margin: auto 0;
  white-space: nowrap;
}
.phase-time.long { font-size: min(34cqw, 50cqh, 180px); }

.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(0,0,0,.1); }
.progress-bar { height: 100%; width: 0; background: rgba(0,0,0,.45); }

.reset-fab {
  position: absolute;
  top: -27px;
  right: 15%;
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--bg);
  border: 3px solid var(--yellow);
  color: var(--yellow);
  display: grid; place-items: center;
  z-index: 2;
  cursor: pointer;
}
.reset-fab svg { width: 26px; height: 26px; }
.reset-fab:active { transform: scale(.93); }

/* ---------- próxima fase ---------- */
.next-panel {
  flex: none;
  background: var(--next, var(--green));
  color: var(--ink);
  text-align: center;
  padding: 8px 0 6px;
  transition: background-color .25s ease;
}
.next-label { font-size: clamp(16px, 3.2vh, 26px); line-height: 1; }
.next-time { font-size: clamp(36px, min(21vw, 11vh), 110px); line-height: .9; font-variant-numeric: tabular-nums; }

/* ---------- rodapé com contadores ---------- */
.timer-foot {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: min(14px, 1.6vh) 6px min(10px, 1.2vh);
  gap: 4px;
}
.counter { text-align: center; min-width: 0; }
.counter-num { font-size: clamp(36px, min(20vw, 11vh), 100px); line-height: .95; font-variant-numeric: tabular-nums; }
#r-last { font-size: clamp(28px, min(13vw, 7vh), 70px); line-height: 1.35; }
.counter-label { font-size: clamp(13px, 4.2vw, 20px); color: #fff; margin-top: 6px; white-space: nowrap; }
.c-blue { color: var(--blue); }
.c-yellow { color: var(--yellow); }

.play-wrap { display: flex; flex-direction: column; align-items: center; }
.play-btn {
  width: clamp(64px, 12vh, 98px); height: clamp(64px, 12vh, 98px);
  border-radius: 50%;
  background: var(--yellow);
  display: grid; place-items: center;
  position: relative;
  color: #232323;
}
.play-btn::after {
  content: ""; position: absolute; inset: 9px;
  border-radius: 50%; border: 2.5px solid #232323;
}
.play-btn svg { width: 45%; height: 45%; }
.play-btn .ico-play { margin-left: 5px; }
.play-btn .ico-pause { display: none; }
.play-btn.running .ico-play { display: none; }
.play-btn.running .ico-pause { display: block; }
.play-btn:active { transform: scale(.95); }
.play-label { color: var(--yellow); font-size: clamp(18px, 3.4vh, 28px); margin-top: 8px; line-height: 1; }

/* ---------- barra de abas ---------- */
.tabbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 6px 16px calc(var(--safe-bottom) + 8px);
  background: var(--bg);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11.5px; color: #fff;
  padding: 7px 0 5px;
  border-radius: 25px;
}
.tab svg { width: 26px; height: 26px; }
.tab.active { background: var(--bg-3); }

/* ---------- configuração ---------- */
.cfg-head {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  border-bottom: 1px solid #2f2f2f;
  font-size: 27px;
}
.cfg-head > :first-child { justify-self: start; }
.cfg-head > :last-child { justify-self: end; }
.cfg-title { color: #fff; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txt-btn { font-size: 27px; }
.txt-btn.muted { color: var(--muted); }
.txt-btn.green { color: var(--green); }
.txt-btn:active { opacity: .6; }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 28px; }

.section-title {
  position: relative;
  background: var(--bg-2);
  color: #5d5d5d;
  font-size: 26px;
  text-align: center;
  padding: 12px 0 9px;
  margin-top: 22px;
}
.section-title.with-action .icon-btn { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); }

.row {
  display: grid;
  grid-template-columns: 20px 1fr auto 18px;
  align-items: center;
  gap: 0 12px;
  padding: 10px 14px 9px 18px;
  border-bottom: 1px solid var(--line);
  margin: 0 0 0 0;
  cursor: pointer;
}
.row:active { background: #2a2a2a; }
.dot { width: 20px; height: 20px; border-radius: 50%; background: var(--c, var(--yellow)); display: inline-block; flex: none; }
.row-main { min-width: 0; }
.row-title { font-size: 25px; line-height: 1.05; }
.row-sub { font-size: 15.5px; color: var(--muted); line-height: 1.15; margin-top: 3px; }
.row-value { font-size: 44px; line-height: 1; font-variant-numeric: tabular-nums; }
.row-chev { width: 18px; height: 18px; color: var(--muted); }
.row .switch, .row input[type=range] { grid-column: 3 / 5; }
.total-row { cursor: default; border-bottom: 0; }
.total-row:active { background: none; }
.total-row .row-value { font-size: 40px; }

.add-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: calc(100% - 32px);
  margin: 32px 16px 0;
  padding: 13px 10px;
  border-radius: 14px;
  background: #4a4a4a;
  font-size: 24px;
}
.add-btn svg { width: 30px; height: 30px; }
.add-btn:active { background: #555; }

.workout {
  display: grid;
  grid-template-columns: 1fr 44px;
  align-items: center;
  column-gap: 8px;
  padding: 12px 14px 12px 18px;
  border-bottom: 1px solid var(--line);
}
.workout-name { color: var(--green); font-size: 34px; line-height: 1; margin-bottom: 6px; grid-column: 1 / -1; }
.workout-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 2px 8px;
  font-size: 22px;
  line-height: 1.3;
}
.workout-grid .v { text-align: right; font-variant-numeric: tabular-nums; }
.workout-grid .dim { color: var(--muted); }
.check {
  width: 38px; height: 38px; border-radius: 50%;
  background: #4a4a4a; color: #232323;
  display: grid; place-items: center;
  justify-self: end;
}
.check svg { width: 26px; height: 26px; }
.check.on { background: var(--green); }
.workout-actions { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 10px; }
.workout-actions button { flex: 1; padding: 9px 4px; border-radius: 10px; background: var(--bg-3); font-size: 20px; }
.workout-actions .danger { background: #5a1f1c; color: #ffb3ad; }
.workout-actions button:disabled { opacity: .35; }

/* ---------- rondas & cronômetro ---------- */
.tap-panel { cursor: pointer; font: inherit; border: 0; }
.tap-panel:active { filter: brightness(.95); }
.tap-panel .phase-label { font-size: min(12cqw, 16cqh, 64px); }
.tap-hint { font-size: min(26px, 8cqh); opacity: .65; min-height: 30px; }

.laps {
  flex: none;
  height: 19vh;
  height: 19dvh;
  overflow-y: auto;
  background: var(--bg-2);
  font-size: 22px;
}
.lap {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 18px;
  padding: 6px 20px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.lap .muted { color: var(--muted); }
.lap.best .t { color: var(--green); }
.lap.worst .t { color: var(--red); }
.laps-empty { color: #5d5d5d; text-align: center; padding: 18px 16px; font-size: 20px; }

.crono-panel { --panel: var(--bg); color: #fff; justify-content: center; }
.crono-panel.running { --panel: var(--green); color: var(--ink); }
.crono-panel.paused { --panel: var(--yellow); color: var(--ink); }
.crono-panel .phase-time { margin: auto 0 0; }
.crono-cs { font-size: min(14cqw, 18cqh, 76px); line-height: 1; margin-bottom: auto; font-variant-numeric: tabular-nums; }

.side-btn-wrap { display: grid; place-items: center; }
.side-btn { width: 76px; height: 76px; border-radius: 50%; background: var(--bg-3); font-size: 22px; }
.side-btn:disabled { opacity: .3; }
.side-btn:active { transform: scale(.95); }

/* ---------- mais ---------- */
.switch { position: relative; width: 54px; height: 32px; display: inline-block; justify-self: end; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: #4a4a4a; transition: background .2s; cursor: pointer; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px;
  border-radius: 50%; background: #fff; transition: transform .2s;
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(22px); }
#screen-mais .row { cursor: default; }
#screen-mais .row:active { background: none; }

input[type=range] { width: 110px; accent-color: var(--yellow); justify-self: end; }

.test-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px 0; }
.test-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 6px; border-radius: 12px; background: var(--bg-3); font-size: 21px;
}
.test-btn .dot { width: 14px; height: 14px; }
.test-btn:active { background: #4a4a4a; }
.info { padding: 12px 18px; font-size: 18px; color: #bdbdbd; line-height: 1.25; }
.info b { color: var(--yellow); font-weight: normal; }
.info p { margin: 0 0 10px; }

/* ---------- sheet ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px;
  background: var(--bg-2);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(var(--safe-bottom) + 16px);
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; gap: 12px; font-size: 30px; }
.sheet-body { padding: 20px 0 10px; }
.sheet-actions { display: flex; justify-content: space-between; padding-top: 10px; }

.picker { display: flex; align-items: center; justify-content: center; gap: 10px; }
.picker-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.picker-col small { color: var(--muted); font-size: 17px; }
.picker-sep { font-size: 56px; line-height: 1; padding-bottom: 22px; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 52px; height: 52px; border-radius: 50%; background: var(--bg-3); font-size: 34px; line-height: 1; }
.stepper button:active { background: #555; }
.picker select, .picker input[type=number] {
  font: inherit; font-size: 56px; line-height: 1.1;
  width: 96px; text-align: center; text-align-last: center;
  background: var(--bg); color: #fff;
  border: 2px solid #444; border-radius: 12px;
  padding: 4px 0;
  appearance: none; -webkit-appearance: none; -moz-appearance: textfield;
}
.picker input::-webkit-outer-spin-button, .picker input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.quick button { padding: 7px 13px; border-radius: 10px; background: var(--bg-3); font-size: 21px; }
.quick button:active { background: #555; }
.text-input {
  width: 100%; font: inherit; font-size: 34px; padding: 8px 12px;
  background: var(--bg); color: #fff; border: 2px solid #444; border-radius: 12px;
  text-transform: uppercase; -webkit-user-select: text; user-select: text;
}
.text-input:focus { outline: none; border-color: var(--green); }
.sheet-msg { font-size: 23px; color: #ccc; line-height: 1.25; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 96px); transform: translateX(-50%);
  background: #000; color: #fff; padding: 9px 16px; border-radius: 12px; font-size: 20px; z-index: 30;
  white-space: nowrap; border: 1px solid #333;
}

@media (min-width: 521px) {
  #app { box-shadow: 0 0 60px rgba(0,0,0,.6); }
}
