:root {
  --bg: #0e1116;
  --panel: #161b22;
  --border: #2a3340;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #6ea8fe;
  --accent-2: #3dd6c6;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 10% -10%, #1a2740 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font);
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-height: 100dvh;
}

body.is-booting {
  overflow: hidden;
}

/* —— Boot splash —— */
.boot-splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background:
    radial-gradient(800px 400px at 50% 30%, #1a2740 0%, transparent 60%),
    var(--bg);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.boot-splash.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-card {
  text-align: center;
  padding: 2rem 1.5rem;
}

.boot-logo {
  display: block;
  margin: 0 auto 0.75rem;
  border-radius: 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  animation: boot-pop 0.6s ease both;
}

.boot-wordmark {
  display: block;
  margin: 0 auto;
  height: 48px;
  width: auto;
  animation: boot-fade 0.7s 0.1s ease both;
}

.boot-tagline {
  margin: 0.35rem 0 1.25rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  animation: boot-fade 0.7s 0.2s ease both;
}

.boot-bar {
  width: min(220px, 60vw);
  height: 4px;
  margin: 0 auto;
  border-radius: 999px;
  background: #1c2430;
  overflow: hidden;
}

.boot-bar-fill {
  height: 100%;
  width: 30%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  animation: boot-load 1.1s ease-in-out infinite;
}

.boot-hint {
  margin: 0.85rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  animation: boot-fade 0.7s 0.3s ease both;
}

@keyframes boot-pop {
  from {
    opacity: 0;
    transform: scale(0.88) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes boot-fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes boot-load {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(360%);
  }
}

.app-shell {
  display: contents;
}

.app-shell[hidden] {
  display: none !important;
}

body.app-ready .app-shell {
  display: contents;
}

body.app-ready .app-shell[hidden] {
  display: contents;
}

/* —— Install banner —— */
.install-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  padding-top: max(0.65rem, var(--safe-top));
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, #152033, #12241f);
}

.update-banner {
  background: linear-gradient(90deg, #1a2740, #152033);
  border-bottom-color: #3d6df0;
}

.install-banner.hidden {
  display: none !important;
}

.install-copy {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.85rem;
}

.install-banner img {
  border-radius: 8px;
  flex-shrink: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 17, 22, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.brand-logo {
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.brand-mark {
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.net-pill {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}

.net-pill.is-offline {
  color: var(--warn);
  border-color: #9e6a03;
  background: #2a2108;
}

.save-status {
  font-size: 0.75rem;
  color: var(--warn);
}

.save-status.is-error {
  color: var(--danger);
}

.save-status.is-ok {
  color: var(--ok);
}

/* Capacity / time consciousness */
.capacity-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(145deg, #161b22 0%, #121820 100%);
  padding: 1rem 1.1rem;
  margin: 0.75rem 0;
}

.capacity-card h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.capacity-meter {
  height: 10px;
  border-radius: 999px;
  background: #0d1117;
  border: 1px solid var(--border);
  overflow: hidden;
  margin: 0.55rem 0 0.4rem;
}

.capacity-meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.35s ease;
}

.capacity-meter-fill.is-warn {
  background: linear-gradient(90deg, var(--warn), #e3b341);
}

.capacity-meter-fill.is-over {
  background: linear-gradient(90deg, var(--danger), #ff7b72);
}

.ally-line {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.45;
}

.ally-line strong {
  color: var(--accent-2);
}

.intention-chip {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.ally-propose-card {
  border-color: #2a4a6a;
  background: linear-gradient(160deg, #152033 0%, #121820 70%);
}

.empty-hero {
  text-align: center;
  padding: 1.5rem 1rem 0.5rem;
  margin-bottom: 0.5rem;
}

.empty-hero img {
  border-radius: 16px;
  margin-bottom: 0.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.empty-hero h2 {
  margin: 0 0 0.4rem;
  font-size: 1.2rem;
}

.target-card {
  flex-direction: column !important;
  align-items: stretch !important;
}

.target-card-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
}

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

.intention-modal .intention-body {
  margin: 0.25rem 0 0.75rem;
  line-height: 1.5;
  font-size: 1.05rem;
}

.intention-hint {
  margin: 0 0 0.25rem;
  font-size: 0.85rem;
}

.breakglass-countdown {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
  margin: 0.5rem 0 1rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.breakglass-countdown.is-ready {
  color: var(--ok);
}

.form-label {
  display: block;
  margin: 0.5rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.form-label input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
}

.usage-bars {
  margin: 0.75rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.usage-bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.85rem;
}

.usage-bar-track {
  height: 8px;
  border-radius: 999px;
  background: #0d1117;
  border: 1px solid var(--border);
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.usage-bar-mins {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.file-pick {
  cursor: pointer;
}

.file-pick-label {
  display: inline-block;
  background: #21262d;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

.file-pick-label:hover {
  filter: brightness(1.08);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

button.ghost:hover {
  color: var(--text);
  filter: none;
}

/* Toasts */
.toast-host {
  position: fixed;
  bottom: max(1rem, var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(420px, calc(100% - 2rem));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #1c2430;
  color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  font-size: 0.9rem;
  animation: toast-in 0.25s ease both;
}

.toast.is-error {
  border-color: #da3633;
  background: #2a1214;
}

.toast.is-ok {
  border-color: #238636;
  background: #12261a;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.brand-mark .ai {
  color: var(--accent);
}

.brand-mark .ly {
  color: var(--accent-2);
}

.tagline {
  color: var(--muted);
  font-size: 0.9rem;
}

.tray {
  font-size: 0.85rem;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
}

.layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}

nav.side {
  padding: 1rem 0.75rem;
  border-right: 1px solid var(--border);
}

nav.side button {
  display: flex;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  margin-bottom: 0.25rem;
}

nav.side button:hover {
  background: #1c2430;
  color: var(--text);
}

nav.side button.active {
  background: #1e2a3d;
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}

.badge {
  margin-left: auto;
  background: var(--warn);
  color: #111;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.nav-count {
  margin-left: auto;
  min-width: 1.1rem;
  text-align: center;
  background: var(--accent);
  color: #0e1116;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.3rem;
  border-radius: 999px;
}

main {
  padding: 1.25rem 1.5rem 2rem;
  min-width: 0;
}

.panel-head h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.muted {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  background: var(--panel);
}

.banner.ok {
  border-color: #238636;
  background: #12261a;
}

.banner.warn {
  border-color: #9e6a03;
  background: #2a2108;
}

.banner.danger {
  border-color: #da3633;
  background: #2a1214;
}

.banner.focus-armed {
  border-color: #3d6df0;
  background: linear-gradient(120deg, #152033, #1a2438);
  box-shadow: inset 3px 0 0 var(--accent);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 0.75rem 0;
}

.quick-chips {
  gap: 0.4rem;
}

button.chip {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: #1a2330;
  color: var(--accent);
  border-color: #2d3b4f;
}

input,
select,
button,
textarea {
  font: inherit;
}

input,
select {
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
}

button {
  background: #21262d;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

button.primary {
  background: linear-gradient(135deg, #3d6df0, #2bb5a8);
  border: 0;
  color: #fff;
  font-weight: 600;
}

button:hover {
  filter: brightness(1.08);
}

.list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.list li {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
}

.tag {
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #243044;
  color: var(--accent);
}

.tag.armed {
  background: #3d1f24;
  color: #ff7b72;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 1rem;
  margin: 1rem 0;
}

.form label {
  display: block;
  margin: 0.5rem 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.form label input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
}

.chk {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--border);
  display: inline-block;
}

.dot.done {
  background: var(--ok);
}

.dot.skipped {
  background: var(--muted);
}

.dot.pending {
  background: var(--warn);
}

.footer {
  border-top: 1px solid var(--border);
  padding: 0.6rem 1.25rem;
  color: var(--muted);
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

button.version-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.15rem 0.35rem;
  text-decoration: none;
}

button.version-btn:hover {
  color: var(--text);
  filter: none;
}

/* Tutorial modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}

.modal {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem 1.35rem 1.1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.modal h2 {
  margin: 0 0 0.5rem;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.nav-ico {
  display: none;
  width: 1.1rem;
  text-align: center;
  opacity: 0.85;
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  main {
    order: 1;
    padding: 1rem;
    padding-bottom: 1rem;
  }
  nav.side {
    order: 2;
    position: sticky;
    bottom: 0;
    z-index: 12;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.15rem;
    border-right: 0;
    border-top: 1px solid var(--border);
    border-bottom: 0;
    padding: 0.35rem 0.35rem max(0.35rem, var(--safe-bottom));
    background: rgba(14, 17, 22, 0.94);
    backdrop-filter: blur(10px);
  }
  nav.side button {
    width: auto;
    font-size: 0.68rem;
    padding: 0.4rem 0.2rem;
    margin: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    text-align: center;
    line-height: 1.15;
  }
  nav.side button .nav-ico {
    display: block;
    font-size: 1rem;
  }
  nav.side button .badge {
    position: absolute;
    top: 0.15rem;
    right: 0.35rem;
    margin: 0;
  }
  nav.side button {
    position: relative;
  }
  /* Keep primary 4 + overflow setup/activity still reachable */
  nav.side button[data-nav="activity"],
  nav.side button[data-nav="setup"] {
    grid-column: span 1;
  }
  .topbar {
    padding: 0.65rem 0.85rem;
  }
  .tagline {
    display: none;
  }
  .brand-logo {
    width: 28px;
    height: 28px;
  }
  .footer {
    display: none;
  }
  .install-banner {
    flex-wrap: wrap;
  }
}

/* Safe area for Android gesture nav when installed as PWA */
@supports (padding: max(0px)) {
  body {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

@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;
  }
  .boot-bar-fill {
    animation: none;
    width: 100%;
  }
}

body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

body.density-compact .list li {
  padding: 0.5rem 0.65rem;
}

body.density-compact main {
  padding: 0.85rem 1rem 1.25rem;
}

body.density-compact .panel-head h1 {
  font-size: 1.25rem;
}

body.density-compact .capacity-card {
  padding: 0.75rem 0.85rem;
}

body.high-contrast {
  --bg: #000000;
  --panel: #0a0a0a;
  --border: #6b7280;
  --text: #ffffff;
  --muted: #d1d5db;
  --accent: #93c5fd;
  --accent-2: #5eead4;
}

body.high-contrast {
  background: #000;
}

body.high-contrast .banner.ok {
  border-color: #4ade80;
  background: #052e16;
}

body.high-contrast .banner.warn {
  border-color: #fbbf24;
  background: #422006;
}

body.high-contrast .banner.danger {
  border-color: #f87171;
  background: #450a0a;
}
