:root {
  color-scheme: dark;
  --bg: #101418;
  --panel: #171d22;
  --panel-soft: #1d252b;
  --text: #f4f7f8;
  --muted: #95a0aa;
  --line: rgba(255, 255, 255, 0.09);
  --accent: #3ddc97;
  --accent-strong: #10b981;
  --warn: #ef4444;
  --amber: #f59e0b;
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 0%, rgba(61, 220, 151, 0.12), transparent 32rem),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 18px 16px calc(36px + var(--safe-bottom));
}

.topbar,
.section-head,
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: -18px -16px 14px;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: rgba(16, 20, 24, 0.86);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
}

h3 {
  font-size: 21px;
  line-height: 1.2;
}

.top-actions,
.backup-actions,
.field-grid {
  display: flex;
  gap: 10px;
}

.icon-button,
.small-button,
.primary-button,
.secondary-button,
.category-tab {
  border: 0;
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  font-weight: 700;
}

.icon-button.ghost {
  background: rgba(255, 255, 255, 0.06);
}

.small-button,
.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 0 16px;
  font-weight: 700;
}

.small-button {
  min-width: 78px;
}

.primary-button {
  width: 100%;
  background: linear-gradient(135deg, #35d89a, #19b6a8);
  color: #07100d;
}

.secondary-button,
.small-button {
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.danger-button {
  border-color: rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

.backup-reminder {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius);
  background: rgba(245, 158, 11, 0.1);
}

.backup-reminder p,
.plain-copy,
.backup-time {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.hero-panel,
.exercise-section,
.history-section {
  background: rgba(23, 29, 34, 0.78);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.hero-panel {
  padding: 14px;
}

.heatmap-card {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: var(--radius);
  background: #0c1115;
}

.body-reference,
.muscle-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.body-reference {
  object-fit: contain;
  filter: saturate(0.88) brightness(0.85) contrast(1.05);
  opacity: 0.72;
}

.body-reference.user-photo {
  filter: saturate(0.7) brightness(0.72) contrast(1.08);
  opacity: 0.58;
}

.muscle-overlay {
  pointer-events: none;
}

.muscle-zone path {
  fill: rgba(148, 163, 184, 0.08);
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 1.6;
  transition: fill 220ms ease, filter 220ms ease, stroke 220ms ease;
}

.muscle-zone.is-hot path {
  stroke: rgba(255, 255, 255, 0.68);
  filter: drop-shadow(0 0 14px rgba(61, 220, 151, 0.42));
}

.muscle-zone.is-over path {
  stroke: rgba(255, 255, 255, 0.8);
  filter: drop-shadow(0 0 16px rgba(239, 68, 68, 0.5));
}

.week-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.week-stats > div {
  min-width: 0;
  padding: 10px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
}

.stat-value,
.stat-label {
  display: block;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
}

.stat-value.warning {
  color: #ff8075;
}

.stat-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.focus-strip {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.focus-row {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.bar span {
  display: block;
  height: 100%;
  width: var(--pct);
  max-width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2dd4bf, #3ddc97);
}

.bar.over span {
  background: linear-gradient(90deg, #f59e0b, #ef4444);
}

.exercise-section,
.history-section {
  margin-top: 14px;
  padding: 14px;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
}

.category-tabs {
  display: grid;
  grid-auto-columns: max-content;
  grid-auto-flow: column;
  gap: 8px;
  margin: 12px -14px 8px;
  padding: 0 14px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.category-tab {
  min-height: 38px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.category-tab.active {
  background: rgba(61, 220, 151, 0.18);
  color: var(--text);
  border: 1px solid rgba(61, 220, 151, 0.38);
}

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

.exercise-card,
.history-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  text-align: left;
}

.exercise-card strong,
.history-row strong {
  display: block;
  font-size: 15px;
}

.exercise-card span,
.history-row span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.exercise-card em {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(61, 220, 151, 0.15);
  color: var(--accent);
  font-style: normal;
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.empty-state {
  padding: 16px;
  border: 1px dashed rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.sheet {
  width: min(100% - 24px, 500px);
  margin: auto auto 12px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.64);
  backdrop-filter: blur(8px);
}

.sheet-content {
  display: grid;
  gap: 16px;
  max-height: calc(100dvh - 28px);
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151b20;
  box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.35);
}

.sheet-content.tall {
  min-height: 64dvh;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: rgba(61, 220, 151, 0.72);
  box-shadow: 0 0 0 3px rgba(61, 220, 151, 0.14);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.muscle-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.muscle-tags span {
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(61, 220, 151, 0.12);
  color: #9cf6ce;
  font-size: 12px;
}

.targets-list {
  display: grid;
  gap: 10px;
}

.target-row {
  display: grid;
  grid-template-columns: 1fr 82px 82px;
  gap: 8px;
  align-items: end;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.target-row:last-child {
  border-bottom: 0;
}

.target-row strong {
  display: block;
  margin-bottom: 3px;
  font-size: 14px;
}

.target-row small {
  color: var(--muted);
}

.backup-actions {
  display: grid;
  grid-template-columns: 1fr;
}

.file-button {
  display: grid;
  place-items: center;
}

.file-button input {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  z-index: 10;
  width: min(92vw, 420px);
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(244, 247, 248, 0.94);
  color: #111827;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  transform: translate(-50%, 24px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 760px) {
  .app-shell {
    width: min(100%, 960px);
  }

  main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-items: start;
  }

  .backup-reminder,
  .history-section {
    grid-column: 1 / -1;
  }

  .exercise-section {
    margin-top: 0;
  }
}
