:root {
    /* OmmWriter-inspired palette (Dark Mode Default) */
    --bg-color: #121212;
    /* Deeper dark grey */
    --text-color: #d0d0d0;
    /* Soft grey text */
    --highlight-color: #d0d0d0;
    /* Same as text for highlight layer */
    --caret-color: #fff;
    --toolbar-bg: rgba(18, 18, 18, 0.9);
    --toolbar-border: transparent;
    --button-bg: transparent;
    --button-hover: rgba(255, 255, 255, 0.1);
    --button-active: rgba(255, 255, 255, 0.2);
    --button-text: #888;
    --button-text-active: #fff;
    --button-select-active: #4a90e2;
    /* Blue for active selection mode */

    /* Typography */
    --font-family: "Hiragino Mincho ProN", "Yu Mincho", Georgia, "Times New Roman", serif;
    --font-size: 17px;
    --line-height: 2.0;
    --editor-pad-top: 60px;
    --editor-pad-side: 32px;
    --editor-pad-bottom: 140px;
}

/* Light Mode Override - Softer Grey */
body.light-mode {
    --bg-color: #e6e6e6;
    /* Softer grey, easier on eyes */
    --text-color: #333333;
    /* Dark grey text */
    --highlight-color: #333333;
    --caret-color: #000;
    --toolbar-bg: rgba(230, 230, 230, 0.9);
    --button-hover: rgba(0, 0, 0, 0.05);
    --button-active: rgba(0, 0, 0, 0.1);
    --button-text: #666;
    --button-text-active: #222;
    /* Light mode gradient: light grey at top, darker grey at bottom */
    background: linear-gradient(to bottom, #f0f0f0 0%, #b8b8b8 100%);
}

* {
    box-sizing: border-box;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: var(--font-family);
    background: linear-gradient(to bottom, #1a1a1a 0%, #000000 100%);
    /* Dark mode: darker gradient */
    color: var(--text-color);
    overflow: hidden;
    transition: background 0.5s ease, color 0.5s ease;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    z-index: 1;
    /* Ensure app content is above background if needed, but we want bg inside */
}

#bg-image {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    /* 画面全体の高さを確保して画像の下の部分も表示 */
    background-image: url('../assets/bg-mekong.webp');
    background-repeat: no-repeat;
    background-position: center bottom;
    background-size: cover;
    z-index: -1;
    /* Behind everything */
    pointer-events: none;
    /* フィルターとマスクを削除してくっきり表示しつつ、暗くする */
    /* 画面下部をより暗くして文字を見やすくする */
    opacity: 1;
    filter: brightness(0.4);
    mask-image: linear-gradient(to top,
            rgba(0, 0, 0, 0.5) 0%,
            rgba(0, 0, 0, 0.6) 10%,
            rgba(0, 0, 0, 0.7) 20%,
            rgba(0, 0, 0, 0.75) 30%,
            rgba(0, 0, 0, 0.65) 40%,
            rgba(0, 0, 0, 0.5) 50%,
            rgba(0, 0, 0, 0.3) 60%,
            rgba(0, 0, 0, 0.15) 70%,
            rgba(0, 0, 0, 0.05) 80%,
            transparent 90%);
    -webkit-mask-image: linear-gradient(to top,
            rgba(0, 0, 0, 0.5) 0%,
            rgba(0, 0, 0, 0.6) 10%,
            rgba(0, 0, 0, 0.7) 20%,
            rgba(0, 0, 0, 0.75) 30%,
            rgba(0, 0, 0, 0.65) 40%,
            rgba(0, 0, 0, 0.5) 50%,
            rgba(0, 0, 0, 0.3) 60%,
            rgba(0, 0, 0, 0.15) 70%,
            rgba(0, 0, 0, 0.05) 80%,
            transparent 90%);
    transition: opacity 0.5s ease;
}

body.light-mode #bg-image {
    opacity: 0.7;
    /* ライトモードでは色をしっかり見せる */
    filter: none;
    /* ダークモードのgrayscaleをリセット - 元の美しいパステルカラーを表示 */
    /* ライトモードではマスクを外してくっきり表示 */
    mask-image: none;
    -webkit-mask-image: none;
}

/* Sidebar (Drawer) */
#sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 300px;
    height: 100%;
    background-color: rgba(30, 30, 30, 0.25);
    backdrop-filter: blur(6px);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

#sidebar.open {
    transform: translateX(0);
}

