/* ===========================================================================
   Zhopwe base: reset, document, typography, focus, script handling
   =========================================================================== */

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

* { margin: 0; }

html {
    /* Not a global font-size change: scaling the root breaks user zoom
       expectations. Only smooth scrolling and tap behaviour are set here. */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    /* Anchored headings are not hidden behind the sticky header. */
    scroll-padding-top: calc(var(--header-height) + var(--space-4));
    height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-md);
    line-height: var(--leading-normal);
    font-weight: var(--weight-regular);
    color: var(--text-primary);
    background-color: var(--surface-page);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Opt into Inter's tabular figures for anything numeric by default would be
       wrong for prose, so it is applied per component instead. Contextual
       alternates give Inter its proper letter shapes. */
    font-feature-settings: "cv11", "ss01";
    text-rendering: optimizeLegibility;
}

/* ── Script-specific families ───────────────────────────────────────────────
   Sinhala and Tamil are set in fonts designed for them. Without this they fall
   back to whatever the OS picks, which on Windows is often a face with broken
   conjunct rendering — words appear with letters in the wrong order. The
   slightly larger line-height is not decorative: both scripts have tall
   ascenders and descenders that collide at Latin leading.                    */

:lang(si), [lang="si"] {
    font-family: var(--font-sinhala);
    line-height: var(--leading-relaxed);
}

:lang(ta), [lang="ta"] {
    font-family: var(--font-tamil);
    line-height: var(--leading-relaxed);
}

/* Display serif is Latin-only; Sinhala and Tamil headings use their own sans,
   which is correct typographically — there is no matching serif at this weight
   for either script, and substituting one produces a mismatched page. */
:lang(si) .display, [lang="si"] .display,
:lang(ta) .display, [lang="ta"] .display {
    font-family: inherit;
    letter-spacing: var(--tracking-normal);
}

/* ── Headings ─────────────────────────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
    font-weight: var(--weight-semibold);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-heading);
    color: var(--text-primary);
    /* Prevents a single word being left alone on the last line of a heading. */
    text-wrap: balance;
}

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 { font-size: var(--text-md); }
h6 { font-size: var(--text-sm); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-muted); }

.display {
    font-family: var(--font-display);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-display);
    line-height: var(--leading-tight);
    /* Fraunces is variable: lower optical sizing at display sizes gives it
       finer serifs, which is what makes it read as a display face rather than
       an oversized body serif. */
    font-variation-settings: "SOFT" 0, "WONK" 0, "opsz" 48;
}

p { text-wrap: pretty; }

/* ── Links ────────────────────────────────────────────────────────────────── */

a {
    color: var(--text-link);
    text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
    text-underline-offset: 0.18em;
    text-decoration-thickness: 1px;
    transition: color var(--duration-fast) var(--ease-out),
                text-decoration-color var(--duration-fast) var(--ease-out);
}

a:hover {
    color: var(--text-link-hover);
    text-decoration-color: currentColor;
}

/* ── Focus ────────────────────────────────────────────────────────────────────
   :focus-visible only, so a mouse click does not leave a ring, but every
   keyboard user always gets one. The outline is 2px with an offset so it is
   visible against both the element and the page behind it.                   */

:focus { outline: none; }

:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}

/* An element that is scrolled to programmatically should still show focus. */
:target { scroll-margin-top: calc(var(--header-height) + var(--space-6)); }

/* ── Media ────────────────────────────────────────────────────────────────── */

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Images whose dimensions are known render at the right aspect ratio before
   they load, which is most of what keeps CLS at zero. */
img[width][height] { height: auto; }

svg { flex-shrink: 0; }

/* ── Forms ────────────────────────────────────────────────────────────────── */

input, button, textarea, select {
    font: inherit;
    color: inherit;
}

textarea { resize: vertical; min-height: 6rem; }

button { cursor: pointer; background: none; border: none; padding: 0; }

button:disabled, input:disabled, select:disabled, textarea:disabled,
[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.55;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */

table { border-collapse: collapse; width: 100%; }

/* ── Lists ────────────────────────────────────────────────────────────────── */

ul, ol { padding-inline-start: var(--space-5); }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }

/* ── Code ─────────────────────────────────────────────────────────────────── */

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

code:not(pre code) {
    background: var(--surface-sunken);
    padding: 0.1em 0.35em;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border-subtle);
}

pre {
    background: var(--surface-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    overflow-x: auto;
}

hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin-block: var(--space-6);
}

/* ── Utilities ────────────────────────────────────────────────────────────── */

/* Visible to screen readers, invisible on screen. Not display:none, which
   removes it from the accessibility tree too. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* The skip link: off-screen until focused, then anchored top-left. Every page
   has one as its first focusable element. */
.skip-link {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: var(--z-toast);
    padding: var(--space-3) var(--space-4);
    background: var(--surface-card);
    color: var(--text-primary);
    border: 2px solid var(--focus-ring);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-weight: var(--weight-medium);
    transform: translateY(-160%);
    transition: transform var(--duration-fast) var(--ease-out);
}

.skip-link:focus { transform: translateY(0); }

.container {
    width: 100%;
    max-width: var(--container-xl);
    margin-inline: auto;
    padding-inline: var(--gutter);
}

.container-lg { max-width: var(--container-lg); }
.container-md { max-width: var(--container-md); }
.container-sm { max-width: var(--container-sm); }

/* Numeric columns line up only with tabular figures; without this a column of
   prices visibly jitters. */
.tabular { font-variant-numeric: tabular-nums; }

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

.clamp-2, .clamp-3 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.clamp-2 { -webkit-line-clamp: 2; }
.clamp-3 { -webkit-line-clamp: 3; }

/* ── Reduced motion ─────────────────────────────────────────────────────────
   Animation is removed rather than shortened. A vestibular trigger is not made
   safe by being quick. Transitions are collapsed to a near-zero duration
   rather than `none` so that transitionend handlers still fire and JS that
   waits for them does not hang.                                             */

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }

    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Forced colours (Windows high contrast) ───────────────────────────────── */

@media (forced-colors: active) {
    /* Borders drawn with background colour vanish in forced-colours mode, so
       anything that relies on one gets a real border. */
    .btn, .card, .input, .badge, .table { border: 1px solid ButtonBorder; }
    :focus-visible { outline: 3px solid Highlight; }
}

/* ── Print ────────────────────────────────────────────────────────────────── */

@media print {
    body { background: #fff; color: #000; font-size: 11pt; }
    .no-print, nav, .skip-link, .btn { display: none !important; }
    a::after { content: " (" attr(href) ")"; font-size: 9pt; color: #555; }
    .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
    table { break-inside: auto; }
    tr, img { break-inside: avoid; }
}
