/* SpineRx — mobile-first, dark-first */
:root {
  --bg: #0b1014; --bg2: #0f161c; --card: #141d25; --card2: #1a2530;
  --txt: #e9f0f5; --muted: #8aa0b0; --line: #223240;
  --accent: #34d8ab; --accent-dim: #1d8f72; --accent-soft: rgba(52, 216, 171, .12);
  --gold: #eac56a; --danger: #f0716e; --warn: #e8a64f; --info: #62b2f0;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --r: 18px; --r-sm: 12px;
  --nav-h: calc(64px + env(safe-area-inset-bottom));
}
[data-theme="light"] {
  --bg: #f2f5f7; --bg2: #eaeff2; --card: #ffffff; --card2: #f4f7f9;
  --txt: #15222c; --muted: #5d7384; --line: #dde6ec;
  --accent: #0ca678; --accent-dim: #0a8a64; --accent-soft: rgba(12, 166, 120, .1);
  --shadow: 0 8px 24px rgba(21, 50, 70, .1);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--txt);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: var(--nav-h);
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--txt); background: var(--card2);
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.hidden { display: none !important; }

/* ---------- login ---------- */
#login {
  position: fixed; inset: 0; z-index: 100; background: radial-gradient(120% 90% at 50% 0%, #12222b 0%, var(--bg) 60%);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
[data-theme="light"] #login { background: radial-gradient(120% 90% at 50% 0%, #dcefe9 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-mark {
  width: 76px; height: 76px; margin: 0 auto 18px; border-radius: 22px;
  background: linear-gradient(135deg, var(--accent) 0%, #1e7f95 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 800; color: #07211a; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.02em; }
.login-card p { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.login-card form { display: grid; gap: 12px; }
.login-err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 0; }

/* ---------- shell ---------- */
.wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px 24px; }
.apphead {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: max(8px, env(safe-area-inset-top)); margin-bottom: 14px;
}
.apphead .date { color: var(--muted); font-size: 13px; }
.apphead h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 650;
}
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px; background: var(--card);
  border: 1px solid var(--line); display: flex; align-items: center; justify-content: center;
  font-size: 17px;
}

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 10px; }
.coach { border-left: 4px solid var(--info); }
.coach.tone-hold { border-left-color: var(--warn); }
.coach.tone-go { border-left-color: var(--accent); }
.coach.tone-adjust { border-left-color: var(--gold); }
.coach p { margin: 0; font-size: 14.5px; }
.coach .who { font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }

/* ---------- buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 14px; padding: 14px 18px; font-weight: 650; font-size: 15.5px;
  background: var(--card2); border: 1px solid var(--line); width: 100%;
  transition: transform .06s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #25b9c9); color: #06231b; border: 0; }
.btn.ghost { background: transparent; }
.btn.small { padding: 9px 14px; font-size: 13.5px; width: auto; border-radius: 11px; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--card2); border-radius: 999px;
  padding: 8px 16px; font-size: 14px; font-weight: 600;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- task rows ---------- */
.task {
  display: flex; align-items: center; gap: 12px; padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.task:last-child { border-bottom: 0; }
.task .tcheck {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line);
  flex: none; display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.task.done .tcheck { background: var(--accent); border-color: var(--accent); color: #06231b; }
.task.done .tmain { opacity: .55; text-decoration: line-through; }
.task .tmain { flex: 1; min-width: 0; }
.task .tname { font-weight: 600; font-size: 15px; }
.task .tmeta { color: var(--muted); font-size: 12.5px; }

/* ---------- progress ring + big stat ---------- */
.statrow { display: flex; gap: 12px; }
.stat { flex: 1; background: var(--card2); border-radius: var(--r-sm); padding: 12px; text-align: center; }
.stat .v { font-size: 22px; font-weight: 750; letter-spacing: -.02em; }
.stat .l { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .v.good { color: var(--accent); }
.stat .v.bad { color: var(--danger); }

/* ---------- sliders / checkin ---------- */
.field { margin-bottom: 14px; }
.field label { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 7px; }
.field label .val { color: var(--accent); font-weight: 750; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 34px; background: transparent; padding: 0; border: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--gold), var(--danger)); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); margin-top: -10px; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.togglerow { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); }
.togglerow:last-child { border-bottom: 0; }
.togglerow .tl { font-size: 14.5px; font-weight: 550; }
.togglerow .td { font-size: 12px; color: var(--muted); }
.switch { position: relative; width: 52px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; z-index: 2; }
.switch .knob {
  position: absolute; inset: 0; border-radius: 999px; background: var(--card2);
  border: 1px solid var(--line); transition: background .15s;
}
.switch .knob::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 23px; height: 23px;
  border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.switch input:checked + .knob { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(21px); }

/* ---------- library ---------- */
.exgrid { display: grid; gap: 12px; }
.excard {
  display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 10px; align-items: center; width: 100%; text-align: left;
}
.excard img { width: 104px; height: 68px; object-fit: cover; border-radius: 10px; flex: none; background: var(--card2); }
.excard .exname { font-weight: 650; font-size: 15px; }
.excard .exmeta { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line); color: var(--muted); }
.tag.acc { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft); }
.tag.lock { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }

