* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--amber); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

.wrap { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }

nav.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
}
.brand .mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--amber), color-mix(in srgb, var(--amber) 60%, black));
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35) inset;
}
.nav-links { display: flex; gap: 18px; align-items: center; }
.nav-links a { color: var(--muted); font-size: 14px; text-decoration: none; }
.nav-links a:hover { color: var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 650;
  cursor: pointer;
  font-size: 14px;
  color: var(--ink);
  background: var(--amber);
}
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.mint { background: var(--mint); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.hero {
  position: relative;
  min-height: 78vh;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 56px;
}
.hero img { width: 100%; height: 78vh; object-fit: cover; filter: saturate(0.9) contrast(1.05); }
.hero .veil {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, rgb(3 7 18 / 0.88) 0%, rgb(3 7 18 / 0.35) 55%, rgb(3 7 18 / 0.15) 100%);
}
.hero .copy {
  position: absolute; left: 40px; bottom: 40px; right: 40px;
  max-width: 640px;
}
.kicker {
  color: var(--amber);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
}
h1 {
  font-family: var(--font-display);
  font-size: clamp(36px, 6vw, 64px);
  line-height: 0.95;
  margin: 10px 0 16px;
  font-weight: 600;
}
.lede { color: var(--color-gray-300); font-size: 18px; max-width: 52ch; }

.grid-3, .grid-2 { display: grid; gap: 18px; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-2 { grid-template-columns: 1.1fr 0.9fr; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
}
.card .body { padding: 20px; }
.card h3 { margin: 0 0 8px; font-size: 20px; }
.card p { margin: 0; color: var(--muted); }
.card img { height: 180px; width: 100%; object-fit: cover; }

.section { padding: 20px 0 64px; }
.section h2 {
  font-family: var(--font-display);
  font-size: 32px;
  margin: 0 0 12px;
}

.diagram {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  overflow: auto;
}

.note { color: var(--muted); font-size: 13px; }
.trend { font-size: 13px; margin-right: 2px; }
.trend.up { color: var(--mint); }
.trend.down { color: var(--rose); }
.trend.flat { color: var(--muted); }
.sport-card .label svg { vertical-align: -2px; margin-right: 4px; }

footer {
  border-top: 1px solid var(--line);
  padding: 28px 0 48px;
  color: var(--muted);
  font-size: 13px;
}

/* App shell: topbar + floating glass dock navigation */
.app {
  min-height: 100vh;
  padding-bottom: calc(var(--footnav-h, 76px) + env(safe-area-inset-bottom) + 18px);
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 32px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { margin: 0; }

.footnav {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: stretch;
  gap: 2px;
  max-width: calc(100vw - 20px);
  padding: 8px;
  border-radius: 22px;
  border: 1px solid color-mix(in srgb, var(--text) 8%, transparent);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--text) 5%, transparent), color-mix(in srgb, var(--text) 1%, transparent)),
    color-mix(in srgb, var(--bg-2) 82%, transparent);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: var(--shadow);
  overflow-x: auto;
  scrollbar-width: none;
}
.footnav::-webkit-scrollbar { display: none; }
.footnav .linkish {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 72px;
  padding: 9px 14px 8px;
  border-radius: 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
  white-space: nowrap;
  transition: color 0.2s ease, background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}
.footnav .linkish svg {
  width: 20px;
  height: 20px;
  opacity: 0.85;
  transition: opacity 0.2s ease, transform 0.2s ease, filter 0.2s ease;
}
.footnav .linkish:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 6%, transparent);
}
.footnav .linkish:hover svg { opacity: 1; }
.footnav .linkish:active { transform: scale(0.96); }
.footnav .linkish.active {
  color: var(--mint);
  background: linear-gradient(180deg, color-mix(in srgb, var(--mint) 16%, transparent), color-mix(in srgb, var(--mint) 5%, transparent));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--mint) 25%, transparent), 0 4px 16px color-mix(in srgb, var(--mint) 12%, transparent);
}
.footnav .linkish.active svg {
  opacity: 1;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--mint) 60%, transparent));
}
@media (min-width: 900px) {
  .footnav { gap: 4px; }
  .footnav .linkish { padding: 10px 16px 9px; font-size: 11.5px; }
}
@media (max-width: 640px) {
  .footnav { padding: 6px; border-radius: 20px; bottom: calc(env(safe-area-inset-bottom) + 10px); }
  .footnav .linkish { min-width: 62px; padding: 8px 10px 7px; font-size: 10px; }
  .footnav .linkish svg { width: 19px; height: 19px; }
}

