Files
poli0981-dev/src/styles/global.css
T
poli0981andClaude Opus 5.5 484907439a feat(content): content labels, an age check, blurred images and a warning banner (#138)
* feat(content): content labels, an age check, blurred images and a warning banner

Posts, chapters and albums can carry content labels and an age rating:
- Labels (src/lib/content-labels.ts, names in src/i18n `labels`): horror, blood,
  jumpscare, violence, self-harm, death — banner and blurred images; politics,
  religion, strong-language, flashing-lights, spoilers — banner only. `contentWarning`
  moves from stories to every long-form entry and albums, and single gallery photos can
  carry their own (R2 list or captions.json). Unknown labels fail the build.
- Banner (ContentNotice.astro, replaces ContentWarning.astro): names every label in the
  page's language, skipped by search. Images in a labelled region are blurred in plain
  CSS by default — nothing sharp flashes before a script — and a real "Hiện ảnh"
  checkbox un-blurs them through :has(), so it works with the keyboard and with
  JavaScript off. A region without pictures shows no such line.
- Age check (AgeGate.astro, src/lib/age-gate.ts) for `ageRating` 13+/16+/18+: the text
  sits in a closed <details> (search indexes the title, not the text); its summary asks
  in a native modal <dialog> — focus starts on "No", Esc cancels and never means yes,
  "No" explains and offers to choose again — and the answer is kept in localStorage
  only (age thresholds, never an age or birth date). It never pops up on its own, and
  without JavaScript the summary simply opens the text.
- Everywhere else: story/post/album cards name the labels (blurred covers), the lightbox
  shows labelled photos blurred behind "Hiện ảnh", RSS descriptions start with the
  warning in the item's language, OG cards carry it for blog posts too, JSON-LD
  contentRating. The post page now uses the cover's alt text when there is one.
- Admin: a `multiselect` field for labels (with Vietnamese names), an age-rating select,
  and per-photo labels in the gallery manager.
- Content (poli0981/content 98f7692): privacy policy §6 lists the age-check answer;
  "Đêm không tiếng" chapters 1–2 are rated 16+.
- Tests: label and age-check logic, admin validation, labels kept on album save, RSS
  prefix; the accessibility suite scans the gate folded and asked, checks focus, Esc,
  No/Yes/reset and the keyboard reveal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(a11y): appendChild for the blur probe (astro check's DOM typing)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(content): findings from an independent review of the labels branch

- Album pages: the lightbox now sits outside the labelled section, whose blur rule also
  blurred the viewer's photo — its "show" button removed the veil but not the blur.
- Age check: the browser opens a <details> by itself (find-in-page, a #:~:text= link
  from a search engine, an #id inside the text); without a "yes" on record the gate now
  folds it straight back. After "Chọn lại" → "Có", focus moves to the summary instead of
  being lost with the row that just hid.
- Search indexes nothing inside the gate, not even its status lines, which could have
  become the excerpt of a page the reader has not been let into.
- Albums take their labels and age rating from BOTH language entries (same photos, two
  pages; the stricter rating wins), on the album page and on its card.
- An age-rated post folds its cover away with the text (PostCover.astro), and post and
  album cards blur the cover of age-rated items too. The album card names the cover
  photo's own labels, not only the album's.
- Tests: the gate re-folds an unasked open and keeps focus after choosing again;
  albumWarning merges both languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 08:30:09 +07:00

447 lines
15 KiB
CSS

@import "tailwindcss";
/* The theme is resolved into a [data-theme] attribute (the OS setting is only the
default, a saved choice wins), so the dark/light variants key off that attribute. */
@custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *));
@custom-variant light (&:where([data-theme="light"], [data-theme="light"] *));
/* ------------------------------------------------------------------ *
* Runtime palettes ("Glacier Teal") — the single source that flips on [data-theme].
* Components reference the semantic tokens below (var(--bg), var(--accent)…)
* or the Tailwind utilities generated from the @theme block further down.
* src/lib/palette.ts mirrors the values for code outside CSS; tests/palette.test.ts
* keeps the two in step and checks the WCAG AA pairs.
*
* The pre-paint bootstrap (astro.config.mjs) resolves [data-theme] from the saved
* choice or, by default, the OS setting, and keeps following the OS while the choice
* is "system". Without JS the page stays dark. Any element can pin a palette for its
* subtree: the story reader's "paper"/"dark" backgrounds and the always-dark lightbox.
* ------------------------------------------------------------------ */
:root,
[data-theme="dark"],
[data-reader-theme="dark"] {
color-scheme: dark;
/* Dark — glacier night, the no-JS default */
--bg: #0b1220;
--surface: #0f192a;
--elevated: #16233a;
--line: #223047;
--line-strong: #5b6f8f;
--text: #e6edf5;
--muted: #94a3b8;
--accent: #2dd4bf;
--accent-strong: #5eead4;
--accent-contrast: #042f2e;
--horror: #fb7185;
--ok: #34d399;
--warn: #fbbf24;
--err: #f87171;
--overlay: rgb(2 6 23 / 0.66);
--shadow-color: rgb(0 0 0 / 0.45);
/* Scrollbar thumb ≥ 3:1 against --bg (WCAG 1.4.11); accent on hover. */
--scrollbar-thumb: color-mix(in oklab, var(--muted) 65%, var(--bg));
--scrollbar-thumb-hover: color-mix(in oklab, var(--accent) 85%, var(--bg));
--scrollbar-track: transparent;
}
[data-theme="light"],
[data-reader-theme="paper"] {
color-scheme: light;
/* Light — glacier day. Accent and status colours are deeper to hold AA on white. */
--bg: #f4f8fb;
--surface: #ffffff;
--elevated: #ffffff;
--line: #d6e0ea;
--line-strong: #7c8ca3;
--text: #0f1b2d;
--muted: #4a5a70;
--accent: #0f766e;
--accent-strong: #115e59;
--accent-contrast: #ffffff;
--horror: #be123c;
--ok: #047857;
--warn: #b45309;
--err: #b91c1c;
--overlay: rgb(15 27 45 / 0.42);
--shadow-color: rgb(15 27 45 / 0.14);
--scrollbar-thumb: color-mix(in oklab, var(--muted) 75%, var(--bg));
--scrollbar-thumb-hover: var(--accent);
--scrollbar-track: transparent;
}
/* ------------------------------------------------------------------ *
* Theme tokens → Tailwind utilities.
* `inline` so utilities inline `var(--bg)` etc. and flip with [data-theme].
* ------------------------------------------------------------------ */
@theme inline {
--color-bg: var(--bg);
--color-surface: var(--surface);
--color-elevated: var(--elevated);
--color-line: var(--line);
--color-line-strong: var(--line-strong);
--color-text: var(--text);
--color-muted: var(--muted);
--color-accent: var(--accent);
--color-accent-strong: var(--accent-strong);
--color-accent-contrast: var(--accent-contrast);
--color-horror: var(--horror);
--color-ok: var(--ok);
--color-warn: var(--warn);
--color-err: var(--err);
/* Font families come from the Astro Fonts API (--ff-*), self-hosted. */
--font-sans: var(--ff-body);
--font-display: var(--ff-display);
--font-reading: var(--ff-reading);
--font-mono: var(--ff-mono);
}
/* Static design tokens (emitted as :root vars AND Tailwind utilities). */
@theme {
/* Fluid type scale, 360px → 1280px (docs 03 §3). */
--text-meta: clamp(0.875rem, 0.85rem + 0.11vw, 0.9375rem);
--text-body: clamp(1rem, 0.95rem + 0.22vw, 1.125rem);
--text-lead: clamp(1.25rem, 1.15rem + 0.43vw, 1.5rem);
--text-h3: clamp(1.563rem, 1.39rem + 0.76vw, 2rem);
--text-h2: clamp(1.953rem, 1.64rem + 1.39vw, 2.75rem);
--text-h1: clamp(2.441rem, 1.93rem + 2.28vw, 3.75rem);
--text-hero: clamp(3.05rem, 2.29rem + 3.39vw, 5rem);
/* Section rhythm + a spacing token usable as p-section / py-section / gap-section. */
--spacing-section: clamp(3rem, 8vw, 6rem);
--radius-control: 6px;
--radius-card: 10px;
--radius-modal: 16px;
--shadow-elevated: 0 8px 30px var(--shadow-color);
/* Motion (docs 03 §6). Primary ease ~ cubic-bezier(0.22, 1, 0.36, 1). */
--ease-site: cubic-bezier(0.22, 1, 0.36, 1);
--duration-fast: 150ms;
--duration-base: 250ms;
--duration-slow: 400ms;
}
/* ------------------------------------------------------------------ *
* Base element styles
* ------------------------------------------------------------------ */
html {
/* Height of the sticky site header: the story reader bar docks under it and in-page
anchors stop below it. */
--header-h: 3.75rem;
/* What covers the bottom edge of the viewport: the fixed mobile tab bar (set below) and,
while it is showing, the legal notice sheet (LegalGateSheet sets --sheet-h). */
--bottom-bar-h: 0px;
scroll-padding-block-start: calc(var(--header-h) + var(--subheader-h, 0px) + 1rem);
/* Focus and in-page anchors scroll clear of those bars instead of landing underneath
them (WCAG 2.4.11 Focus Not Obscured). */
scroll-padding-block-end: calc(max(var(--bottom-bar-h), var(--sheet-h, 0px)) + 1rem);
-webkit-text-size-adjust: 100%;
scrollbar-gutter: stable;
/* Native checkboxes, radios and range inputs take the palette accent. */
accent-color: var(--accent);
}
/* Scrollbars, tinted from the palette. `scrollbar-color` inherits, so every inner
scroller (menu sheet, search results, code blocks…) picks up the same colours;
`scrollbar-width` does not, hence the universal selector. Forced-colors mode ignores
both and uses system colours, which is what we want there. The width is gated on
scrollbar-color support because Safari honours `scrollbar-width` but not the colour,
and a non-auto width would switch off the ::-webkit-scrollbar styling below. */
:root {
scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
@supports (scrollbar-color: auto) {
* {
scrollbar-width: thin;
}
}
/* "Hide scrollbar" preference (footer switch → localStorage, applied pre-paint by the
bootstrap in astro.config.mjs). Only the page's own bar is hidden — the page still
scrolls by wheel, touch and keyboard, and inner scrollers keep their thin bar so a
wide code block still shows it can scroll sideways. */
:root[data-scrollbar="hidden"] {
scrollbar-width: none;
}
:root[data-scrollbar="hidden"]::-webkit-scrollbar {
display: none;
}
/* WebKit without the standard properties (Safari < 18.2 for width; no scrollbar-color). */
@supports not (scrollbar-color: auto) {
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-track {
background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
border: 2px solid transparent;
border-radius: 999px;
background: var(--scrollbar-thumb) padding-box;
}
::-webkit-scrollbar-thumb:hover {
background: var(--scrollbar-thumb-hover) padding-box;
}
}
body {
margin: 0;
min-block-size: 100dvh;
background-color: var(--bg);
color: var(--text);
font-family: var(--ff-body);
font-size: var(--text-body);
line-height: 1.7;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
/* Leave room for the fixed mobile tab bar so the footer isn't hidden behind it. */
@media (max-width: 767px) {
html {
/* MobileTabBar: 3.5rem of tabs, its 1px top border, and the home-indicator inset. */
--bottom-bar-h: calc(3.5rem + 1px + env(safe-area-inset-bottom, 0px));
}
}
/* …and, at every width, room for the legal notice while it is up. Scroll padding cannot
help at the very end of the document: without this the last links of the footer could
not scroll out from under the sheet (full-width on a phone, a card over the footer's
right half on a tablet). */
body {
padding-block-end: max(var(--bottom-bar-h), var(--sheet-h, 0px));
}
h1,
h2,
h3,
h4 {
font-family: var(--ff-display);
line-height: 1.15;
font-weight: 700;
text-wrap: balance;
}
code,
kbd,
samp,
pre {
font-family: var(--ff-mono);
}
a {
color: inherit;
text-decoration: none;
}
::selection {
background: var(--accent);
color: var(--accent-contrast);
}
/* Tailwind's preflight zeroes every margin, which also undoes the browser's centring of
modal dialogs (margin: auto): the report dialog sat in the top-left corner. */
dialog {
margin: auto;
}
/* Visible, consistent focus ring for keyboard users (docs 03 §8). */
:where(a, button, input, textarea, select, summary, [tabindex]):focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
border-radius: 2px;
}
/* Page width container. */
.page {
max-inline-size: 72rem;
margin-inline: auto;
padding-inline: clamp(1rem, 4vw, 2rem);
}
/* ------------------------------------------------------------------ *
* Grain overlay — one element, whole page, ~3%, never intercepts input.
* Inline SVG feTurbulence keeps it asset-free and CSP-safe (data: is in img-src).
* ------------------------------------------------------------------ */
body::after {
content: "";
position: fixed;
inset: 0;
z-index: 9999;
pointer-events: none;
/* No mix-blend-mode: a full-viewport blended layer is a per-paint cost that
hurts the perf budget. A plain low-opacity overlay composites once. */
opacity: 0.045;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
background-size: 160px 160px;
}
/* ------------------------------------------------------------------ *
* Staged reveal — one moment on load, ≤6 elements (docs 03 §6). CSS-only;
* the reduced-motion reset above collapses it to an instant appearance.
* ------------------------------------------------------------------ */
@keyframes reveal-in {
from {
opacity: 0;
transform: translateY(12px);
}
to {
opacity: 1;
transform: none;
}
}
.reveal > * {
animation: reveal-in 0.5s var(--ease-site) both;
}
.reveal > *:nth-child(1) {
animation-delay: 0.04s;
}
.reveal > *:nth-child(2) {
animation-delay: 0.1s;
}
.reveal > *:nth-child(3) {
animation-delay: 0.16s;
}
.reveal > *:nth-child(4) {
animation-delay: 0.22s;
}
.reveal > *:nth-child(5) {
animation-delay: 0.28s;
}
.reveal > *:nth-child(6) {
animation-delay: 0.34s;
}
/* ------------------------------------------------------------------ *
* Content labels (src/lib/content-labels.ts, ContentNotice.astro). In a region marked
* [data-cw-blur], every image is blurred until the reader ticks that region's "Hiện ảnh"
* checkbox. Blurred is the default state and plain CSS: nothing sharp flashes before a
* script runs, and it works with JavaScript off. A browser without :has() keeps the blur
* (safe side). clip-path keeps the blur inside the image's own box.
* ------------------------------------------------------------------ */
[data-cw-blur] :is(img, video) {
filter: blur(1.5rem) saturate(0.6);
clip-path: inset(0);
}
[data-cw-blur]:has(.cw-reveal-input:checked) :is(img, video) {
filter: none;
clip-path: none;
}
/* Nothing to blur (a chapter without pictures): no "images are blurred / show" line. */
[data-cw-blur]:not(:has(img, video)) .cw-blur-row {
display: none;
}
/* One photo in an unlabelled album (its own contentWarning): blurred the same way. */
.cw-photo :is(img, video) {
filter: blur(1.5rem) saturate(0.6);
clip-path: inset(0);
}
[data-cw-scope]:has(.cw-reveal-input:checked) .cw-photo :is(img, video) {
filter: none;
clip-path: none;
}
/* ------------------------------------------------------------------ *
* Reduced motion — every animation/transition has a still branch.
* ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.001ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.001ms !important;
scroll-behavior: auto !important;
}
}
/* ------------------------------------------------------------------ *
* More contrast (the OS "increase contrast" setting): hairlines take the 3:1 line
* colour and the film grain goes away, since it only lowers contrast.
* ------------------------------------------------------------------ */
@media (prefers-contrast: more) {
:root,
[data-theme],
[data-reader-theme] {
--line: var(--line-strong);
}
body::after {
display: none;
}
}
/* Konami easter egg (src/lib/easter.ts): flips the accent to the horror tone for a
beat. Self-reverting after 4s; no layout shift, so reduced-motion needs nothing. */
:root[data-konami="on"] {
--accent: var(--horror);
--accent-strong: var(--horror);
}
/* ------------------------------------------------------------------ *
* Turnstile gate. src/lib/gate/render.ts swaps a page's whole <body> for this markup
* (public/gate.js drives it), so it has to live in the global stylesheet every page
* already links — the gate can't add a <style> without breaking the page's CSP hashes.
* ------------------------------------------------------------------ */
.human-check {
display: grid;
place-items: center;
min-block-size: 100dvh;
padding: 1.5rem;
}
.human-check-card {
inline-size: min(100%, 27rem);
padding: 2rem 1.75rem 1.5rem;
border: 1px solid var(--line);
border-radius: var(--radius-modal);
background: var(--surface);
box-shadow: var(--shadow-elevated);
text-align: center;
}
.human-check-title {
margin: 0 0 0.5rem;
font-family: var(--ff-display);
font-size: var(--text-h3);
line-height: 1.2;
}
.human-check-lead {
margin: 0;
color: var(--muted);
}
.human-check-widget {
display: flex;
justify-content: center;
min-block-size: 65px; /* Turnstile's managed widget height — no jump when it mounts */
margin-block: 1.25rem 0.5rem;
}
.human-check-status {
min-block-size: 1.6em;
margin: 0;
color: var(--muted);
font-size: var(--text-meta);
}
.human-check-retry {
margin-block-start: 0.5rem;
padding: 0.5rem 1rem;
border: 1px solid var(--line);
border-radius: var(--radius-control);
background: var(--elevated);
color: var(--text);
font: inherit;
cursor: pointer;
}
.human-check-retry:hover {
border-color: var(--accent);
color: var(--accent);
}
.human-check-noscript {
color: var(--warn);
}
.human-check-note {
margin: 1rem 0 0;
font-size: var(--text-meta);
}
.human-check-note a {
color: var(--muted);
}