:root {
    --bg-primary: #222222;
    --bg-secondary: #1a1a2e;
    --bg-code: #16213e;
    --text-primary: #eaeaea;
    --text-muted: #a0a0a0;
    --accent-gold: #ffd700;
    --accent-cyan: #4eeaff;
    --accent-magenta: #ff6bd6;
    --border-rpg: #4a4a6a;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at top, #2a2a4a 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, #1a1a3e 0%, transparent 30%);
    color: var(--text-primary);
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 16px;
    line-height: 1.8;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

.container {
    max-width: 860px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Header */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 8px 0;
    background: var(--bg-primary);
    border-bottom: 2px solid var(--border-rpg);
}

header::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-magenta), var(--accent-gold));
    opacity: 0.6;
}

header a {
    text-decoration: none;
    color: inherit;
}

header h1 {
    font-family: 'DotGothic16', sans-serif;
    font-size: 24px;
    margin: 0;
    letter-spacing: 2px;
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: inline-block;
}

header h1:hover {
    filter: brightness(1.2);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* TOC Button */
.toc-button {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border-rpg);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 14px;
    transition: all 0.2s;
}

.toc-button:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.toc-button .icon {
    font-family: 'Material Symbols Outlined';
    font-size: 20px;
}

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

@media (min-width: 540px) {
    .toc-label-full {
        display: inline;
    }
    .toc-label-short {
        display: none;
    }
}

/* TOC Dropdown */
.toc-container {
    position: relative;
}

.toc-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-secondary);
    border: 2px solid var(--border-rpg);
    border-radius: 8px;
    min-width: 280px;
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 200;
}

.toc-dropdown.open {
    display: block;
    animation: dropdownFadeIn 0.2s ease-out;
}

@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.toc-dropdown-header {
    padding: 12px 16px;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-magenta));
    color: var(--bg-primary);
    font-family: 'DotGothic16', sans-serif;
    font-weight: bold;
    font-size: 14px;
}

.toc-dropdown ol {
    list-style: none;
    padding: 8px 0;
    margin: 0;
}

.toc-dropdown li {
    margin: 0;
}

.toc-dropdown a {
    display: block;
    padding: 10px 16px;
    color: var(--text-primary);
    border-bottom: none;
    transition: background 0.2s;
}

.toc-dropdown a:hover {
    background: rgba(78, 234, 255, 0.1);
    color: var(--accent-cyan);
}

.toc-dropdown a.current {
    background: rgba(255, 215, 0, 0.1);
    color: var(--accent-gold);
}

.toc-dropdown .lesson-number {
    color: var(--text-muted);
    font-size: 12px;
    margin-right: 8px;
}

/* Main Content */
main {
    padding-top: 24px;
    padding-bottom: 16px;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Typography */
h1, h2, h3, h4 {
    font-family: 'DotGothic16', sans-serif;
    color: var(--text-primary);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    letter-spacing: 1px;
}

main h1 {
    font-size: 26px;
    padding-bottom: 8px;
    border-bottom: 3px double var(--accent-gold);
    margin-top: 0;
}

h2 {
    font-size: 20px;
    position: relative;
    padding-left: 28px;
    display: flex;
    align-items: center;
    color: var(--accent-cyan);
}

h2::before {
    content: 'play_arrow';
    font-family: 'Material Symbols Outlined';
    position: absolute;
    left: 0;
    color: var(--accent-cyan);
    font-size: 20px;
    transition: transform 0.2s ease;
}

h2:hover::before {
    transform: translateX(4px);
}

h3 {
    font-size: 17px;
    color: var(--accent-gold);
}

p {
    margin: 1em 0;
}

/* Links */
a {
    color: var(--accent-cyan);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

a:hover {
    color: var(--accent-gold);
    border-bottom-color: var(--accent-gold);
}

/* Lists */
ul, ol {
    padding-left: 1.5em;
    margin: 1em 0;
}

li {
    margin: 0.5em 0;
}

ol li::marker {
    color: var(--accent-gold);
    font-weight: bold;
}

ul li::marker {
    color: var(--accent-cyan);
}

/* Code Blocks - RPG Window Style */
.highlighter-rouge {
    background: var(--bg-code);
    border: 2px solid var(--border-rpg);
    border-radius: 8px;
    margin: 1.5em 0;
    overflow: hidden;
    box-shadow:
        inset 0 0 30px rgba(0, 0, 0, 0.3),
        0 4px 20px rgba(0, 0, 0, 0.4);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-magenta));
    font-size: 12px;
}