body.sidebar-pinned #sidebar {
    position: fixed;
    transform: translateX(0);
    box-shadow: none;
}

#sidebar-header {
    padding: 20px;
    padding-top: 60px;
    /* Extra top padding to avoid overlap with floating menu button */
    font-size: 1.2rem;
    font-weight: bold;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    /* Space between left empty area and right buttons */
    align-items: center;
    min-height: 60px;
    /* Ensure header has enough height */
    position: relative;
    z-index: 1;
}

/* Ensure buttons in sidebar header are visible */
#sidebar-header .tool-btn {
    min-width: 32px;
    height: 32px;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#sidebar-header .tool-btn svg {
    width: 16px;
    height: 16px;
}

#search-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-bottom: 1px solid #333;
}

#search-bar.hidden {
    display: none;
}

#search-input {
    flex: 1;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    color: inherit;
    font: inherit;
}

#search-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.25);
}

body.light-mode #search-bar {
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

body.light-mode #search-input {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.08);
}

#btn-clear-search {
    min-width: 28px;
    height: 28px;
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: inherit;
    cursor: pointer;
    font: inherit;
}

#btn-clear-search:hover,
#btn-clear-search:focus-visible {
    border-color: rgba(255, 255, 255, 0.2);
}

body.light-mode #btn-clear-search {
    border-color: rgba(0, 0, 0, 0.08);
    background: rgba(0, 0, 0, 0.03);
}

#note-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    margin: 0;
    list-style: none;
}

.sidebar-footnote,
#sidebar-footer-links {
    padding: 8px 14px 12px;
    font-size: 11px;
    color: #777;
    font-family: "Helvetica Neue", Arial, system-ui, -apple-system, sans-serif;
    border-top: 1px solid #333;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 0.01em;
}

#sidebar-footer-links a,
#sidebar-footer-links button {
    color: inherit;
    text-decoration: none;
    opacity: 0.75;
    transition: opacity 0.2s ease, color 0.2s ease;
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    cursor: pointer;
}

#sidebar-footer-links a:hover,
#sidebar-footer-links a:focus-visible,
#sidebar-footer-links button:hover,
#sidebar-footer-links button:focus-visible {
    opacity: 1;
    text-decoration: underline;
}

body.light-mode #sidebar-footer-links {
    color: #555;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

/* Help modal */
#help-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 4000;
}

#help-modal[aria-hidden="true"],
#help-modal[hidden] {
    display: none;
}

#help-modal.active {
    display: flex;
}

#help-modal .help-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
}

#help-modal .help-dialog {
    position: relative;
    width: min(900px, 92vw);
    max-height: 86vh;
    overflow: hidden;
    background: rgba(18, 18, 20, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
    border-radius: 18px;
    padding: 20px 20px 14px;
    color: #e6e6e6;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

body.light-mode #help-modal .help-dialog {
    background: rgba(255, 255, 255, 0.94);
    color: #222;
    border-color: rgba(0, 0, 0, 0.06);
}

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

#help-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.help-sub {
    font-size: 0.82rem;
    color: #9aa0aa;
}

body.light-mode .help-sub {
    color: #555;
}

#btn-close-help {
    min-width: 32px;
    height: 32px;
    padding: 6px;
}

.help-body {
    overflow-y: auto;
    padding-right: 4px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.help-body .help-intro {
    grid-column: 1 / -1;
    font-size: 13.5px;
    line-height: 1.7;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
    border-radius: 10px;
    padding: 12px;
}

.help-body section {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 12px;
    font-size: 13px;
    line-height: 1.65;
}

.help-body section h2 {
    margin: 0 0 8px;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    color: inherit;
}

.help-body ul {
    padding-left: 16px;
    margin: 0;
    list-style: disc;
}

.help-body li {
    margin-bottom: 4px;
}

.help-body table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    margin: 4px 0 6px;
}

.help-body th,
.help-body td {
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 6px 8px;
    text-align: left;
}

.help-body th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
}

.help-body .muted {
    color: #8f95a3;
    margin: 6px 0 0;
    font-size: 12px;
}

body.light-mode .help-body section {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.07);
}

body.light-mode .help-body .help-intro {
    border-color: rgba(0, 0, 0, 0.07);
    background: rgba(0, 0, 0, 0.02);
}

body.light-mode .help-body th,
body.light-mode .help-body td {
    border-color: rgba(0, 0, 0, 0.07);
}

