:root {
    --guide-content-max: 1050px;
}

body {
    min-height: 100vh;
    padding-top: 56px;
}

.back-to-app {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1000;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-color);
    color: #ffffff;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.9rem;
    border-radius: 999px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
    transition: background 0.15s ease;
}

.back-to-app:hover {
    background: var(--primary-hover);
}

.back-to-app:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.back-to-app-text-short {
    display: none;
}

.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 999px;
    background: var(--primary-color);
    color: #ffffff;
    cursor: pointer;
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.back-to-top--visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--primary-hover);
}

.back-to-top:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 3px;
}

body.dark-mode .back-to-top {
    background: #1d4ed8;
}

body.dark-mode .back-to-top:hover {
    background: #2563eb;
}

.guide-container {
    max-width: var(--guide-content-max);
    margin: 0 auto;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.guide-header {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #ffffff;
    padding: 28px 22px 22px;
    text-align: center;
}

.guide-header h1 {
    margin: 0;
    font-size: 2.2rem;
}

.guide-header p {
    margin-top: 10px;
    opacity: 0.92;
    font-size: 1rem;
}

.guide-main {
    padding: 28px 22px 36px;
    display: flex;
    align-items: flex-start;
    gap: 26px;
}

.guide-content {
    flex: 1;
    min-width: 0;
}

.toc {
    flex: 0 0 250px;
    position: sticky;
    top: 72px;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    background: var(--light-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px 18px;
}

.toc-toggle {
    display: none;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: none;
    border: none;
    color: inherit;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    padding: 0;
}

.toc-toggle-chevron {
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.toc-toggle[aria-expanded="true"] .toc-toggle-chevron {
    transform: rotate(180deg);
}

.toc-toggle:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

.toc a:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 2px;
}

.toc-heading {
    margin: 0 0 12px;
    border: none;
    padding: 0;
    font-size: 1.15rem;
    color: var(--text-primary);
}

.toc-list {
    margin: 0;
    padding-left: 20px;
    line-height: 1.8;
}

.toc a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.toc a:hover {
    text-decoration: underline;
}

.guide-section {
    margin-bottom: 22px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 18px;
}

.guide-section h2 {
    margin-top: 0;
    margin-bottom: 14px;
    font-size: 1.35rem;
}

.guide-section h3 {
    margin-top: 18px;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.guide-section p,
.guide-section li {
    color: var(--text-primary);
    line-height: 1.6;
}

.guide-section ul,
.guide-section ol {
    padding-left: 20px;
}

.guide-table-wrap {
    overflow-x: auto;
    margin: 10px 0 6px;
}

.guide-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 540px;
}

.guide-table th,
.guide-table td {
    border: 1px solid var(--border-color);
    padding: 10px;
    text-align: left;
    vertical-align: top;
    font-size: 0.95rem;
}

.guide-table thead th {
    background: var(--primary-color);
    color: #ffffff;
    font-weight: 700;
}

.guide-note {
    border-left: 4px solid var(--primary-color);
    background: var(--light-bg);
    border-radius: 8px;
    padding: 10px 12px;
    margin: 10px 0;
}

.guide-warning {
    border-left: 4px solid var(--danger-color);
    background: #fff5f5;
    border-radius: 8px;
    padding: 10px 12px;
    margin: 10px 0;
}

.guide-footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.92rem;
    margin-top: 20px;
}

body.dark-mode .guide-container {
    background: #1e293b;
}

body.dark-mode .guide-section {
    background: #1e293b;
    border-color: #334155;
}

body.dark-mode .toc {
    background: #0f172a;
    border-color: #334155;
}

body.dark-mode .guide-table th,
body.dark-mode .guide-table td {
    border-color: #334155;
}

body.dark-mode .guide-table thead th {
    background: #2563eb;
}

body.dark-mode .guide-note {
    background: #0f172a;
}

body.dark-mode .guide-warning {
    background: #3b0f0f;
    color: #fecaca;
}

body.dark-mode .back-to-app {
    background: #1d4ed8;
    color: #ffffff;
}

body.dark-mode .back-to-app:hover {
    background: #2563eb;
}

/* High Contrast theme (GitHub issue #33) - see the matching, more fully
   commented section in styles.css. guide.html links both stylesheets, so
   most shared elements already pick up styles.css's swapped CSS custom
   properties; these are guide.html's own hardcoded-color spots. */
body.dark-mode.high-contrast-mode .guide-container,
body.dark-mode.high-contrast-mode .guide-section,
body.dark-mode.high-contrast-mode .toc,
body.dark-mode.high-contrast-mode .guide-note {
    background: #000000;
    border-color: #ffffff;
}

body.dark-mode.high-contrast-mode .guide-header {
    background: #000000;
    border-bottom: 2px solid #ffffff;
}

body.dark-mode.high-contrast-mode .guide-table th,
body.dark-mode.high-contrast-mode .guide-table td {
    border-color: #ffffff;
}

body.dark-mode.high-contrast-mode .guide-table thead th {
    background: #000000;
    color: #ffffff;
    border-bottom: 2px solid #ffffff;
}

body.dark-mode.high-contrast-mode .guide-warning {
    background: #000000;
    color: #ff9999;
    border: 2px solid #ff6b6b;
}

body.dark-mode.high-contrast-mode .back-to-app,
body.dark-mode.high-contrast-mode .back-to-top {
    background: #000000;
    color: #66b3ff;
    border: 2px solid #66b3ff;
}

@media (max-width: 768px) {
    body {
        padding: 12px;
        padding-top: 76px;
    }

    .guide-header {
        padding: 22px 14px 16px;
    }

    .guide-header h1 {
        font-size: 1.8rem;
    }

    .guide-main {
        display: block;
        padding: 16px 12px 24px;
    }

    .guide-content {
        width: 100%;
    }

    .guide-section {
        padding: 14px;
        scroll-margin-top: 64px;
    }

    .toc {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 999;
        flex: none;
        max-height: none;
        overflow: visible;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid var(--border-color);
        padding: 0;
        margin-bottom: 0;
    }

    .toc-toggle {
        display: flex;
        justify-content: flex-end;
        height: 50px;
        padding: 0 16px;
        background: var(--light-bg);
    }

    .toc-heading {
        display: none;
    }

    .toc-list {
        display: none;
        position: fixed;
        top: 50px;
        left: 0;
        right: 0;
        max-height: calc(100vh - 50px);
        overflow-y: auto;
        margin: 0;
        padding: 12px 18px 16px 38px;
        background: var(--light-bg);
        box-shadow: var(--shadow-lg);
    }

    .toc-list.toc-list--open {
        display: block;
    }
}

@media (max-width: 380px) {
    .back-to-app-text-full {
        display: none;
    }

    .back-to-app-text-short {
        display: inline;
    }

    .toc-toggle-label {
        display: none;
    }
}