.main {
  padding: 28px 32px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}
.page-title {
  font-family: var(--font-display);
  font-size: clamp(32px, 4vw, 40px);
  line-height: 1.05;
  margin: 6px 0 12px;
  font-weight: 600;
}
.page-lede { margin-bottom: 4px; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin: 20px 0 28px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  min-width: 0;
}
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.stat .value { font-variant-numeric: tabular-nums; font-size: 28px; margin-top: 6px; }
.stat .value.mint { color: var(--mint); }
.stat .value.amber { color: var(--amber); }
.stat .value.rose { color: var(--rose); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }

.banner {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  margin: 0 0 24px;
}
.error { color: var(--rose); font-size: 14px; min-height: 1.2em; }
.ok { color: var(--mint); }

form.stack { display: grid; gap: 12px; max-width: 420px; }
label { font-size: 13px; color: var(--muted); }
input, textarea, select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.tight { gap: 8px; }
.file-import-row select { max-width: 220px; flex: 0 1 220px; }
.file-import-row input[type="file"] {
  width: auto;
  max-width: 280px;
  flex: 1 1 200px;
  padding: 8px 10px;
  font-size: 13px;
}
.icu-key-input {
  max-width: 240px;
  flex: 1 1 180px;
}
.oauth-app-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}
.oauth-app-fields .icu-key-input {
  max-width: 200px;
}
.oauth-callback code.callback-url {
  display: inline-block;
  margin-top: 4px;
  word-break: break-all;
  font-size: 12px;
  color: var(--text);
}
.check { display: flex; gap: 8px; align-items: center; color: var(--text); }

.chart-wrap {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 14px 10px;
  margin: 0 0 20px;
}
.chart-wrap .uplot-box {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 260px;
  position: relative;
  overflow: hidden;
}
.chart-wrap .uplot-box > div { position: absolute; inset: 0; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.chart-legend i.line { height: 3px; border-radius: 1px; width: 14px; }
.chart-legend i.load { background: var(--color-gray-600); }
.chart-legend i.ctl { background: var(--amber); }
.chart-legend i.atl { background: var(--rose); }
.chart-legend i.tsb { background: var(--mint); }
.chart-legend i.bc-weight { background: var(--amber); }
.chart-legend i.bc-fat { background: var(--rose); }
.chart-legend i.bc-lean { background: var(--mint); }

.connect-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.connect-grid > .card {
  margin-top: 0;
  display: flex;
  flex-direction: column;
}
.connect-grid > .card > .body {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 8px;
}
.connect-grid > .card > .body > .row,
.connect-grid > .card > .body > form {
  margin-top: auto;
}
.provider-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.provider-head h3 {
  margin: 0;
}
.provider-blurb {
  margin: 0;
  flex: 1;
}

.tile-spinner {
  display: none;
  width: 16px;
  height: 16px;
  margin-left: auto;
  align-self: flex-end;
  border: 2px solid color-mix(in srgb, var(--mint) 25%, transparent);
  border-top-color: var(--mint);
  border-radius: 50%;
  animation: tile-spin 0.8s linear infinite;
}
.provider-tile.syncing .tile-spinner { display: inline-block; }
@keyframes tile-spin { to { transform: rotate(360deg); } }

.missed-row td { color: var(--muted); }
.missed-row .tag.err { margin-left: 4px; }
.btn-xs { min-height: 26px; padding: 2px 10px; font-size: 11px; margin-left: 4px; }
.sport-cell { white-space: nowrap; }
.sport-icon { display: inline-flex; vertical-align: -3px; margin-right: 5px; color: var(--mint); }
.link-modal { margin-top: 16px; }
.link-modal.hidden { display: none; }
.link-candidate {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  margin: 4px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  min-height: 40px;
}
.link-candidate:hover { border-color: var(--mint); }
.link-candidate:disabled { opacity: 0.5; cursor: wait; }
.link-candidate-main { flex: 1; font-size: 13px; }
.link-candidate-sub { font-size: 11px; color: var(--muted); }

.sync-progress {
  margin: 0 0 20px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.sync-progress.hidden { display: none; }
.sync-progress-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}
.sync-track {
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}
.sync-bar {
  height: 100%;
  width: 35%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--amber), color-mix(in srgb, var(--amber) 55%, var(--mint)), var(--mint));
  animation: sync-slide 1.4s ease-in-out infinite;
}
@keyframes sync-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
/* Card stacks: spacing that works regardless of sibling/wrapper structure.
   Cards get bottom margin everywhere; grids reset it via their gap. */