body.light-mode .help-body th {
    background: rgba(0, 0, 0, 0.04);
}

body.light-mode .help-body .muted {
    color: #555;
}

@media (max-width: 640px) {
    #help-modal .help-dialog {
        padding: 16px 14px 12px;
        gap: 8px;
    }
    .help-body {
        grid-template-columns: 1fr;
    }
}

.note-item {
    padding: 15px 20px;
    border-bottom: 1px solid #333;
    cursor: pointer;
    transition: background-color 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    display: flex;
    /* Flex layout for delete btn */
    justify-content: space-between;
    align-items: center;
}

.note-item:hover {
    background-color: #333;
}

.note-item.note-removing {
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.note-actions {
    display: flex;
    gap: 5px;
}

.note-action-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1;
    transition: color 0.2s;
}

.note-action-btn:hover {
    color: #ff4444;
    background-color: rgba(255, 68, 68, 0.1);
}

.note-action-btn.restore:hover {
    color: #44ff44;
    background-color: rgba(68, 255, 68, 0.1);
}

.note-action-btn.favorite {
    color: #666;
}

.note-action-btn.favorite:hover {
    color: #ffd700;
    background-color: rgba(255, 215, 0, 0.1);
}

.note-action-btn.favorite.favorite-active {
    color: #ffd700;
}

.note-action-btn.favorite.favorite-active:hover {
    color: #ffed4e;
    background-color: rgba(255, 215, 0, 0.2);
}

body.light-mode .note-action-btn.favorite {
    color: #999;
}

body.light-mode .note-action-btn.favorite:hover {
    color: #ffb300;
    background-color: rgba(255, 179, 0, 0.1);
}

body.light-mode .note-action-btn.favorite.favorite-active {
    color: #ffb300;
}

body.light-mode .note-action-btn.favorite.favorite-active:hover {
    color: #ffc933;
    background-color: rgba(255, 179, 0, 0.2);
}

.note-item.active {
    background-color: #2a4050;
    /* Active note highlight */
    border-left: 4px solid #a8d5e2;
}

.note-title {
    font-size: 1rem;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: bold;
}

.note-meta {
    font-size: 0.8rem;
    color: #888;
    display: flex;
    justify-content: space-between;
}

.note-fav-icon {
    color: #ffd700;
    display: none;
}

.note-item.favorite .note-fav-icon {
    display: inline;
}

/* Overlay for Sidebar */
#sidebar-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Keep overlay off the sidebar area on desktop so the panel doesn't darken */
body.sidebar-open #sidebar-overlay {
    left: 300px;
    width: calc(100% - 300px);
}

body.sidebar-pinned #sidebar-overlay {
    opacity: 0 !important;
    pointer-events: none !important;
}

body.sidebar-pinned #btn-floating-menu {
    display: none !important;
}

body.sidebar-pinned #editor-container,
body.sidebar-pinned #toolbar {
    margin-left: 300px;
}

body.sidebar-pinned #toolbar #toolbar {
    margin-left: 0;
}

@media (max-width: 900px) {
    body.sidebar-pinned #editor-container,
    body.sidebar-pinned #toolbar {
        margin-left: 0;
    }
    body.sidebar-pinned #sidebar {
        position: absolute;
    }
    body.sidebar-open #sidebar-overlay {
        left: 0;
        width: 100%;
    }
}

/* Editor Container */
#editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    /* Scroll handled by scroll-area */
    display: flex;
    justify-content: center;
    /* Center the editor */
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
}

#editor-container.fade-in {
    animation: fadeIn 0.4s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#editor-scroll-area {
    position: relative;
    width: 100%;
    max-width: 820px;
    height: 100%;
    margin: 0 auto;
    overflow-y: auto;
    overflow-x: hidden;
    /* パディングを削除 - #editorと#highlight-layerに設定 */
    padding: 0;
    box-sizing: border-box;
}

#editor-scroll-area::-webkit-scrollbar {
    width: 4px;
    background-color: transparent;
}

#editor-scroll-area::-webkit-scrollbar-track {
    background-color: transparent;
}

#editor-scroll-area::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0);
    /* Explicitly transparent */
    border-radius: 2px;
    transition: background-color 0.3s ease;
}

/* Show scrollbar when scrolling */
#editor-scroll-area.scrolling::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
}

body.light-mode #editor-scroll-area.scrolling::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
}

#note-list {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

