:root {
  --bg: #0f1419;
  --bg-panel: #161b22;
  --bg-elevated: #1c2330;
  --border: #2d3640;
  --text: #e8ecf1;
  --text-muted: #8b9aab;
  --accent: #e8a838;
  --tier-a: #3dd68c;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: var(--safe-bottom);
}

.hidden { display: none !important; }

.m-loading {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-muted);
}

.m-brand {
  background: linear-gradient(135deg, var(--accent), #c47f20);
  color: #0f1419;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
}

.m-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.m-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(15, 20, 25, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: calc(0.75rem + var(--safe-top)) 1rem 0.85rem;
}

.m-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.m-brand-block {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  min-width: 0;
}

.m-brand-block h1 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
}

.m-brand-block p {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.m-mode-switch {
  display: flex;
  flex-shrink: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.m-mode-btn {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.m-mode-btn.active {
  background: linear-gradient(135deg, var(--accent), #c47f20);
  color: #0f1419;
}

.m-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.5rem;
}

.m-search svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.m-search input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
}

.m-stats {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.m-chips-wrap {
  position: sticky;
  top: calc(var(--header-h, 140px));
  z-index: 30;
  background: rgba(15, 20, 25, 0.94);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0;
}

.m-chips {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0 1rem 0.35rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.m-chips::-webkit-scrollbar { display: none; }

.m-chip {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.m-chip.active {
  border-color: var(--accent);
  background: rgba(232, 168, 56, 0.15);
  color: var(--accent);
}

.m-chip.is-placeholder {
  opacity: 0.45;
}

.m-main {
  flex: 1;
  padding: 0.85rem 1rem 1.5rem;
}

.m-view-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.m-view-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.m-cards {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.m-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s;
}

.m-card:active {
  border-color: var(--accent);
}

.m-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.m-card-name {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
}

.m-card-site {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--accent);
  text-decoration: none;
  font-size: 1rem;
}

.m-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.m-card-summary {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.status-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-a { background: rgba(61, 214, 140, 0.2); color: var(--tier-a); }
.status-b { background: rgba(91, 156, 245, 0.2); color: #5b9cf5; }
.status-verified { background: rgba(124, 108, 240, 0.2); color: #7c6cf0; }
.status-base { background: var(--bg-elevated); color: var(--text-muted); }

.m-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}

.m-btn-ghost {
  margin-top: 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.m-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  padding: 1rem 1rem calc(1rem + var(--safe-bottom));
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
}

.m-foot a {
  color: var(--text-muted);
  text-decoration: none;
}

.m-foot a:active {
  color: var(--accent);
}

/* Bottom sheet */
.m-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.m-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 101;
  max-height: 88vh;
  background: var(--bg-panel);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  transform: translateY(0);
  animation: sheetIn 0.25s ease;
}

@keyframes sheetIn {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.m-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0.5rem auto 0;
  flex-shrink: 0;
}

.m-sheet-close {
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 1.35rem;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
}

.m-sheet-body {
  overflow-y: auto;
  padding: 0.75rem 1.15rem 1.25rem;
  -webkit-overflow-scrolling: touch;
}

.m-sheet-body h3 {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 0.35rem;
  padding-right: 2.5rem;
}

.m-sheet-cat {
  font-size: 0.78rem;
  color: var(--accent);
  margin-bottom: 1rem;
}

.m-sheet-section {
  margin-bottom: 1.15rem;
}

.m-sheet-section h4 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.m-sheet-section p {
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.m-sheet-section dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  font-size: 0.85rem;
}

.m-sheet-section dt {
  color: var(--text-muted);
}

.m-sheet-section dd {
  word-break: break-word;
}

.m-sheet-section a {
  color: var(--accent);
}

.m-sheet-btn {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #c47f20);
  color: #0f1419;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
}

body.mode-opt .m-brand-block .m-brand,
.m-loading .m-brand.mode-opt {
  /* brand mark text set via JS */
}