.code-buttons {
    display: flex;
    gap: 8px;
}

.code-lang {
    font-family: 'M PLUS 1 Code', monospace;
    color: var(--bg-primary);
    font-weight: bold;
}

.code-copy {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 12px;
    line-height: 1;
    transition: background 0.2s, color 0.2s;
}

.code-copy .icon {
    font-family: 'Material Symbols Outlined';
    font-size: 16px;
}

.code-copy:hover {
    background: rgba(0, 0, 0, 0.5);
}

.code-copy.copied {
    color: var(--accent-gold);
}

.code-preview {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 12px;
    line-height: 1;
    transition: background 0.2s;
}

.code-preview .icon {
    font-family: 'Material Symbols Outlined';
    font-size: 16px;
}

.code-preview:hover {
    background: rgba(0, 0, 0, 0.5);
}

.code-dimmed {
    opacity: 0.5;
}

/* Folded code block */
.code-folded-placeholder {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: var(--bg-code);
}

.code-show-btn,
.code-fold-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 12px;
    line-height: 1;
    transition: background 0.2s;
}

.code-show-btn .icon,
.code-fold-btn .icon {
    font-family: 'Material Symbols Outlined';
    font-size: 16px;
}

.code-show-btn:hover,
.code-fold-btn:hover {
    background: rgba(0, 0, 0, 0.5);
}

/* 狭い画面ではボタンのテキストを非表示 */
@media (max-width: 539px) {
    .code-copy > span:not(.icon),
    .code-preview > span:not(.icon),
    .code-show-btn > span:not(.icon),
    .code-fold-btn > span:not(.icon) {
        display: none;
    }
    .code-copy,
    .code-preview,
    .code-show-btn,
    .code-fold-btn {
        padding: 4px 8px;
    }
}

/* Preview Modal */
.preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.preview-modal-content {
    background: var(--bg-secondary);
    border: 2px solid var(--border-rpg);
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    height: 80%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.preview-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-magenta));
    color: var(--bg-primary);
    font-family: 'DotGothic16', sans-serif;
    font-weight: bold;
}

.preview-modal-close {
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.preview-modal-close:hover {
    background: rgba(0, 0, 0, 0.5);
}

.preview-modal-close .icon {
    font-family: 'Material Symbols Outlined';
    font-size: 20px;
}

.preview-iframe {
    flex: 1;
    border: none;
    background: white;
}

pre {
    padding: 20px;
    margin: 0;
    overflow-x: auto;
}

code {
    font-family: 'M PLUS 1 Code', monospace;
    font-size: 14px;
}

pre code {
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-primary);
}

