/* =========================================================
   theme.css — Shared design system for kelvinlinkk.github.io
   Monochrome zinc palette + subtle blue accent (#60a5fa).
   Link this FIRST on every page, then page-specific CSS.
   ========================================================= */

/* ---------- 1. Design tokens ---------- */
:root {
    color-scheme: dark;

    /* Surfaces */
    --bg: #09090b;
    --bg-elevated: #121215;
    --surface: #18181b;
    --surface-2: #202024;
    --surface-hover: #27272a;
    --overlay: rgba(9, 9, 11, 0.85);

    /* Borders */
    --border: #27272a;
    --border-strong: #3f3f46;

    /* Text */
    --text: #fafafa;
    --text-muted: #a1a1aa;
    --text-subtle: #71717a;
    --text-inverse: #09090b;

    /* Accent (single brand colour) */
    --accent: #60a5fa;
    --accent-strong: #3b82f6;
    --accent-soft: rgba(96, 165, 250, 0.12);
    --accent-border: rgba(96, 165, 250, 0.35);

    /* Status */
    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.12);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);

    /* Typography */
    --font-sans: "Inter", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

    /* Radius */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);

    /* Motion */
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --transition: 0.25s var(--ease);

    /* Layout */
    --container: 1200px;
    --header-h: 64px;
}

/* ---------- 2. Reset & base ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.65;
    letter-spacing: -0.005em;
    color: var(--text);
    background-color: var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

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

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

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

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

h1,
h2,
h3,
h4 {
    line-height: 1.25;
    letter-spacing: -0.02em;
    font-weight: 700;
}

::selection {
    background: var(--accent);
    color: var(--text-inverse);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Unified scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-pill);
}

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

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- 3. Layout helpers ---------- */
.container {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 24px;
}

/* Generic page shell for tool / sub pages */
.page {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 48px 24px 120px;
}

.page-header {
    margin-bottom: 32px;
}

.page-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-subtle);
    margin-bottom: 10px;
}

.page-title {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text);
}

.page-subtitle {
    margin-top: 8px;
    font-size: 1.05rem;
    color: var(--text-muted);
    max-width: 640px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

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

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ---------- 4. Site header (top navigation) ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--header-h);
    background: rgba(9, 9, 11, 0.8);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border);
}

.site-header .container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
    letter-spacing: -0.02em;
}

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

.brand img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-strong);
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.site-nav a {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.925rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: color var(--transition), background var(--transition);
}

.site-nav a:hover {
    color: var(--text);
    background: var(--surface);
}

.site-nav a.active {
    color: var(--text);
    background: var(--surface-2);
}

@media (max-width: 768px) {
    .site-nav {
        display: none;
    }
}

/* ---------- 5. Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    min-height: 40px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}

.btn:hover {
    background: var(--surface-hover);
    border-color: var(--text-subtle);
    color: var(--text);
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--text);
    border-color: var(--text);
    color: var(--text-inverse);
}

.btn-primary:hover {
    background: #e4e4e7;
    border-color: #e4e4e7;
    color: var(--text-inverse);
}

.btn-accent {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent);
}

.btn-accent:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text-inverse);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.btn-sm {
    padding: 6px 12px;
    min-height: 32px;
    font-size: 0.85rem;
}

.btn-lg {
    padding: 12px 24px;
    min-height: 48px;
    font-size: 1rem;
}

.btn-icon {
    width: 40px;
    padding: 0;
}

/* ---------- 6. Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}

a.card,
.card-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

a.card:hover,
.card-link:hover,
.card.is-interactive:hover {
    border-color: var(--border-strong);
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    color: inherit;
}

.card-icon {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.1rem;
    margin-bottom: 18px;
    transition: color var(--transition), border-color var(--transition);
}

a.card:hover .card-icon {
    color: var(--accent);
    border-color: var(--accent-border);
}

.card-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.card-text {
    font-size: 0.95rem;
    color: var(--text-muted);
}

.grid {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* ---------- 7. Tags / badges ---------- */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.5;
    white-space: nowrap;
}

.tag-accent {
    border-color: var(--accent-border);
    background: var(--accent-soft);
    color: var(--accent);
}

/* ---------- 8. Forms ---------- */
.input,
input[type="text"],
input[type="number"],
input[type="search"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 10px 14px;
    min-height: 40px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.input::placeholder,
input::placeholder,
textarea::placeholder {
    color: var(--text-subtle);
}

.input:focus,
input[type="text"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="email"]:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: var(--radius-pill);
    background: var(--border-strong);
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text);
    border: 3px solid var(--bg);
    box-shadow: 0 0 0 1px var(--border-strong);
    transition: transform var(--transition);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text);
    border: 3px solid var(--bg);
    box-shadow: 0 0 0 1px var(--border-strong);
}

input[type="range"]:hover::-webkit-slider-thumb {
    transform: scale(1.15);
}

/* ---------- 9. Tables ---------- */
.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 10px 14px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover td {
    background: var(--surface-hover);
}

/* ---------- 10. Alerts / feedback ---------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.95rem;
}

.alert:empty {
    display: none;
}

.alert-success {
    border-color: rgba(52, 211, 153, 0.35);
    background: var(--success-soft);
    color: var(--success);
}

.alert-danger {
    border-color: rgba(248, 113, 113, 0.35);
    background: var(--danger-soft);
    color: var(--danger);
}

/* ---------- 11. Section headings (long pages) ---------- */
.section {
    padding: 96px 0;
}

.section-header {
    margin-bottom: 48px;
}

.section-header.center {
    text-align: center;
}

.section-title {
    font-size: clamp(1.75rem, 3.5vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}

.section-subtitle {
    margin-top: 10px;
    font-size: 1.05rem;
    color: var(--text-muted);
}

.section-header.center .section-subtitle {
    margin-left: auto;
    margin-right: auto;
    max-width: 600px;
}

@media (max-width: 768px) {
    .section {
        padding: 64px 0;
    }

    .section-header {
        margin-bottom: 32px;
    }

    .container,
    .page {
        padding-left: 16px;
        padding-right: 16px;
    }

    .page {
        padding-top: 32px;
    }
}

/* ---------- 12. Footer ---------- */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 32px 0;
    color: var(--text-subtle);
    font-size: 0.875rem;
}

.site-footer .container {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

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

.site-footer a:hover {
    color: var(--text);
}

/* ---------- 13. Motion utilities ---------- */
.reveal {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}

.reveal.is-visible {
    opacity: 1;
    transform: none;
}

@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.fade-up {
    animation: fade-up 0.7s var(--ease) both;
}
