/* myAIPT web UI — mobile-first, light/dark, no inline styles (strict CSP). */
:root {
  --brand: #3d8eab;          /* myAIPT blue (darkened #64abc4 for contrast) */
  --brand-soft: #64abc4;
  --accent: #f97316;         /* orange: primary actions, streak */
  --accent-hover: #ea580c;
  --ai-design-1: #06b6d4; --ai-design-2: #0e7490;
  --ai-suggest-1: #8b5cf6; --ai-suggest-2: #6d28d9;
  --green: #16a34a; --red: #dc2626; --amber: #b45309; --blue: #2563eb;
  --bg: #f3f5f7; --surface: #ffffff; --surface-2: #f8fafb; --border: #e3e8ee;
  --text: #17202a; --muted: #5f6b7a; --topbar: #0b0f14;
  --radius: 14px; --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b0f14; --surface: #141a21; --surface-2: #1b232c; --border: #26303b;
  --text: #e8edf2; --muted: #98a4b3; --brand: #64abc4; --amber: #fbbf24; --blue: #60a5fa; --green: #4ade80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.5; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }
img { max-width: 100%; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, .h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2, .h2 { font-size: 1.35rem; margin: 0 0 .5rem; }
.h3 { font-size: 1.1rem; margin: 0 0 .4rem; }
.h4 { font-size: 1rem; margin: .6rem 0 .3rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.lead { font-size: 1.15rem; }
.accent { color: var(--accent); }
.plain { list-style: none; margin: 0; padding: 0; }
.sr-only, .sprite { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hp { position: absolute; left: -9999px; }
.inline { display: inline; margin: 0; }
.row { display: flex; align-items: center; }
.gap { gap: .75rem; }
[hidden] { display: none !important; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 0; }
:focus-visible { outline: 3px solid var(--brand-soft); outline-offset: 2px; }

.icon { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; vertical-align: -.2em; }
#i-play polygon, #i-pause rect { fill: currentColor; }
.icon-xs { width: .85em; height: .85em; }
.icon-xl { width: 3rem; height: 3rem; }
:root:not([data-theme="dark"]) .theme-dark-only, :root[data-theme="dark"] .theme-light-only { display: none; }

/* top bar */
.topbar { background: var(--topbar); color: #fff; position: sticky; top: 0; z-index: 50; padding-top: env(safe-area-inset-top); }
.topbar-inner { max-width: 1040px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; min-height: 60px; }
.brand-logo { height: 30px; width: auto; display: block; }
.mainnav { display: flex; gap: .25rem; margin-left: 1rem; }
.mainnav a { color: #c9d3dd; padding: .45rem .75rem; border-radius: 999px; display: flex; align-items: center; gap: .4rem; font-weight: 500; }
.mainnav a:hover { background: rgba(255, 255, 255, .08); text-decoration: none; color: #fff; }
.mainnav a.active { background: rgba(249, 115, 22, .18); color: #fdba74; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .25rem; }
.icon-btn { background: none; border: 0; color: inherit; cursor: pointer; padding: .45rem; border-radius: 10px; display: inline-flex; align-items: center; gap: .25rem; font: inherit; }
.icon-btn:hover { background: rgba(127, 127, 127, .15); text-decoration: none; }
.topbar .icon-btn { color: #dbe3ea; }
.icon-btn.small { padding: .3rem; }
.icon-btn.danger { color: var(--red); }
.lang-code { font-size: .8rem; font-weight: 600; }

/* bottom nav on phones */
@media (max-width: 720px) {
  .mainnav { position: fixed; bottom: 0; left: 0; right: 0; margin: 0; background: var(--topbar); justify-content: space-around; padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom)); border-top: 1px solid #1d2630; z-index: 60; }
  .mainnav a { flex-direction: column; gap: .1rem; font-size: .72rem; padding: .3rem .8rem; }
  .mainnav a .icon { width: 1.35rem; height: 1.35rem; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .fab { bottom: calc(80px + env(safe-area-inset-bottom)) !important; }
  .sticky-actions { bottom: calc(64px + env(safe-area-inset-bottom)) !important; }
}

.container { width: 100%; max-width: 1040px; margin: 0 auto; padding: 1.25rem 1rem 5.5rem; flex: 1; }
.footer { max-width: 1040px; margin: 0 auto; width: 100%; padding: 1rem; display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.stack > * + * { margin-top: .85rem; }
.page-head { margin-bottom: 1rem; }
.back-link { display: inline-block; font-size: .9rem; margin-bottom: .25rem; color: var(--muted); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.grid-2, .grid-3 { display: grid; gap: .85rem; grid-template-columns: 1fr; }
@media (min-width: 600px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }

/* forms */
.field { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-size: .875rem; color: var(--muted); padding: 0; }
.field.grow { flex: 1; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, input[type=file] {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .75rem; width: 100%; min-height: 44px;
}
input:focus, select:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(100, 171, 196, .25); }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; margin-bottom: .4rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip input, .choice input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: .45rem .9rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-weight: 500; user-select: none; }
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip input:focus-visible + span, .choice input:focus-visible + span { outline: 3px solid var(--brand-soft); outline-offset: 2px; }
.choice-list { display: grid; gap: .5rem; }
.choice span { display: block; padding: .75rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.choice input:checked + span { border-color: var(--accent); background: rgba(249, 115, 22, .08); font-weight: 600; }
.search { margin-bottom: .75rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; font: inherit; font-weight: 600; border-radius: 12px; border: 1px solid transparent; padding: .65rem 1.15rem; cursor: pointer; min-height: 44px; text-decoration: none !important; transition: transform .08s ease, background .15s ease; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--brand); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ai { background: linear-gradient(135deg, var(--ai-design-1), var(--ai-design-2)); color: #fff; }
.btn-block { width: 100%; }
.btn.small { min-height: 34px; padding: .35rem .8rem; font-size: .9rem; }
.btn[disabled] { opacity: .6; cursor: wait; }

/* alerts & toasts */
.alert { border-radius: var(--radius-sm); padding: .7rem .9rem; border: 1px solid; }
.alert-danger { background: rgba(220, 38, 38, .08); border-color: rgba(220, 38, 38, .3); color: var(--red); }
.alert-warning { background: rgba(180, 83, 9, .08); border-color: rgba(180, 83, 9, .3); color: var(--amber); }
.alert-info { background: rgba(61, 142, 171, .08); border-color: rgba(61, 142, 171, .3); color: var(--brand); }
.toasts { position: fixed; top: calc(70px + env(safe-area-inset-top)); right: 1rem; left: 1rem; z-index: 90; display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; pointer-events: none; }
.toast { pointer-events: auto; max-width: 420px; display: flex; align-items: center; gap: .5rem; padding: .7rem .8rem .7rem 1rem; border-radius: 12px; color: #fff; background: #334155; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); animation: toast-in .25s ease; }
.toast-success { background: var(--green); } .toast-danger { background: var(--red); } .toast-warning { background: #b45309; }
.toast-close { background: none; border: 0; color: inherit; cursor: pointer; padding: .2rem; }
.toast.hide { opacity: 0; transform: translateY(-6px); transition: all .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* auth */
.auth-page .container { display: flex; justify-content: center; align-items: flex-start; }
.auth-card { width: 100%; max-width: 420px; margin-top: 2rem; padding: 1.75rem; }
.auth-logo { display: block; margin: 0 auto .25rem; height: 50px; width: auto; }
.auth-card form { margin: 1rem 0; }

/* dashboard */
.ai-cards { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
@media (max-width: 520px) { .ai-cards { grid-template-columns: 1fr; } }
.ai-card-form { margin: 0; display: flex; }
.ai-card { flex: 1; display: flex; align-items: center; gap: .8rem; padding: .9rem 1rem; border-radius: var(--radius); color: #fff !important; text-decoration: none !important; border: 0; font: inherit; text-align: left; cursor: pointer; box-shadow: var(--shadow); transition: transform .12s ease; }
.ai-card:hover { transform: translateY(-1px); }
.ai-card strong { display: block; font-size: 1rem; }
.ai-card small { display: block; opacity: .85; font-size: .8rem; }
.ai-card-design { background: linear-gradient(135deg, var(--ai-design-1), var(--ai-design-2)); }
.ai-card-suggest { background: linear-gradient(135deg, var(--ai-suggest-1), var(--ai-suggest-2)); }
.ai-card-icon { width: 40px; height: 40px; border-radius: 11px; background: rgba(255, 255, 255, .2); display: grid; place-items: center; }
.ai-card-icon .icon { width: 1.3rem; height: 1.3rem; }
.stats-bar { display: flex; align-items: center; gap: 1.25rem; padding: .75rem 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); margin-bottom: 1rem; }
.stat { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: .5rem; align-items: center; color: var(--muted); }
.stat .icon { grid-row: span 2; width: 1.5rem; height: 1.5rem; }
.stat-value { font-size: 1.35rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .72rem; }
.stat-hot { color: var(--accent); } .stat-blue { color: var(--blue); }
.stat-divider { width: 1px; height: 32px; background: var(--border); }
.group { margin-bottom: 1.1rem; }
.group-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 0 0 .4rem .2rem; }
.workout-list { list-style: none; margin: 0; padding: 0; overflow: visible; }
.workout-row { display: flex; align-items: center; gap: .5rem; padding: .75rem .9rem; border-bottom: 1px solid var(--border); }
.workout-row:last-child { border-bottom: 0; }
.workout-main { flex: 1; min-width: 0; color: inherit; text-decoration: none !important; }
.workout-title { font-weight: 650; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .3rem; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: .25rem; font-size: .74rem; font-weight: 600; padding: .12rem .55rem; border-radius: 999px; }
.badge-blue { background: rgba(37, 99, 235, .1); color: var(--blue); }
.badge-amber { background: rgba(245, 158, 11, .15); color: var(--amber); }
.badge-green { background: rgba(22, 163, 74, .12); color: var(--green); }
.badge-muted { background: rgba(100, 116, 139, .12); color: var(--muted); }
.row-actions { display: flex; gap: .3rem; align-items: center; }
.action { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; border: 0; background: rgba(100, 116, 139, .1); color: var(--muted); cursor: pointer; list-style: none; }
.action::-webkit-details-marker { display: none; }
.action-start { background: rgba(22, 163, 74, .12); color: var(--green); }
.action-edit { background: rgba(37, 99, 235, .1); color: var(--blue); }
.action-danger { color: var(--red); background: rgba(220, 38, 38, .08); }
.action:hover { filter: brightness(.95); text-decoration: none; }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: 44px; z-index: 20; padding: .35rem; min-width: 170px; }
.menu-pop form { margin: 0; }
.menu-item { display: flex; gap: .5rem; align-items: center; width: 100%; background: none; border: 0; padding: .55rem .7rem; border-radius: 8px; font: inherit; color: var(--text); cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--red); }
.empty { text-align: center; padding: 2.5rem 1rem; }
.fab { position: fixed; right: max(1.25rem, env(safe-area-inset-right)); bottom: calc(1.5rem + env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%; background: linear-gradient(135deg, #fb923c, var(--accent-hover)); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 20px rgba(249, 115, 22, .45); z-index: 40; }
.fab .icon { width: 28px; height: 28px; }
.fab:hover { transform: scale(1.05); }

/* AI */
.ai-overlay { position: fixed; inset: 0; background: rgba(11, 15, 20, .6); display: grid; place-items: center; z-index: 95; backdrop-filter: blur(3px); }
.ai-overlay-box { text-align: center; max-width: 320px; padding: 1.75rem; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--accent); margin: 0 auto .75rem; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.suggest-list { list-style: none; margin: 1rem 0 5rem; padding: 0; display: grid; gap: .6rem; }
.suggest-row { display: flex; gap: .85rem; align-items: center; padding: .7rem; }
.suggest-row img, .thumb-placeholder { width: 72px; height: 72px; border-radius: 12px; object-fit: cover; background: var(--surface-2); flex-shrink: 0; display: grid; place-items: center; }
.explain summary { cursor: pointer; }

/* sticky action bar */
.sticky-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: .6rem; padding: .75rem; margin: 1rem -.25rem 0; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--border); z-index: 30; }

/* editor */
.ex-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; }
.ex-row { padding: .8rem; }
.ex-row > * + * { margin-top: .6rem; }
.ex-row-head { display: flex; align-items: center; gap: .55rem; }
.ex-index { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; font-size: .8rem; font-weight: 700; flex-shrink: 0; }
.ex-row.pair-a .ex-index { background: var(--accent); color: #fff; border-color: var(--accent); }
.ex-row.pair-b .ex-index { background: var(--brand); color: #fff; border-color: var(--brand); }
.ex-thumb { width: 52px; height: 52px; border-radius: 10px; border: 1px dashed var(--border); background: var(--surface-2); display: grid; place-items: center; cursor: pointer; padding: 0; overflow: hidden; flex-shrink: 0; color: var(--muted); }
.ex-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ex-tools { display: flex; gap: .1rem; }
.ex-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .6rem; }
@media (max-width: 420px) { .ex-grid { grid-template-columns: 1fr 1fr; } .ex-grid .field:last-child { grid-column: span 2; } }
.stepper { display: flex; align-items: stretch; }
.stepper input { text-align: center; border-radius: 0; -moz-appearance: textfield; min-width: 0; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.stepper button { width: 40px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1.15rem; cursor: pointer; }
.stepper button:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); border-right: 0; }
.stepper button:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: 0; }

/* modal */
.modal { border: 0; border-radius: var(--radius); padding: 1rem; width: min(640px, 94vw); max-height: 85vh; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal::backdrop { background: rgba(11, 15, 20, .55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.image-choice { border: 2px solid transparent; border-radius: 12px; padding: 0; background: var(--surface-2); cursor: pointer; overflow: hidden; aspect-ratio: 1; }
.image-choice:hover, .image-choice:focus-visible { border-color: var(--accent); }
.image-choice img { width: 100%; height: 100%; object-fit: cover; display: block; }
.info-list dt { font-weight: 700; margin-top: .4rem; } .info-list dd { margin: 0; color: var(--muted); }
.bullets { margin: .2rem 0 .6rem; padding-left: 1.2rem; }

/* player */
.player { max-width: 640px; margin: 0 auto; }
.player-head { text-align: center; }
.player-title { font-size: 1.35rem; }
.player-meta { display: flex; justify-content: center; align-items: center; gap: .75rem; flex-wrap: wrap; margin: .5rem 0; }
.led { font-family: var(--mono); font-size: 2rem; font-weight: 700; color: #39ff5a; background: #05080b; padding: .1rem .7rem; border-radius: 10px; box-shadow: 0 0 12px rgba(57, 255, 90, .45); font-variant-numeric: tabular-nums; }
.hr-zone { display: inline-flex; gap: .4rem; align-items: center; background: #05080b; color: #fde047; padding: .35rem .7rem; border-radius: 10px; font-family: var(--mono); font-size: .9rem; }
.hr-zone strong { color: #f87171; font-family: var(--font); }
.hr-zone .icon { color: #f87171; }
.progress { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; margin: .6rem 0 .25rem; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #facc15); transition: width .35s ease; }
.progress-text { font-size: .85rem; }
.player-stage { text-align: center; padding: 1.25rem; min-height: 360px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem; }
.player-stage img { width: min(320px, 80vw); aspect-ratio: 1; object-fit: cover; border-radius: 18px; background: var(--surface-2); }
.player-ex-name { font-size: 1.45rem; font-weight: 800; margin: .5rem 0 .2rem; }
.pair-tag { display: inline-block; background: var(--accent); color: #fff; border-radius: 8px; padding: 0 .5rem; margin-right: .35rem; }
.pair-tag.b { background: var(--brand); }
.player-set { color: var(--muted); font-weight: 600; }
.player-load { font-size: 1.25rem; font-weight: 700; }
.player-note { color: var(--amber); font-weight: 600; }
.rest-view .rest-label { font-size: 1.25rem; font-weight: 800; letter-spacing: .2em; color: var(--muted); }
.rest-view .rest-time { font-size: 5rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1; }
.rest-view .rest-next { color: var(--muted); }
.done-view .icon { width: 5rem; height: 5rem; color: var(--green); }
.player-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: 1rem 0; }
.player-controls.single { grid-template-columns: 1fr; }
.player-controls .btn { min-height: 56px; font-size: 1.05rem; }
.btn-go { background: var(--accent); color: #fff; }
.btn-blue { background: var(--brand); color: #fff; }
.btn-green { background: var(--green); color: #fff; }

/* settings */
.danger-zone summary { cursor: pointer; color: var(--red); font-weight: 600; }
.prose { max-width: 720px; margin: 0 auto; }
.prose p { margin: .8rem 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
