/* ============================================================
   Pavillio Battle Cards — DESKTOP POLISH PASS
   Loaded after styles.css. Only activates at >=1024px.
   Optimized for second-monitor / always-on glance use.
   Common viewports: 1366x768, 1440x900, 1512x982, 1728x1117,
                     1920x1080, 2560x1440
   ============================================================ */

/* CSS vars for the desktop bits */
:root {
  --kbd-footer-h: 36px;
}

/* ============================================================
   1. WIDER, DENSER GRID AT DESKTOP
   Reps glance — more visible without scroll = better.
   ============================================================ */

@media (min-width: 1024px) {
  .grid-view {
    max-width: 1320px;
    padding-left: 28px;
    padding-right: 28px;
    padding-top: 28px;
  }
  .grid-cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }
  .tile {
    min-height: 178px;
    padding: 13px;
  }
}

@media (min-width: 1280px) {
  .grid-view { max-width: 1440px; }
  .grid-cards { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .tile { min-height: 168px; }
}

@media (min-width: 1440px) {
  .grid-view {
    max-width: 1560px;
    padding-left: 36px;
    padding-right: 36px;
  }
  .grid-cards {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
  }
  .tile {
    min-height: 172px;
    padding: 14px;
  }
  .tile-name { font-size: 15.5px; }
  .tile-framing {
    font-size: 13px;
    -webkit-line-clamp: 5;
    min-height: calc(1.45em * 4);
  }
}

@media (min-width: 1920px) {
  .grid-view { max-width: 1760px; }
  .grid-cards {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 16px;
  }
  .tile { min-height: 180px; }
}

/* ============================================================
   8. WIDER HERO TEXT AT >=1440px
   ============================================================ */

@media (min-width: 1440px) {
  .hero {
    padding: 12px 4px 28px;
    gap: 18px;
  }
  .hero h1 {
    font-size: clamp(28px, 2.6vw, 44px) !important;
    letter-spacing: -0.035em;
  }
  .hero-sub {
    font-size: 15px;
    max-width: 720px;
  }
}

/* ============================================================
   3. HOVER STATES WITH PERSONALITY (desktop, hover-capable only)
   Stronger lift + accent glow + content reveal.
   ============================================================ */

@media (min-width: 1024px) and (hover: hover) {
  .tile {
    transition:
      border-color 0.22s var(--ease-out),
      transform 0.22s var(--ease-out),
      background 0.22s var(--ease-out),
      box-shadow 0.28s var(--ease-out);
  }
  .tile:hover {
    transform: translateY(-3px);
    border-color: var(--c-border, var(--hairline-strong));
    background: var(--surface-2);
    box-shadow:
      0 14px 32px -14px rgba(0, 0, 0, 0.65),
      0 0 0 1px var(--c-border, transparent),
      0 0 28px -8px var(--c-glow, transparent);
  }
  .tile:hover::before { opacity: 1; height: 3px; }
  .tile:hover .tile-mark {
    box-shadow:
      0 6px 18px -3px var(--c-glow, rgba(0,0,0,0.4)),
      0 0 0 3px var(--c-tint);
  }
  .tile:hover .tile-name { color: var(--text); }
  .tile:hover .tile-framing { color: var(--text-soft); }
  .tile:hover .arrow {
    color: var(--c-accent);
    transform: translateX(3px);
  }

  /* Battle cards (objection/landmine) — gentle hover */
  .battle-card:not(.flipped):hover .bc-face.front {
    transform: translateY(-2px);
    box-shadow:
      0 12px 28px -14px rgba(0,0,0,0.6),
      0 0 0 1px var(--c-border, transparent);
  }
  .bc-face.front { transition: transform 0.22s var(--ease-out), box-shadow 0.22s var(--ease-out), border-color 0.22s, background 0.22s; }

  /* Win story cards */
  .win-story-card { transition: transform 0.22s var(--ease-out), box-shadow 0.22s var(--ease-out); }
  .win-story-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px -14px rgba(0,0,0,0.55);
  }

  /* Pavillio tile gets a stronger lift too */
  .pavillio-tile {
    transition: transform 0.22s var(--ease-out), border-color 0.22s, background 0.22s, box-shadow 0.22s var(--ease-out);
  }
  .pavillio-tile:hover {
    transform: translateY(-2px);
    box-shadow:
      0 14px 32px -14px rgba(0,0,0,0.6),
      0 0 28px -8px var(--accent-glow);
  }
}

/* ============================================================
   2. STICKY TWO-COLUMN DETAIL VIEW AT >=1280px
   Left rail: detail-hero + section pills (sticky).
   Right pane: section content (scrollable).
   ============================================================ */

