/* ==========================================================================
   Polymarket-style market browser
   Plain CSS. Dark theme mirroring the real site's visual language.
   ========================================================================== */

:root {
  --bg: #0e1014;
  --bg-elevated: #14171d;
  --surface: #16191f;
  --surface-hover: #1c2029;
  --surface-active: #232833;

  --border: #262b34;
  --border-strong: #333a46;

  --text: #ffffff;
  --text-secondary: #b6bcc8;
  --muted: #7f8796;
  --muted-dim: #626a78;

  --brand: #1652f0;
  --brand-hover: #2a63f2;
  --yes: #2a6ef5;
  --yes-soft: rgba(42, 110, 245, 0.14);
  --no: #e0524d;
  --no-soft: rgba(224, 82, 77, 0.14);
  --up: #26a17b;
  --live: #e5484d;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --shell: 1400px;
  --header-h: 60px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.55);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

:focus-visible {
  outline: 2px solid var(--brand-hover);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 10px 16px;
  background: var(--brand);
  border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
  left: 0;
}

/* ---------------------------------------------------------------- header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(14, 16, 20, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 20px;
  height: var(--header-h);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  flex: none;
}

.brand-logo {
  width: 26px;
  height: 26px;
  border-radius: 7px;
}

.primary-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.primary-nav a {
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.primary-nav a:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.primary-nav a.active {
  color: var(--text);
  background: var(--surface-hover);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 240px;
  padding: 0 12px;
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  transition: border-color 0.15s, background 0.15s;
}

.search-box:focus-within {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.search-box svg {
  width: 15px;
  height: 15px;
  flex: none;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.search-box input {
  width: 100%;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  outline: none;
}

.search-box input::placeholder {
  color: var(--muted-dim);
}

/* ------------------------------------------------------ category tab bar */

.category-bar {
  border-top: 1px solid var(--border);
}

.category-scroll {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: var(--shell);
  margin: 0 auto;
  padding: 8px 20px;
  overflow-x: auto;
  scrollbar-width: none;
}

.category-scroll::-webkit-scrollbar {
  display: none;
}

.category-tab {
  flex: none;
  padding: 6px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.category-tab:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.category-tab[aria-selected="true"] {
  background: var(--surface-active);
  color: var(--text);
}

.category-more {
  color: var(--muted);
  padding: 6px 10px;
}

/* ------------------------------------------------------------ page shell */

.page {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 26px 20px 60px;
}

.section + .section {
  margin-top: 40px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2 {
  font-size: 22px;
  letter-spacing: -0.02em;
}

.result-count {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 13.5px;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--surface-hover);
  border-color: var(--muted-dim);
}

/* --------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-btn,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.toolbar-btn:hover,
.chip:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

.toolbar-btn svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.7;
}

.chip[aria-pressed="true"] {
  background: var(--surface-active);
  border-color: var(--border-strong);
  color: var(--text);
}

.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.seg button {
  height: 26px;
  padding: 0 13px;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}

.seg button:hover {
  color: var(--text);
}

.seg button.is-selected {
  background: var(--surface-active);
  color: var(--text);
}

/* ------------------------------------------------------------------ menu */

.menu {
  position: relative;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 176px;
  padding: 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}

.menu-panel button {
  display: block;
  width: 100%;
  padding: 8px 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  text-align: left;
  font-size: 13.5px;
  transition: background 0.12s, color 0.12s;
}

.menu-panel button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.menu-panel button.is-selected {
  color: var(--text);
  font-weight: 600;
}

/* ----------------------------------------------------------- market grid */

.market-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 12px;
}

.market-card {
  display: flex;
  flex-direction: column;
  min-height: 168px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.market-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
  transform: translateY(-2px);
}

.market-card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.market-icon {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-active);
}

.market-icon-fallback {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 8px;
  background: var(--surface-active);
  color: var(--muted);
  font-weight: 700;
  font-size: 15px;
}

.market-title {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.32;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge-live {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 6px;
  color: var(--live);
  font-size: 11.5px;
  font-weight: 600;
  vertical-align: 1px;
}

.badge-live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* outcome rows */

.market-outcomes {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
  padding: 0;
  list-style: none;
}

.outcome-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  margin: 0 -8px;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
}

.outcome-row + .outcome-row {
  border-top: 1px solid var(--border);
}

.outcome-row:hover {
  background: var(--surface-active);
}

