:root {
    color-scheme: light;
    --bg: #F0F8FF;
    --surface: #FFFFFF;
    --surface-strong: #F8F2EA;
    --text: #111111;
    --muted: #555555;
    --border: #D8D8D8;
    --accent: #0078D4;
    --accent-hover: #005BB5;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
    --highlight-bg: rgba(255, 229, 100, 0.45);
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    padding: 10px;
    transition: background 0.25s ease, color 0.25s ease;
}

body.dark {
    color-scheme: dark;
    --bg: #181818;
    --surface: #2C2C2C;
    --surface-strong: #3A3A3A;
    --text: #F3F3F3;
    --muted: #C8C8C8;
    --border: #4D4D4D;
    --accent: #8AB4F8;
    --accent-hover: #A6C8FF;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    --highlight-bg: rgba(255, 209, 72, 0.2);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

::selection {
    background: var(--accent);
    color: #fff;
}

img {
    max-width: 100%;
    display: block;
}

/* ---- SVG icon alignment ---- */
svg {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

button svg,
.btn-report svg {
    display: block;
}

.event-icon svg,
.io-icon svg {
    display: block;
    line-height: 0;
}

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

a:hover,
a:focus {
    color: var(--accent-hover);
}

p {
    margin: 0 0 1rem;
    color: var(--text);
}

.topnav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface);
    border-radius: 10px;
    padding: 0.25rem;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.topnav a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    color: var(--text);
    border-radius: 8px;
    transition: background 0.2s ease, color 0.2s ease;
}

.topnav a:hover,
.topnav a:focus {
    background: var(--surface-strong);
}

.topnav a.active {
    background: var(--accent);
    color: #fff;
    font-weight: bold;
}

/* ---- Compact nav for sub-pages ---- */
.topnav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
}

.topnav-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    padding: 0 4px;
}

.topnav-tools input {
    min-width: 120px;
    max-width: 160px;
    width: auto;
    padding: 6px 10px;
    font-size: 0.85rem;
}

.topnav-tools button {
    padding: 6px 12px;
    font-size: 0.85rem;
    white-space: nowrap;
}

.topnav-clock {
    color: var(--muted);
    font-size: 0.85rem;
    white-space: nowrap;
    min-width: 60px;
}

@media (max-width: 800px) {
    .topnav {
        justify-content: center;
    }
    .topnav-tools {
        margin-left: 0;
        padding: 4px 0;
    }
}

.header {
    padding: 30px;
    text-align: center;
    background: var(--surface);
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.header img {
    display: block;
    margin: 0 auto 1rem;
}

.header h1 {
    font-size: clamp(2.5rem, 4vw, 4rem);
    margin: 0.25rem 0;
}

/* Slim sub-page header */
.subheader {
    padding: 12px 20px;
    margin-bottom: 0;
}

.subheader h1 {
    font-size: 1.5rem;
    margin: 0;
}

/* Nav home icon */
.nav-home-icon {
    vertical-align: middle;
    margin-right: 4px;
}

.header h3,
.header #date,
.header #time {
    margin: 0.35rem 0;
    color: var(--muted);
}

input,
button {
    font: inherit;
}

