:root {
  color-scheme: light;
  --bg: #f4f5ef;
  --surface: #ffffff;
  --surface-soft: #edf3ea;
  --surface-warm: #fff6ed;
  --ink: #17221d;
  --muted: #657065;
  --line: #d7ddcf;
  --accent: #235b44;
  --accent-2: #b9572c;
  --danger: #a63631;
  --focus: #0e7a55;
  --shadow: 0 12px 32px rgba(23, 34, 29, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --timeline-top: calc(73px + var(--safe-top));
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(14, 122, 85, 0.28);
  outline-offset: 2px;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.ghost {
  background: transparent;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) calc(14px + var(--safe-right)) 14px calc(14px + var(--safe-left));
  background: rgba(244, 245, 239, 0.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.topbar h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.layout {
  display: grid;
  gap: 14px;
}

.training-list,
.training-view,
.panel,
.quick-card,
.reserve,
.issues {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.training-list {
  padding: 12px;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.list-head h2 {
  margin: 0;
  font-size: 18px;
}

.training-items {
  display: grid;
  gap: 8px;
}

.training-card {
  display: grid;
  width: 100%;
  min-height: 76px;
  padding: 10px;
  text-align: left;
  background: #f9faf7;
}

.training-card.active {
  border-color: var(--accent);
  background: var(--surface-soft);
}

.training-card strong {
  display: block;
  margin-bottom: 2px;
}

.training-card span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.training-view {
  min-height: 60vh;
  overflow: hidden;
}

.empty-state {
  padding: 28px 16px;
}

.detail-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f6f8f2 100%);
}

.detail-head h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.08;
}

.detail-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.timeline {
  position: sticky;
  top: var(--timeline-top);
  z-index: 15;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.timeline a {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  background: #fbfcf8;
}

.detail-body {
  padding: 12px;
}

.quick-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.quick-card {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px;
  text-decoration: none;
  color: inherit;
  box-shadow: none;
}

.time {
  color: var(--accent);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.quick-card strong,
.block-summary strong {
  display: block;
}

.quick-card span,
.block-summary span {
  color: var(--muted);
  font-size: 14px;
}

details.block {
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

details.block[open] {
  box-shadow: var(--shadow);
}

summary {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  min-height: 62px;
  padding: 13px 12px;
  list-style: none;
  cursor: pointer;
}

summary::-webkit-details-marker {
  display: none;
}

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

h3,
h4 {
  margin: 14px 0 8px;
  line-height: 1.2;
  letter-spacing: 0;
}

h3 {
  font-size: 20px;
}

h4 {
  font-size: 17px;
}

p,
ul,
ol {
  margin-top: 8px;
  margin-bottom: 8px;
}

ul,
ol {
  padding-left: 22px;
}

li {
  margin: 4px 0;
}

.say {
  margin: 10px 0;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: var(--surface-soft);
  font-weight: 750;
}

.warn {
  border-left-color: var(--accent-2);
  background: var(--surface-warm);
}

.danger {
  border-left-color: var(--danger);
  background: #fff0ef;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 8px;
  background: #edf1eb;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mini-table {
  display: grid;
  gap: 6px;
  margin: 10px 0;
}

.mini-row {
  display: grid;
  grid-template-columns: 126px 1fr;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf7;
}

.exercise {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.exercise:last-child {
  border-bottom: 0;
}

.reserve,
.issues,
.notes {
  margin-top: 12px;
  padding: 14px;
}

.notes textarea {
  width: 100%;
  min-height: 118px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf8;
  color: var(--ink);
}

@media (min-width: 860px) {
  .layout {
    grid-template-columns: 300px 1fr;
    align-items: start;
  }

  .training-list {
    position: sticky;
    top: 86px;
  }

  .quick-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .quick-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  :root {
    --timeline-top: calc(66px + var(--safe-top));
  }

  .app-shell {
    padding: 0;
  }

  .topbar {
    align-items: flex-start;
    padding: calc(12px + var(--safe-top)) calc(12px + var(--safe-right)) 12px calc(12px + var(--safe-left));
  }

  .top-actions button {
    min-height: 38px;
    padding: 6px 9px;
    font-size: 14px;
  }

  .layout {
    gap: 10px;
  }

  .training-list,
  .training-view {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .timeline {
    top: var(--timeline-top);
  }
}
