@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --paper: #f5f5ef;
  --surface: #fff;
  --ink: #191d17;
  --muted: #62685d;
  --line: #e3e6dc;
  --soft: #f3f5ed;
  --lime: #d7fa55;
  --olive: #3f5019;
  --danger: #a52a35;
  --shadow: 0 2px 4px #222c1110;
  --safe-top: max(env(safe-area-inset-top), var(--tg-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left), var(--tg-safe-area-inset-left, 0px));
  --safe-right: max(env(safe-area-inset-right), var(--tg-safe-area-inset-right, 0px));
  font-family: Manrope, 'Segoe UI', sans-serif;
  background: var(--paper);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-width: 280px; margin: 0; }
button, input, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p, dl, dd { margin: 0; }
:focus-visible { outline: 2px solid #5d761b; outline-offset: 3px; }

.site-header { background: var(--surface); border-bottom: 1px solid var(--line); padding-top: var(--safe-top); }
.header-inner, .shell {
  max-width: 1168px;
  margin-inline: auto;
  padding-left: max(28px, var(--safe-left));
  padding-right: max(28px, var(--safe-right));
}
.header-inner { min-height: 80px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 1.65rem; font-weight: 800; line-height: .95; letter-spacing: -.075em; }
.brand-mark { display: grid; place-items: center; width: 43px; height: 43px; border-radius: 13px; color: var(--lime); background: var(--ink); }
.brand-mark .icon { font-size: 1.4rem; }
.brand-dot { color: #698512; }
.brand small { display: block; margin-top: 5px; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: 0; }
.nav { display: flex; gap: 4px; padding: 4px; background: var(--soft); border: 1px solid var(--line); border-radius: 13px; }
.nav a { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 7px 14px; color: var(--muted); font-size: .875rem; font-weight: 800; border-radius: 9px; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current] { background: var(--surface); box-shadow: var(--shadow); color: var(--ink); }
.nav a[aria-current] .icon { color: var(--olive); }

.shell { padding-top: 32px; padding-bottom: max(40px, var(--safe-bottom)); }
.hero { position: relative; isolation: isolate; display: flex; min-height: 280px; align-items: center; overflow: hidden; border-radius: 24px; background: #181e16; color: #fbfcf6; }
.hero-content { z-index: 1; padding: 37px 40px; }
.hero-date { color: #d4ef85; font-size: .8125rem; font-weight: 800; text-transform: uppercase; letter-spacing: .13em; }
.hero h1, .page-heading h1 { font-size: clamp(2.25rem, 5.2vw, 3.65rem); line-height: 1.06; letter-spacing: -.068em; font-weight: 800; }
.hero h1 { margin-top: 11px; }
.hero-description { margin-top: 12px; color: #ced4c9; font-weight: 600; }
.hero .button { margin-top: 24px; }
.hero-art { position: absolute; inset: 0 0 0 auto; width: 52%; pointer-events: none; }
.hero-art-grid { position: absolute; inset: 0; opacity: .23; background: repeating-linear-gradient(0deg, transparent 0 31px, #898e6c 31px 32px), repeating-linear-gradient(90deg, transparent 0 31px, #898e6c 31px 32px); mask-image: linear-gradient(90deg, transparent, black 58%, black); }
.barbell { position: absolute; top: 50%; left: 57%; width: 27.5rem; height: 10.625rem; transform: translate(-50%, -50%) rotate(-23deg); display: flex; align-items: center; justify-content: center; gap: .39rem; filter: drop-shadow(0 19px 16px #080b06a0); }
.barbell::before { content: ''; position: absolute; inset: 44% 0; border-radius: .5rem; background: linear-gradient(#d2d7b9, #5b6546 60%, #313c25); }
.barbell i, .barbell b { position: relative; border: solid #bbd06070; }
.barbell i { height: 92%; width: 2.18rem; border-radius: 45% / 9%; border-width: 1px 3px 1px 1px; background: linear-gradient(90deg, #849d28, #d8f36c 17%, #a3bd3f 39%, #586e1b 75%, #35451c); box-shadow: inset 0 -12px 15px #18230670; }
.barbell i:nth-child(1), .barbell i:nth-child(7) { height: 62%; width: 1.3rem; }
.barbell i:nth-child(2), .barbell i:nth-child(6) { height: 76%; width: 1.78rem; }
.barbell b { height: 12%; width: 36%; border-radius: .3rem; border-width: 1px; background: repeating-linear-gradient(128deg, #50593e 0 2px, #687254 2px 4px); }

.button, .icon-button, .text-button { display: inline-flex; align-items: center; justify-content: center; border-radius: 11px; font-size: .875rem; font-weight: 800; }
.button { gap: 8px; min-height: 46px; padding: 9px 16px; border: 1px solid transparent; text-align: center; }
.button-primary { background: var(--lime); color: #1d260b; border-color: #bed957; }
.button-primary:hover { background: #c9ee40; }
.button-secondary { background: var(--soft); color: var(--ink); border-color: var(--line); }
.button-secondary:hover, .icon-button:hover { background: #e9ede0; }
.button-danger, .button-danger-solid { color: var(--danger); background: #fcf0f1; border-color: #f0d2d5; }
.button-danger:hover, .button-danger-solid:hover { background: #f8dde0; }
.text-button { border: 0; color: var(--olive); background: transparent; min-height: 40px; padding: 5px 0 5px 4px; }
.text-button:hover { text-decoration: underline; }
.icon-button { flex: 0 0 auto; width: 42px; height: 42px; border: 1px solid var(--line); background: var(--soft); color: var(--ink); }
.icon-button .icon { font-size: 1rem; }

.stats { margin-block: 18px 26px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stats > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'value icon' 'label icon'; align-items: center; column-gap: 8px; padding: 17px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.stats dt { grid-area: label; margin-top: 3px; font-size: .875rem; color: var(--muted); font-weight: 700; }
.stats dd { grid-area: value; font-size: 1.8rem; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stats .icon { grid-area: icon; width: 38px; height: 38px; font-size: 1.1rem; border-radius: 11px; color: var(--olive); background: #f0f5df; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.panel { min-width: 0; padding: 19px 21px; background: var(--surface); border: 1px solid var(--line); border-radius: 19px; box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; min-height: 42px; gap: 12px; margin-bottom: 11px; }
.panel-heading h2, .dialog-heading h2, .dialog-body > h2 { font-size: 1.3rem; font-weight: 800; letter-spacing: -.045em; }
.panel-heading .text-button { white-space: nowrap; }
.empty { min-height: 162px; display: grid; justify-items: center; align-content: center; gap: 7px; padding: 17px 12px; border: 1px dashed #d8dece; background: #fafbf7; border-radius: 13px; text-align: center; }
.empty > .icon { width: 38px; height: 38px; border-radius: 11px; background: #edf2e3; color: var(--olive); }
.empty strong { font-size: .95rem; }
.empty p { color: var(--muted); font-size: .875rem; }
.empty .text-button { min-height: 35px; padding-inline: 5px; }

.page-heading { display: flex; gap: 22px; align-items: flex-end; justify-content: space-between; margin: 6px 0 24px; }
.page-heading h1 { font-size: clamp(2rem, 5.5vw, 3.05rem); }
.page-heading p { margin-top: 9px; color: var(--muted); }
.page-heading .button { flex-shrink: 0; }
.library-panel .empty { min-height: 250px; }
.exercise-row { display: flex; align-items: center; gap: 11px; min-width: 0; padding-block: 11px; }
.exercise-row + .exercise-row, .log-group + .log-group { border-top: 1px solid var(--line); }
.exercise-row > .icon { width: 40px; height: 40px; border-radius: 11px; color: var(--olive); background: #f0f5df; }
.exercise-row .exercise-info { flex: 1; min-width: 0; }
.exercise-row h3, .log-group h3 { font-size: 1rem; font-weight: 800; overflow-wrap: anywhere; }
.exercise-row p { margin-top: 2px; color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.log-group { padding-block: 10px; }
.log-group h3 { margin-bottom: 5px; }
.result-row { display: grid; grid-template-columns: 4ch 1fr 1fr auto; align-items: center; gap: 9px; min-height: 49px; padding-left: 9px; font-size: .9rem; font-variant-numeric: tabular-nums; border-radius: 8px; }
.result-row:nth-child(even) { background: #f8f9f4; }
.result-row span:first-child { color: var(--muted); }
.result-row .icon-button { width: 40px; height: 40px; background: transparent; border-color: transparent; }
.result-row .icon-button:hover { background: #edf1e4; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 20px; font-size: .875rem; font-weight: 800; }
.filter-bar .select-wrap { width: min(100%, 320px); }
.history-day { margin-bottom: 14px; }
.history-day h2 { padding-bottom: 7px; font-size: 1rem; color: var(--olive); font-weight: 800; }

dialog { width: min(100% - 28px, 500px); max-height: 90vh; max-height: 90dvh; padding: 0; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 20px 80px #15171350; overscroll-behavior: contain; }
dialog::backdrop { background: #191e17a0; }
.dialog-body { padding: 23px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.field { min-width: 0; display: grid; align-content: start; gap: 6px; color: var(--muted); font-size: .875rem; font-weight: 800; }
.log-fields { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); gap: 10px; margin-bottom: 18px; }
input, select { display: block; min-width: 0; width: 100%; height: 46px; padding: 8px 10px; border: 1px solid #d7dccf; border-radius: 10px; color: var(--ink); background: var(--surface); font-size: 1rem; font-weight: 600; }
input::placeholder { color: #71786c; }
input[name='reps'] { appearance: textfield; }
input[name='reps']::-webkit-inner-spin-button { appearance: none; }
.select-wrap { position: relative; display: block; min-width: 0; }
.select-wrap::after { content: ''; position: absolute; top: 18px; right: 14px; width: 8px; height: 8px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); pointer-events: none; }
select { appearance: none; padding-right: 30px; text-overflow: ellipsis; }
.set-labels, .set-row { display: grid; grid-template-columns: 23px minmax(0, 1fr) minmax(0, 1fr) 42px; align-items: center; gap: 8px; }
.set-labels { margin-bottom: 6px; font-size: .875rem; color: var(--muted); font-weight: 800; }
.set-row { margin-bottom: 8px; }
.set-index { font-size: .875rem; font-weight: 800; text-align: center; }
.weight-hint, .confirmation-copy { margin-block: 9px 12px; color: var(--muted); font-size: .875rem; }
.add-set { width: 100%; }
.dialog-actions { display: flex; gap: 8px; margin-top: 14px; }
.dialog-actions > * { flex: 1; }
.dialog-submit { width: 100%; }
.dialog-body > .dialog-submit { margin-top: 16px; }
.form-error { margin-top: 10px; color: var(--danger); font-size: .875rem; font-weight: 700; }
.toast { position: fixed; z-index: 3; bottom: calc(22px + var(--safe-bottom)); left: 50%; width: max-content; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px; color: white; background: var(--ink); box-shadow: var(--shadow); font-size: .9rem; font-weight: 700; transform: translateX(-50%); }
.toast:empty { display: none; }

.icon { position: relative; display: inline-grid; place-items: center; width: 1em; height: 1em; flex: 0 0 auto; font-size: 1rem; }
.icon::before, .icon::after { position: absolute; content: ''; }
.icon-barbell::before { width: 96%; height: 58%; background: currentColor; clip-path: polygon(0 28%, 10% 28%, 10% 42%, 19% 42%, 19% 0, 32% 0, 32% 41%, 68% 41%, 68% 0, 81% 0, 81% 42%, 90% 42%, 90% 28%, 100% 28%, 100% 72%, 90% 72%, 90% 58%, 81% 58%, 81% 100%, 68% 100%, 68% 59%, 32% 59%, 32% 100%, 19% 100%, 19% 58%, 10% 58%, 10% 72%, 0 72%); }
.icon-barbell:not(.brand-mark .icon)::before { max-width: 20px; max-height: 13px; }
.icon-plus::before, .icon-plus::after, .icon-close::before, .icon-close::after { width: .8em; height: 2px; border-radius: 2px; background: currentColor; }
.icon-plus::after { transform: rotate(90deg); }
.icon-close::before { transform: rotate(45deg); }
.icon-close::after { transform: rotate(-45deg); }
.icon-today::before { width: .83em; height: .82em; border: 1.7px solid currentColor; border-radius: 3px; }
.icon-today::after { width: .75em; height: .32em; border-top: 1.7px solid currentColor; }
.icon-history::before { width: .86em; height: .86em; border: 1.7px solid currentColor; border-radius: 50%; }
.icon-history::after { width: .24em; height: .31em; border: solid currentColor; border-width: 0 0 1.7px 1.7px; transform: translate(28%, -22%); }
.icon-stack::before { width: .73em; height: .45em; border: 1.7px solid currentColor; border-radius: 2px; transform: translateY(-28%); }
.icon-stack::after { width: .73em; height: .27em; border: solid currentColor; border-width: 0 1.7px 1.7px; border-radius: 0 0 2px 2px; transform: translateY(85%); }
.icon-repeat::before { width: .75em; height: .75em; border: 1.7px solid currentColor; border-left-color: transparent; border-radius: 50%; }
.icon-repeat::after { width: .29em; height: .29em; border: solid currentColor; border-width: 0 0 1.7px 1.7px; transform: translate(-89%, -62%) rotate(-22deg); }
.icon-edit::before { width: .7em; height: .28em; border: 1.6px solid currentColor; border-radius: 1px; transform: rotate(-44deg); }
.icon-edit::after { width: .26em; height: 1.6px; border-radius: 2px; background: currentColor; transform: translate(-96%, 240%); }

@media (max-width: 760px) {
  .header-inner { min-height: 62px; }
  .header-inner, .shell { padding-left: max(16px, var(--safe-left)); padding-right: max(16px, var(--safe-right)); }
  .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
  .nav { position: fixed; z-index: 2; left: 0; right: 0; bottom: 0; justify-content: space-around; gap: 3px; padding: 6px max(8px, var(--safe-right)) calc(6px + var(--safe-bottom)) max(8px, var(--safe-left)); background: var(--surface); border: 0; border-top: 1px solid var(--line); border-radius: 0; }
  .nav a { flex: 1; flex-direction: column; gap: 4px; min-height: 50px; padding: 5px 3px; font-size: .8rem; }
  .nav a[aria-current] { background: #edf3dd; box-shadow: none; }
  .nav .icon { font-size: 1.05rem; }
  .shell { padding-top: 16px; padding-bottom: calc(84px + var(--safe-bottom)); }
  .hero { min-height: 238px; border-radius: 20px; }
  .hero-content { padding: 28px 22px; }
  .hero-art { width: 50%; opacity: .44; mask-image: linear-gradient(90deg, transparent, black 55%); }
  .barbell { left: 84%; font-size: 1rem; transform: translate(-50%, -50%) rotate(-33deg) scale(.72); }
  .stats { gap: 7px; margin-block: 12px 18px; }
  .stats > div { padding: 12px 9px; border-radius: 13px; }
  .stats dt { font-size: .8rem; overflow-wrap: anywhere; }
  .stats dd { font-size: 1.45rem; }
  .stats .icon { display: none; }
  .home-grid { grid-template-columns: 1fr; gap: 12px; }
  .panel { padding: 13px 14px; border-radius: 16px; }
  .panel-heading h2 { font-size: 1.18rem; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 14px; }
  .toast { bottom: calc(76px + var(--safe-bottom)); }
}

@media (max-width: 400px) {
  .dialog-body { padding: 16px; }
  .log-fields { grid-template-columns: 1fr; }
  .panel-heading { gap: 7px; }
}