.card { margin: 0 0 22px; }
.grid-3 > .card,
.grid-2 > .card,
.connect-grid > .card,
.bento > .card { margin: 0; }
.card:last-child { margin-bottom: 0; }
.stack-card { margin-top: 22px; }

.plan-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.plan-day {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  min-height: 160px;
}
.plan-day .dow { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.plan-day h4 { margin: 8px 0 6px; font-size: 14px; }
.plan-target {
  margin-top: 8px;
  font-size: 13px;
  color: var(--mint);
}
.plan-target strong { color: var(--text); font-weight: 650; }
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--mint);
}
.tag.ok { background: color-mix(in srgb, var(--mint) 14%, transparent); color: var(--mint); }
.tags-cell { white-space: nowrap; }
.tags-cell .tag { margin-right: 4px; }
.tag.src-tag { text-decoration: none; }
a.tag.src-tag:hover { background: color-mix(in srgb, var(--mint) 22%, transparent); }
.tag.err { background: color-mix(in srgb, var(--rose) 14%, transparent); color: var(--rose); }
.cloud-box { margin-top: 28px; max-width: 640px; }
.cloud-box h3 { margin-bottom: 6px; }
.cloud-box .check { margin-top: 4px; }
label .note { margin-left: 8px; }

.section-title { margin: 28px 0 8px; font-size: 18px; }
.goals-form,
form.stack.goals-form { max-width: 640px; margin-top: 16px; }
.week-editor {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
}
.week-editor-disabled .week-days,
.week-editor-disabled [name="week_focus_edit"] { opacity: 0.45; }
.week-picker-label select {
  margin-top: 6px;
  width: 100%;
  max-width: none;
}
.week-custom-toggle.hidden { display: none; }
.week-days {
  display: grid;
  gap: 8px;
}
.week-day-wrap {
  display: grid;
  gap: 4px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.week-day-wrap:last-child { border-bottom: none; }
.week-day-row {
  display: grid;
  grid-template-columns: 3.2rem minmax(7.5rem, 9rem) 6.2rem minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.week-slot-add { justify-self: start; font-size: 12px; opacity: 0.8; }
.week-slot-del { padding: 2px 6px; opacity: 0.6; }
.week-day-name {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.week-sport,
.week-day-focus {
  width: 100%;
  margin: 0;
}
.ideas-block { margin-top: 36px; max-width: 900px; }
.ideas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.idea-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: var(--card);
}
.idea-card h4 { margin: 0 0 6px; }
.focus-reminder { margin-top: 10px; }

@media (max-width: 640px) {
  .week-day-row {
    grid-template-columns: 3rem 1fr 6.2rem;
    grid-template-areas:
      "name sport time"
      "focus focus focus";
  }
  .week-day-name { grid-area: name; }
  .week-sport { grid-area: sport; }
  .week-day-time { grid-area: time; }
  .week-day-focus { grid-area: focus; }
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
}
.login-photo { position: relative; }
.login-photo img { height: 100vh; width: 100%; object-fit: cover; }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(420px, 100%); }


@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .plan-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .grid-3, .grid-2, .stats, .plan-grid, .app, .login-shell { grid-template-columns: 1fr; }
  .main { padding: 20px 16px 32px; }
  .topbar { padding: 12px 16px; }
  .hero img, .hero { height: auto; min-height: 68vh; }
  .hero .copy { left: 20px; right: 20px; bottom: 20px; }
  .login-photo { display: none; }
}