#note-list::-webkit-scrollbar {
    width: 4px;
    background-color: transparent;
}

#note-list::-webkit-scrollbar-track {
    background-color: transparent;
}

#note-list::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0);
    border-radius: 2px;
    transition: background-color 0.3s ease;
}

#note-list.scrolling {
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

#note-list.scrolling::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
}

body.light-mode #note-list.scrolling {
    scrollbar-color: rgba(0, 0, 0, 0.1) transparent;
}

body.light-mode #note-list.scrolling::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
}

/* Editor Layers */
.editor-layer {
    width: 100%;
    min-height: 100%;
    /* Ensure it fills scroll area */
    font-size: var(--font-size);
    /* Slightly smaller */
    line-height: var(--line-height);
    /* Relaxed line height */
    border: none;
    outline: none;
    background: transparent;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    font-family: inherit;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

#editor {
    color: transparent;
    /* Hide text color for overlay */
    caret-color: #a8d5e2;
    /* Custom caret color */
    position: relative;
    z-index: 2;
    resize: none;
    overflow: hidden;
    /* パディングを設定 - #highlight-layerと同じ */
    padding: var(--editor-pad-top) var(--editor-pad-side) var(--editor-pad-bottom) var(--editor-pad-side);
    margin: 0;
    box-sizing: border-box;
    width: 100%;
    /* Font properties are inherited from .editor-layer */
}

#highlight-layer {
    position: absolute;
    /* #editorの上に重ねる - 同じ位置に配置 */
    top: 0;
    left: 0;
    z-index: 1;
    pointer-events: none;
    color: #e0e0e0;
    /* Text color */
    /* #editorと同じパディングを設定 */
    padding: var(--editor-pad-top) var(--editor-pad-side) var(--editor-pad-bottom) var(--editor-pad-side);
    margin: 0;
    box-sizing: border-box;
    /* Font properties are inherited from .editor-layer */
    width: 100%;
    /* Ensure same font rendering */
    font-size: inherit;
    line-height: inherit;
    font-family: inherit;
    white-space: inherit;
    word-wrap: inherit;
    overflow-wrap: inherit;
    word-break: inherit;
}

/* タッチデバイス時: Textwell風カーソル追従機能のため、タッチイベントを有効化 */
/* マウス操作ではカーソルは追従しない（JavaScript側でタッチイベントのみ処理） */
@media (hover: none) and (pointer: coarse) {
    #highlight-layer {
        pointer-events: auto;
        /* タッチイベントを有効化して、なぞり操作でカーソルを移動できるようにする */
    }
}

.touch-device #highlight-layer {
    pointer-events: auto;
}

/* Light Mode Overrides */
body.light-mode {
    /* Background gradient is set in body.light-mode above */
    color: #333;
}

body.light-mode #sidebar {
    background-color: rgba(240, 240, 240, 0.25);
    backdrop-filter: blur(6px);
    border-right: 1px solid #ccc;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

body.light-mode #sidebar-header {
    border-bottom: 1px solid #ddd;
    color: #333;
}

body.light-mode .note-item {
    border-bottom: 1px solid #ddd;
}

body.light-mode .note-item:hover {
    background-color: #e0e0e0;
}

body.light-mode .note-item.active {
    background-color: #d0e0f0;
    border-left-color: #007aff;
}

body.light-mode #highlight-layer {
    color: #333;
}

body.light-mode #editor {
    caret-color: #007aff;
}

/* Toolbar */
#toolbar {
    height: 50px;
    /* Smaller toolbar */
    background-color: rgba(30, 30, 30, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    padding: 0 10px;
    gap: 2px;
    /* Tighter gap */
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    overflow-x: auto;
    overflow-y: hidden;
    /* Enhanced scrolling for mobile */
    -webkit-overflow-scrolling: touch;
    /* Touch action: allow horizontal scrolling and pinch zoom */
    touch-action: pan-x pinch-zoom;
    /* Improved scrollbar visibility */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
    /* Prevent flex items from shrinking */
    flex-wrap: nowrap;
}

/* Custom scrollbar for toolbar (WebKit browsers) */
#toolbar::-webkit-scrollbar {
    height: 4px;
}

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

#toolbar::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    transition: background-color 0.2s ease;
}

#toolbar::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

body.light-mode #toolbar {
    background-color: rgba(255, 255, 255, 0.9);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
}

body.light-mode #toolbar::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.3);
}

body.light-mode #toolbar::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.5);
}

