:root {
  --bg: #0f1115;
  --bg2: #161a22;
  --card: #1c212c;
  --card2: #232a38;
  --border: #2c3445;
  --text: #e8ecf3;
  --muted: #8b94a7;
  --accent: #4f8cff;
  --accent2: #2e63c9;
  --green: #3ecf8e;
  --amber: #ffb02e;
  --red: #ff5d5d;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
}

#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(15,17,21,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; }

#session-chip {
  font-variant-numeric: tabular-nums;
  background: var(--card2); border: 1px solid var(--border);
  color: var(--green); font-weight: 600; font-size: 14px;
  padding: 4px 12px; border-radius: 999px;
}

#app {
  padding: 14px 14px calc(150px + var(--safe-bottom));
  max-width: 560px; margin: 0 auto;
}

h2.section { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 20px 4px 8px; }
h2.section:first-child { margin-top: 4px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.card.tappable:active { background: var(--card2); }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.bold { font-weight: 600; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; }
.green { color: var(--green); } .amber { color: var(--amber); } .red { color: var(--red); }

button {
  font: inherit; color: var(--text); background: var(--card2);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; font-weight: 600; cursor: pointer;
}
button:active { transform: scale(.97); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.success { background: var(--green); border-color: var(--green); color: #06281a; }
button.danger { background: transparent; border-color: var(--red); color: var(--red); }
button.ghost { background: transparent; }
button.wide { width: 100%; padding: 14px; font-size: 16px; }
button.icon-btn { padding: 8px 10px; border-radius: 10px; font-size: 15px; line-height: 1; }
button:disabled { opacity: .45; pointer-events: none; }

input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 110px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
label.field { display: block; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
label.field > span { display: block; margin-bottom: 5px; }

/* ----- exercise card / set grid ----- */
.ex-name { font-weight: 700; font-size: 17px; }
.target-line { color: var(--muted); font-size: 14px; margin-top: 2px; }

.set-grid { display: grid; grid-template-columns: 30px 1fr 1fr 1fr 46px; gap: 6px; align-items: center; margin-top: 10px; }
.set-grid .head { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); text-align: center; }
.set-grid input { text-align: center; padding: 9px 4px; }
.set-no { text-align: center; color: var(--muted); font-weight: 600; }
.set-done-btn {
  height: 42px; border-radius: 10px; font-size: 17px; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.set-row-done input { border-color: var(--green); background: rgba(62,207,142,.08); }

/* ----- tab bar ----- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex;
  background: rgba(18,21,28,.96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
#tabbar .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; border-radius: 0;
  padding: 9px 0 7px; font-size: 11px; font-weight: 600; color: var(--muted);
}
#tabbar .tab.active { color: var(--accent); }
.tab-icon { font-size: 20px; }

/* ----- rest timer banner ----- */
#rest-banner {
  position: fixed; left: 10px; right: 10px;
  bottom: calc(64px + var(--safe-bottom)); z-index: 25;
  background: var(--card2); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 12px 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
#rest-banner.over { border-color: var(--green); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(62,207,142,.18); } }
.rest-time { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rest-bar { height: 5px; background: var(--bg); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.rest-bar > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s linear; }
#rest-banner.over .rest-bar > div { background: var(--green); }

/* ----- modal ----- */
#modal-root .overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 20px 20px 0 0; width: 100%; max-width: 560px;
  max-height: 86vh; overflow-y: auto;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  animation: slideup .2s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { font-size: 18px; margin-bottom: 12px; }
.sheet .actions { display: flex; gap: 8px; margin-top: 14px; }
.sheet .actions button { flex: 1; padding: 13px; }

/* ----- toast ----- */
#toast-root { position: fixed; top: calc(60px + var(--safe-top)); left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 9px 18px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.45); animation: slideup .2s ease-out;
}
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

/* ----- misc ----- */
.hidden { display: none !important; }
.day-pill { background: var(--bg2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--muted); }
.pr-badge { background: rgba(255,176,46,.15); color: var(--amber); border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.swap-note { font-size: 12px; color: var(--amber); margin-top: 2px; }
.chev { color: var(--muted); font-size: 18px; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.spark { display: block; margin-top: 6px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; line-height: 1.6; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }
code.inline { background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; font-size: 13px; }
