:root {
  --navy: #0e3a64;
  --navy-2: #132847;
  --teal: #16a296;
  --teal-dark: #0d9488;
  --orange: #f26c23;
  --gold: #ffb657;
  --cream: #fff7eb;
  --cream-2: #fffaf2;
  --paper: rgba(255, 253, 248, 0.84);
  --paper-solid: #fffdf8;
  --ink: #152235;
  --muted: #667085;
  --line: rgba(14, 58, 100, 0.14);
  --line-strong: rgba(14, 58, 100, 0.22);
  --shadow: 0 24px 70px rgba(19, 40, 71, 0.12);
  --soft-shadow: 0 14px 34px rgba(19, 40, 71, 0.08);
  --radius-xl: 34px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --max: 1180px;
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
  min-height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 10%, rgba(22, 162, 150, 0.13), transparent 30%),
    radial-gradient(circle at 90% 5%, rgba(242, 108, 35, 0.12), transparent 26%),
    linear-gradient(135deg, #fffaf1 0%, #f8fbfb 56%, #eef9f7 100%);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
code {
  padding: 0.16rem .35rem;
  border-radius: .5rem;
  background: rgba(14,58,100,.07);
  color: var(--navy-2);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-shell {
  width: min(var(--max), calc(100% - 32px));
  margin: 20px auto 30px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.72);
  backdrop-filter: blur(14px);
  box-shadow: var(--soft-shadow);
  position: sticky;
  top: 12px;
  z-index: 50;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: linear-gradient(135deg, var(--teal), var(--navy));
  font-size: 1.5rem;
  font-weight: 900;
}
.brand strong,
.brand small { display: block; }
.brand strong {
  color: var(--navy-2);
  font-size: 1.05rem;
  letter-spacing: -.03em;
}
.brand small {
  max-width: 180px;
  color: var(--muted);
  font-size: .78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.main-nav {
  display: flex;
  gap: 6px;
  padding-right: 4px;
}
.nav-link {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: transparent;
  color: #39536b;
  font-weight: 800;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.nav-link:hover { transform: translateY(-1px); }
.nav-link.active {
  background: var(--navy-2);
  color: #fff;
}

.view { display: none; }
.view.active { display: block; }

.today-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1.04fr) minmax(340px, .82fr);
  gap: 20px;
  align-items: stretch;
}
.hero-card,
.primary-card,
.talk-card,
.mode-card,
.progress-card,
.history-card,
.settings-card,
.module-option {
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.hero-card {
  min-height: 720px;
  border-radius: var(--radius-xl);
  padding: 32px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
  overflow: hidden;
}
.hero-card::after {
  content: "";
  position: absolute;
  inset: auto -120px -150px -120px;
  height: 300px;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(14, 58, 100, .10), transparent 65%);
}
.hero-copy { position: relative; z-index: 3; }
.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: var(--teal-dark);
  font-weight: 900;
  letter-spacing: .11em;
  text-transform: uppercase;
  font-size: .76rem;
}
h1 {
  margin: 0;
  max-width: 720px;
  color: var(--navy-2);
  font-size: clamp(2.3rem, 6vw, 5.1rem);
  line-height: .94;
  letter-spacing: -.065em;
}
.lead,
.page-heading p,
.mode-card p,
.settings-card p {
  color: #31465c;
  line-height: 1.55;
}
.lead {
  max-width: 520px;
  margin: 14px 0 0;
  font-size: 1.08rem;
}
.stage {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: end center;
  min-height: 470px;
  padding-top: 14px;
}
.speech-bubble {
  position: absolute;
  right: 8px;
  top: 32px;
  z-index: 5;
  width: min(360px, 78%);
  padding: 16px 18px;
  border-radius: 23px 23px 6px 23px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 18px 48px rgba(19,40,71,.12);
  color: #20324a;
  font-weight: 750;
  line-height: 1.45;
}
.speech-bubble::after {
  content: "";
  position: absolute;
  right: 28px;
  bottom: -10px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}