/* Prism.js テーマ上書き */
code[class*="language-"],
pre[class*="language-"] {
    background: transparent;
    color: var(--text-primary);
    font-family: 'M PLUS 1 Code', monospace;
    margin: 0;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata { color: #6a9955; font-style: italic; }

.token.punctuation { color: var(--text-primary); }

.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted { color: #569cd6; }

.token.boolean,
.token.number { color: #b5cea8; }

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted { color: #ce9178; }

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string { color: var(--text-primary); }

.token.atrule,
.token.attr-value,
.token.keyword { color: #c586c0; }

.token.function,
.token.class-name { color: #4ec9b0; }

.token.regex,
.token.important,
.token.variable { color: var(--accent-cyan); }

/* Line Numbers */
.line-numbers .line-numbers-rows {
    border-right: 1px solid var(--border-rpg);
}

.line-numbers-rows > span::before {
    color: var(--text-muted);
}

/* Line Highlight */
.line-highlight {
    background: linear-gradient(to right, rgba(255, 215, 0, 0.15) 70%, rgba(255, 215, 0, 0));
}

.line-highlight::before,
.line-highlight[data-end]::after {
    display: none;
}

/* Inline code (Prism.jsの後に配置して優先させる) */
:not(pre) > code,
:not(pre) > code[class*="language-"] {
    background: var(--bg-code);
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-rpg);
    color: #569cd6;
}

/* h3内のcodeは見出しの色を継承 */
h3 code,
h3 > code[class*="language-"] {
    color: inherit;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    background: var(--bg-secondary);
    border: 2px solid var(--border-rpg);
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-rpg);
}

th {
    background: rgba(255, 215, 0, 0.1);
    color: var(--accent-gold);
    font-family: 'DotGothic16', sans-serif;
}

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

/* Horizontal Rule */
hr {
    border: none;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--border-rpg), transparent);
    margin: 1em 0;
}

/* Blockquote */
blockquote {
    border-left: 4px solid var(--accent-gold);
    margin: 1.5em 0;
    padding: 1em 1.5em;
    background: rgba(255, 215, 0, 0.05);
    border-radius: 0 8px 8px 0;
}

blockquote p {
    margin: 0;
}

/* Aside - Supplementary Notes */
aside {
    position: relative;
    margin: 1.5em 0;
    padding: 1em 1.5em 1em 3em;
    background:
        linear-gradient(135deg, rgba(78, 234, 255, 0.02) 0%, rgba(78, 234, 255, 0.06) 100%);
    border: 1px solid rgba(78, 234, 255, 0.15);
    border-left: 3px solid var(--accent-cyan);
    border-radius: 0 6px 6px 0;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-muted);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.02),
        0 2px 8px rgba(0, 0, 0, 0.1);
}

aside::before {
    content: 'info';
    font-family: 'Material Symbols Outlined';
    position: absolute;
    left: 0.7em;
    top: 0.85em;
    color: var(--accent-cyan);
    font-size: 18px;
    opacity: 0.6;
}

aside p {
    margin: 0;
}

aside p + p {
    margin-top: 0.75em;
}

aside code {
    font-size: 13px;
}

/* Footer */
footer {
    text-align: center;
    padding: 8px 0;
    border-top: 1px solid var(--border-rpg);
    color: var(--text-muted);
    font-size: 14px;
}

/* Download Button */
.download-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 1em 0;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta));
    color: var(--bg-primary);
    font-family: 'DotGothic16', sans-serif;
    font-size: 14px;
    font-weight: bold;
    text-decoration: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(78, 234, 255, 0.3);
}

.download-button::before {
    content: 'download';
    font-family: 'Material Symbols Outlined';
    font-size: 18px;
}

.download-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(78, 234, 255, 0.4);
    color: var(--bg-primary);
    border-bottom-color: transparent;
}

.download-button:active {
    transform: translateY(0);
}

/* Navigation Links */
.nav-links {
    display: flex;
    justify-content: space-between;
    margin-top: 1em;
    padding-top: 0.75em;
    border-top: 1px solid var(--border-rpg);
}

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

.nav-links .icon {
    font-family: 'Material Symbols Outlined';
    font-size: 18px;
}

.nav-links .nav-title {
    display: inline;
}

@media (max-width: 539px) {
    .nav-links .nav-title {
        display: none;
    }
    .nav-prev .nav-label {
        display: none;
    }
}

/* Selection */
::selection {
    background: var(--accent-gold);
    color: var(--bg-primary);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-rpg);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-cyan);
}

/* Volume Control */
.volume-control {
    background: rgba(34, 34, 34, 0.9);
    border: 2px solid var(--border-rpg);
    border-radius: 4px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-primary);
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s;
}

.volume-icon {
    cursor: pointer;
    transition: color 0.2s;
}

.volume-icon:hover {
    color: var(--accent-cyan);
}

.volume-control.visible {
    opacity: 1;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-rpg);
    border-radius: 3px;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta));
    border-radius: 50%;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta));
    border: none;
    border-radius: 50%;
    cursor: pointer;
}
