/* Training Log — dark, mobile-first. No framework, no webfonts (fast first paint). */

:root {
  --bg: #08090b;
  --surface: #101216;
  --surface-2: #171a20;
  --line: #24282f;
  --text: #eef1f5;
  --muted: #8b93a1;
  --accent: #29e07f;
  --accent-dim: rgba(41, 224, 127, 0.14);
  --danger: #ff5d5d;
  --radius: 14px;
  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.error {
  color: var(--danger);
  font-size: 14px;
  margin: 4px 0 0;
}

/* ------------------------------------------------------------------ boot */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 100;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ----------------------------------------------------------------- login */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade 0.25s ease;
}

.login-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.brand-mark {
  width: 10px;
  height: 24px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 18px var(--accent);
}

.brand h1 {
  font-size: 22px;
  letter-spacing: -0.02em;
  margin: 0;
}

.pin-input {
  width: 100%;
  margin: 20px 0 0;
  padding: 16px;
  font-size: 24px;
  text-align: center;
  letter-spacing: 0.35em;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.pin-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, opacity 0.18s ease;
}

.btn:active {
  transform: scale(0.985);
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  margin-top: 14px;
  color: #04150c;
  background: var(--accent);
  border-color: var(--accent);
}

.btn-ghost {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}

.btn-danger {
  margin-top: 8px;
  color: var(--danger);
  background: transparent;
  border-color: rgba(255, 93, 93, 0.35);
}

.btn-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.link-btn {
  padding: 8px 4px;
  font: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}

.link-btn.accent {
  color: var(--accent);
  font-weight: 600;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: var(--muted);
}

/* ---------------------------------------------------------------- topbar */

.app {
  min-height: 100dvh;
  animation: fade 0.25s ease;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: var(--safe-t);
  background: rgba(8, 9, 11, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--pad) 4px;
}

.topbar-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px var(--pad) 12px;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.chip[aria-selected='true'] {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: rgba(41, 224, 127, 0.4);
}

/* -------------------------------------------------------------- timeline */

.timeline {
  padding: 8px var(--pad) calc(120px + var(--safe-b));
  max-width: 720px;
  margin: 0 auto;
}

/* A day is one card. Its face is the date; the rest is behind a tap. */
.day-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color 0.18s ease;
  animation: rise 0.28s ease both;
}

.day-card.open {
  border-color: #2f3540;
}

.day-face {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 16px 14px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  cursor: pointer;
}

.day-face:active {
  background: var(--surface-2);
}