input {
    min-width: 220px;
    max-width: 320px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    transition: background 0.2s ease, border-color 0.2s ease;
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

button {
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

button:hover,
button:focus {
    background: var(--surface-strong);
    border-color: var(--accent);
}

.row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.leftcolumn,
.rightcolumn,
.fullcolumn {
    width: 100%;
}

.leftcolumn {
    flex: 2 1 640px;
}

.rightcolumn {
    flex: 1 1 280px;
}

.fullcolumn {
    flex: 1 1 100%;
}

.card {
    background: var(--surface);
    color: var(--text);
    padding: 20px;
    margin-top: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, background 0.2s ease;
}

.card:hover {
    transform: translateY(-3px);
}

@media (prefers-reduced-motion: reduce) {
    .card,
    .card:hover {
        transition: none;
        transform: none;
    }

    .topnav a,
    a,
    button,
    input,
    body {
        transition: none;
    }

    html {
        scroll-behavior: auto;
    }
}

/* Keyboard accessibility */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.card h2 {
    margin: 0 0 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.card h5 {
    margin: 0 0 1rem;
    color: var(--muted);
}

.card a {
    color: var(--text);
}

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

.highlight {
    display: inline-block;
    background: var(--highlight-bg);
    border-radius: 4px;
    padding: 0 4px;
}

#search-results {
    display: grid;
    gap: 18px;
}

.search-summary {
    margin-bottom: 1rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.search-path {
    color: var(--muted);
    font-size: 0.95rem;
    margin-top: 0.5rem;
}

.card p {
    margin-bottom: 0;
}

.footer {
    padding: 20px 0;
    text-align: center;
    margin-top: 30px;
    color: var(--muted);
}

@media (max-width: 800px) {
    .row {
        flex-direction: column;
    }

    .leftcolumn,
    .rightcolumn,
    .fullcolumn {
        width: 100%;
        flex: 1 1 auto;
    }

    .header {
        padding: 22px 18px;
    }

    .header h1 {
        font-size: clamp(2rem, 6vw, 3rem);
    }

    .card {
        padding: 18px;
    }
}

@media (max-width: 600px) {
    .topnav {
        justify-content: center;
    }

    .topnav a {
        flex: 1 1 auto;
        min-width: 0;
        padding: 10px 12px;
    }

    .header {
        padding: 18px 12px;
    }

    .header img {
        width: 48px;
        height: 48px;
    }
}

/* ================================================================
   Game: 15-Puzzle  (games/puzzle/)
   ================================================================ */

.puzzle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 20px;
}

.puzzle-board {
    display: grid;
    grid-template-columns: repeat(4, 80px);
    grid-template-rows: repeat(4, 80px);
    gap: 4px;
    background: var(--border);
    padding: 4px;
    border-radius: 8px;
    touch-action: manipulation;
}

.puzzle-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    font-size: 1.6rem;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.12s ease, background 0.2s ease;
}

.puzzle-tile.empty {
    background: transparent;
    cursor: default;
}

.puzzle-tile:hover:not(.empty) {
    background: var(--accent-hover);
}

.puzzle-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.puzzle-controls button {
    padding: 10px 20px;
    font-size: 1rem;
}

.puzzle-message {
    font-size: 1.1rem;
    color: var(--accent);
    font-weight: bold;
    min-height: 1.5em;
}

@media (max-width: 400px) {
    .puzzle-board {
        grid-template-columns: repeat(4, 70px);
        grid-template-rows: repeat(4, 70px);
    }

    .puzzle-tile {
        font-size: 1.3rem;
    }
}

/* ---- Game: 找不同 (super) ---- */
#variants p {
    font-family: 'Courier New', 'Consolas', 'Source Code Pro', monospace;
    font-size: 1rem;
    letter-spacing: 1px;
    word-break: break-all;
}

/* ================================================================
   Tool: Reliability History  (tools/reliability-history.html)
   ================================================================ */