.chat-log { flex: 1; min-height: 220px; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-wrap { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: stretch; height: calc(100vh - 220px); min-height: 420px; }
.chat-main { display: flex; flex-direction: column; min-height: 0; }
.chat-side { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.skill-quick { padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.skill-quick-form { gap: 8px; max-width: none; }
.skill-quick-form label { font-size: 12px; }
.skill-quick-form input, .skill-quick-form textarea { padding: 8px 10px; font-size: 13px; }
.chat-sessions { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.chat-side { display: flex; flex-direction: column; gap: 8px; }
.chat-session { display: flex; justify-content: space-between; align-items: center; gap: 6px; width: 100%; text-align: left; padding: 8px 10px; border: 1px solid var(--line); background: transparent; border-radius: 8px; cursor: pointer; font-size: 0.9rem; }
.chat-session.current { border-color: var(--mint); font-weight: 600; }
.chat-session-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-session-x { color: var(--muted); font-size: 0.8rem; }
.chat-session-x:hover { color: var(--rose); }
.chat-form select { max-width: 200px; }
@media (max-width: 900px) {
  .chat-wrap { grid-template-columns: 1fr; height: auto; }
  .chat-log { max-height: 60vh; }
  .chat-sessions { max-height: 180px; }
}
.chat-msg { display: flex; margin-bottom: 2px; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble { max-width: 78%; padding: 10px 14px; border-radius: 14px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; }
.chat-msg.user .chat-bubble { background: color-mix(in srgb, var(--mint) 16%, var(--card)); color: var(--color-gray-100); border-bottom-right-radius: 4px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25); }
.chat-msg.bot .chat-bubble { background: var(--bg-2); color: var(--text); border-bottom-left-radius: 4px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); border: 1px solid color-mix(in srgb, var(--text) 4%, transparent); }
.chat-bubble.md > *:first-child { margin-top: 0; }
.chat-bubble.md > *:last-child { margin-bottom: 0; }
.chat-form { display: flex; gap: 8px; margin-top: 14px; }
.chat-form input { flex: 1; }
.chat-write { margin-top: 12px; }
.chat-bubble.md { white-space: normal; }
.chat-bubble.md p { margin: 0 0 8px; }
.chat-bubble.md p:last-child { margin-bottom: 0; }
.chat-bubble.md h3, .chat-bubble.md h4 { margin: 12px 0 6px; font-size: 1.02em; color: var(--text); }
.chat-bubble.md h3:first-child, .chat-bubble.md h4:first-child { margin-top: 0; }
.chat-bubble.md ul, .chat-bubble.md ol { margin: 6px 0; padding-left: 20px; }
.chat-bubble.md li { margin: 3px 0; }
.chat-bubble.md li::marker { color: var(--mint); }
.chat-bubble.md code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; border: 1px solid color-mix(in srgb, var(--text) 6%, transparent); }
.chat-bubble.md blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--amber); background: color-mix(in srgb, var(--amber) 7%, transparent); border-radius: 0 8px 8px 0; color: var(--color-gray-300); }
.chat-bubble.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.chat-bubble.md .md-table-wrap { overflow-x: auto; margin: 8px 0; max-width: 100%; }
.chat-bubble.md .md-table { border-collapse: collapse; font-size: 13px; white-space: normal; }
.chat-bubble.md .md-table th, .chat-bubble.md .md-table td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.chat-bubble.md .md-table th { background: color-mix(in srgb, var(--text) 4%, transparent); color: var(--text); font-weight: 600; }
.chat-bubble.md .md-table tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }
.chat-bubble.md .md-code { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 8px 0; font-size: 13px; white-space: pre; }
.chat-bubble.md strong { color: var(--text); }
.chat-pre { white-space: pre-wrap; font-size: 12px; background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
@media (max-width: 640px) {
  .chat-bubble { max-width: 92%; }
  .chat-form { flex-direction: column; }
}

/* Alignment + mobile polish */
:root { --radius: 12px; }
.card { border-radius: var(--radius); }
.btn, .btn.ghost, button.linkish { min-height: 44px; }
input, select, textarea { font-size: 16px; }
@media (max-width: 640px) {
  .app { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .wrap { width: calc(100% - 24px); }
  .kicker, .page-title { padding-left: env(safe-area-inset-left); }
  table { font-size: 13px; }
}
html { -webkit-text-size-adjust: 100%; }
input, select, textarea, button { touch-action: manipulation; }
.tool-matrix { width: 100%; border-collapse: collapse; }
.tool-matrix th, .tool-matrix td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); }
.tool-matrix td[title]:first-child { cursor: help; }
.tool-group { margin-bottom: 18px; }
.tool-group table { font-size: 13px; }
.skill-item, .skill-file { margin: 10px 0; }
.skill-item summary, .skill-file summary { cursor: pointer; font-size: 14px; }
.skill-file { margin-left: 18px; }
.hidden { display: none !important; }

