From 4e9e05bc4e9551db8838aed1d80637630b238bce Mon Sep 17 00:00:00 2001 From: Cesar Alcazar Date: Mon, 19 Oct 2026 21:47:25 -0600 Subject: [PATCH] 3p1idvga1: Add dark and light design tokens with a persisted pre-paint theme --- src/app/globals.css | 181 +++++++++++++--------------------------- src/app/layout.tsx | 8 +- src/components/Logo.tsx | 4 +- src/lib/theme.ts | 51 +++++++++++ src/lib/use-theme.ts | 44 ++++++++++ src/styles/legacy.css | 130 +++++++++++++++++++++++++++++ tests/theme.test.ts | 103 +++++++++++++++++++++++ 7 files changed, 394 insertions(+), 127 deletions(-) create mode 100644 src/lib/theme.ts create mode 100644 src/lib/use-theme.ts create mode 100644 src/styles/legacy.css create mode 100644 tests/theme.test.ts diff --git a/src/app/globals.css b/src/app/globals.css index 9a573ca..52dd1b6 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -1,128 +1,61 @@ -:root { --red: #E8202A; --ink: #111; --grey: #6b6b6b; --line: #d9d9d9; --bg: #f5f5f5; } -* { box-sizing: border-box; } -body { margin: 0; font-family: Roboto, system-ui, sans-serif; color: var(--ink); background: var(--bg); } -.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; } -.card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 32px 24px; display: flex; flex-direction: column; gap: 8px; } -.card h1 { font-size: 22px; margin: 12px 0 8px; } -label { font-size: 14px; font-weight: 500; margin-top: 8px; } -input { font: inherit; padding: 12px; border: 1px solid #999; border-radius: 8px; background: #fff; color: var(--ink); } -input:focus-visible, button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; } -button { font: inherit; font-weight: 500; margin-top: 16px; padding: 12px; border: 0; border-radius: 8px; background: var(--red); color: #fff; cursor: pointer; } -button:disabled { opacity: .5; cursor: not-allowed; } -.error { margin: 0 0 4px; padding: 10px 12px; border: 1px solid var(--red); border-radius: 8px; color: #a8141b; background: #fff3f3; font-size: 14px; } -.shell header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line); } -.shell header div { display: flex; flex-direction: column; font-size: 14px; } -.shell header span { color: var(--grey); } -.shell header { position: sticky; top: 0; z-index: 5; } -.shell header button { margin: 0 0 0 auto; padding: 8px 14px; background: #fff; color: var(--ink); border: 1px solid var(--ink); } -.feed { max-width: 640px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; } -.post { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 12px; } -.post-head { display: flex; align-items: center; gap: 12px; } -.avatar { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--line); flex: none; } -.avatar-initials { display: grid; place-items: center; background: var(--ink); color: #fff; font-weight: 500; font-size: 14px; } -.post-who { display: flex; flex-direction: column; font-size: 14px; min-width: 0; } -.post-who time { color: var(--grey); font-size: 13px; } -.post-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; } -.post-media img { display: block; width: 100%; height: auto; border-radius: 8px; } -.post-video { background: #000; border-radius: 8px; overflow: hidden; } -.post-video-pending { color: #fff; padding: 48px 12px; text-align: center; } -.post-video video { display: block; width: 100%; max-height: 520px; background: #000; } -.post-stats { display: flex; gap: 16px; color: var(--grey); font-size: 14px; } -.heart { color: var(--red); } -.feed-message { text-align: center; color: var(--grey); padding: 32px 16px; } -.feed-message button { margin-top: 8px; } -.feed-center { display: grid; place-items: center; padding: 16px; } -.spinner { width: 24px; height: 24px; border: 3px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; } -@keyframes spin { to { transform: rotate(360deg); } } -.new-posts { position: sticky; top: 68px; z-index: 4; align-self: center; margin: 0; padding: 8px 16px; border-radius: 999px; } -.sentinel { height: 1px; } -.like-btn { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px 8px; background: transparent; color: var(--grey); border-radius: 8px; font-size: 14px; font-weight: 400; } -.like-btn:hover:not(:disabled) { color: var(--red); background: #fff3f3; } -.like-btn.liked { color: var(--red); } -.like-btn:disabled { opacity: 1; cursor: default; } -.like-btn:disabled:not(.liked) { color: var(--grey); } -.like-error { color: #a8141b; font-size: 13px; align-self: center; } -.post-stats { align-items: center; } -.composer { background: #fff; border: 1px solid var(--line); border-radius: 0; padding: 16px; display: flex; flex-direction: column; gap: 8px; } -.composer-label { margin: 0; } -.composer textarea { font: inherit; width: 100%; padding: 12px; border: 1px solid #999; border-radius: 0; resize: vertical; background: #fff; color: var(--ink); } -.composer textarea:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; } -.composer .composer-post { align-self: flex-end; margin: 0; padding: 10px 24px; border-radius: 0; } -.composer-media { display: flex; flex-direction: column; gap: 8px; } -.composer-image { display: inline-flex; align-items: center; gap: 8px; align-self: flex-start; cursor: pointer; } -.composer-image span { padding: 6px 12px; border: 1px solid #999; background: #fafafa; } -.composer-image input[type="file"] { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; } -.composer-preview { display: flex; align-items: center; gap: 10px; } -.composer-preview video { width: 96px; height: 64px; object-fit: cover; border: 1px solid var(--line); background: #000; } -.composer-preview img { width: 64px; height: 64px; object-fit: cover; border: 1px solid var(--line); } -.composer-filename { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -.composer-remove { margin: 0; padding: 6px 12px; border-radius: 0; } +/* Global styles only (ADR 0001, section 6): layer order, tokens, reset, focus ring. */ +@layer reset, base; -.comments { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; border-top: 1px solid #eee; } -.comment-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; } -.comment p { margin: 2px 0 0; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; } -.comment-head { display: flex; gap: 8px; align-items: baseline; font-size: 13px; } -.comment-head time { color: var(--grey); font-size: 12px; } -.comment.removed .comment-removed { color: var(--grey); font-style: italic; } -.comments-empty { margin: 0; color: var(--grey); font-size: 14px; } -.comment-error { margin: 0; color: #a8141b; font-size: 13px; } -.comment-form { display: flex; gap: 8px; } -.comment-form input { flex: 1; margin: 0; } -.comment-form button { margin: 0; } -.link-btn { background: transparent; color: inherit; text-decoration: underline; padding: 0; margin: 0; font-size: inherit; width: auto; } -.comments-toggle { background: transparent; color: var(--grey); padding: 4px 8px; margin: 0; font-size: 14px; font-weight: 400; width: auto; } - -.post-menu { position: relative; margin-left: auto; } -.menu-btn { margin: 0; padding: 2px 10px; background: transparent; color: var(--grey); border-radius: 8px; font-size: 18px; line-height: 1; letter-spacing: 1px; } -.menu { position: absolute; right: 0; top: 100%; z-index: 5; display: flex; flex-direction: column; gap: 2px; min-width: 150px; padding: 6px; background: #fff; border: 1px solid #e3e3e3; border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,.12); } -.menu button { margin: 0; text-align: left; background: transparent; color: inherit; padding: 6px 8px; border-radius: 6px; font-size: 14px; font-weight: 400; } -.menu button:hover { background: #f4f4f4; } -.menu .menu-danger { color: #a8141b; } -.menu-ask { font-size: 13px; color: var(--grey); padding: 4px 8px; } - -/* 3-column signed-in layout: nav | feed | rails. Wraps on narrow widths. */ -.columns { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; max-width: 1240px; margin: 0 auto; padding: 0 16px; } -.col-left { flex: 0 0 180px; position: sticky; top: 72px; padding-top: 16px; } -.col-left > ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; } -.col-left a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; } -.col-left a[aria-current="page"] { background: var(--ink); color: #fff; } -.col-center { flex: 1 1 400px; min-width: 0; } -.col-center .feed { padding-left: 0; padding-right: 0; } -.col-right { flex: 0 0 300px; position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow-y: auto; padding-top: 16px; display: flex; flex-direction: column; gap: 20px; } -.rail h2 { margin: 0 0 8px; font-size: 16px; font-weight: 700; } -.rail-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; } -.rail-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; gap: 10px; } -.expert-card { align-items: center; } -.minnect-card { flex-direction: column; } -.rail-text { display: flex; flex-direction: column; min-width: 0; font-size: 14px; } -.rail-name { font-size: 14px; } -.rail-byline { color: var(--grey); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -.rail-meta { color: var(--grey); font-size: 13px; } -.minnect-who { display: flex; align-items: center; gap: 8px; } -.avatar-sm { width: 28px; height: 28px; font-size: 11px; } -.minnect-thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; background: var(--line); } -.minnect-question { margin: 0; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; } -.minnect-video { background: #000; border-radius: 0; } -.minnect-audio { width: 100%; height: 36px; } -@media (max-width: 959px) { - .col-left { flex: 1 1 100%; position: static; padding-top: 8px; } - .col-left > ul { flex-direction: row; } - .col-center { flex: 1 1 100%; order: 3; } - .col-right { flex: 1 1 100%; order: 2; position: static; max-height: none; overflow: visible; padding-top: 0; } - .col-right .rail-list { flex-direction: row; overflow-x: auto; padding-bottom: 8px; } - .col-right .rail-card { flex: 0 0 260px; } +/* Tokens. Dark is the default, so it applies even without data-theme. */ +:root, +:root[data-theme="dark"] { + --bg: #09090B; + --tile: #121215; + --tile-2: #19191D; + --tile-3: #232328; + --line: rgba(255,255,255,.07); + --line-2: rgba(255,255,255,.15); + --ink: #F4F2EE; + --ink-2: #BFBDB8; + --ink-3: #95938E; + --accent: #C8141C; + --danger: #FF6B70; + --glass: rgba(18,18,21,.72); + --shadow-pop: 0 10px 28px rgba(0,0,0,.5); + color-scheme: dark; } -/* Expert search + category chips (left column). Squared corners, monochrome + red. */ -.expert-search { margin-top: 16px; } -.expert-search summary { font-weight: 700; font-size: 16px; cursor: pointer; padding: 4px 0; } -.expert-search form { display: flex; flex-direction: column; } -.expert-search input { border-radius: 0; width: 100%; } -.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; } -.chip { margin: 0; padding: 6px 10px; border-radius: 0; background: #fff; color: var(--ink); border: 1px solid var(--ink); font-size: 13px; } -.chip[aria-pressed="true"] { background: var(--red); border-color: var(--red); color: #fff; } -.search-results { margin-top: 12px; } -.search-note { margin: 0; font-size: 14px; color: var(--grey); } -@media (max-width: 959px) { - .col-left .expert-search { flex-basis: 100%; } +:root[data-theme="light"] { + --bg: #EFEDE9; + --tile: #FBFAF8; + --tile-2: #F3F1EE; + --tile-3: #E8E5E0; + --line: rgba(26,28,31,.08); + --line-2: rgba(26,28,31,.16); + --ink: #1A1C1F; + --ink-2: #46484D; + --ink-3: #686A70; + --accent: #C8141C; + --danger: #B3121A; + --glass: rgba(251,250,248,.74); + --shadow-pop: 0 10px 28px rgba(26,28,31,.14); + color-scheme: light; +} + +:root { + /* Crimson shades, derived from --accent (spec "Design tokens"). */ + --accent-hi: color-mix(in srgb, var(--accent), white 26%); + --accent-lo: color-mix(in srgb, var(--accent), black 30%); + --accent-soft: color-mix(in srgb, var(--accent), transparent 88%); + + /* Shape and motion. */ + --r-panel: 18px; + --r-card: 16px; + --r-ctl: 12px; + --ease: cubic-bezier(.2,.8,.2,1); +} + +@layer reset { + *, *::before, *::after { box-sizing: border-box; } + body { margin: 0; } +} + +@layer base { + body { color: var(--ink); background: var(--bg); } + :focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; } } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 0e5fac5..db848f2 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,7 +1,9 @@ import type { Metadata } from "next"; import type { ReactNode } from "react"; import { Roboto } from "next/font/google"; +import { DEFAULT_THEME, THEME_SCRIPT } from "@/lib/theme"; import "./globals.css"; +import "../styles/legacy.css"; const roboto = Roboto({ subsets: ["latin"], weight: ["400", "500", "700"] }); @@ -12,7 +14,11 @@ export const metadata: Metadata = { export default function RootLayout({ children }: { children: ReactNode }) { return ( - + + + {/* Applies the stored theme before first paint (ADR 0001, section 5). */} +