.tool-btn {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    min-width: 36px;
    /* Smaller buttons */
    height: 36px;
    /* Prevent buttons from shrinking to maintain scrollability */
    flex-shrink: 0;
    flex-grow: 0;
    /* touch-action は削除 - 親要素（ツールバー）の pan-x に任せる */
    /* これにより、ボタン上でのスクロールがツールバーのスクロールとして処理される */
}

.tool-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

body.light-mode .tool-btn {
    color: #666;
}

body.light-mode .tool-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: #000;
}

.tool-btn.active {
    color: #a8d5e2;
    background-color: rgba(168, 213, 226, 0.1);
}

body.light-mode .tool-btn.active {
    color: #007aff;
    background-color: rgba(0, 122, 255, 0.1);
}

/* Pin Sidebar Button - Active state matches # button color */
#btn-pin-sidebar.active {
    color: #5dade2 !important;
    /* Light blue (cyan) for dark mode - same as # button */
    background-color: rgba(93, 173, 226, 0.1) !important;
}

body.light-mode #btn-pin-sidebar.active {
    color: #dc3545 !important;
    /* Red for light mode - same as # button */
    background-color: rgba(220, 53, 69, 0.1) !important;
}

.tool-btn.favorite-active {
    color: #ffd700 !important;
}

/* BGM Button Color States */
#btn-bgm {
    color: #888;
    /* Gray when off */
}

#btn-bgm.active {
    color: #a8d5e2;
    /* Light blue when on (dark mode) */
}

body.light-mode #btn-bgm {
    color: #999;
    /* Lighter gray when off (light mode) */
}

body.light-mode #btn-bgm.active {
    color: #007aff;
    /* Blue when on (light mode) */
}

.tool-btn svg {
    width: 18px;
    /* Smaller icons */
    height: 18px;
    fill: currentColor;
}

.tool-btn span {
    font-size: 14px;
    font-weight: bold;
}

.separator {
    width: 1px;
    height: 20px;
    background-color: rgba(255, 255, 255, 0.2);
    margin: 0 4px;
    flex-shrink: 0;
    flex-grow: 0;
}

body.light-mode .separator {
    background-color: rgba(0, 0, 0, 0.1);
}

/* Toast */
#toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 2000;
}

body.light-mode #toast {
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#char-count-indicator {
    position: fixed;
    left: 50%;
    bottom: 62px;
    transform: translateX(-50%) translateY(8px);
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.35);
    color: var(--text-color);
    font-size: 12px;
    letter-spacing: 0.02em;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 1500;
    backdrop-filter: blur(8px);
}

#char-count-indicator.visible {
    opacity: 0.75;
    transform: translateX(-50%) translateY(0);
}

body.light-mode #char-count-indicator {
    background: rgba(255, 255, 255, 0.65);
    color: #333;
}

/* Markdown Styles - Restored */
.md-bold {
    font-weight: normal;
    color: #5dade2;
    /* Light blue (cyan) for dark mode - same color as markers */
}

body.light-mode .md-bold {
    color: #dc3545;
    /* Red matching browser spellcheck underline color for light mode */
}

.md-heading {
    display: inline;
    font-weight: normal;
    text-decoration-line: underline;
    text-decoration-style: solid;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.15em;
}

.md-bullet {
    color: #5dade2;
    /* Light blue (cyan) for dark mode */
}

body.light-mode .md-bullet {
    color: #dc3545;
    /* Red matching browser spellcheck underline color for light mode */
}

.md-mark {
    color: #5dade2;
    /* Light blue (cyan) for dark mode - for markdown symbols like #, ** */
}

body.light-mode .md-mark {
    color: #dc3545;
    /* Red matching browser spellcheck underline color for light mode */
}

.md-quote {
    font-weight: normal;
    color: #5dade2;
    /* Light blue (cyan) for dark mode - same color as bold */
}

body.light-mode .md-quote {
    color: #dc3545;
    /* Red matching browser spellcheck underline color for light mode */
}

/* Font Styles - keep editor and highlight perfectly aligned */
.font-gothic .editor-layer {
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    line-height: 2.0;
    /* Same line height as Mincho */
}

/* Floating Menu Button */
#btn-floating-menu {
    position: fixed;
    top: 15px;
    left: 20px;
    z-index: 1500;
    /* Above editor, below overlay/toast */
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.3);
    /* Faint */
    cursor: pointer;
    padding: 5px;
    transition: color 0.3s ease;
}