@media (min-width: 1280px) {
  .detail-view {
    max-width: 1280px;
    display: grid;
    grid-template-columns: 300px 1fr;
    column-gap: 36px;
    padding: 0 28px;
    align-items: start;
  }

  /* Hero is wrapped by .desktop-rail (added by JS). The wrapper handles sticky. */
  .detail-hero {
    padding: 20px 0 0;
  }
  .detail-hero::before {
    top: -40px;
    left: 0;
    transform: none;
    width: 320px;
    height: 280px;
  }

  /* Compact the hero internals for the narrower rail */
  .detail-header-top { gap: 12px; margin-bottom: 2px; }
  .detail-mark {
    width: 44px;
    height: 44px;
    font-size: 17px;
    border-radius: 10px;
  }
  .detail-name {
    font-size: clamp(20px, 1.6vw, 26px) !important;
    letter-spacing: -0.026em;
    line-height: 1.1;
  }
  .detail-tagline { font-size: 12.5px; margin-top: 4px; }
  .detail-framing {
    margin-top: 14px;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.5;
  }
  .detail-meta-row { margin-top: 12px; gap: 4px; }
  .meta-chip { font-size: 10.5px; padding: 3px 8px; }

  /* Pills get moved into a wrapper inside the left rail by JS on desktop.
     That wrapper (.desktop-rail) is sticky and contains both hero + pills. */
  .section-pills {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-bottom: 0;
    border-top: 1px solid var(--hairline);
    margin: 14px 0 0;
    padding: 14px 0 0;
    flex-direction: column;
    gap: 4px;
    overflow: visible;
    align-items: stretch;
    position: static;
  }
  .section-pills::-webkit-scrollbar { width: 4px; }
  .section-pills::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 2px; }

  /* When JS adds the desktop-rail wrapper around hero + pills */
  .desktop-rail {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: calc(var(--header-h) + var(--safe-top) + 16px);
    align-self: start;
    max-height: calc(100vh - var(--header-h) - var(--safe-top) - 32px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--hairline-strong) transparent;
    z-index: 10;
  }
  .desktop-rail::-webkit-scrollbar { width: 6px; }
  .desktop-rail::-webkit-scrollbar-thumb { background: var(--hairline-strong); border-radius: 3px; }
  .desktop-rail .detail-hero { position: static; max-height: none; overflow: visible; padding-top: 24px; }
  .desktop-rail .section-pills { z-index: 5; }

  .pill {
    text-align: left;
    padding: 8px 14px;
    font-size: 13px;
    border-radius: 8px;
    width: 100%;
    justify-content: flex-start;
    transition: background 0.18s, color 0.18s, border-color 0.18s, padding 0.18s;
  }
  .pill.active {
    box-shadow: 0 4px 14px -6px var(--c-glow);
    padding-left: 16px;
  }
  .pill:hover:not(.active) {
    background: var(--surface-2);
    border-color: var(--hairline-strong);
  }

  /* Detail body: col 2, row 1. With pills now inside .desktop-rail in col 1,
     detail-view becomes a simple 2-col layout. */
  .detail-body {
    grid-column: 2;
    grid-row: 1;
    padding: 24px 0 80px;
    min-width: 0;
    align-self: start;
  }
  .section { margin-top: 0; padding-top: 8px; }
  .section + .section { margin-top: 36px; }
  .section:first-child { margin-top: 8px; }
}

/* On wider screens give the right pane more breathing room */
@media (min-width: 1440px) {
  .detail-view {
    max-width: 1400px;
    grid-template-columns: 320px 1fr;
    column-gap: 44px;
  }
}
@media (min-width: 1800px) {
  .detail-view {
    max-width: 1680px;
    grid-template-columns: 340px 1fr;
    column-gap: 56px;
  }
}
@media (min-width: 2200px) {
  .detail-view {
    max-width: 1920px;
    grid-template-columns: 360px 1fr;
    column-gap: 64px;
  }
}

/* ============================================================
   7. PER-COMPETITOR MULTI-COLUMN ON DETAIL VIEW AT >=1440px
   ============================================================ */

@media (min-width: 1440px) {
  /* Objection-handler / landmine flip cards — 2 per row */
  .deck {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  /* KV grid — 4 columns */
  .kv-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  /* Win stories — 2 per row */
  .win-stories {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  /* Verbatim quote cards — 2 per row */
  .quote-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  /* Differentiators (Pavillio detail) — 2 per row */
  .diff-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  /* News list — 2 per row at wide */
  .news-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  /* Talk tracks — 3 across */
  .section#talk-tracks {
    /* leave label as is */
  }
}

/* Even wider screens — push to 3-up on flip cards */
@media (min-width: 1800px) {
  .deck {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kv-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Compare grid is already 2-col at 640px — verify it stays */
@media (min-width: 1024px) {
  .compare { grid-template-columns: 1fr 1fr; }
  .duo { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   4-5. COMMAND PALETTE MODAL
   ============================================================ */

.cmdk-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.62);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  z-index: 500;
  display: grid;
  place-items: start center;
  padding-top: 12vh;
  padding-left: 16px;
  padding-right: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s var(--ease-out);
}
.cmdk-backdrop[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
}

.cmdk {
  width: 100%;
  max-width: 620px;
  background: linear-gradient(180deg, rgba(25, 28, 38, 0.95), rgba(18, 20, 28, 0.95));
  border: 1px solid var(--hairline-strong);
  border-radius: 16px;
  box-shadow:
    0 32px 80px -16px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
  transform: translateY(-12px) scale(0.98);
  transition: transform 0.22s var(--ease-out);
}
.cmdk-backdrop[data-open="true"] .cmdk {
  transform: translateY(0) scale(1);
}

.cmdk-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--hairline);
}
.cmdk-input-wrap svg {
  color: var(--text-mute);
  flex-shrink: 0;
}
.cmdk-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 450;
  padding: 6px 0;
  letter-spacing: -0.01em;
}
.cmdk-input::placeholder { color: var(--text-mute); }
.cmdk-esc {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-mute);
  flex-shrink: 0;
}

