/* =========================================
   SafeW Global Styles & Design System
   ========================================= */

/* --- Variables & Reset --- */
:root {
    /* Colors */
    --color-dark-bg: #231334;
    --color-paper: #E9E8EA;
    --color-text-main: #1C1523;
    --color-brand: #7D14EB;
    --color-accent: #EDD26E;
    
    /* UI Tokens */
    --radius-card: 20px;
    --radius-btn: 12px;
    --card-border: 2px solid var(--color-text-main);
    --card-shadow: 4px 4px 0 var(--color-text-main);
    
    /* Spacing & Layout */
    --section-y: clamp(5rem, 10vw, 9rem);
    --gap: clamp(1.5rem, 3vw, 2.5rem);
    --content-max: 1120px;
    
    /* Typography */
    --font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --h1-size: clamp(2rem, 4.6vw, 3.4rem);
    --h2-size: clamp(1.6rem, 3vw, 2.4rem);
    --h3-size: 1.25rem;
    --body-size: 1rem;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    background-color: var(--color-dark-bg); /* Fallback for gaps between light sections */
}

body {
    font-family: var(--font-family);
    font-size: var(--body-size);
    line-height: 1.75;
    color: var(--color-text-main);
    background-color: var(--color-paper);
    -webkit-font-smoothing: antialiased;
}

/* --- Layout Utilities --- */
.container {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 var(--gap);
}

.section {
    padding-top: var(--section-y);
    padding-bottom: var(--section-y);
    position: relative;
}

/* Dark Section Override */
.section.dark {
    background-color: var(--color-dark-bg);
    color: var(--color-paper);
}
.section.dark .hl {
    color: var(--color-accent);
}
.section.dark .badge {
    color: var(--color-accent);
}
.section.dark a {
    color: var(--color-accent);
}
.section.dark h2, .section.dark h3, .section.dark p, .section.dark li {
    color: var(--color-paper);
}
/* Light Card inside Dark Section */
.card-light-in-dark {
    background-color: var(--color-paper);
    color: var(--color-text-main);
    border: var(--card-border);
    box-shadow: var(--card-shadow);
    padding: var(--gap);
    border-radius: var(--radius-card);
}
.card-light-in-dark .hl {
    color: var(--color-brand);
}
.card-light-in-dark a {
    color: var(--color-brand);
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: 0;
}

h1 {
    font-size: var(--h1-size);
    margin-bottom: 1rem;
}

h2 {
    font-size: var(--h2-size);
    margin-bottom: 1.5rem;
    text-wrap: balance;
}

h3 {
    font-size: var(--h3-size);
    margin-bottom: 0.75rem;
}

p {
    margin-bottom: 1rem;
    max-width: 38em;
}

.badge {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 0.75rem;
    color: var(--color-brand);
}

.hl {
    color: var(--color-brand);
    font-weight: 700;
}

/* --- Components --- */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    padding: 0 24px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-btn);
    text-decoration: none;
    transition: transform 0.2s ease, background-color 0.2s ease, color 0.2s ease;
    cursor: pointer;
    gap: 8px;
}

.btn:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

.btn-primary {
    background-color: var(--color-accent);
    color: var(--color-dark-bg);
    border: none;
}
.btn-primary:hover {
    transform: translateY(-2px);
    filter: brightness(1.05);
}

.btn-secondary {
    background-color: transparent;
    color: var(--color-text-main);
    border: 2px solid var(--color-text-main);
}
.section.dark .btn-secondary {
    color: var(--color-paper);
    border-color: var(--color-paper);
}
.btn-secondary:hover {
    background-color: rgba(0,0,0,0.05);
    transform: translateY(-2px);
}

/* Cards */
.card {
    background-color: var(--color-paper);
    border: var(--card-border);
    box-shadow: var(--card-shadow);
    border-radius: var(--radius-card);
    padding: var(--gap);
    height: 100%;
    display: flex;
    flex-direction: column;
}
.card p {
    flex-grow: 1;
}

/* Grids */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr));
    gap: var(--gap);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: var(--gap);
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
    border: var(--card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--card-shadow);
    background-color: var(--color-paper);
}
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}
th, td {
    padding: 16px 24px;
    text-align: left;
    border-bottom: 1px solid rgba(28, 21, 35, 0.1);
}
th {
    background-color: rgba(28, 21, 35, 0.05);
    font-weight: 700;
    white-space: nowrap;
}
tr:last-child td {
    border-bottom: none;
}