.chaski-figure {
  position: relative;
  z-index: 3;
  width: min(76%, 430px);
  transform-origin: 50% 88%;
  filter: drop-shadow(0 28px 36px rgba(14, 58, 100, 0.18));
  transition: transform .35s ease, opacity .35s ease, filter .35s ease;
}
.chaski-figure img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  pointer-events: none;
}
.chaski-figure::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 10%;
  bottom: 2%;
  height: 22px;
  border-radius: 50%;
  background: rgba(14, 58, 100, 0.12);
  filter: blur(2px);
  transform: scaleX(0.9);
  z-index: -1;
}
.state-symbol {
  position: absolute;
  right: 2%;
  top: 15%;
  min-width: 54px;
  min-height: 54px;
  display: grid;
  place-items: center;
  color: var(--orange);
  font-size: 3.1rem;
  font-weight: 900;
  text-shadow: 0 4px 0 rgba(255,255,255,.9);
  opacity: 0;
  transform: translateY(8px) scale(.8);
  transition: all .25s ease;
}
.state-idle { animation: breathe 3.2s ease-in-out infinite; }
.state-happy { animation: happyHop .8s cubic-bezier(.2,.8,.2,1) 1; }
.state-thinking { transform: rotate(-2deg) translateY(-4px); }
.state-thinking .state-symbol::before { content: "?"; }
.state-alert { transform: scale(1.03); filter: drop-shadow(0 28px 36px rgba(242,108,35,.22)); }
.state-alert .state-symbol::before { content: "!"; }
.state-tired { transform: translateY(16px) scale(.98); opacity: .86; filter: grayscale(.05) drop-shadow(0 22px 30px rgba(14,58,100,.10)); }
.state-running { animation: runPulse .62s ease-in-out infinite; }
.state-sleeping { transform: translateY(22px) scale(.96); opacity: .92; }
.state-sleeping .state-symbol::before { content: "Zzz"; font-size: 2rem; color: var(--teal-dark); }
.state-thinking .state-symbol,
.state-alert .state-symbol,
.state-sleeping .state-symbol { opacity: 1; transform: translateY(0) scale(1); }

.stat-strip {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.stat-strip div,
.metric-grid div,
.status-grid div {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.58);
  padding: 12px;
}
.stat-strip span,
.metric-grid span,
.status-grid span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.stat-strip strong,
.metric-grid strong,
.status-grid strong {
  display: block;
  margin-top: 3px;
  color: var(--navy-2);
  font-size: 1rem;
}

.mission-column {
  display: grid;
  gap: 16px;
  align-content: start;
}
.primary-card,
.talk-card,
.mode-card,
.progress-card,
.history-card,
.settings-card,
.module-option {
  border-radius: var(--radius-lg);
  padding: 24px;
}
.mission-card {
  min-height: 360px;
  display: flex;
  flex-direction: column;
}
.mission-header,
.card-title-row,
.module-option-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.mission-type,
.reward-pill,
#level-pill,
.module-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 8px 11px;
  font-weight: 900;
  font-size: .76rem;
}
.mission-type {
  background: #fff1e8;
  color: var(--orange);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.reward-pill,
#level-pill,
.module-status {
  background: #eef8f6;
  color: var(--teal-dark);
}
.mission-card h2 {
  margin: 18px 0 10px;
  color: var(--navy-2);
  font-size: clamp(1.65rem, 3.5vw, 2.35rem);
  line-height: 1.02;
  letter-spacing: -.045em;
}
.mission-card p {
  margin: 0 0 16px;
  color: #344b62;
  line-height: 1.5;
}
.mission-meta,
.hint-list,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.mission-meta span,
.hint-list button {
  border-radius: 999px;
  padding: 8px 11px;
  background: rgba(22, 162, 150, .10);
  color: var(--teal-dark);
  font-weight: 850;
  font-size: .82rem;
}
.action-stack {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.action-stack .primary { grid-column: 1 / -1; }
.btn {
  border: 0;
  border-radius: 999px;
  min-height: 46px;
  padding: 12px 16px;
  background: var(--navy-2);
  color: white;
  font-weight: 900;
  box-shadow: 0 13px 24px rgba(19,40,71,.15);
  transition: transform .18s ease, background .18s ease, opacity .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, var(--navy-2), var(--teal-dark)); }
.btn.secondary { background: #eaf5f3; color: var(--teal-dark); box-shadow: none; }
.btn.ghost { background: rgba(14,58,100,.06); color: var(--navy-2); box-shadow: none; }
.btn.danger { background: #fff1ed; color: #b33916; box-shadow: none; }
.btn.compact { min-height: 40px; padding: 9px 12px; }
.btn.send { min-height: 44px; padding-inline: 18px; }
.link-button {
  border: 0;
  background: transparent;
  color: var(--teal-dark);
  font-weight: 900;
  cursor: pointer;
}
.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}
.chat-form input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 13px 16px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
.chat-form input:focus {
  border-color: rgba(22, 162, 150, .5);
  box-shadow: 0 0 0 4px rgba(22, 162, 150, .12);
}
.hint-list { margin-top: 12px; }
.hint-list button {
  border: 0;
  box-shadow: none;
  cursor: pointer;
}
.mode-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.mode-card strong {
  display: block;
  margin-bottom: 4px;
  color: var(--navy-2);
  font-size: 1.1rem;
}
.mode-card p { margin: 0; font-size: .93rem; }

.page-heading {
  margin: 8px 0 18px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: rgba(255,253,248,.68);
  box-shadow: var(--soft-shadow);
}
.page-heading h1 {
  max-width: 860px;
  font-size: clamp(2rem, 5vw, 4.4rem);
}
.page-heading p:last-child {
  max-width: 650px;
  margin: 14px 0 0;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.module-option {
  display: flex;
  flex-direction: column;
  min-height: 260px;
  box-shadow: var(--soft-shadow);
}
.module-option.active { border-color: rgba(22, 162, 150, .45); outline: 4px solid rgba(22, 162, 150, .10); }
.module-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(22,162,150,.16), rgba(242,108,35,.12));
  color: var(--navy-2);
  font-size: 1.5rem;
}
.module-option h2 {
  margin: 18px 0 8px;
  color: var(--navy-2);
  letter-spacing: -.035em;
}
.module-option p {
  margin: 0 0 14px;
  color: #364c63;
  line-height: 1.5;
}
.module-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
}
.module-tags span {
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(14,58,100,.06);
  color: #39536b;
  font-weight: 850;
  font-size: .78rem;
}
.module-option .btn { margin-top: 18px; width: 100%; }

