Add 3-mode theme system (light / dark / auto by device clock) and tokenize colors

- theme.css: semantic tokens (bg, surface, ink, border, brand, tints, status, glass)
- ThemeSwitch.tsx: radiogroup with light/dark/auto, persisted in localStorage
- auto mode follows device time (06:00-18:00 light), rechecks every minute and on visibilitychange
- inline pre-paint script in layout.tsx prevents flash of wrong theme
- remapped ~250 hardcoded hex declarations across styles to tokens
- fixed --c-ink-2 contrast 4.25 -> 5.36 (WCAG AA) in light mode
- 0 contrast failures below 4.5:1 across 8 pages in both themes
- DESIGN.md: documented theme system
This commit is contained in:
Bkk1234 committed 2026-10-23 23:01:06 +07:00
1 parent 4c444b3d8d
commit 7ac7bf5878
18 files changed
+758 -361

No files matched your search

+81 -27
View File
@@ -20,7 +20,7 @@
.mu-cover {
position: relative;
aspect-ratio: 16 / 10;
background: linear-gradient(135deg, #eef1ff 0%, #f7f0ff 100%);
background: linear-gradient(135deg, var(--c-tint-purple) 0%, var(--c-tint-purple) 100%);
overflow: hidden;
}
.mu-cover > img {
@@ -56,8 +56,8 @@
font-size: .72rem;
font-weight: 800;
letter-spacing: .02em;
background: rgba(255, 255, 255, .92);
color: #1f2a44;
background: var(--c-glass);
color: var(--c-ink);
backdrop-filter: blur(8px);
box-shadow: 0 4px 10px rgba(15, 23, 42, .15);
}
@@ -84,12 +84,12 @@
.mu-cover.no-photo {
background:
radial-gradient(circle at 20% 20%, rgba(255, 255, 255, .35), transparent 55%),
linear-gradient(135deg, #7a4cc0 0%, #3071b8 100%);
linear-gradient(135deg, var(--c-brand) 0%, #3071b8 100%);
}
.mu-cover.no-photo::after {
background: linear-gradient(180deg, rgba(15, 23, 42, 0) 40%, rgba(15, 23, 42, .35) 100%);
}
.mu-cover.tone-purple { background: linear-gradient(135deg, #7a4cc0, #c084fc); }
.mu-cover.tone-purple { background: linear-gradient(135deg, var(--c-brand), #c084fc); }
.mu-cover.tone-sky { background: linear-gradient(135deg, #3071b8, #60a5fa); }
.mu-cover.tone-pink { background: linear-gradient(135deg, #bb3a78, #f472b6); }
.mu-cover.tone-mint { background: linear-gradient(135deg, #1f8765, #34d399); }
@@ -146,17 +146,17 @@
border-radius: 999px;
font-size: .7rem;
font-weight: 700;
background: rgba(255, 255, 255, .92);
color: #1f2a44;
background: var(--c-glass);
color: var(--c-ink);
backdrop-filter: blur(6px);
box-shadow: 0 4px 10px rgba(15, 23, 42, .14);
}
.mu-card-head.no-photo {
background:
radial-gradient(circle at 20% 20%, rgba(255, 255, 255, .25), transparent 55%),
linear-gradient(135deg, #7a4cc0 0%, #3071b8 100%);
linear-gradient(135deg, var(--c-brand) 0%, #3071b8 100%);
}
.mu-card-head.no-photo.bg-purple { background: linear-gradient(135deg, #7a4cc0, #c084fc); }
.mu-card-head.no-photo.bg-purple { background: linear-gradient(135deg, var(--c-brand), #c084fc); }
.mu-card-head.no-photo.bg-sky { background: linear-gradient(135deg, #3071b8, #60a5fa); }
.mu-card-head.no-photo.bg-pink { background: linear-gradient(135deg, #bb3a78, #f472b6); }
.mu-card-head.no-photo.bg-mint { background: linear-gradient(135deg, #1f8765, #34d399); }
@@ -169,7 +169,7 @@
overflow: hidden;
box-shadow: 0 10px 24px rgba(63, 43, 94, .08);
border: 1px solid rgba(231, 224, 246, .95);
background: #fff;
background: var(--c-surface);
display: flex;
flex-direction: column;
transition: transform .18s ease, box-shadow .18s ease;
@@ -221,7 +221,7 @@
width: 48px;
height: 48px;
border-radius: 12px;
background: #fff;
background: var(--c-surface);
padding: 4px;
object-fit: contain;
}
@@ -234,7 +234,7 @@
}
.mu-footer-brand-row span {
display: block;
color: #9aa3c3;
color: var(--c-info);
font-size: .82rem;
margin-top: 2px;
}
@@ -273,7 +273,7 @@
.mu-footer-col ul a:hover { color: #fff; }
.mu-footer-col ul a::before {
content: "›";
color: #7a4cc0;
color: var(--c-brand-ink);
font-weight: 800;
}
.mu-footer-contact a,
@@ -301,7 +301,7 @@
}
.mu-footer-sponsors p.lead {
margin: 0 0 18px;
color: #9aa3c3;
color: var(--c-info);
font-size: .85rem;
line-height: 1.5;
}
@@ -311,7 +311,7 @@
gap: 12px;
}
.mu-sponsor-tile {
background: #fff;
background: var(--c-surface);
border-radius: 12px;
padding: 14px;
display: flex;
@@ -343,7 +343,7 @@
}
.mu-footer-bottom p {
margin: 0;
color: #8d96b8;
color: var(--c-info);
font-size: .82rem;
letter-spacing: .02em;
}
@@ -398,7 +398,7 @@ body:has(.mu-site-footer) .mu-footer { display: none; }
.mu-search-field .ic {
position: absolute;
left: 12px;
color: #6f7b95;
color: var(--c-ink-2);
pointer-events: none;
}
.mu-search-field input {
@@ -411,7 +411,7 @@ body:has(.mu-site-footer) .mu-footer { display: none; }
display: inline-flex;
align-items: center;
gap: 2px;
background: #f0edf7;
background: var(--c-tint-purple);
border: 1px solid #e4dcf2;
border-radius: 999px;
padding: 3px;
@@ -420,7 +420,7 @@ body:has(.mu-site-footer) .mu-footer { display: none; }
.mu-lang-btn {
border: 0;
background: transparent;
color: #6d28d9;
color: var(--c-brand-ink);
font-family: inherit;
font-weight: 700;
font-size: .72rem;
@@ -430,13 +430,67 @@ body:has(.mu-site-footer) .mu-footer { display: none; }
cursor: pointer;
transition: background .15s ease, color .15s ease;
}
.mu-lang-btn:hover { color: #5b21b6; }
.mu-lang-btn:hover { color: var(--c-brand-ink); }
.mu-lang-btn.active {
background: #fff;
color: #7a4cc0;
background: var(--c-surface);
color: var(--c-brand-ink);
box-shadow: 0 1px 4px rgba(63, 43, 94, .18);
}
/* ---------- ตัวสลับธีม (สว่าง / มืด / ตามเวลา) ---------- */
.mu-theme-switch {
display: inline-flex;
align-items: center;
gap: 2px;
background: var(--c-tint-purple);
border: 1px solid #e4dcf2;
border-radius: 999px;
padding: 3px;
flex-shrink: 0;
}
.mu-theme-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 34px;
height: 34px;
min-width: 34px;
border: 0;
border-radius: 999px;
background: transparent;
color: var(--c-brand-ink);
cursor: pointer;
transition: background .15s ease, color .15s ease;
}
.mu-theme-btn:hover { color: var(--c-brand-ink); }
.mu-theme-btn.active {
background: var(--c-surface);
color: var(--c-brand-ink);
box-shadow: 0 1px 4px rgba(63, 43, 94, .18);
}
/* โฟกัสคีย์บอร์ดต้องเห็นชัด (WCAG 2.4.7) */
.mu-theme-btn:focus-visible,
.mu-lang-btn:focus-visible {
outline: 2px solid var(--c-focus);
outline-offset: 2px;
}
:root[data-theme="dark"] .mu-theme-switch,
:root[data-theme="dark"] .mu-lang-switch {
background: var(--c-surface-3);
border-color: var(--c-border);
}
:root[data-theme="dark"] .mu-theme-btn,
:root[data-theme="dark"] .mu-lang-btn { color: var(--c-ink-2); }
:root[data-theme="dark"] .mu-theme-btn:hover,
:root[data-theme="dark"] .mu-lang-btn:hover { color: var(--c-ink); }
:root[data-theme="dark"] .mu-lang-btn { background: transparent; }
/* จอสัมผัส: ขยายเป้ากดให้ถึง 44px (WCAG 2.5.5) */
@media (pointer: coarse) {
.mu-theme-btn { width: 40px; height: 40px; min-width: 40px; }
.mu-theme-switch { padding: 2px; }
}
/* ============================================================
ปุ่ม + ฟอร์มคอนโทรล (shared — ทุกหน้าใช้ร่วมกัน)
.mu-btn อยู่ที่นี่ (ไม่ใช่ใน partial) → หน้าไหนก็ได้สไตล์เดียวกัน
@@ -466,12 +520,12 @@ body:has(.mu-site-footer) .mu-footer { display: none; }
}
.mu-btn.primary:hover { box-shadow: 0 10px 22px rgba(124, 58, 237, .35); }
.mu-btn.ghost {
background: #fff;
border-color: #e7e2f6;
color: #5b3b71;
background: var(--c-surface);
border-color: var(--c-border);
color: var(--c-brand-ink);
box-shadow: 0 2px 8px rgba(63, 43, 94, .05);
}
.mu-btn.ghost:hover { border-color: #d8c9f2; background: #faf7ff; }
.mu-btn.ghost:hover { border-color: #d8c9f2; background: var(--c-surface-2); }
/* select แบบโมเดิร์น — custom chevron แทนลูกศร native (prefix #view ชนะ partial style) */
#view .mu-toolbar select {
@@ -490,7 +544,7 @@ body:has(.mu-site-footer) .mu-footer { display: none; }
#view .mu-toolbar input:focus-visible,
#view .mu-toolbar select:focus-visible,
#view .mu-toolbar .mu-btn:focus-visible {
outline: 2px solid #7a4cc0;
outline: 2px solid var(--c-brand-ink);
outline-offset: 2px;
}