:root {
  --bg: #0a0e14; --surface: #141920; --surface2: #1c2330; --surface3: #242d3d;
  --border: #2a3344; --text: #e2eaf5; --text-muted: #6b7a99; --text-dim: #3d4f6e;
  --accent: #4d9cf8; --accent-dim: #1a3a6a; --green: #3dd68c; --green-dim: #0d3d23;
  --yellow: #f0b429; --yellow-dim: #3d2e00; --red: #f05252; --red-dim: #3d0f0f;
  --purple: #a78bfa; --purple-dim: #2a1f4a; --radius: 14px; --radius-sm: 8px;
  --nav-h: 68px; --header-h: 58px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; font-size: 15px; line-height: 1.5; overflow: hidden; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, textarea, select { font: inherit; color: inherit; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; outline: none; transition: border-color .2s; width: 100%; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: none; }
::-webkit-scrollbar { width: 4px; height: 4px; } ::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

#auth-screen {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg); gap: 28px; padding: 24px;
}
.auth-logo h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -1px; background: linear-gradient(135deg, #4d9cf8, #a78bfa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.auth-logo p { color: var(--text-muted); font-size: .875rem; margin-top: 4px; text-align: center; }
.auth-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.auth-form input { font-size: 1rem; padding: 14px 16px; }
.auth-msg { font-size: .83rem; color: var(--text-muted); text-align: center; min-height: 18px; }
.auth-msg.error { color: var(--red); }
.auth-form button {
  padding: 14px; border-radius: var(--radius-sm); background: var(--accent); color: #fff;
  font-size: 1rem; font-weight: 700; transition: all .15s;
}
.auth-form button:hover { filter: brightness(1.1); }
.auth-form button:disabled { opacity: .5; cursor: not-allowed; }

#app { display: none; flex-direction: column; height: 100vh; }
#app.visible { display: flex; }
#app-header { height: var(--header-h); flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--border); }
.header-title { font-size: 1.05rem; font-weight: 700; letter-spacing: -.3px; }
.header-date { font-size: .8rem; color: var(--text-muted); }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--surface2); border: 1px solid var(--border); font-size: 1rem; transition: all .15s; }
.icon-btn:hover { background: var(--surface3); }
#page-container { flex: 1; overflow-y: auto; overflow-x: hidden; padding-bottom: 8px; }
.page { display: none; padding: 16px; gap: 14px; flex-direction: column; min-height: 100%; }
.page.active { display: flex; }

#bottom-nav { height: var(--nav-h); flex-shrink: 0; background: var(--surface); border-top: 1px solid var(--border); display: flex; align-items: center; }
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 100%; transition: all .15s; color: var(--text-dim); }
.nav-btn.active { color: var(--accent); }
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn span { font-size: .68rem; font-weight: 600; letter-spacing: .3px; }