.reliability-container { max-width: 960px; margin: 20px auto 0; }
.stats-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-tile {
    flex: 1; min-width: 120px; background: var(--surface);
    border-radius: 12px; box-shadow: var(--shadow); padding: 16px 20px; text-align: center;
}
.stat-tile .stat-value { font-size: 1.8rem; font-weight: bold; color: var(--accent); }
.stat-tile .stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.stat-tile.good .stat-value { color: #4CAF50; }
.stat-tile.warn .stat-value { color: #F9A825; }
.stat-tile.bad .stat-value { color: #E74856; }
.monitor-card {
    background: var(--surface); border-radius: 12px;
    box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px;
}
.monitor-card h2 { margin: 0 0 4px; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.monitor-card h2 .icon { font-size: 1.3rem; }
.monitor-card .subtitle { color: var(--muted); font-size: 0.85rem; margin: 0 0 16px; }
.chart-wrapper { position: relative; width: 100%; height: 300px; margin: 8px 0 0; }
.chart-wrapper canvas { width: 100%; height: 100%; display: block; }
.chart-tooltip {
    display: none; position: absolute;
    background: var(--surface-strong); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 14px; font-size: 0.85rem;
    pointer-events: none; z-index: 10; white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.chart-tooltip .tt-date { font-weight: bold; margin-bottom: 2px; }
.chart-tooltip .tt-score { color: var(--accent); }
.chart-tooltip .tt-events { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.chart-legend { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 12px; font-size: 0.82rem; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.legend-dot.critical { background: #E74856; }
.legend-dot.warning  { background: #F9A825; }
.legend-dot.info     { background: var(--accent); }
.report-area { text-align: center; margin-bottom: 20px; }
.btn-report {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 12px 28px; font-size: 1rem; font-weight: 600;
    border: 2px solid #E74856; border-radius: 10px;
    background: #E74856; color: #fff; cursor: pointer;
    transition: all 0.2s ease;
}
.btn-report:hover { background: #d1343f; border-color: #d1343f; transform: translateY(-1px); }
.btn-report:active { transform: translateY(0); }
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--surface); border-radius: 14px; padding: 28px;
    max-width: 500px; width: 90%; max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal h3 { margin: 0 0 8px; font-size: 1.2rem; }
.modal .modal-sub { color: var(--muted); font-size: 0.85rem; margin: 0 0 20px; }
.modal label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; }
.issue-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
@media (max-width: 400px) { .issue-grid { grid-template-columns: 1fr; } }
.issue-option {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border: 2px solid var(--border); border-radius: 10px;
    cursor: pointer; transition: all 0.15s ease; font-size: 0.88rem;
}
.issue-option:hover { border-color: var(--accent); background: var(--surface-strong); }
.issue-option.selected { border-color: var(--accent); background: var(--surface-strong); }
.issue-option .io-icon {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: bold; color: #fff; flex-shrink: 0;
}
.issue-option .io-icon.critical { background: #E74856; }
.issue-option .io-icon.warning  { background: #F9A825; color: #333; }
.issue-option .io-icon.info     { background: var(--accent); }
.issue-option .io-impact { margin-left: auto; font-size: 0.75rem; color: var(--muted); }
.modal textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; background: var(--surface); color: var(--text);
    font: inherit; resize: vertical; min-height: 60px; margin-bottom: 20px;
}
.modal textarea:focus { outline: none; border-color: var(--accent); }
.modal-buttons { display: flex; gap: 10px; justify-content: flex-end; }
.btn {
    padding: 10px 22px; border-radius: 8px; font-weight: 600;
    border: none; cursor: pointer; font: inherit; transition: all 0.2s ease;
}
.btn-primary { background: #E74856; color: #fff; }
.btn-primary:hover { background: #d1343f; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-cancel { background: var(--surface-strong); color: var(--text); border: 1px solid var(--border); }
.btn-cancel:hover { background: var(--border); }
.event-day-group { margin-bottom: 16px; }
.event-day-label {
    font-weight: bold; font-size: 0.95rem; padding: 6px 0;
    border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.event-item {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 10px 12px; border-radius: 8px; transition: background 0.15s ease;
}
.event-item:hover { background: var(--surface-strong); }
.event-item .event-icon {
    flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: bold; color: #fff; margin-top: 2px;
}
.event-item .event-icon.critical { background: #E74856; }
.event-item .event-icon.warning  { background: #F9A825; color: #333; }
.event-item .event-icon.info     { background: var(--accent); }
.event-item .event-details { flex: 1; min-width: 0; }
.event-item .event-details .event-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 2px; }
.event-item .event-details .event-desc { color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.event-item .event-time { flex-shrink: 0; color: var(--muted); font-size: 0.82rem; }
.event-item .event-delete {
    flex-shrink: 0; background: none; border: none; color: var(--muted);
    cursor: pointer; font-size: 0.8rem; padding: 2px 6px; border-radius: 4px;
    opacity: 0; transition: opacity 0.15s;
}
.event-item:hover .event-delete { opacity: 1; }
.event-item .event-delete:hover { color: #E74856; background: rgba(231,72,86,0.1); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    background: #333; color: #fff; padding: 12px 24px; border-radius: 8px;
    font-size: 0.9rem; z-index: 2000; pointer-events: none;
    opacity: 0; transition: opacity 0.3s ease;
}
.toast.show { opacity: 1; }
@media (max-width: 600px) {
    .monitor-card { padding: 14px; }
    .chart-wrapper { height: 220px; }
    .stats-row { gap: 8px; }
    .stat-tile { padding: 12px 10px; }
    .stat-tile .stat-value { font-size: 1.4rem; }
    .event-item .event-time { display: none; }
    .modal { padding: 16px; }
}

