/**
 * DeePonyCap — HIG reskin of the 3.x shell and shared components.
 * Sits in `@layer components` (above `legacy`). SF type (SF Rounded for titles — friendly, still system);
 * the user's accent theme tints controls only. Docs: DESIGN.md.
 */

@layer components {

/* ---------- Canvas + document scrolling (iOS) ---------- */

html,
body {
  height: auto;
  min-height: 100%;
  overflow-y: visible;
  overscroll-behavior-x: none;
  overscroll-behavior-y: auto;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font-ui);
  font-weight: 400;
}

body::before,
body::after,
html.dark-mode body::before,
html.dark-mode body::after,
.stars,
.cap-ambient,
.cap-scroll-progress,
#cap-scene {
  display: none;
}

.app {
  height: auto;
  min-height: 100dvh;
}

html.dark-mode body,
html.dark-mode #main,
#main {
  background: transparent;
}

.main {
  flex: none;
  overflow: visible;
  -webkit-overflow-scrolling: auto;
  overscroll-behavior: auto;
  min-height: 0;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  /* top: clear the floating Add + Settings buttons */
  padding: calc(env(safe-area-inset-top) + 60px) var(--gutter) calc(var(--tabbar-h) + 48px + env(safe-area-inset-bottom));
}

@media (min-width: 700px) {
  .main {
    padding: 64px 32px 64px;
  }
}

.g4-bulk-panel,
html.dark-mode .g4-bulk-panel {
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--label);
  box-shadow: var(--shadow-1);
}

.g4-bulk-panel p {
  color: var(--label-2) !important;
}

/* ---------- Type ---------- */

h1,
h2,
h3,
.greet,
.section-title,
.pony-name,
.shelf-hdr,
.nav-label,
.btn-p,
.btn-g,
.btn-d {
  font-family: var(--font-rounded);
  letter-spacing: -0.01em;
}

h1,
.greet {
  font-size: var(--t-large);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--label);
}

h2 {
  font-size: var(--t-title3);
  font-weight: 700;
}

.section-title {
  font-size: var(--t-title3);
  font-weight: 700;
  color: var(--label);
}

.big-num {
  font-family: var(--font-rounded);
  font-size: 4rem;
  font-weight: 700;
  color: var(--tint);
  animation: none;
}

.fl {
  font-size: var(--t-footnote);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--label-2);
  margin: 0 4px 6px;
}

/* ---------- Floating glass tab bar (<700px) ---------- */

.nav,
html.dark-mode .nav {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 6px));
  height: var(--tabbar-h);
  padding: 0 6px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--glass-material);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  box-shadow: 0 0 0 0.5px var(--glass-border), 0 10px 30px rgba(0, 0, 0, 0.12);
  z-index: 40;
}

.nav-btn,
html.dark-mode .nav-btn {
  max-width: none;
  height: calc(var(--tabbar-h) - 10px);
  min-height: 48px;
  padding: 0 2px;
  justify-content: center;
  border-radius: 999px;
  background: transparent;
  /* Stronger than --label-2: glass bar failed axe color-contrast on inactive tabs */
  color: var(--label);
  font-size: 10.5px;
  font-weight: 600;
}

.nav-btn.on {
  color: var(--tint);
  background: var(--fill);
}

/* Selected tab: lighten tint on dark glass+fill (72% mix failed axe AA over translucent bar) */
html.dark-mode .nav-btn.on {
  color: color-mix(in oklab, var(--accent-src) 45%, #fff);
  background: var(--fill);
}


.nav-btn .nav-icon,
.nav-btn.on .nav-icon {
  background: none;
  box-shadow: none;
  transform: none;
  color: inherit;
}

.nav-label {
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 600;
}

.cap-tab-indicator {
  display: none;
}

@media (min-width: 700px) {
  .cap-desktop-shell {
    display: flex;
    width: 100%;
    max-width: none;
    min-height: 100dvh;
    margin: 0;
    box-shadow: none;
  }
  #cap-nav-sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    align-self: flex-start;
    width: 248px;
    min-width: 248px;
    height: 100dvh;
    overflow-y: auto;
    padding: max(20px, env(safe-area-inset-top)) 12px 16px;
    border-right: 0.5px solid var(--separator);
    background: var(--glass-material);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    backdrop-filter: saturate(180%) blur(24px);
  }
  .cap-desktop-main {
    flex: 1;
    min-width: 0;
  }
  .nav,
  html.dark-mode .nav {
    display: none;
  }
}

.cap-sidebar-brand {
  padding: 0 12px 16px;
  font-family: var(--font-rounded);
  font-size: var(--t-title3);
  font-weight: 700;
  color: var(--label);
}

.cap-side-btn {
  min-height: var(--hit);
  padding: 0 12px;
  gap: 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--label);
  font-family: var(--font-ui);
  font-size: var(--t-body);
  font-weight: 400;
}

.cap-side-btn svg {
  color: var(--tint);
}

.cap-side-btn.on,
.cap-side-btn.active {
  background: var(--tint);
  color: var(--on-tint);
  font-weight: 600;
}

.cap-side-btn.on svg,
.cap-side-btn.active svg {
  color: var(--on-tint);
}

/* Add lives next to Settings (HIG: no floating action button) */
.fab {
  display: none !important;
}