/* Details / FAQ */
details {
    border: var(--card-border);
    border-radius: var(--radius-card);
    margin-bottom: 16px;
    background-color: var(--color-paper);
    overflow: hidden;
}
summary {
    padding: 20px 24px;
    cursor: pointer;
    font-weight: 600;
    list-style: none;
    position: relative;
    padding-left: 40px;
}
summary::-webkit-details-marker {
    display: none;
}
summary::before {
    content: "+";
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.2rem;
    color: var(--color-brand);
    transition: transform 0.2s;
}
details[open] summary::before {
    content: "-";
}
details p {
    padding: 0 24px 24px 24px;
    margin-bottom: 0;
}

/* Header & Footer */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: rgba(233, 232, 234, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(28, 21, 35, 0.1);
}
.section.dark ~ .site-footer,
.site-header {
    /* Header is always light paper, footer matches dark section if needed or stays consistent */
}
.site-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 72px;
}
.nav-links {
    display: flex;
    gap: 24px;
    align-items: center;
}
.nav-links a {
    text-decoration: none;
    color: var(--color-text-main);
    font-weight: 500;
    font-size: 0.95rem;
}
.nav-links a:hover {
    color: var(--color-brand);
}
.nav-links a[aria-current="page"] {
    color: var(--color-brand);
    font-weight: 700;
}
.brand-logo img {
    height: 32px;
    width: auto;
    vertical-align: middle;
}

.site-footer {
    background-color: var(--color-dark-bg);
    color: var(--color-paper);
    padding: 48px 0;
    margin-top: var(--section-y);
}
.footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--gap);
}
.footer-col h4 {
    color: var(--color-accent);
    margin-bottom: 16px;
    font-size: 1rem;
}
.footer-col ul {
    list-style: none;
}
.footer-col li {
    margin-bottom: 8px;
}
.footer-col a {
    color: var(--color-paper);
    text-decoration: none;
    opacity: 0.8;
    font-size: 0.9rem;
}
.footer-col a:hover {
    opacity: 1;
    color: var(--color-accent);
}
.copyright {
    text-align: center;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid rgba(233, 232, 234, 0.1);
    font-size: 0.85rem;
    opacity: 0.6;
}

/* --- SVG Animation System --- */
.svg-icon {
    width: 100%;
    height: auto;
    max-width: 100%;
}
svg path, svg circle, svg rect, svg line, svg polyline {
    stroke: currentColor;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Draw Effect */
.draw {
    stroke-dasharray: 1;
    stroke-dashoffset: 0;
    animation: drawStroke 3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.draw-delay-1 { animation-delay: 0.5s; }
.draw-delay-2 { animation-delay: 1s; }
.draw-delay-3 { animation-delay: 1.5s; }

@keyframes drawStroke {
    from { stroke-dashoffset: 1; }
    to { stroke-dashoffset: 0; }
}

/* Float Effect */
.float {
    animation: floatAnim 4s ease-in-out infinite alternate;
}
.float-delay {
    animation-delay: 1s;
}

@keyframes floatAnim {
    0% { transform: translateY(0); }
    100% { transform: translateY(-8px); }
}

/* Pulse/Breath Effect */
.breath {
    animation: breathAnim 3s ease-in-out infinite alternate;
}

@keyframes breathAnim {
    0% { opacity: 0.6; transform: scale(0.98); }
    100% { opacity: 1; transform: scale(1.02); }
}

/* Flow Line Effect */
.flow-line {
    stroke-dasharray: 4 4;
    animation: flowAnim 1s linear infinite;
}

@keyframes flowAnim {
    to { stroke-dashoffset: -8; }
}

/* Reduced Motion */
@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;
    }
    .draw, .float, .breath, .flow-line {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
}

/* Responsive Fixes */
@media (max-width: 768px) {
    .nav-links {
        display: none; /* Simple hide for mobile, ideally would be a burger menu but keeping it simple/static */
    }
    .grid-2, .grid-3 {
        grid-template-columns: 1fr;
    }
    .scene-row {
        flex-direction: column;
    }
    .scene-context, .scene-action {
        width: 100%;
    }
}
