:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #101d2e;
  --surface-2: #16263a;
  --border: #263a52;
  --text: #f7fafc;
  --muted: #9fb0c4;
  --accent: #5eead4;
  --accent-ink: #05211d;
  --mind: #b794f4;
  --body: #60a5fa;
  --craft: #fbbf24;
  --danger: #fb7185;
  --success: #34d399;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(circle at 50% -10%, rgba(94, 234, 212, .11), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Aptos, Calibri, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
}
body.week-active {
  height: 100dvh;
  overflow: hidden;
}
body.week-active .app {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
button, input { min-height: 44px; font: inherit; }
button { cursor: pointer; }
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}
.auth-gate[hidden] { display: none; }
.auth-card {
  display: grid;
  width: min(100%, 390px);
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  padding: 22px;
  box-shadow: 0 24px 70px rgba(0,0,0,.4);
}
.auth-card p { color: var(--muted); }
.auth-card label { margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 850; }
.auth-card input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  padding: 12px;
}
.auth-error { min-height: 18px; color: var(--danger); font-size: 12px; }

.app {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  border-inline: 1px solid rgba(255,255,255,.05);
  background: rgba(7, 17, 31, .92);
  padding-bottom: 88px;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 17, 31, .92);
  backdrop-filter: blur(18px);
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.sync-indicator {
  display: grid;
  grid-template-columns: 8px auto;
  column-gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.1;
  text-align: right;
}
.sync-indicator > span { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.sync-indicator strong { color: var(--text); font-size: 11px; }
.sync-indicator small { grid-column: 1 / -1; }
.sync-indicator.synced > span { background: var(--success); }
.sync-indicator.pending > span { background: var(--craft); }
.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}
h1, h2, h3, p { margin: 0; }
h1 { margin-top: 3px; font-size: 24px; letter-spacing: -.04em; }
h2 { margin-top: 3px; font-size: 26px; letter-spacing: -.04em; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.icon-button, .send-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 900;
}

