@font-face {
  font-family: "Big Shoulders Display";
  src: url("fonts/bigshoulders-800.woff2") format("woff2");
  font-weight: 700 900;
  font-display: swap;
}
@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --bg: #121413;
  --surface: #1b1e1c;
  --surface-2: #272b28;
  --text: #eeece6;
  --muted: #9a9f98;
  --line: #333834;
  --accent: #d9a45f;     /* madeira do fingerboard */
  --on-accent: #1a1410;

  --c-prep: #f5b700;
  --c-work: #e5383b;
  --c-rest: #2a9d4f;
  --c-setrest: #1d7fb8;
  --c-done: #7b4fd6;

  --display: "Big Shoulders Display", "Arial Narrow", Impact, sans-serif;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #eceeea;
  --surface: #ffffff;
  --surface-2: #e2e5e0;
  --text: #161a17;
  --muted: #586058;
  --line: #cfd3cc;
  --accent: #c98a3e;
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eceeea;
    --surface: #ffffff;
    --surface-2: #e2e5e0;
    --text: #161a17;
    --muted: #586058;
    --line: #cfd3cc;
    --accent: #c98a3e;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

body:has(#run:not([hidden])) { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(84px + env(safe-area-inset-bottom));
}

.view { display: none; }
.view.active { display: block; }

.top { display: flex; align-items: center; gap: 12px; padding: 8px 0 12px; }
.top img { border-radius: 11px; flex: none; }
.top h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  text-wrap: balance;
}
.top p { margin: 3px 0 0; font-size: 0.875rem; }
.muted { color: var(--muted); }
small.muted { font-size: 0.8em; }

/* ---------- presets ---------- */
.chips {
  display: flex; gap: 8px;
  overflow-x: auto;
  margin: 0 -16px;
  padding: 4px 16px 12px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }

/* ---------- campos ---------- */
.fields { display: grid; gap: 8px; }
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 6px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.field .name { display: flex; align-items: center; gap: 12px; font-weight: 600; min-width: 0; }
.field .bar-c { align-self: stretch; width: 6px; flex: none; }
.field .label { line-height: 1.15; }
.stepper { display: flex; align-items: center; gap: 2px; flex: none; }
.stepper button {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 0;
  background: var(--surface-2);
  font-size: 1.5rem;
  line-height: 1;
}
.stepper button:active { transform: scale(0.93); }
.stepper input {
  width: 72px;
  height: 44px;
  text-align: center;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: transparent;
  border: 0;
  border-radius: 8px;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.unit { color: var(--muted); font-size: 0.85rem; width: 12px; margin-right: 2px; }

/* ---------- painel: faixa + iniciar ---------- */
.panel {
  position: sticky;
  bottom: calc(60px + env(safe-area-inset-bottom));
  margin: 14px -16px 0;
  padding: 12px 16px 6px;
  background: linear-gradient(to top, var(--bg) 82%, transparent);
}
.strip { display: flex; gap: 2px; height: 22px; }
.strip i { display: block; flex-basis: 0; min-width: 2px; border-radius: 3px; }
.strip .prep { background: var(--c-prep); }
.strip .work { background: var(--c-work); }
.strip .rest { background: var(--c-rest); }
.strip .setrest { background: var(--c-setrest); }
.total { text-align: center; margin: 8px 0 10px; color: var(--muted); font-size: 0.9rem; }
.total strong { color: var(--text); font-family: var(--display); font-size: 1.5rem; font-variant-numeric: tabular-nums; margin-left: 6px; vertical-align: -2px; }

.primary {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%;
  min-height: 64px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.primary:active { transform: scale(0.985); }
.ghost {
  flex: 1;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
}
.row { display: flex; gap: 10px; margin-top: 10px; }

@media (hover: hover) {
  .chip:hover:not([aria-pressed="true"]), .ghost:hover, .icon-btn:hover, .stepper button:hover { background: var(--surface-2); }
  .primary:hover { filter: brightness(1.06); }
}

/* ---------- abas ---------- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}
.tabs button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 8px 8px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.tabs button.active { color: var(--accent); }

/* ---------- cards / ajustes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-top: 14px;
}
.card h3 { margin: 0 0 6px; font-size: 1rem; }
.card p { margin: 0 0 8px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; }
.setting + .setting { border-top: 1px solid var(--line); }
.setting input[type="range"] { flex: 1; max-width: 220px; accent-color: var(--accent); }
.setting select {
  min-height: 44px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 10px;
}
.switch {
  appearance: none;
  width: 52px; height: 30px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  position: relative;
  transition: background 0.15s;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { transform: translateX(22px); background: var(--on-accent); }

/* ---------- histórico ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 6px;
  text-align: center;
}
.stats strong { display: block; font-family: var(--display); font-size: 2.1rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats span { font-size: 0.75rem; color: var(--muted); }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 8px; }
.cal-head h2 { margin: 0; font-size: 1.1rem; text-transform: capitalize; }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 0;
  background: var(--surface-2);
  font-size: 1.3rem;
  line-height: 1;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.dow { text-align: center; color: var(--muted); font-size: 0.75rem; padding: 4px 0; }
.day {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}
.day.done { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.day.today { border-color: var(--text); }
.day.sel { outline: 3px solid var(--text); outline-offset: 1px; }
.day[data-n]:not([data-n=""])::after {
  content: attr(data-n);
  position: absolute; top: 2px; right: 5px;
  font-size: 0.65rem;
}
.entry { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.entry + .entry { border-top: 1px solid var(--line); }
.entry div { display: flex; flex-direction: column; font-size: 0.9rem; }
#day-detail h3 { font-size: 1.05rem; }

/* ---------- execução ---------- */
#run {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  padding: calc(18px + env(safe-area-inset-top)) 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--phase);
  color: var(--on-phase);
  transition: background 0.25s;
  text-align: center;
  user-select: none;
  overscroll-behavior: contain;
}
#run[data-phase="prep"]    { --phase: var(--c-prep);    --on-phase: #1b1500; }
#run[data-phase="work"]    { --phase: var(--c-work);    --on-phase: #fff; }
#run[data-phase="rest"]    { --phase: var(--c-rest);    --on-phase: #fff; }
#run[data-phase="setrest"] { --phase: var(--c-setrest); --on-phase: #fff; }
#run[data-phase="done"]    { --phase: var(--c-done);    --on-phase: #fff; }
#run[data-paused="true"] #run-time { animation: blink 1.2s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) {
  #run[data-paused="true"] #run-time { animation: none; opacity: 0.6; }
  #run, .chip, .switch, .switch::after { transition: none; }
}

.run-top {
  display: flex; justify-content: space-between; gap: 12px;
  font-weight: 600; font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.run-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
#run-label {
  margin-bottom: 0.25em;
  font-family: var(--display);
  font-size: clamp(2.4rem, 11vw, 4rem);
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
#run-time {
  font-family: var(--display);
  font-size: min(78vw, 38dvh);
  font-weight: 800;
  line-height: 0.88;
  font-variant-numeric: tabular-nums;
}
.bar { width: min(80%, 420px); height: 8px; border-radius: 999px; background: rgb(0 0 0 / 0.2); overflow: hidden; margin-top: 8px; }
#run-bar { height: 100%; width: 100%; background: var(--on-phase); transform-origin: left; }

/* um degrau por repetição: preenche conforme você avança */
.pips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: min(90%, 420px); margin-top: 18px; min-height: 14px; }
.pips i { width: 26px; height: 12px; border-radius: 6px; border: 2px solid var(--on-phase); opacity: 0.5; }
.pips i.done { background: var(--on-phase); opacity: 1; }
.pips i.now { opacity: 1; background: color-mix(in srgb, var(--on-phase) 35%, transparent); }
.pips.many i { width: 14px; height: 10px; border-width: 1.5px; }