/* Drawer / menu */
#menu-overlay { position: fixed; inset: 0; z-index: 400; background: rgba(0,0,0,.5); display: none; }
#menu-overlay.open { display: block; }
#menu { position: fixed; top: 0; right: 0; bottom: 0; width: 270px; max-width: 80vw; background: var(--surface); border-left: 1px solid var(--border); transform: translateX(100%); transition: transform .25s; z-index: 401; padding: 18px; display: flex; flex-direction: column; gap: 4px; }
#menu.open { transform: translateX(0); }
#menu h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted); padding: 8px 12px; margin-top: 8px; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 500; color: var(--text); transition: background .15s; }
.menu-item:hover { background: var(--surface2); }
.menu-item.active { background: var(--accent-dim); color: var(--accent); }
.menu-icon { width: 18px; height: 18px; flex-shrink: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.card-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted); }
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: .75rem; font-weight: 600; letter-spacing: .3px; }
.badge-accent { background: var(--accent-dim); color: var(--accent); }
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-purple { background: var(--purple-dim); color: var(--purple); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 600; transition: all .15s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--surface2); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface3); }
.btn-green { background: var(--green); color: #0a1a10; }
.btn-red { background: var(--red); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: .8rem; }
.btn-full { width: 100%; }
.slider-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.slider-label { font-size: .8rem; color: var(--text-muted); min-width: 120px; }
.slider-val { font-size: .875rem; font-weight: 700; min-width: 24px; text-align: right; color: var(--accent); }
input[type=range] { flex: 1; height: 4px; border-radius: 99px; border: none; padding: 0; background: var(--surface3); accent-color: var(--accent); }
.check-list { display: flex; flex-direction: column; gap: 8px; }
.check-item { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface2); border: 1px solid transparent; cursor: pointer; transition: all .15s; user-select: none; }
.check-item:hover { border-color: var(--border); }
.check-item.checked { background: var(--green-dim); border-color: var(--green); }
.check-icon { width: 20px; height: 20px; min-width: 20px; border-radius: 50%; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; margin-top: 1px; transition: all .2s; }
.check-item.checked .check-icon { background: var(--green); border-color: var(--green); }
.check-icon svg { width: 11px; height: 11px; display: none; }
.check-item.checked .check-icon svg { display: block; }
.check-text strong { font-size: .875rem; display: block; }
.check-text small { font-size: .78rem; color: var(--text-muted); }
.progress-bar { height: 6px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width .5s ease; }
.progress-fill.green { background: var(--green); }
.tab-bar { display: flex; gap: 6px; background: var(--surface2); padding: 5px; border-radius: var(--radius-sm); overflow-x: auto; }
.tab-btn { flex: 1; min-width: max-content; padding: 7px 10px; border-radius: 6px; font-size: .8rem; font-weight: 600; color: var(--text-muted); transition: all .15s; white-space: nowrap; }
.tab-btn.active { background: var(--surface3); color: var(--text); }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric-card { background: var(--surface2); border-radius: var(--radius-sm); padding: 12px; border: 1px solid var(--border); }
.metric-card .label { font-size: .73rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.metric-card .value { font-size: 1.6rem; font-weight: 800; margin-top: 2px; letter-spacing: -1px; }
.metric-card .sub { font-size: .75rem; color: var(--text-muted); }

.day-phase-banner { border-radius: var(--radius); padding: 18px; display: flex; align-items: center; gap: 14px; background: linear-gradient(135deg, var(--accent-dim), var(--purple-dim)); border: 1px solid var(--accent-dim); }
.phase-icon { font-size: 2rem; }
.phase-info h2 { font-size: 1.1rem; font-weight: 700; }
.phase-info p { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

.workout-day-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.workout-day-card { background: var(--surface2); border-radius: var(--radius-sm); padding: 14px; border: 2px solid transparent; cursor: pointer; transition: all .2s; text-align: center; }
.workout-day-card:hover { border-color: var(--border); }
.workout-day-card.active-day { border-color: var(--accent); background: var(--accent-dim); }
.workout-day-card.completed-today { border-color: var(--green); background: var(--green-dim); }
.workout-day-letter { font-size: 1.5rem; font-weight: 900; }
.exercise-block { background: var(--surface2); border-radius: var(--radius-sm); padding: 14px; border: 1px solid var(--border); margin-bottom: 10px; }
.exercise-name { font-size: .9rem; font-weight: 700; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.sets-table { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: .82rem; }
.sets-table th { color: var(--text-muted); font-size: .72rem; font-weight: 600; text-align: left; padding-bottom: 6px; }
.sets-table td { padding: 4px 0; vertical-align: middle; }
.sets-table td input { padding: 6px 8px; text-align: center; }
.set-row-num { color: var(--text-muted); font-size: .75rem; width: 24px; }
.prev-data { font-size: .72rem; color: var(--text-dim); margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.pr-badge { display: inline-block; font-size: .65rem; font-weight: 700; padding: 2px 6px; border-radius: 99px; background: var(--yellow-dim); color: var(--yellow); margin-left: 6px; vertical-align: middle; }

.protocol-card { background: var(--surface2); border-radius: var(--radius-sm); padding: 16px; border: 1px solid var(--border); cursor: pointer; transition: all .2s; }
.protocol-card:hover { border-color: var(--accent); background: var(--surface3); }
.protocol-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.protocol-name { font-size: .95rem; font-weight: 700; }
.protocol-rhythm { font-size: .75rem; font-weight: 600; margin-top: 2px; }
.protocol-desc { font-size: .8rem; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }
.protocol-tags { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

#breathing-modal { position: fixed; inset: 0; z-index: 500; background: rgba(10,14,20,.97); backdrop-filter: blur(16px); display: none; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 24px; }
#breathing-modal.open { display: flex; }
.breath-protocol-name { font-size: 1.1rem; font-weight: 700; }
.breath-cycle-info { font-size: .8rem; color: var(--text-muted); }
.breath-ring-wrap { position: relative; display: flex; align-items: center; justify-content: center; }
#breath-svg { width: 200px; height: 200px; }
.breath-ring-bg { fill: none; stroke: var(--surface2); stroke-width: 8; }
.breath-ring-fill { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 565; stroke-dashoffset: 565; transition: stroke-dashoffset .1s linear, stroke .3s; transform-origin: center; transform: rotate(-90deg); }
.breath-center-text { position: absolute; text-align: center; }
.breath-phase { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.breath-count { font-size: 3rem; font-weight: 900; letter-spacing: -3px; }
.breath-controls { display: flex; gap: 12px; }

.chart-wrap { position: relative; height: 180px; }
.stat-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-box { background: var(--surface2); border-radius: var(--radius-sm); padding: 12px; text-align: center; border: 1px solid var(--border); }
.stat-box .sv { font-size: 1.5rem; font-weight: 800; }
.stat-box .sl { font-size: .72rem; color: var(--text-muted); margin-top: 2px; }

#toast { position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface3); border: 1px solid var(--border); border-radius: 99px; padding: 10px 20px; font-size: .85rem; font-weight: 500; opacity: 0; transition: all .3s; pointer-events: none; white-space: nowrap; z-index: 300; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { position: absolute; inset: 0; background: rgba(10,14,20,.7); display: flex; align-items: center; justify-content: center; border-radius: var(--radius); z-index: 10; }

/* Modal for forms */
.modal-overlay { position: fixed; inset: 0; z-index: 600; background: rgba(0,0,0,.7); display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal h3 { font-size: 1rem; font-weight: 700; margin-bottom: 14px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: .75rem; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* List rows */
.list-row { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-title { font-size: .9rem; font-weight: 600; }
.list-row .lr-sub { font-size: .76rem; color: var(--text-muted); margin-top: 2px; }
.list-row .lr-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn-sm { width: 32px; height: 32px; border-radius: 6px; background: var(--surface3); display: flex; align-items: center; justify-content: center; font-size: .85rem; }
.icon-btn-sm:hover { background: var(--accent-dim); }

/* Drag handle for ordering */
.drag-handle { cursor: grab; color: var(--text-dim); padding: 0 6px; user-select: none; }
.dragging { opacity: .5; }