.view { display: none; padding: 16px; }
.view.active { display: block; }
#weekView.active {
  display: flex;
  height: calc(100dvh - 78px - 78px);
  min-height: 480px;
  flex-direction: column;
  overflow: hidden;
}
.mind { --category: var(--mind); }
.body { --category: var(--body); }
.craft { --category: var(--craft); }
.daily-mobility { --category: #2dd4bf; }
.practice { --category: #fb923c; }
.game { --category: #f43f5e; }
.sgt-rock { --category: #a3e635; }
.made-shots { --category: #f59e0b; }
.recovery { --category: #22c55e; }
.downtime { --category: #94a3b8; }
.work { --category: #818cf8; }

.thread {
  display: flex;
  min-height: 470px;
  max-height: calc(100vh - 235px);
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 8px 2px 18px;
}
.message {
  max-width: 88%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 5px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.45;
  white-space: pre-line;
}
.message.user {
  align-self: flex-end;
  border-color: rgba(94, 234, 212, .35);
  border-radius: 18px 18px 5px 18px;
  background: rgba(94, 234, 212, .12);
}
.message .message-label {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 12px;
}
.choice {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 13px;
  font-weight: 800;
}
.choice.category {
  border-color: color-mix(in srgb, var(--category), transparent 45%);
  background: color-mix(in srgb, var(--category), transparent 87%);
}
.composer {
  position: sticky;
  bottom: 78px;
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(16, 29, 46, .96);
  backdrop-filter: blur(14px);
}
.composer input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.composer input::placeholder { color: #71839a; }
.send-button { border: 0; background: var(--accent); color: var(--accent-ink); }

.section-heading, .panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.section-heading { margin-bottom: 16px; }
.primary, .secondary, .danger {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 11px 13px;
  font-weight: 900;
}
.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.secondary { background: var(--surface-2); color: var(--text); }
.danger { border-color: rgba(251,113,133,.35); background: rgba(251,113,133,.1); color: var(--danger); }
.small { padding: 9px 11px; font-size: 13px; }

.week-list {
  display: flex;
  width: min(100%, 720px);
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: clamp(10px, 1.8vw, 16px);
  margin: 0 auto;
}
#weekView > .section-heading {
  width: min(100%, 720px);
  flex: 0 0 auto;
  margin-inline: auto;
}
.readiness-strip {
  display: flex;
  width: min(100%, 720px);
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -6px auto 10px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--muted);
  border-radius: 12px;
  background: var(--surface);
  padding: 8px 11px;
  font-size: 12px;
}
.readiness-strip span { color: var(--muted); text-align: right; }
.readiness-strip.green { border-left-color: var(--success); }
.readiness-strip.yellow { border-left-color: var(--craft); }
.readiness-strip.red { border-left-color: var(--danger); }
.day-card, .panel, .stat {
  border: 1px solid var(--border);
  border-radius: 17px;
  background: var(--surface);
}
.day-card {
  display: flex;
  width: 100%;
  min-height: 48px;
  flex: 0 0 auto;
  flex-direction: column;
  overflow: hidden;
  padding: clamp(8px, 1.7vh, 14px);
}
.day-card.expanded { min-height: 0; flex: 1 1 auto; }
.day-card.today { border-color: var(--accent); box-shadow: inset 3px 0 var(--accent); }
.day-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.day-name {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text);
  min-height: 44px;
  padding: 0;
  text-align: left;
}
.day-name strong { display: block; font-size: 17px; }
.day-name span { color: var(--muted); font-size: 12px; }
.day-add {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 900;
  min-width: 60px;
}
.block-list {
  display: grid;
  min-height: 0;
  gap: 8px;
  margin-top: 8px;
  overflow: hidden;
}
.day-card:not(.expanded) .block-list { display: none; }
.day-card:not(.expanded) .day-name strong,
.day-card:not(.expanded) .day-name span { display: inline; }
.day-card:not(.expanded) .day-name span::before { content: " · "; }
.block {
  display: grid;
  grid-template-columns: 5px 1fr auto;
  gap: 10px;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
  padding: 10px 10px 10px 0;
}
.block::before { content: ""; align-self: stretch; border-radius: 99px; background: var(--category); }
.block-title { font-weight: 850; }
.block-meta { margin-top: 2px; color: var(--muted); font-size: 12px; }
.block-actions { display: flex; gap: 6px; }
.block-actions button {
  border: 0;
  border-radius: 9px;
  background: rgba(255,255,255,.06);
  color: var(--muted);
  min-width: 44px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 800;
}
.block-actions .complete { color: var(--success); }
.empty-day { padding: 12px 2px 2px; color: var(--muted); font-size: 13px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.range-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.range-row button {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  padding: 9px 5px;
  font-size: 11px;
  font-weight: 900;
}
.range-row button.active {
  border-color: var(--accent);
  background: rgba(94, 234, 212, .1);
  color: var(--accent);
}
.stat { padding: 14px; }
.stat strong { display: block; font-size: 28px; letter-spacing: -.04em; }
.stat span { color: var(--muted); font-size: 12px; }
.panel { margin-top: 12px; padding: 15px; }
.category-progress { display: grid; gap: 10px; margin-top: 16px; }
.category-card {
  display: grid;
  gap: 9px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--category);
  border-radius: 13px;
  background: var(--surface-2);
  padding: 12px;
}
.category-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.progress-label { color: var(--category); font-size: 13px; font-weight: 900; }
.success-rate { font-size: 20px; font-weight: 950; letter-spacing: -.04em; }
.category-detail { color: var(--muted); font-size: 12px; }
.track { height: 8px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.08); }
.fill { height: 100%; border-radius: inherit; background: var(--category); }
.history-list { display: grid; gap: 0; margin-top: 8px; }
.weekly-history { display: grid; gap: 0; margin-top: 8px; }
.week-history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.week-history-item:first-child { border-top: 0; }
.week-history-item strong, .week-history-item span { display: block; }
.week-history-item span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.week-history-rate { color: var(--accent); font-size: 20px; font-weight: 950; }
.history-item { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: start; padding: 12px 0; border-top: 1px solid var(--border); }
.history-item:first-child { border-top: 0; }
.history-mark { width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: var(--category); }
.history-item strong, .history-item span { display: block; }
.history-item span, .history-item time { color: var(--muted); font-size: 12px; }
.sync-status { color: var(--success); font-size: 11px; font-weight: 900; }

.planner-sheet[hidden] { display: none; }
.planner-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-items: end;
  justify-items: center;
}
.planner-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(3px);
}
.planner-card {
  position: relative;
  z-index: 1;
  width: min(100%, 480px);
  max-height: 82vh;
  overflow-y: auto;
  padding: 10px 16px calc(22px + env(safe-area-inset-bottom));
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: var(--bg);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .35);
}
.planner-handle {
  width: 42px;
  height: 5px;
  margin: 0 auto 16px;
  border-radius: 99px;
  background: var(--border);
}
.planner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.planner-summary {
  min-height: 22px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}
.modal-note, .safety-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.safety-note { padding: 10px; border-left: 4px solid var(--danger); background: var(--surface); }
.metric-form { display: grid; gap: 14px; margin-top: 16px; }
.metric-form > label:not(.flag-check) { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 850; }
.metric-form input[type="number"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px;
}
.metric-row { margin: 0; border: 0; padding: 0; }
.metric-row legend { margin-bottom: 6px; color: var(--muted); font-size: 13px; font-weight: 850; }
.metric-row > div { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.metric-row label { position: relative; }
.metric-row input { position: absolute; opacity: 0; }
.metric-row span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 900;
}
.metric-row input:checked + span { border-color: var(--accent); background: rgba(94, 234, 212, .12); color: var(--accent); }
.metric-row input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.flag-check { display: flex; min-height: 44px; align-items: center; gap: 10px; font-weight: 800; }
.flag-check input { width: 24px; min-height: 24px; }
.compact-sheet .planner-card { max-height: 92vh; }
.planner-options {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}
.planner-option {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 13px 14px;
  text-align: left;
}
.planner-option:hover, .planner-option:focus-visible {
  border-color: var(--accent);
  outline: 0;
}
.planner-option.category {
  border-left: 5px solid var(--category);
}
.planner-option strong, .planner-option span { display: block; }
.planner-option span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.planner-option b { color: var(--accent); font-size: 13px; }
.planner-back {
  margin-top: 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 0;
  font-weight: 850;
}
.custom-time[hidden] { display: none; }
.custom-time {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}
.time-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.time-fields label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}
.time-fields input {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px;
}
.time-error { min-height: 18px; color: var(--danger); font-size: 12px; }
body.planner-open { overflow: hidden; }
.toast[hidden] { display: none; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 40;
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 14px;
  box-shadow: 0 12px 35px rgba(0,0,0,.35);
  font-size: 13px;
  font-weight: 850;
}
.toast.error { border-color: var(--danger); color: var(--danger); }

.nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  z-index: 10;
  display: grid;
  width: min(100%, 480px);
  transform: translateX(-50%);
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(7, 17, 31, .94);
  backdrop-filter: blur(18px);
}
.nav button {
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  min-height: 54px;
  padding: 8px;
  font-size: 11px;
  font-weight: 900;
}
.nav button span { display: block; margin-bottom: 3px; font-size: 18px; }
.nav button.active { background: var(--surface-2); color: var(--accent); }

@media (min-width: 760px) {
  .app { width: min(100%, 900px); }
  .nav { width: min(100%, 900px); }
  .category-progress { grid-template-columns: repeat(2, 1fr); }
  .thread { max-height: calc(100vh - 235px); }
}

@media (max-height: 700px) {
  #weekView.active { height: calc(100dvh - 70px - 70px); min-height: 420px; padding-block: 10px; }
  #weekView > .section-heading { margin-bottom: 10px; }
  #weekView h2 { font-size: 22px; }
  .week-list { gap: 6px; }
  .day-card { padding: 7px 10px; border-radius: 12px; }
  .day-name strong { font-size: 14px; }
  .day-name span, .day-add { font-size: 11px; }
  .empty-day { padding-top: 4px; font-size: 11px; }
}