/* ---------- video ---------- */
.vid { position: relative; border-radius: 14px; overflow: hidden; aspect-ratio: 16/9; background: #000; margin-bottom: 12px; }
.vid img { width: 100%; height: 100%; object-fit: cover; opacity: .85; }
.vid iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.vid .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
}
.vid .play span {
  width: 64px; height: 64px; border-radius: 50%; background: rgba(10, 14, 18, .72);
  border: 2px solid rgba(255,255,255,.85); display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 24px; padding-left: 5px; backdrop-filter: blur(4px);
}
.vid .vcredit { position: absolute; left: 8px; bottom: 8px; font-size: 11px; color: #fff; background: rgba(0,0,0,.55); padding: 3px 8px; border-radius: 7px; }

/* ---------- sheets / player ---------- */
.sheet-back {
  position: fixed; inset: 0; background: rgba(4, 8, 12, .6); z-index: 50;
  backdrop-filter: blur(3px); animation: fade .18s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--bg2); border-radius: 24px 24px 0 0; max-height: 92dvh; overflow-y: auto;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  animation: up .22s cubic-bezier(.2, .9, .3, 1);
}
.sheet .grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 14px; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

#player { position: fixed; inset: 0; z-index: 60; background: var(--bg); overflow-y: auto; padding: 0 18px calc(20px + env(safe-area-inset-bottom)); }
.player-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 0 10px; position: sticky; top: 0; background: var(--bg); z-index: 2;
}
.pbar { display: flex; gap: 4px; flex: 1; margin: 0 14px; }
.pbar i { height: 4px; flex: 1; border-radius: 2px; background: var(--line); }
.pbar i.on { background: var(--accent); }
.cuelist { margin: 0 0 14px; padding: 0; list-style: none; }
.cuelist li { display: flex; gap: 10px; padding: 7px 0; font-size: 14.5px; }
.cuelist li::before { content: "·"; color: var(--accent); font-weight: 900; }
.holdring { display: flex; flex-direction: column; align-items: center; margin: 10px 0 16px; }
.holdring svg { transform: rotate(-90deg); }
.holdring .num { font-size: 40px; font-weight: 800; letter-spacing: -.03em; margin-top: -118px; height: 78px; display:flex; align-items:center; }
.holdring .lab { color: var(--muted); font-size: 13px; margin-top: 2px; }
.setdots { display: flex; gap: 8px; justify-content: center; margin: 8px 0 14px; }
.setdots i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.setdots i.on { background: var(--accent); }
.gentle {
  background: color-mix(in srgb, var(--gold) 12%, transparent); border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
  border-radius: var(--r-sm); padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px;
}
.caution {
  background: color-mix(in srgb, var(--warn) 10%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: var(--r-sm); padding: 10px 12px; font-size: 13px; margin: 0 0 12px; color: var(--txt);
}

/* ---------- charts & calendar ---------- */
canvas.chart { width: 100%; height: 180px; display: block; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal .dow { text-align: center; font-size: 10.5px; color: var(--muted); font-weight: 700; padding: 3px 0; }
.cal .day {
  aspect-ratio: 1; border-radius: 10px; background: var(--card2); border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; gap: 2px;
}
.cal .day.out { opacity: .25; }
.cal .day.today { border-color: var(--accent); }
.cal .dots { display: flex; gap: 2px; }
.cal .dots i { width: 5px; height: 5px; border-radius: 50%; }
.weekbar { display: flex; gap: 4px; align-items: flex-end; height: 90px; }
.weekbar .wb { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.weekbar .bar { width: 100%; max-width: 26px; border-radius: 6px 6px 2px 2px; background: var(--accent-dim); min-height: 3px; }
.weekbar .bl { font-size: 10px; color: var(--muted); }

/* ---------- bottom nav ---------- */
nav#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom); height: var(--nav-h);
}
nav#tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 10.5px; font-weight: 650; padding-top: 8px;
}
nav#tabbar button svg { width: 23px; height: 23px; }
nav#tabbar button.on { color: var(--accent); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 14px); transform: translateX(-50%) translateY(20px);
  background: var(--card); border: 1px solid var(--line); color: var(--txt);
  border-radius: 999px; padding: 11px 20px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); opacity: 0; transition: all .25s ease; z-index: 70; pointer-events: none;
  max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.note { font-size: 12.5px; color: var(--muted); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.center { text-align: center; }
h4.secthead { margin: 22px 4px 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* ---------- responsive tuning ---------- */
@media (max-width: 389px) {
  .wrap { padding: 12px 12px 20px; }
  .card { padding: 14px; }
  .stat { padding: 10px 4px; }
  .stat .v { font-size: 18px; }
  .stat .l { font-size: 10px; }
  .excard img { width: 88px; height: 58px; }
  .chip { padding: 8px 13px; font-size: 13px; }
}
@media (min-width: 700px) {
  .wrap { max-width: 620px; padding-top: 28px; }
  body { background: linear-gradient(180deg, var(--bg2), var(--bg) 320px); }
  nav#tabbar { max-width: 620px; left: 50%; transform: translateX(-50%); border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0; }
}
html { -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