.backfill-days {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  max-width: 150px;
}

.chart-tip {
  position: absolute;
  top: 10px;
  left: 10px;
  background: color-mix(in srgb, var(--bg-2) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  pointer-events: none;
  z-index: 5;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.35);
}

.fetch-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
}

.fetch-overlay.show {
  display: flex;
}

.fetch-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: color-mix(in srgb, var(--bg-2) 96%, transparent);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 22px;
  font-size: 14px;
  color: var(--text);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.fetch-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid color-mix(in srgb, var(--mint) 25%, transparent);
  border-top-color: var(--mint);
  border-radius: 50%;
  animation: tile-spin 0.8s linear infinite;
}

/* Activity log: mobile tiles */
.log-tiles { display: none; }
.log-filters-mobile { display: none; }
.log-tile {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.log-tile.missed { opacity: 0.75; }
.log-tile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.log-tile-sport { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; color: var(--text); text-transform: capitalize; }
.log-tile-sport svg { color: var(--mint); }
.log-tile-title { font-size: 14px; line-height: 1.35; }
.log-tile-title .tag { margin-left: 4px; }
.log-tile-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.log-tile-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
@media (max-width: 700px) {
  .log-tiles { display: grid; gap: 10px; }
  .log-tiles-card > table { display: none; }
  .log-filters-mobile { display: block; }
  .log-filters-mobile .row { display: grid; }
  .log-filters-mobile select,
  .log-filters-mobile input { width: 100%; }
}

/* Activity log: header filters + pager */
th .log-filter {
  display: block;
  margin-top: 4px;
  min-width: 70px;
  padding: 3px 6px;
  font-size: 12px;
}
th select.log-filter {
  width: auto;
}
#log-pager {
  flex-wrap: wrap;
}

/* Chat reasoning steps (tool trace) */
.chat-steps { margin-top: 2px; }
.chat-steps summary {
  cursor: pointer; font-size: 11px; color: var(--muted);
  user-select: none; list-style: none;
}
.chat-steps summary::before { content: "\25B8 "; }
.chat-steps[open] summary::before { content: "\25BE "; }
.chat-steps summary:hover { color: var(--text); }
.chat-step-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chat-step {
  font-size: 11px; padding: 3px 8px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-2);
  color: var(--text); max-width: 280px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.chat-step.ok { border-color: color-mix(in srgb, var(--mint) 40%, transparent); color: var(--mint); }
.chat-step.warn { border-color: color-mix(in srgb, var(--amber) 40%, transparent); color: var(--amber); }
.chat-step.bad { border-color: color-mix(in srgb, var(--rose) 40%, transparent); color: var(--rose); }
.chat-trace .chat-steps { border-left: 2px solid var(--line); padding-left: 10px; }

/* --- PWA / a11y niceness pass --- */
:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
@media (pointer: coarse) {
  .btn, button.linkish, .footnav button { min-height: 44px; }
}
@media (display-mode: standalone), (display-mode: fullscreen) {
  .app {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}