.run-side { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.run-actions { display: flex; justify-content: center; align-items: flex-end; gap: 14px; }

/* botões em forma de agarra: contornos irregulares, um para cada função */
.ctl {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  width: 84px; height: 76px;
  border: 0;
  color: var(--on-phase);
  background: rgb(0 0 0 / 0.22);
  font-size: 0.75rem;
  font-weight: 600;
}
.ctl.h1 { border-radius: 56% 44% 52% 48% / 58% 50% 50% 42%; }
.ctl.h3 { border-radius: 44% 56% 48% 52% / 50% 58% 42% 50%; }
.ctl.main {
  width: 124px; height: 112px;
  gap: 2px;
  background: var(--on-phase);
  color: var(--phase);
  border-radius: 54% 46% 58% 42% / 48% 56% 44% 52%;
  font-size: 0.8rem;
}
.ctl:active { transform: scale(0.94); }
#run:not([data-paused="true"]) .i-play, #run[data-paused="true"] .i-pause { display: none; }

.wide {
  min-width: 200px; height: 64px;
  padding: 0 40px;
  border: 0;
  border-radius: 20px;
  background: #fff;
  color: var(--c-done);
  font-family: var(--display);
  font-size: 1.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stop {
  background: none;
  border: 0;
  color: var(--on-phase);
  opacity: 0.85;
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 44px;
  padding: 0 14px;
}
#run[data-phase="done"] .stop { display: none; }
#run[data-phase="done"] #run-bar { transform: scaleX(1); }

/* celular deitado: tempo à esquerda, controles à direita */
@media (orientation: landscape) and (max-height: 520px) {
  #run {
    display: grid;
    grid-template-columns: 1fr 260px;
    grid-template-rows: auto 1fr;
    column-gap: 24px;
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
  }
  .run-top { grid-column: 1 / -1; }
  .run-center { grid-column: 1; }
  .run-side { grid-column: 2; justify-content: center; gap: 10px; }
  #run-time { font-size: min(46vw, 52dvh); }
  #run-label { font-size: clamp(1.8rem, 9dvh, 3rem); }
  .pips { margin-top: 8px; }
  .run-actions { gap: 8px; }
  .ctl { width: 70px; height: 64px; }
  .ctl.main { width: 100px; height: 92px; }
}

/* ---------- telas largas ---------- */
@media (min-width: 900px) {
  body { display: flex; flex-direction: column; }
  main { width: 100%; max-width: 1040px; padding: 8px 32px 48px; }
  .top h1 { font-size: 2.6rem; }
  .top img { width: 56px; height: 56px; }

  /* abas viram barra no topo */
  .tabs {
    order: -1;
    position: sticky; top: 0; bottom: auto;
    justify-content: center; gap: 4px;
    border-top: 0; border-bottom: 1px solid var(--line);
    padding: 6px 0;
  }
  .tabs button { flex: none; flex-direction: row; gap: 8px; padding: 0 20px; min-height: 44px; border-radius: 12px; font-size: 0.95rem; }
  .tabs button.active { background: var(--surface-2); }

  #view-timer { max-width: 560px; margin: 0 auto; }
  .chips { margin: 0 -16px; padding: 4px 16px 12px; }
  .panel { bottom: 0; }

  .hist { display: grid; grid-template-columns: minmax(0, 520px) minmax(280px, 360px); gap: 28px; align-items: start; }
  .hist .card { margin-top: 16px; }
  #view-settings { max-width: 560px; margin: 0 auto; }

  #run-time { font-size: min(44vw, 48dvh); }
  .pips i { width: 34px; height: 14px; }
}

#run[data-phase="done"] #run-time { font-size: min(30vw, 22dvh); }

@media (max-width: 360px) {
  main { padding-left: 12px; padding-right: 12px; }
  .chips { margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
  .panel { margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; }
  .field .name { gap: 8px; font-size: 0.9rem; }
  .stepper button { width: 40px; height: 40px; }
  .stepper input { width: 52px; font-size: 1.8rem; }
  .unit { display: none; }
  .ctl { width: 76px; }
  .ctl.main { width: 112px; }
}

/* telas baixas: o painel rola junto com a página para não cobrir os campos */
@media (max-height: 700px) and (max-width: 899px) {
  .panel { position: static; background: none; padding-bottom: 0; }
}