.outcome-label {
  flex: 1;
  min-width: 0;
  color: var(--text-secondary);
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outcome-pct {
  font-family: var(--font-num);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.outcome-actions {
  position: absolute;
  inset: 0 0 0 auto;
  display: flex;
  align-items: center;
  gap: 5px;
  padding-right: 8px;
  background: linear-gradient(90deg, transparent, var(--surface-active) 22%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.outcome-row:hover .outcome-actions,
.outcome-row:focus-within .outcome-actions {
  opacity: 1;
  pointer-events: auto;
}

.buy {
  height: 26px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  transition: filter 0.12s;
}

.buy:hover {
  filter: brightness(1.14);
}

.buy-yes {
  background: var(--yes-soft);
  border-color: rgba(42, 110, 245, 0.4);
  color: #7fa8ff;
}

.buy-no {
  background: var(--no-soft);
  border-color: rgba(224, 82, 77, 0.4);
  color: #ff8a86;
}

/* binary (single yes/no) presentation */

.market-chance {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 18px;
}

.market-chance strong {
  font-family: var(--font-num);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.market-chance span {
  color: var(--muted);
  font-size: 13px;
}

.binary-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.binary-actions .buy {
  flex: 1;
  height: 34px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* card footer */

.market-card-foot {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: auto;
  padding-top: 14px;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.market-card-foot .vol {
  color: var(--text-secondary);
  font-weight: 500;
}

.market-card-foot .dot {
  color: var(--muted-dim);
}

.market-cat {
  color: var(--muted);
  transition: color 0.12s;
}

.market-cat:hover {
  color: var(--text-secondary);
  text-decoration: underline;
}

.market-details {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12.5px;
  transition: color 0.12s;
}

.market-details:hover {
  color: var(--text);
  text-decoration: underline;
}

/* ---------------------------------------------------------- featured row */

.carousel {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(268px, 300px);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x proximity;
}

.carousel > * {
  scroll-snap-align: start;
}

/* ----------------------------------------------------- states & skeletons */

.market-card.is-skeleton {
  pointer-events: none;
}

.sk {
  background: linear-gradient(
    90deg,
    var(--surface-hover) 25%,
    var(--surface-active) 37%,
    var(--surface-hover) 63%
  );
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.sk-icon { width: 36px; height: 36px; border-radius: 8px; }
.sk-title { height: 14px; margin-top: 14px; width: 85%; }
.sk-row { height: 26px; margin-top: 10px; }
.sk-foot { height: 12px; margin-top: auto; width: 45%; }

.error-state {
  padding: 22px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid rgba(224, 82, 77, 0.35);
  border-radius: var(--radius-lg);
}

.error-state strong {
  display: block;
  margin-bottom: 5px;
}

.error-state p {
  margin: 0 0 14px;
  color: var(--muted);
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

.load-more-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 26px;
}

.feed-note {
  color: var(--muted-dim);
  font-size: 12.5px;
  min-height: 18px;
}

/* ----------------------------------------------------------------- dialog */

.market-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: min(80vh, 760px);
  padding: 0;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}

.market-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.dialog-close:hover {
  background: var(--surface-active);
  color: var(--text);
}

.dialog-body {
  padding: 24px;
  max-height: min(80vh, 760px);
  overflow-y: auto;
}

.dialog-head {
  display: flex;
  gap: 14px;
  padding-right: 40px;
}

.dialog-head h2 {
  font-size: 19px;
  line-height: 1.3;
}

.dialog-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 16px 0 20px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
}

.dialog-meta b {
  color: var(--text-secondary);
  font-weight: 600;
}

.dialog-market {
  margin-bottom: 18px;
}

.dialog-market h3 {
  margin-bottom: 8px;
  font-size: 13.5px;
  color: var(--text-secondary);
  font-weight: 500;
}

.dialog-outcomes {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.dialog-outcomes div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 13px;
  font-size: 13.5px;
  background: var(--surface);
}

.dialog-outcomes div + div {
  border-top: 1px solid var(--border);
}

.dialog-outcomes strong {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

.dialog-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: #7fa8ff;
  font-weight: 600;
  font-size: 13.5px;
}

.dialog-link:hover {
  text-decoration: underline;
}

/* ---------------------------------------------------------------- footer */

.site-footer {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 24px 20px 40px;
  border-top: 1px solid var(--border);
  color: var(--muted-dim);
  font-size: 12.5px;
}

.site-footer p {
  margin: 0;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1100px) {
  .primary-nav {
    display: none;
  }
}

@media (max-width: 760px) {
  .header-inner {
    gap: 12px;
    padding: 0 14px;
  }

  .search-box {
    width: 150px;
  }

  .btn-ghost {
    display: none;
  }

  .page {
    padding: 20px 14px 48px;
  }

  .category-scroll {
    padding: 8px 14px;
  }

  .market-grid {
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 10px;
  }

  .section-head h2 {
    font-size: 19px;
  }

  .market-chance strong {
    font-size: 26px;
  }
}

@media (max-width: 420px) {
  .search-box {
    display: none;
  }

  .market-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
