@layer reset, base, components;

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

  body, h1, h2, p, ul {
    margin: 0;
  }

  ul {
    padding: 0;
    list-style: none;
  }

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

@layer base {
  :root {
    color-scheme: light dark;

    --bg: light-dark(#f8fafc, #090a0f);
    --surface: light-dark(#ffffff, #12141c);
    --surface-hover: light-dark(#f1f5f9, #181b26);
    --surface-border: light-dark(#e2e8f0, #1e2230);
    --text-main: light-dark(#090d16, #f8fafc);
    --text-muted: light-dark(#475569, #94a3b8);
    --accent: light-dark(#16a34a, #22c55e);
    --danger: light-dark(#dc2626, #ef4444);
    --danger-bg: light-dark(rgba(220, 38, 38, 0.08), rgba(239, 68, 68, 0.12));
    --danger-border: light-dark(rgba(220, 38, 38, 0.28), rgba(239, 68, 68, 0.35));
    --warn: light-dark(#d97706, #f59e0b);
    --warn-bg: light-dark(rgba(217, 119, 6, 0.08), rgba(245, 158, 11, 0.14));
    --warn-border: light-dark(rgba(217, 119, 6, 0.28), rgba(245, 158, 11, 0.35));
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    &:has(> head > meta[name="color-scheme"][content="dark"]) {
      color-scheme: dark;
    }

    &:has(> head > meta[name="color-scheme"][content="light"]) {
      color-scheme: light;
    }
  }

  [data-theme="terminal"] {
    color-scheme: dark;
    --bg: #030a04;
    --surface: #061408;
    --surface-hover: #091d0c;
    --surface-border: #0e3013;
    --text-main: #22c55e;
    --text-muted: #4ade80;
    --accent: #4ade80;
    --danger: #4ade80;
    --danger-bg: rgba(34, 197, 94, 0.08);
    --danger-border: #15803d;
    --font-body: var(--font-mono);
  }

  body {
    background: var(--bg);
    color: var(--text-main);
    font-family: var(--font-body);
    line-height: 1.5;
    min-block-size: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1.5rem;
  }

  a {
    color: inherit;
  }

  :where(a:any-link, button, summary):focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
  }

  .visually-hidden:where(:not(:focus-within, :active)) {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }
}

@layer components {
  .site-header,
  .site-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-inline-size: 900px;
    margin-inline: auto;
    inline-size: 100%;
    font-size: 0.8rem;
  }

  .site-footer {
    color: var(--text-muted);
    flex-wrap: wrap;
    gap: 0.75rem;
    padding-block-start: 2rem;
  }

  .footer-links {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
  }

  .footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
  }

  .footer-links a:hover {
    color: var(--text-main);
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  .footer-sep {
    opacity: 0.4;
  }

  .status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    font-weight: 600;
    letter-spacing: 0.04em;
  }

  .status-indicator {
    inline-size: 8px;
    block-size: 8px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 8px var(--danger);
  }

  .theme-btn,
  .btn-secondary {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    color: var(--text-muted);
    padding: 0.45rem 0.9rem;
    min-block-size: 2.25rem;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background-color 0.15s;
  }

  .theme-btn:hover,
  .btn-secondary:hover {
    color: var(--text-main);
    background: var(--surface-hover);
  }

  .btn-compact {
    font-size: 0.8rem;
    padding: 0.35rem 0.75rem;
    min-block-size: 2rem;
  }

  main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-inline-size: 900px;
    margin-inline: auto;
    inline-size: 100%;
    padding-block: 1.5rem;
    gap: 2rem;
  }

  .hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    inline-size: 100%;
  }

  .status-banner {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 14px;
    padding: 1.5rem 1.25rem 1.15rem;
  }

  .question {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-weight: 700;
    color: var(--text-muted);
  }

  .verdict {
    font-size: clamp(2.5rem, 7vw, 4.25rem);
    font-weight: 900;
    line-height: 1.05;
    margin-block: 0.45rem 0.65rem;
    letter-spacing: -0.02em;
    transition: opacity 0.2s;
    display: flex;
    align-items: baseline;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35ch;
  }

  .verdict-zero {
    color: var(--danger);
  }

  .verdict-label {
    font-family: var(--font-mono);
    font-size: clamp(0.85rem, 2vw, 1.05rem);
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-inline-start: 0.35ch;
  }

  .subtitle {
    color: var(--text-muted);
    max-inline-size: 560px;
    margin-block-end: 1.25rem;
    font-size: 0.92rem;
  }

  .action-group {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-block-end: 1.25rem;
  }

  .btn-primary {
    background: var(--text-main);
    color: var(--bg);
    border: none;
    font-weight: 600;
    padding: 0.75rem 1.6rem;
    min-block-size: 2.5rem;
    border-radius: 9999px;
    cursor: pointer;
    transition: opacity 0.15s;
  }

  .btn-primary:hover {
    opacity: 0.88;
  }

  .scanner-log {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--accent);
    min-block-size: 1.5rem;
  }

  .diagnostic-panel {
    inline-size: 100%;
    max-inline-size: 680px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    padding: 1.25rem;
    text-align: start;
    margin-block-start: 1rem;
  }

  .diagnostic-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
    margin-block-end: 0.65rem;
  }

  .diagnostic-header h2 {
    font-size: 0.95rem;
    font-weight: 700;
  }

  .panel-version {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent);
  }

  .panel-intro {
    font-size: 0.84rem;
    color: var(--text-muted);
    margin-block-end: 0.85rem;
  }

  .checklist {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    font-size: 0.84rem;
  }

  .checklist .check-icon {
    color: var(--accent);
    font-weight: 700;
    margin-inline-end: 0.45rem;
  }

  .tracker-section {
    inline-size: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .tracker-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
  }

  .tracker-title-group h2 {
    font-size: 1.15rem;
    font-weight: 700;
  }

  .tracker-meta {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-block-start: 0.15rem;
  }

  .tracker-meta a {
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  .tracker-controls {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
  }

  .filter-group {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    padding: 0.2rem;
    gap: 0.2rem;
  }

  .filter-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    min-block-size: 1.85rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
  }

  .filter-btn:hover {
    color: var(--text-main);
  }

  .filter-btn.is-active {
    background: var(--text-main);
    color: var(--bg);
  }

  [command="--toggle-all"][aria-expanded="true"] .expand,
  [command="--toggle-all"][aria-expanded="false"] .collapse {
    display: none;
  }

  .accordion {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    overflow: hidden;
  }

  .accordion details {
    background: transparent;
    border-block-end: 1px solid var(--surface-border);
    transition: background-color 0.15s;
  }

  .accordion details:last-child {
    border-block-end: none;
  }

  .accordion details[open] {
    background: var(--surface-hover);
  }

  .accordion summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.15rem;
    cursor: pointer;
    text-align: start;
    user-select: none;
  }

  .accordion summary::-webkit-details-marker {
    display: none;
  }

  .accordion summary:hover {
    background: var(--surface-hover);
  }

  .accordion summary::before {
    content: "";
    inline-size: 1rem;
    block-size: 1rem;
    flex-shrink: 0;
    background-color: currentColor;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat center / contain;
    rotate: -90deg;
  }

  .accordion summary:dir(rtl)::before {
    rotate: 90deg;
  }

  .accordion details[open] > summary::before {
    rotate: 0deg;
  }

  @media (prefers-reduced-motion: no-preference) {
    .accordion summary::before {
      transition: rotate 0.2s ease;
    }
  }

  .summary-main {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
    min-inline-size: 0;
  }

  .promise-title {
    font-weight: 700;
    font-size: 0.96rem;
  }

  .promise-author {
    font-size: 0.8rem;
    color: var(--text-muted);
  }

  .audit-preview {
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: var(--danger);
    margin-block-start: 0.2rem;
  }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.28rem 0.65rem;
    border-radius: 9999px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .badge-dot {
    inline-size: 7px;
    block-size: 7px;
    border-radius: 50%;
    background: currentColor;
  }

  .badge-nope {
    color: var(--danger);
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
  }

  details[data-audit="checking"] .badge-nope {
    color: var(--warn);
    background: var(--warn-bg);
    border-color: var(--warn-border);
  }

  @media (prefers-reduced-motion: no-preference) {
    details[data-audit="checking"] .badge-dot {
      animation: pulse-dot 0.6s ease-in-out infinite alternate;
    }
  }

  @keyframes pulse-dot {
    from { opacity: 0.35; }
    to { opacity: 1; }
  }

  .accordion details::details-content {
    interpolate-size: allow-keywords;
    overflow: clip;
    contain: layout;
  }

  .accordion details:not([open])::details-content {
    block-size: 0;
  }

  @media (prefers-reduced-motion: no-preference) {
    .accordion details::details-content {
      transition: block-size, content-visibility, display;
      transition-duration: 0.28s;
      transition-timing-function: ease-in-out;
      transition-behavior: allow-discrete;
    }
  }

  .details-body {
    padding: 0 1.15rem 1.15rem 2.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    font-size: 0.86rem;
    color: var(--text-muted);
    border-block-start: 1px solid var(--surface-border);
    padding-block-start: 0.9rem;
  }

  .details-body strong {
    color: var(--text-main);
  }

  .audit-line {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--danger);
    margin-block-start: 0.2rem;
  }

  .empty-state {
    background: var(--surface);
    border: 1px dashed var(--surface-border);
    border-radius: 12px;
    padding: 2rem 1.25rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
  }

  .empty-state strong {
    color: var(--text-main);
  }

  .toast-region {
    position: fixed;
    inset-block-end: 1.5rem;
    inset-inline: 1rem;
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 50;
  }

  .toast[popover] {
    inset: auto;
    position: relative;
    margin: 0;
    background: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--surface-border);
    border-radius: 9999px;
    padding: 0.65rem 0.85rem 0.65rem 1.15rem;
    font-size: 0.82rem;
    max-inline-size: min(520px, 92vw);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    pointer-events: auto;
    align-items: center;
    gap: 0.75rem;
  }

  .toast[popover]:where(:popover-open, .\:popover-open) {
    display: inline-flex;
  }

  .toast-close {
    background: transparent;
    border: 1px solid var(--surface-border);
    border-radius: 50%;
    inline-size: 1.65rem;
    block-size: 1.65rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .toast-close:hover {
    color: var(--text-main);
    background: var(--surface-hover);
  }

  @media (max-width: 600px) {
    body {
      padding: 1rem;
    }

    .accordion summary {
      flex-wrap: wrap;
    }

    .details-body {
      padding-inline: 1.15rem;
    }
  }
}