.progress-layout,
.settings-grid {
  display: grid;
  grid-template-columns: minmax(320px, .78fr) minmax(360px, 1.22fr);
  gap: 16px;
}
.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-card.wide { grid-column: 1 / -1; }
.card-title-row h2,
.settings-card h2,
.progress-card h2,
.history-card h2 {
  margin: 0;
  color: var(--navy-2);
  letter-spacing: -.025em;
}
.meter-row { margin: 18px 0; }
.meter-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .88rem;
}
.meter-label strong { color: var(--navy-2); }
.meter {
  height: 11px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(14,58,100,.09);
}
.meter div {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width .25s ease;
}
.metric-grid,
.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.history-list {
  margin: 14px 0 0;
  padding-left: 20px;
  color: #40576d;
  line-height: 1.45;
}
.history-list li { margin: 10px 0; }
.history-list small { display: block; color: var(--muted); font-weight: 750; margin-top: 2px; }
.small-note { color: var(--muted); }
.install-button:not([hidden]) { display: inline-flex; margin-top: 16px; }

@keyframes breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-5px) scale(1.01); }
}
@keyframes happyHop {
  0%, 100% { transform: translateY(0) rotate(0); }
  35% { transform: translateY(-18px) rotate(-1.5deg); }
  70% { transform: translateY(2px) rotate(1deg); }
}
@keyframes runPulse {
  0%, 100% { transform: translateX(-4px) rotate(-1deg); }
  50% { transform: translateX(8px) rotate(1deg); }
}

@media (max-width: 980px) {
  .today-layout,
  .progress-layout,
  .settings-grid { grid-template-columns: 1fr; }
  .hero-card { min-height: 640px; }
  .module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .app-shell { width: min(100% - 18px, var(--max)); margin-top: 9px; }
  .topbar {
    position: static;
    border-radius: 24px;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }
  .main-nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 0; }
  .nav-link { padding: 10px 6px; font-size: .86rem; }
  .brand { padding: 4px; }
  .hero-card,
  .primary-card,
  .talk-card,
  .mode-card,
  .progress-card,
  .history-card,
  .settings-card,
  .module-option,
  .page-heading { border-radius: 24px; padding: 20px; }
  .hero-card { min-height: 620px; }
  .stage { min-height: 390px; }
  .speech-bubble {
    left: 0;
    right: auto;
    top: 42px;
    width: min(100%, 340px);
  }
  .chaski-figure { width: min(92%, 350px); }
  .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-strip div:last-child { grid-column: 1 / -1; }
  .action-stack { grid-template-columns: 1fr; }
  .chat-form { grid-template-columns: 1fr; }
  .mode-card { align-items: stretch; flex-direction: column; }
  .module-grid { grid-template-columns: 1fr; }
  .metric-grid,
  .status-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