#btn-floating-menu:hover {
    color: rgba(255, 255, 255, 0.9);
}

body.light-mode #btn-floating-menu {
    color: rgba(0, 0, 0, 0.3);
}

body.light-mode #btn-floating-menu:hover {
    color: rgba(0, 0, 0, 0.9);
}

#btn-floating-menu svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* ========================================
   Mobile Responsive Styles
   ======================================== */

/* Tablet: 768px and below */
@media (max-width: 768px) {

    /* Sidebar: Overlay style for mobile */
    #sidebar {
        width: 280px;
        z-index: 2000;
        /* Above overlay */
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    }

    /* Editor adjustments */
    #editor-scroll-area {
        padding: 0;
        max-width: 100%;
        overflow-x: hidden;
        /* Prevent horizontal scrolling */
    }

    #editor,
    #highlight-layer {
        padding: 70px 28px 120px 28px;
    }

    .editor-layer {
        font-size: 16px;
        /* Slightly smaller font for mobile */
        line-height: 1.9;
        overflow-wrap: break-word;
        word-break: break-word;
        max-width: 100%;
    }

    /* Floating menu button - ensure it's visible on mobile */
    #btn-floating-menu {
        display: block !important;
        /* Explicitly show on mobile */
        z-index: 1500;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }

    /* Hide floating menu button when sidebar is open on mobile */
    body.sidebar-open #btn-floating-menu {
        display: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
}

/* Mobile: 480px and below */
@media (max-width: 480px) {

    /* Sidebar: Full width on small screens */
    #sidebar {
        width: 100%;
        max-width: 320px;
        /* Max width to prevent too wide */
    }

    #sidebar-header {
        padding: 15px;
        padding-top: 50px;
        /* Less top padding on mobile */
        font-size: 1rem;
        min-height: 50px;
    }

    /* Editor adjustments for small screens */
    #editor-scroll-area {
        padding: 0;
        overflow-x: hidden;
        /* Prevent horizontal scrolling */
    }

    #editor,
    #highlight-layer {
        padding: 80px 24px 120px 24px;
    }

    .editor-layer {
        font-size: 16px;
        line-height: 1.8;
        overflow-wrap: break-word;
        word-break: break-word;
        max-width: 100%;
    }

    /* Note items - smaller padding */
    .note-item {
        padding: 12px 15px;
    }

    .note-title {
        font-size: 0.9rem;
    }

    .note-meta {
        font-size: 0.75rem;
    }

    /* Floating menu button - position adjustment */
    #btn-floating-menu {
        top: 10px;
        left: 10px;
    }

    #btn-floating-menu svg {
        width: 28px;
        height: 28px;
        /* Slightly larger for easier tapping */
    }

    /* Toolbar adjustments */
    #toolbar {
        height: 50px;
        padding: 0 8px;
        gap: 1px;
        /* Enhanced scrolling for mobile */
        -webkit-overflow-scrolling: touch;
        /* Ensure flex items don't shrink and maintain scrollability */
        flex-wrap: nowrap;
    }

    .tool-btn {
        min-width: 38px;
        height: 38px;
        padding: 6px;
    }

    .tool-btn svg {
        width: 20px;
        height: 20px;
    }
}

/* Ensure sidebar overlay is visible on mobile when open */
@media (max-width: 768px) {
    #sidebar-overlay.visible {
        z-index: 1900;
        /* Below sidebar but above everything else */
    }

    /* Prevent body scroll when sidebar is open on mobile */
    body.sidebar-open {
        overflow: hidden;
    }
}

/* Auth Section Styles */
#auth-section {
    background-color: rgba(0, 0, 0, 0.2);
}

#auth-login button,
#auth-status button {
    border: 1px solid var(--button-text);
    border-radius: 4px;
    transition: all 0.2s ease;
}

#auth-login button:hover,
#auth-status button:hover {
    background-color: var(--button-hover);
    border-color: var(--button-text-active);
}

#user-avatar {
    flex-shrink: 0;
}

#sync-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

#sync-indicator {
    font-size: 8px;
    transition: color 0.3s ease;
}

#sync-indicator.syncing {
    animation: syncPulse 1s ease-in-out infinite;
}

@keyframes syncPulse {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.3);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 0.6;
    }
}

body.light-mode #auth-section {
    background-color: rgba(255, 255, 255, 0.2);
}
