/* ═══════════════════════════════════════════
   Base - reset, typography, utility classes
   ═══════════════════════════════════════════ */

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

html {
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: var(--fw-normal);
    line-height: var(--leading-normal);
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Typography ── */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: var(--fw-semibold);
    line-height: var(--leading-tight);
    text-wrap: balance;
    color: var(--color-text);
}

h1 {
    font-size: var(--text-3xl);
}

h2 {
    font-size: var(--text-2xl);
}

h3 {
    font-size: var(--text-xl);
}

h4 {
    font-size: var(--text-lg);
}

h5,
h6 {
    font-size: var(--text-base);
}

p {
    margin: 0;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: none;
}

code,
pre,
kbd {
    font-family: var(--font-mono);
    font-size: .9em;
}

/* ── Utility ── */
.text-xs {
    font-size: var(--text-xs);
}

.text-sm {
    font-size: var(--text-sm);
}

.text-base {
    font-size: var(--text-base);
}

.text-lg {
    font-size: var(--text-lg);
}

.text-xl {
    font-size: var(--text-xl);
}

.text-muted {
    color: var(--color-text-muted);
}

.text-secondary {
    color: var(--color-text-secondary);
}

.text-danger {
    color: var(--color-danger-fg);
}

.text-success {
    color: var(--color-success-fg);
}

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fw-medium {
    font-weight: var(--fw-medium);
}

.fw-semibold {
    font-weight: var(--fw-semibold);
}

.fw-bold {
    font-weight: var(--fw-bold);
}

.mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* ── Layout utilities ── */
.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.flex-wrap     { flex-wrap: wrap; }
.flex-1        { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.min-w-0       { min-width: 0; }
.align-center  { align-items: center; }
.align-start   { align-items: flex-start; }
.align-end     { align-items: flex-end; }
.justify-end   { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }

.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-5 { gap: var(--sp-5); }
.gap-6 { gap: var(--sp-6); }

.mb-1 { margin-bottom: var(--sp-1); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-5 { margin-bottom: var(--sp-5); }
.mb-6 { margin-bottom: var(--sp-6); }
.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }
.mt-8 { margin-top: var(--sp-8); }
.ml-auto { margin-left: auto; }
.page-narrow { max-width: 560px; }
/* Logo light/dark swap — mirrors favicon dark logic */
.logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo-dark  { display: block; }
}
[data-theme="dark"] .logo-light { display: none; }
[data-theme="dark"] .logo-dark  { display: block; }
.p-3  { padding: var(--sp-3); }
.p-4  { padding: var(--sp-4); }
.p-6  { padding: var(--sp-6); }
.p-8  { padding: var(--sp-8); }
.text-center { text-align: center; }
.text-right  { text-align: right; }

.grid-2col { display: grid; grid-template-columns: 1fr auto; }
.grid-2    { display: grid; grid-template-columns: 1fr 1fr; }

.hidden         { display: none; }
.block          { display: block; }
.w-full         { width: 100%; }
.cursor-pointer { cursor: pointer; }
.resize-y       { resize: vertical; }
.break-all      { word-break: break-all; }
.text-primary   { color: var(--color-primary); }
.text-warning   { color: var(--color-warning); }

/* ── Divider ── */
.divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 0;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: var(--r-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* ── Focus ring ── */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ── Screen reader only ── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

/* ── Settings sub-nav ── */
.settings-nav {
    display: flex;
    gap: var(--sp-1);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--sp-6);
    padding-bottom: 0;
}

.settings-tab {
    display: block;
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--text-sm);
    font-weight: var(--fw-medium);
    color: var(--color-text-secondary);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--dur-base), border-color var(--dur-base);
    white-space: nowrap;
}

.settings-tab:hover {
    color: var(--color-text);
}

.settings-tab.is-active {
    color: var(--color-text);
    border-color: var(--color-primary);
}

.form-hint {
    font-size: 0.75rem;
    opacity: 0.5;
    font-weight: 100;
}