.cmdk-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline-strong) transparent;
}
.cmdk-results::-webkit-scrollbar { width: 8px; }
.cmdk-results::-webkit-scrollbar-thumb {
  background: var(--hairline-strong);
  border-radius: 4px;
}
.cmdk-group-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-mute);
  padding: 12px 12px 6px;
}
.cmdk-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-soft);
  border: 1px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  min-width: 0;
}
.cmdk-item:hover,
.cmdk-item[data-active="true"] {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--hairline-strong);
}
.cmdk-item[data-active="true"] {
  background: linear-gradient(180deg, rgba(249,115,22,0.08), rgba(249,115,22,0.04));
  border-color: rgba(249,115,22,0.32);
}
.cmdk-item-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
  background: var(--c-accent, var(--surface-3));
  flex-shrink: 0;
}
.cmdk-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
.cmdk-item-title {
  font-weight: 500;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmdk-item-sub {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmdk-item-kbd {
  font-size: 11px;
  color: var(--text-mute);
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 5px;
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.cmdk-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-mute);
  font-size: 13px;
}

/* ============================================================
   KEYBOARD HELP OVERLAY
   ============================================================ */

.kbd-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 510;
  display: grid;
  place-items: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s var(--ease-out);
}
.kbd-overlay[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
}
.kbd-panel {
  width: 100%;
  max-width: 480px;
  background: linear-gradient(180deg, rgba(25, 28, 38, 0.96), rgba(18, 20, 28, 0.96));
  border: 1px solid var(--hairline-strong);
  border-radius: 16px;
  box-shadow: 0 32px 80px -16px rgba(0,0,0,0.7);
  padding: 22px 24px 20px;
}
.kbd-panel h3 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 14px;
  color: var(--text);
}
.kbd-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-soft);
  border-bottom: 1px solid var(--hairline);
}
.kbd-row:last-child { border-bottom: 0; }
.kbd-keys { display: inline-flex; gap: 4px; }
.kbd-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2);
  border: 1px solid var(--hairline-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text);
}

/* ============================================================
   6. KEYBOARD HINT FOOTER (desktop only)
   ============================================================ */

.kbd-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--kbd-footer-h);
  background: rgba(8, 9, 13, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--hairline);
  display: none;
  align-items: center;
  justify-content: center;
  gap: 22px;
  font-size: 11.5px;
  color: var(--text-mute);
  letter-spacing: -0.005em;
  z-index: 90;
  padding: 0 16px;
  user-select: none;
  -webkit-user-select: none;
}
.kbd-footer-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.kbd-footer-hint .k {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 10.5px;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2);
  border: 1px solid var(--hairline-strong);
  border-radius: 4px;
  color: var(--text-soft);
  line-height: 1;
}
.kbd-footer-hint .sep { color: var(--text-mute); opacity: 0.6; }
.kbd-footer-brand {
  position: absolute;
  right: 20px;
  color: var(--text-mute);
  opacity: 0.55;
  font-weight: 500;
}

@media (min-width: 1024px) {
  .kbd-footer { display: flex; }
  /* Add bottom padding so footer doesn't overlap content */
  body { padding-bottom: calc(var(--safe-bottom) + var(--kbd-footer-h)); }
  .app-footer { margin-bottom: 0; }
  /* Push fab stack up if visible on desktop */
  .fab-stack { bottom: calc(var(--kbd-footer-h) + 16px) !important; }
}

/* Hide the mobile-only FAB on desktop where keyboard shortcuts win */
@media (min-width: 1280px) {
  .fab-stack { display: none !important; }
}

/* ============================================================
   9. REDUCED MOTION — disable transitions/animations
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .cmdk-backdrop,
  .cmdk,
  .kbd-overlay,
  .tile,
  .battle-card,
  .win-story-card,
  .pavillio-tile,
  .bc-face.front {
    transition: none !important;
    animation: none !important;
  }
  @media (min-width: 1024px) and (hover: hover) {
    .tile:hover { transform: none !important; }
    .battle-card:not(.flipped):hover .bc-face.front { transform: none !important; }
    .win-story-card:hover { transform: none !important; }
    .pavillio-tile:hover { transform: none !important; }
  }
}

/* ============================================================
   Small fixes: ensure search bar / detail nav don't break on
   desktop, and the pavillio-tile spans the wider grid nicely.
   ============================================================ */

@media (min-width: 1280px) {
  .pavillio-tile {
    max-width: 720px;
    margin: 0 auto;
  }
}

/* Section anchor offset accounting for missing sticky pills at >=1280px */
@media (min-width: 1280px) {
  .section { scroll-margin-top: calc(var(--header-h) + 24px); }
}