.day-date {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.day-date b {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.day-weekday {
  font-size: 12px;
  color: var(--muted);
}

.day-meta {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.day-names {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-progress {
  flex: 0 0 auto;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 650;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 999px;
}

.chev {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  transition: transform 0.22s ease;
}

.day-card.open .chev {
  transform: rotate(180deg);
}

.day-body {
  padding: 0 14px 6px;
  animation: fade 0.2s ease;
}

.entry {
  display: block;
  padding: 12px 0 14px;
  border-top: 1px solid var(--line);
}

.entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.entry-name {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0;
}

.edit-btn {
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.edit-btn:active {
  color: var(--text);
}

/* ------------------------------------------------------ checklist rows */

.check-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: opacity 0.18s ease;
}

.tick {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: 1.5px solid #39404c;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.tick svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: #04150c;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.check-row.done .tick,
.item-row .tick[aria-checked='true'] {
  background: var(--accent);
  border-color: var(--accent);
}

.check-row.done .tick svg,
.item-row .tick[aria-checked='true'] svg {
  opacity: 1;
  transform: scale(1);
}

.check-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.check-name {
  font-size: 15px;
  transition: color 0.18s ease;
}

.check-row.done .check-name {
  color: var(--muted);
  text-decoration: line-through;
}

.check-detail {
  font-size: 12px;
  color: var(--muted);
}

.check-note {
  flex: 0 1 96px;
  min-width: 0;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.check-note::placeholder {
  color: #5b6474;
}

.check-note:focus {
  outline: none;
  flex-basis: 130px;
  background: var(--surface);
  border-color: var(--accent);
}

.entry-notes {
  margin: 8px 0 0;
  font-size: 15px;
  color: #c9d0da;
  white-space: pre-wrap;
  word-break: break-word;
}

.entry-videos {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.entry-videos video {
  width: 100%;
  max-height: 62vh;
  background: #000;
  border-radius: 10px;
  display: block;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 64px 20px;
}

.empty h3 {
  color: var(--text);
  margin: 0 0 6px;
  font-size: 17px;
}

/* ------------------------------------------------------------------- fab */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + var(--safe-b));
  z-index: 30;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  background: var(--accent);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 8px 26px rgba(41, 224, 127, 0.32);
  cursor: pointer;
  transition: transform 0.14s ease;
}

.fab:active {
  transform: scale(0.92);
}

.fab svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: #04150c;
  stroke-width: 2.6;
  stroke-linecap: round;
}

/* -------------------------------------------------------- sheet & backdrop */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.6);
  animation: fade 0.2s ease;
}

.sheet,
.menu {
  position: fixed;
  z-index: 50;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  animation: slide-up 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.sheet {
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
}

.sheet-grip {
  width: 38px;
  height: 4px;
  margin: 8px auto 2px;
  background: var(--line);
  border-radius: 2px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px var(--pad) 10px;
  border-bottom: 1px solid var(--line);
}

.sheet-head h2 {
  font-size: 16px;
  font-weight: 650;
  margin: 0;
}

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--pad) var(--pad) calc(28px + var(--safe-b));
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.field-hint {
  font-size: 12px;
  color: var(--muted);
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.55;
}

input[type='date'] {
  -webkit-appearance: none;
  appearance: none;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
  padding: 10px 12px;
  background: var(--accent-dim);
  border: 1px solid rgba(41, 224, 127, 0.28);
  border-radius: 12px;
}

.checkbox-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.checkbox-row b {
  color: var(--text);
}

/* ------------------------------------------------- exercise row editor */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-row .chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.chip-count {
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 999px;
}

.item-editor {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-grip {
  flex: 0 0 auto;
  width: 4px;
  height: 32px;
  background: var(--line);
  border-radius: 2px;
}

.item-fields {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 6px;
}

.item-fields .input {
  min-height: 42px;
  padding: 9px 12px;
}

.item-detail {
  font-size: 14px !important;
  color: var(--muted);
}

.item-row .remove {
  flex: 0 0 auto;
  width: 32px;
  padding: 4px;
  font: inherit;
  font-size: 22px;
  line-height: 1;
  color: var(--danger);
  background: none;
  border: 0;
  cursor: pointer;
}

.item-empty {
  margin: 0 0 8px;
  padding: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 12px;
}

/* -------------------------------------------------------- template list */

.tpl-list {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.tpl-card {
  display: block;
  width: 100%;
  padding: 14px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.18s ease;
}

.tpl-card:active {
  border-color: var(--accent);
}

.tpl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.tpl-head b {
  font-size: 16px;
  font-weight: 650;
}

.tpl-count {
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
}

.tpl-preview {
  display: block;
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}

/* ------------------------------------------------------------ video list */

.video-list {
  display: grid;
  gap: 8px;
}

.video-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 14px;
}

.video-row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-row .size {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.video-row .remove {
  background: none;
  border: 0;
  color: var(--danger);
  font: inherit;
  font-size: 20px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
}

.progress {
  height: 4px;
  margin-top: 8px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ------------------------------------------------------------------ menu */

.menu {
  padding: 14px var(--pad) calc(20px + var(--safe-b));
  display: grid;
  gap: 4px;
}

.stats {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 4px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}

.stats .warn {
  color: #ffb454;
}

.menu-item {
  text-align: left;
  padding: 15px 8px;
  font: inherit;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.menu-item.danger {
  color: var(--danger);
}

.menu-item:active {
  background: var(--surface-2);
}

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(94px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 80;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: rise 0.2s ease;
}

.toast.bad {
  border-color: rgba(255, 93, 93, 0.5);
  color: #ffc9c9;
}

/* ------------------------------------------------------------ animations */

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@keyframes slide-up {
  from {
    transform: translateY(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Desktop: centre the sheets rather than pinning them to the bottom edge. */
@media (min-width: 700px) {
  .sheet,
  .menu {
    left: 50%;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(560px, calc(100vw - 48px));
    border-radius: 18px;
    border: 1px solid var(--line);
    animation: fade 0.2s ease;
  }

  .sheet {
    max-height: 86dvh;
  }

  .sheet-grip {
    display: none;
  }
}
