/* DeviceAtlas-derived palette (from production CSS) */
:root {
  --brand: #407BFF;
  --brand-strong: #2f63d8;
  --accent: #F44336;
  --teal: #23ac9d;
  --bg: #f9f9f9;
  --surface: #ffffff;
  --text: #1a1c1c;
  --muted: #616464;
  --border: #e2e2e2;
  --border-strong: #c9c9c9;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 12px rgba(0, 0, 0, .06);
  --shadow-lifted: 0 4px 8px rgba(0, 0, 0, .06), 0 12px 32px rgba(0, 0, 0, .10);
  --radius: 12px;
  --radius-sm: 8px;
  --tier-platinum: #6a7a8a;
  --tier-gold:     #c9a227;
  --tier-silver:   #9ca3ab;
  --tier-pearl:    #b6a3c9;
  --tier-event:    #23ac9d;
  --tier-premier:  var(--brand);
  --tier-default:  #888;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

/* ---------- Header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 8px;
}

.app-header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.app-title__icon {
  border-radius: 6px;
}

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

.filters__search {
  position: relative;
  flex: 1 1 280px;
  display: flex;
  align-items: stretch;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.filters__search:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(64,123,255,.18);
}
.filters__search-icon {
  align-self: center;
  margin-left: 10px;
  color: var(--muted);
  flex: none;
}
#search-input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 10px 8px;
  font: inherit;
  color: inherit;
  min-width: 0;
}
#search-input::-webkit-search-cancel-button { cursor: pointer; }

#search-field,
#filter-vertical,
#filter-tier {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 9px 10px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  min-height: 38px;
}
#search-field {
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.btn-ghost {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  transition: background .15s ease, color .15s ease;
  min-height: 38px;
}
.btn-ghost:hover, .btn-ghost:focus-visible {
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
  min-height: 38px;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover, .icon-btn:focus-visible {
  border-color: var(--border-strong);
  color: var(--text);
  outline: none;
}
.icon-btn[aria-pressed="true"] {
  background: rgba(244, 67, 54, .08);
  color: var(--accent);
  border-color: rgba(244, 67, 54, .35);
}
.icon-btn[aria-pressed="true"] svg path { fill: var(--accent); stroke: var(--accent); }

.icon-btn__label { font-size: 14px; }

.badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}

.result-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

/* ---------- Grid + cards ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, opacity .25s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  outline: none;
}
.card:hover, .card:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lifted);
  border-color: var(--border-strong);
}
.card:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(64,123,255,.20), var(--shadow-lifted);
}
.card.is-leaving { opacity: 0; transform: scale(.98); }
.card.is-entering { animation: fadeUp .25s ease both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card__fav {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: 0;
  padding: 6px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.card__fav:hover { background: var(--bg); color: var(--accent); }
.card__fav.is-fav { color: var(--accent); }
.card__fav.is-fav .card__fav-path { fill: var(--accent); stroke: var(--accent); }
.card__fav:active { transform: scale(1.2); }

.card__logo-wrap {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: none;
}
.card__logo { width: 28px; height: 28px; object-fit: contain; }
.card__logo[hidden] { display: none; }
.card__logo-fallback {
  font-weight: 600;
  color: var(--muted);
}

.card__name {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  padding-right: 28px; /* room for fav icon */
}

.card__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip--vertical { background: rgba(64,123,255,.08); color: var(--brand-strong); border-color: rgba(64,123,255,.20); }
.chip--tier { color: #fff; border: 0; }
.chip--tier[data-tier="Platinum"] { background: var(--tier-platinum); }
.chip--tier[data-tier="Gold"]     { background: var(--tier-gold); }
.chip--tier[data-tier="Silver"]   { background: var(--tier-silver); }
.chip--tier[data-tier="Pearl"]    { background: var(--tier-pearl); }
.chip--tier[data-tier="Event"]    { background: var(--tier-event); }
.chip--tier[data-tier="Premier"]  { background: var(--tier-premier); }
.chip--tier:not([data-tier="Platinum"]):not([data-tier="Gold"]):not([data-tier="Silver"]):not([data-tier="Pearl"]):not([data-tier="Event"]):not([data-tier="Premier"]) {
  background: var(--tier-default);
}

.card__summary {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__opener {
  margin: 0;
  font-size: 13.5px;
  color: var(--text);
  background: rgba(35,172,157,.08);
  border-left: 3px solid var(--teal);
  padding: 6px 10px;
  border-radius: 4px;
}

.card mark {
  background: rgba(255,235,59,.55);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

.empty-state {
  text-align: center;
  padding: 64px 16px;
  color: var(--muted);
}

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

.detail {
  border: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  box-shadow: var(--shadow-lifted);
  overflow: hidden;
}
.detail::backdrop {
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}
.detail[open] {
  animation: pop .18s ease both;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.detail__close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: transparent;
  border: 0;
  font-size: 28px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
}
.detail__close:hover { background: var(--bg); color: var(--text); }

.detail__body { padding: 20px 22px 22px; max-height: calc(100vh - 32px); overflow: auto; }

.detail__head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 18px;
  padding-right: 48px; /* reserve room for the absolutely positioned close × */
}
.detail__logo-wrap {
  width: 56px; height: 56px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: none;
}
.detail__logo { width: 44px; height: 44px; object-fit: contain; }
.detail__logo[hidden] { display: none; }
.detail__logo-fallback { font-size: 22px; font-weight: 600; color: var(--muted); }
.detail__head-text { flex: 1; min-width: 0; }
.detail__name { margin: 0 0 6px; font-size: 22px; }
.detail__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.detail__fav { flex: none; }

.detail__section { margin-bottom: 16px; }
.detail__section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 6px;
}
.detail__section p { margin: 0 0 12px; }
.detail__section p:last-child { margin-bottom: 0; }

.detail__opener {
  font-size: 16px;
  background: rgba(35,172,157,.10);
  border-left: 4px solid var(--teal);
  padding: 10px 14px;
  border-radius: 4px;
}

.detail__links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.detail__links a::before {
  content: "↗";
  margin-right: 6px;
  color: var(--muted);
}

.detail__sources {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}
.detail__sources a { word-break: break-all; }

/* ---------- Mobile ---------- */

@media (max-width: 600px) {
  .app-header { padding: 10px 12px 6px; }
  .filters { gap: 6px; }
  #filter-vertical, #filter-tier { flex: 1 1 calc(50% - 4px); }
  .card-grid { padding: 12px; gap: 12px; grid-template-columns: 1fr; }
  .detail { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .detail__body { max-height: 100dvh; padding-bottom: 32px; }
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
}

/* ---------- View Transitions API ---------- */

::view-transition-old(card),
::view-transition-new(card) {
  animation-duration: .25s;
}