.app-settings-btn,
.app-add-btn {
  position: fixed;
  top: calc(6px + env(safe-area-inset-top));
  z-index: 85;
  width: var(--hit);
  height: var(--hit);
  border: 0;
  border-radius: 999px;
  background: var(--glass-material);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  box-shadow: 0 0 0 0.5px var(--glass-border);
  color: var(--tint);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.app-settings-btn {
  right: 12px;
}

.app-add-btn {
  right: 64px;
}

/* ---------- Surfaces ---------- */

.card,
html.dark-mode .card,
.pony-card,
.mini-card,
.shelf,
.stat-card {
  border: 0;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  color: var(--label);
}

/* Demo banner: one quiet line */
.demo-banner-inner,
html.dark-mode .demo-banner-inner {
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  color: var(--label-2);
  font-size: var(--t-footnote);
}

html.dark-mode .demo-banner-inner p,
html.dark-mode .demo-banner-inner strong {
  color: var(--label);
}

/* ---------- Buttons, chips ---------- */

.btn-p,
.btn-p.shimmer {
  min-height: 50px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--tint);
  color: var(--on-tint);
  font-family: var(--font-ui);
  font-size: var(--t-headline);
  font-weight: 600;
  animation: none;
  box-shadow: none;
}

.btn-g,
.btn-d {
  min-height: var(--hit);
  border: 0;
  border-radius: var(--r-md);
  background: var(--fill);
  color: var(--label);
  -webkit-text-fill-color: currentColor;
  font-family: var(--font-ui);
  font-weight: 600;
}

.chip {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--fill);
  color: var(--label);
  font-family: var(--font-ui);
  font-size: var(--t-subhead);
  font-weight: 500;
  position: relative;
}

.chip::after {
  content: "";
  position: absolute;
  inset: -5px 0;
}

.chip.on {
  background: var(--label);
  color: var(--bg);
  border: 0;
}

/* Selected option chips — tint (AA) instead of raw --pink on white text */
.opt.on,
button.opt.on {
  background: var(--tint);
  color: var(--on-tint);
  border-color: var(--tint);
  -webkit-text-fill-color: var(--on-tint);
}

.stat-box .n,
.big-num {
  color: var(--tint);
}

/* Achievements: mute with solid AA greys, not opacity (opacity×text failed axe) */
.ach {
  opacity: 1;
  color: #6c6c70; /* ≥4.5:1 on white */
  background: var(--surface);
}

html.dark-mode .ach {
  color: #aeaeb2; /* ≥4.5:1 on graphite cards */
}

.ach.unlocked {
  color: var(--label);
  border: 2px solid var(--warning);
}

.ach > span:nth-child(2) {
  color: inherit;
}

.map-slot-meta {
  color: #6c6c70;
  font-weight: 600;
}

/* Slots were still white in dark → #aeaeb2 meta failed AA; graphite surface matches HIG cards */
html.dark-mode .map-slot {
  background: var(--surface);
  border-color: var(--separator);
}

html.dark-mode .map-slot-meta {
  color: #aeaeb2; /* ≥4.5:1 on --surface */
}

/* ---------- Fields ---------- */

.inp,
.ta,
.sort-select,
.sort-row select,
html.dark-mode .sort-row select,
html.dark-mode .sort-select {
  min-height: var(--hit);
  border: 0;
  border-radius: var(--r-sm);
  background-color: var(--fill);
  color: var(--label);
  font-family: var(--font-ui);
  box-shadow: none;
}

.inp:focus,
.ta:focus {
  box-shadow: 0 0 0 3px var(--tint-soft);
  outline: none;
}

/* ---------- Sheet: grabber + Cancel / Title / Save ---------- */

.sheet-bg {
  background: var(--scrim);
}

.sheet {
  max-width: 560px;
  margin: 0 auto;
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  box-shadow: var(--shadow-3);
  overscroll-behavior: contain;
}

.sheet-handle {
  width: 36px;
  height: 5px;
  margin: 0 auto 8px;
  border-radius: 999px;
  background: var(--label-4);
}

.sheet-hdr h2 {
  font-family: var(--font-ui);
  font-size: var(--t-headline);
  font-weight: 600;
}

.sheet-hdr--bar {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr);
  align-items: center;
  margin: 0 -8px 12px;
}

.sheet-bar-cancel,
.sheet-bar-done {
  min-height: var(--hit);
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--tint);
  font-family: var(--font-ui);
  font-size: var(--t-body);
  cursor: pointer;
}

.sheet-bar-cancel {
  justify-self: start;
}

.sheet-bar-done {
  justify-self: end;
  font-weight: 600;
}

.sheet-close {
  width: 30px;
  height: 30px;
  border: 0;
  background: var(--fill);
  color: var(--label-2);
  -webkit-text-fill-color: currentColor;
  position: relative;
}

.sheet-close::after {
  content: "";
  position: absolute;
  inset: -7px;
}

/* Hover only where a pointer can hover */
@media (hover: none) {
  .btn-p:hover,
  .btn-g:hover,
  .pony-card:hover,
  .nav-btn:hover,
  .chip:hover {
    transform: none;
  }
}

#sheetTitle:focus {
  outline: none;
}

} /* @layer components */
