/* ============================================
   EasyNote - Zen-iOS Hybrid Design System
   ============================================ */

/* === Font Face Declarations === */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../fonts/Inter-Regular.ttf') format('truetype');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('../fonts/Inter-Medium.ttf') format('truetype');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('../fonts/Inter-SemiBold.ttf') format('truetype');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../fonts/Inter-Bold.ttf') format('truetype');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 800;
    font-display: swap;
    src: url('../fonts/Inter-ExtraBold.ttf') format('truetype');
}

/* === CSS Variables === */
:root {
    --bg-base: #F2F2F7;
    --bg-base-alt: #F9F9FB;
    --bg-white: rgba(255, 255, 255, 0.55);
    --bg-white-hover: rgba(255, 255, 255, 0.75);
    --bg-inset: rgba(242, 242, 247, 0.5);
    --border-inner: rgba(255, 255, 255, 0.6);
    --border-outer: rgba(229, 229, 234, 0.4);
    --border-focus: rgba(0, 0, 0, 0.15);
    --shadow-float: 0 24px 48px -12px rgba(0, 0, 0, 0.08);
    --shadow-soft: 0 8px 24px -4px rgba(0, 0, 0, 0.06);
    --shadow-subtle: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-inset: inset 0 2px 4px rgba(0, 0, 0, 0.06);
    --color-primary: #1C1C1E;
    --color-primary-hover: #2C2C2E;
    --color-text: #1C1C1E;
    --color-text-secondary: #636366;
    --color-text-tertiary: #5C5C60;
    --color-success: #34C759;
    --color-warning: #FF9500;
    --color-danger: #FF3B30;
    --radius-xl: 50px;
    --radius-lg: 28px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --blur-heavy: blur(50px);
    --blur-medium: blur(30px);
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* === Dark Theme Variables === */
[data-theme="dark"] {
    --bg-base: #1C1C1E;
    --bg-base-alt: #2C2C2E;
    --bg-white: rgba(44, 44, 46, 0.65);
    --bg-white-hover: rgba(58, 58, 60, 0.75);
    --bg-inset: rgba(28, 28, 30, 0.5);
    --border-inner: rgba(58, 58, 60, 0.6);
    --border-outer: rgba(68, 68, 70, 0.4);
    --border-focus: rgba(255, 255, 255, 0.2);
    --shadow-float: 0 24px 48px -12px rgba(0, 0, 0, 0.3);
    --shadow-soft: 0 8px 24px -4px rgba(0, 0, 0, 0.25);
    --shadow-subtle: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-inset: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    --color-primary: #F5F5F7;
    --color-primary-hover: #E5E5EA;
    --color-text: #F5F5F7;
    --color-text-secondary: #A1A1A6;
    --color-text-tertiary: #8E8E93;
    --color-success: #30D158;
    --color-warning: #FFD60A;
    --color-danger: #FF453A;
}

/* === Reset & Base === */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100%;
    height: 100dvh;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-base);
    color: var(--color-text);
    height: 100%;
    line-height: 1.6;
    overflow: hidden;
}

/* Subtle animated gradient on body */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 30% 20%, rgba(120, 120, 255, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(255, 120, 120, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(120, 255, 180, 0.02) 0%, transparent 60%);
    z-index: -1;
    animation: bgShift 20s ease-in-out infinite alternate;
    will-change: transform;
}

[data-theme="dark"] body::before {
    background: radial-gradient(ellipse at 30% 20%, rgba(80, 80, 200, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(200, 80, 80, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(80, 200, 140, 0.03) 0%, transparent 60%);
}

@keyframes bgShift {
    0% {
        transform: translate(0, 0) rotate(0deg);
    }

    100% {
        transform: translate(-2%, -2%) rotate(3deg);
    }
}

/* === Glass Panel === */
.glass-panel {
    background: var(--bg-white);
    backdrop-filter: var(--blur-heavy);
    -webkit-backdrop-filter: var(--blur-heavy);
    border: 1px solid var(--border-inner);
    box-shadow: var(--shadow-float), inset 0 1px 0 rgba(255, 255, 255, 0.5);
    position: relative;
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.glass-panel::after {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    border: 1px solid var(--border-outer);
    pointer-events: none;
}

/* ============================
   HOME PAGE
   ============================ */
.home-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 24px;
    overflow: hidden;
}

.home-card {
    width: 100%;
    max-width: 520px;
    padding: 48px 40px;
    border-radius: var(--radius-xl);
    text-align: center;
    animation: cardIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
    position: relative;
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.home-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: var(--radius-lg);
    background: var(--bg-base);
    box-shadow: var(--shadow-inset);
    margin-bottom: 24px;
    color: var(--color-text-secondary);
}

.home-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--color-text);
    margin-bottom: 8px;
}

.home-subtitle {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--color-text-tertiary);
    margin-bottom: 20px;
}

.home-desc {
    font-size: 14px;
    color: var(--color-text-secondary);
    line-height: 1.6;
    margin-bottom: 32px;
    max-width: 380px;
    margin-left: auto;
    margin-right: auto;
}

.home-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 32px;
}

.input-group {
    display: flex;
    align-items: center;
    background: var(--bg-base);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-inset);
    padding: 4px;
    border: 1px solid transparent;
    transition: var(--transition);
}

.input-group:focus-within {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-inset), 0 0 0 4px rgba(0, 0, 0, 0.04);
}

.input-prefix {
    font-size: 13px;
    color: var(--color-text-tertiary);
    padding: 12px 2px 12px 16px;
    white-space: nowrap;
    font-weight: 500;
    user-select: none;
}

.note-name-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
    padding: 12px 16px 12px 0;
    outline: none;
    min-width: 0;
}

.note-name-input::placeholder {
    color: var(--color-text-tertiary);
    font-weight: 400;
}

/* === Buttons === */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    user-select: none;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: scale(0.97) translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: white;
    color: var(--color-text);
    border: 1px solid var(--border-outer);
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-subtle);
    user-select: none;
}

.btn-secondary:hover {
    background: var(--bg-base-alt);
    box-shadow: var(--shadow-soft);
}

.btn-secondary:active {
    transform: scale(0.97);
}

.btn-sm {
    padding: 10px 20px;
    font-size: 13px;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    position: relative;
}

.btn-icon:hover {
    background: var(--bg-white-hover);
    border-color: var(--border-outer);
    color: var(--color-text);
    box-shadow: var(--shadow-subtle);
}

.btn-icon:active {
    transform: scale(0.92);
}

.btn-icon.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* Dark mode: no border when inactive, visible border when active */
[data-theme="dark"] .btn-icon {
    border-color: transparent;
}

[data-theme="dark"] .btn-icon.active {
    border-color: var(--color-primary);
}

/* === Language Toggle Button (Home) === */
/* Home page actions bar */
.home-actions {
    position: absolute;
    top: 20px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
}

.btn-lang {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 14px;
    box-sizing: border-box;
    border-radius: 20px;
    background: var(--bg-base);
    box-shadow: var(--shadow-inset);
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: var(--transition);
}

.btn-lang:hover {
    color: var(--color-text);
    background: var(--bg-white-hover);
    box-shadow: var(--shadow-subtle);
}

.btn-lang:active {
    transform: scale(0.95);
}

/* Language Toggle Button (Editor header) */
.lang-flag {
    width: 20px;
    height: 14px;
    border-radius: 2px;
    object-fit: cover;
    display: block;
}

.btn-lang-editor {
    text-decoration: none;
}

/* Hints Container */
.home-hints-container {
    display: inline-flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 auto;
    align-items: stretch;
    text-align: left;
}

.hint-block {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 20px;
    background: var(--bg-base);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-inset);
}

.label-industrial {
    display: inline-block;
    width: 32px;
    text-align: center;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: white;
    background: var(--color-primary);
    padding: 3px 0;
    border-radius: 6px;
    flex-shrink: 0;
}

.label-secondary {
    background: var(--color-text-tertiary);
}

.hint-block code {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.hint-text {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
}

/* Random Icon in Input */
.btn-input-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-xs);
    color: var(--color-text-tertiary);
    font-size: 20px;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    text-decoration: none;
    transition: var(--transition);
    flex-shrink: 0;
    margin-right: 4px;
}

.btn-input-icon:hover {
    color: var(--color-text);
    background: rgba(255, 255, 255, 0.6);
}

.btn-input-icon:active {
    transform: scale(0.9);
}

/* ============================
   NOTE EDITOR PAGE
   ============================ */
.note-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 16px;
    gap: 12px;
    max-width: 960px;
    margin: 0 auto;
    animation: fadeIn 0.4s ease both;
    overflow: hidden;
}

.editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* === Header === */
.note-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    gap: 12px;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.logo-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    transition: var(--transition);
    text-decoration: none;
    flex-shrink: 0;
}

.logo-link:hover {
    color: var(--color-text);
    background: var(--bg-base);
}

.logo-link:active {
    transform: scale(0.92);
}

.note-name-display {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* === Save Status === */
.save-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--color-text-tertiary);
    transition: var(--transition);
    white-space: nowrap;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-tertiary);
    transition: var(--transition);
}

.save-status.saving .status-dot {
    background: var(--color-warning);
    animation: pulse 1s ease-in-out infinite;
}

.save-status.saved .status-dot {
    background: var(--color-success);
}

.save-status.error .status-dot {
    background: var(--color-danger);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

/* === Editor === */
.editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 0;
    box-shadow: none;
    border: none;
}

.editor-wrapper::after {
    display: none;
}

.editor {
    flex: 1;
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    padding: 28px 32px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.7;
    color: var(--color-text);
    background: transparent;
    tab-size: 4;
    -moz-tab-size: 4;
    height: 100%;
    overflow-y: auto;
}

.editor::placeholder {
    color: var(--color-text-tertiary);
    font-family: var(--font-family);
    font-style: normal;
}

.editor:focus {
    background: rgba(255, 255, 255, 0.15);
}

/* === Markdown Preview — macOS Premium === */
.markdown-preview {
    flex: 1;
    padding: 36px 40px;
    overflow-y: auto;
    height: 100%;
    font-family: var(--font-family);
    font-size: 15px;
    line-height: 1.85;
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
}

/* --- Headings --- */
.markdown-preview h1 {
    font-size: 2em;
    font-weight: 800;
    letter-spacing: -0.035em;
    margin: 0 0 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-outer);
    background: linear-gradient(135deg, var(--color-text) 0%, var(--color-text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.markdown-preview h2 {
    font-size: 1.55em;
    font-weight: 750;
    letter-spacing: -0.025em;
    margin: 32px 0 14px;
    color: var(--color-text);
    position: relative;
    padding-left: 14px;
}

.markdown-preview h2::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 4px;
    border-radius: 2px;
    background: linear-gradient(180deg, #007AFF, #5856D6);
}

.markdown-preview h3 {
    font-size: 1.2em;
    font-weight: 700;
    margin: 26px 0 10px;
    color: var(--color-text);
    position: relative;
    padding-left: 24px;
}

.markdown-preview h3::before {
    content: '#';
    position: absolute;
    left: 0;
    color: #007AFF;
    font-weight: 800;
    opacity: 0.5;
}

.markdown-preview h4 {
    font-size: 0.9em;
    font-weight: 700;
    margin: 22px 0 8px;
    color: var(--color-text-secondary);
    letter-spacing: 0.03em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.markdown-preview h4::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 2px;
    border-radius: 1px;
    background: linear-gradient(90deg, #007AFF, transparent);
    flex-shrink: 0;
}

/* --- Paragraphs & Text --- */
.markdown-preview p {
    margin: 0 0 16px;
    color: var(--color-text);
}

.markdown-preview strong {
    font-weight: 700;
    color: var(--color-text);
}

.markdown-preview em {
    font-style: italic;
    color: var(--color-text-secondary);
}

/* --- Lists --- */
.markdown-preview ul,
.markdown-preview ol {
    margin: 16px 0;
    padding-left: 24px;
}

.markdown-preview ul {
    list-style: none;
    padding-left: 20px;
}

.markdown-preview ul>li {
    position: relative;
    margin: 6px 0;
    padding-left: 4px;
}

.markdown-preview ul>li::before {
    content: '';
    position: absolute;
    left: -14px;
    top: 11px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007AFF, #5856D6);
}

.markdown-preview ol>li {
    margin: 6px 0;
}

.markdown-preview li>ul,
.markdown-preview li>ol {
    margin: 4px 0 4px;
}

/* Task list checkboxes */
.markdown-preview li input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-outer);
    border-radius: 4px;
    vertical-align: middle;
    margin-right: 8px;
    margin-top: -2px;
    position: relative;
    cursor: default;
    transition: var(--transition);
}

.markdown-preview li input[type="checkbox"]:checked {
    background: linear-gradient(135deg, #007AFF, #5856D6);
    border-color: transparent;
}

.markdown-preview li input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* --- Inline Code --- */
.markdown-preview code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85em;
    background: rgba(0, 0, 0, 0.04);
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    color: #e83e8c;
}

[data-theme="dark"] .markdown-preview :not(pre) > code {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
    color: #f694c1;
    font-weight: 500;
    white-space: nowrap;
}

/* --- Code Blocks --- */
.markdown-preview pre {
    position: relative;
    background: #1E1E2E;
    border-radius: 8px;
    padding: 0;
    margin: 16px 0;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.markdown-preview pre::before {
    content: '';
    display: block;
    height: 38px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.markdown-preview pre::after {
    content: '';
    position: absolute;
    top: 14px;
    left: 16px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #FF5F57;
    box-shadow: 18px 0 0 #FEBC2E, 36px 0 0 #28C840;
}

.markdown-preview pre code {
    display: block;
    background: none;
    padding: 20px 24px;
    border: none;
    box-shadow: none;
    font-size: 13px;
    line-height: 1.7;
    color: #CDD6F4;
    overflow-x: auto;
    font-weight: 400;
    white-space: pre;
    -webkit-text-fill-color: initial;
    user-select: text;
    -webkit-user-select: text;
    cursor: text;
}

.markdown-preview pre code::selection,
.markdown-preview pre code *::selection {
    background: rgba(0, 122, 255, 0.35);
    color: #fff;
}

/* Copy button for code blocks */
.markdown-preview pre .code-copy-btn {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 2;
    font-size: 0;
}

.markdown-preview pre:hover .code-copy-btn {
    opacity: 1;
}

.markdown-preview pre .code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.8);
    border-color: rgba(255, 255, 255, 0.2);
}

.markdown-preview pre .code-copy-btn:active {
    transform: scale(0.9);
}

.markdown-preview pre .code-copy-btn.copied {
    color: #28C840;
    border-color: rgba(40, 200, 64, 0.3);
    background: rgba(40, 200, 64, 0.1);
}

/* --- Blockquotes --- */
.markdown-preview blockquote {
    position: relative;
    border-left: none;
    padding: 16px 20px 16px 24px;
    margin: 16px 0;
    background: rgba(0, 122, 255, 0.04);
    border-radius: 8px;
    color: var(--color-text-secondary);
    overflow: hidden;
}

.markdown-preview blockquote::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    border-radius: 2px;
    background: linear-gradient(180deg, #007AFF, #5856D6);
}

.markdown-preview blockquote p {
    margin: 0;
    color: var(--color-text-secondary);
}

.markdown-preview blockquote p+p {
    margin-top: 8px;
}

/* Nested blockquotes */
.markdown-preview blockquote blockquote {
    margin: 12px 0 0;
    background: rgba(0, 122, 255, 0.06);
}

/* --- Links --- */
.markdown-preview a {
    color: #007AFF;
    text-decoration: none;
    font-weight: 500;
    background: linear-gradient(transparent 92%, rgba(0, 122, 255, 0.25) 92%);
    transition: all 0.2s ease;
}

.markdown-preview a:hover {
    background: linear-gradient(transparent 85%, rgba(0, 122, 255, 0.35) 85%);
    text-decoration: none;
}

/* --- Images --- */
.markdown-preview img {
    max-width: 100%;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-outer);
    transition: var(--transition);
}

.markdown-preview img:hover {
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12);
    transform: scale(1.005);
}

/* --- Tables --- */
.markdown-preview table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0 0 20px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-outer);
    box-shadow: var(--shadow-subtle);
}

.markdown-preview th,
.markdown-preview td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-outer);
}

.markdown-preview th {
    background: var(--bg-base);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-secondary);
}

.markdown-preview td {
    font-size: 14px;
}

.markdown-preview tr:last-child td {
    border-bottom: none;
}

.markdown-preview tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.015);
}

[data-theme="dark"] .markdown-preview tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.markdown-preview tbody tr:hover {
    background: rgba(0, 122, 255, 0.03);
}

/* --- Horizontal Rule --- */
.markdown-preview hr {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--border-outer) 20%, var(--border-outer) 80%, transparent);
    margin: 32px 0;
}

/* --- Mermaid Diagrams --- */
.markdown-preview .mermaid {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0;
    padding: 24px 16px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-outer);
    overflow-x: auto;
}

.markdown-preview .mermaid svg {
    max-width: 100%;
    height: auto;
}

/* Gantt chart: allow wider SVG with horizontal scroll */
.markdown-preview .mermaid.mermaid-gantt {
    justify-content: flex-start;
}
.markdown-preview .mermaid.mermaid-gantt svg {
    max-width: none;
    min-width: 900px;
}

/* Gantt: fix date label font size */
.markdown-preview .mermaid .grid .tick text {
    font-size: 11px;
}

/* Dark mode: container */
[data-theme="dark"] .markdown-preview .mermaid {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(68, 68, 70, 0.4);
}

/* ===== GLOBAL TEXT: ensure all SVG text is light in dark mode ===== */
[data-theme="dark"] .markdown-preview .mermaid text,
[data-theme="dark"] .markdown-preview .mermaid tspan,
[data-theme="dark"] .markdown-preview .mermaid .nodeLabel,
[data-theme="dark"] .markdown-preview .mermaid .label,
[data-theme="dark"] .markdown-preview .mermaid .edgeLabel,
[data-theme="dark"] .markdown-preview .mermaid .cluster-label {
    fill: #e0e0e0 !important;
    color: #e0e0e0 !important;
}

/* ===== GLOBAL LINES: arrows and edges ===== */
[data-theme="dark"] .markdown-preview .mermaid .edgePath .path,
[data-theme="dark"] .markdown-preview .mermaid .flowchart-link {
    stroke: #8e8e93 !important;
}
[data-theme="dark"] .markdown-preview .mermaid marker path {
    fill: #8e8e93 !important;
}

/* ===== FLOWCHART / GRAPH ===== */
[data-theme="dark"] .markdown-preview .mermaid .node rect,
[data-theme="dark"] .markdown-preview .mermaid .node polygon,
[data-theme="dark"] .markdown-preview .mermaid .node circle,
[data-theme="dark"] .markdown-preview .mermaid .node ellipse,
[data-theme="dark"] .markdown-preview .mermaid .node .label-container {
    fill: #3a3a3c !important;
    stroke: #636366 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .node .nodeLabel {
    color: #e0e0e0 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .cluster rect {
    fill: #2c2c2e !important;
    stroke: #48484a !important;
}
[data-theme="dark"] .markdown-preview .mermaid .cluster-label .nodeLabel {
    color: #e0e0e0 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .edgeLabel rect {
    fill: #2c2c2e !important;
    opacity: 0.9 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .edgeLabel span {
    color: #d1d1d6 !important;
    background: #2c2c2e !important;
}

/* ===== ER DIAGRAM ===== */
/* Entity header box */
[data-theme="dark"] .markdown-preview .mermaid .entityBox,
[data-theme="dark"] .markdown-preview .mermaid .er.entityBox,
[data-theme="dark"] .markdown-preview .mermaid rect.er.entityBox {
    fill: #3a3a3c !important;
    stroke: #636366 !important;
}
/* Entity name text */
[data-theme="dark"] .markdown-preview .mermaid .entityLabel,
[data-theme="dark"] .markdown-preview .mermaid .er.entityLabel,
[data-theme="dark"] .markdown-preview .mermaid text.er.entityLabel {
    fill: #ffffff !important;
    font-weight: 600 !important;
}
/* Attribute rows */
[data-theme="dark"] .markdown-preview .mermaid .attributeBoxOdd,
[data-theme="dark"] .markdown-preview .mermaid .er.attributeBoxOdd,
[data-theme="dark"] .markdown-preview .mermaid rect.er.attributeBoxOdd {
    fill: #2a2a2c !important;
}
[data-theme="dark"] .markdown-preview .mermaid .attributeBoxEven,
[data-theme="dark"] .markdown-preview .mermaid .er.attributeBoxEven,
[data-theme="dark"] .markdown-preview .mermaid rect.er.attributeBoxEven {
    fill: #333336 !important;
}
/* Attribute text */
[data-theme="dark"] .markdown-preview .mermaid .attributeLabel,
[data-theme="dark"] .markdown-preview .mermaid .er.attributeLabel,
[data-theme="dark"] .markdown-preview .mermaid text.er.attributeLabel {
    fill: #d1d1d6 !important;
}
/* Relationship lines and labels */
[data-theme="dark"] .markdown-preview .mermaid .er.relationshipLine,
[data-theme="dark"] .markdown-preview .mermaid .relationshipLine {
    stroke: #8e8e93 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .er.relationshipLabel,
[data-theme="dark"] .markdown-preview .mermaid .relationshipLabel {
    fill: #aeaeb2 !important;
}

/* ===== SEQUENCE DIAGRAM ===== */
[data-theme="dark"] .markdown-preview .mermaid .actor {
    fill: #3a3a3c !important;
    stroke: #636366 !important;
}
[data-theme="dark"] .markdown-preview .mermaid text.actor > tspan {
    fill: #e0e0e0 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .actor-line {
    stroke: #636366 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .messageLine0,
[data-theme="dark"] .markdown-preview .mermaid .messageLine1 {
    stroke: #8e8e93 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .messageText {
    fill: #e0e0e0 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .activation0,
[data-theme="dark"] .markdown-preview .mermaid .activation1,
[data-theme="dark"] .markdown-preview .mermaid .activation2 {
    fill: #48484a !important;
    stroke: #636366 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .loopText,
[data-theme="dark"] .markdown-preview .mermaid .loopText tspan {
    fill: #e0e0e0 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .labelText,
[data-theme="dark"] .markdown-preview .mermaid .labelText tspan {
    fill: #e0e0e0 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .loopLine {
    stroke: #636366 !important;
}
[data-theme="dark"] .markdown-preview .mermaid rect.note,
[data-theme="dark"] .markdown-preview .mermaid .note rect {
    fill: #3a3a3c !important;
    stroke: #636366 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .noteText,
[data-theme="dark"] .markdown-preview .mermaid .noteText tspan {
    fill: #e0e0e0 !important;
}
/* Sequence: rect backgrounds for labels */
[data-theme="dark"] .markdown-preview .mermaid .labelBox {
    fill: #2c2c2e !important;
    stroke: #636366 !important;
}

/* ===== GANTT CHART ===== */
/* Title */
[data-theme="dark"] .markdown-preview .mermaid .titleText {
    fill: #e0e0e0 !important;
}
/* Grid */
[data-theme="dark"] .markdown-preview .mermaid .grid .tick line {
    stroke: #48484a !important;
}
[data-theme="dark"] .markdown-preview .mermaid .grid .tick text {
    fill: #aeaeb2 !important;
}
/* Section backgrounds */
[data-theme="dark"] .markdown-preview .mermaid .section0 {
    fill: #2c2c2e !important;
}
[data-theme="dark"] .markdown-preview .mermaid .section1 {
    fill: #333336 !important;
}
/* Section titles (left labels) */
[data-theme="dark"] .markdown-preview .mermaid .sectionTitle,
[data-theme="dark"] .markdown-preview .mermaid .sectionTitle0,
[data-theme="dark"] .markdown-preview .mermaid .sectionTitle1,
[data-theme="dark"] .markdown-preview .mermaid .sectionTitle2,
[data-theme="dark"] .markdown-preview .mermaid .sectionTitle3 {
    fill: #e0e0e0 !important;
}
/* Task text (on bars and outside) */
[data-theme="dark"] .markdown-preview .mermaid .taskText,
[data-theme="dark"] .markdown-preview .mermaid .taskText0,
[data-theme="dark"] .markdown-preview .mermaid .taskText1,
[data-theme="dark"] .markdown-preview .mermaid .taskText2,
[data-theme="dark"] .markdown-preview .mermaid .taskText3 {
    fill: #ffffff !important;
}
[data-theme="dark"] .markdown-preview .mermaid .taskTextOutside0,
[data-theme="dark"] .markdown-preview .mermaid .taskTextOutside1,
[data-theme="dark"] .markdown-preview .mermaid .taskTextOutside2,
[data-theme="dark"] .markdown-preview .mermaid .taskTextOutside3,
[data-theme="dark"] .markdown-preview .mermaid .taskTextOutsideRight,
[data-theme="dark"] .markdown-preview .mermaid .taskTextOutsideLeft {
    fill: #e0e0e0 !important;
}
/* Gantt domain axis line */
[data-theme="dark"] .markdown-preview .mermaid .domain {
    stroke: #636366 !important;
}
/* Today marker */
[data-theme="dark"] .markdown-preview .mermaid .today {
    stroke: #FF9F0A !important;
}

/* ===== MINDMAP ===== */
[data-theme="dark"] .markdown-preview .mermaid .mindmap-node rect,
[data-theme="dark"] .markdown-preview .mermaid .mindmap-node circle,
[data-theme="dark"] .markdown-preview .mermaid .mindmap-node ellipse,
[data-theme="dark"] .markdown-preview .mermaid .mindmap-node polygon,
[data-theme="dark"] .markdown-preview .mermaid .mindmap-node path {
    stroke: #636366 !important;
}
[data-theme="dark"] .markdown-preview .mermaid .mindmap-node .nodeLabel {
    color: #e0e0e0 !important;
}
/* Mindmap edge lines */
[data-theme="dark"] .markdown-preview .mermaid .mindmap-edge {
    stroke: #8e8e93 !important;
}

/* --- KaTeX Math Formulas --- */
.markdown-preview .katex-display-wrapper {
    margin: 20px 0;
    padding: 16px;
    overflow-x: auto;
    overflow-y: hidden;
    text-align: center;
}

.markdown-preview .katex-display-wrapper .katex-display {
    margin: 0;
}

.markdown-preview .katex {
    font-size: 1.1em;
}

.markdown-preview .katex-error {
    color: var(--color-danger);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85em;
    padding: 4px 8px;
    background: rgba(255, 59, 48, 0.06);
    border-radius: 4px;
}

/* --- Definition Lists --- */
.markdown-preview dl {
    margin: 0 0 16px;
}

.markdown-preview dt {
    font-weight: 700;
    margin-top: 12px;
}

.markdown-preview dd {
    margin-left: 20px;
    color: var(--color-text-secondary);
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    animation: overlayIn 0.2s ease both;
}

@keyframes overlayIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    width: 100%;
    max-width: 400px;
    padding: 32px;
    border-radius: var(--radius-lg);
    animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-title {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.modal-desc {
    font-size: 13px;
    color: var(--color-text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
}

.modal-input {
    width: 100%;
    padding: 14px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--bg-base);
    box-shadow: var(--shadow-inset);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    outline: none;
    transition: var(--transition);
    margin-bottom: 20px;
}

.modal-input:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-inset), 0 0 0 4px rgba(0, 0, 0, 0.04);
}

.modal-input::placeholder {
    color: var(--color-text-tertiary);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* === Toast === */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--color-primary);
    color: white;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* === Read-Only Banner === */
.readonly-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.25);
    border-radius: var(--radius-sm);
    color: var(--color-readonly-banner, #856404);
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    transition: var(--transition);
}

.readonly-banner:hover {
    background: rgba(255, 193, 7, 0.18);
    border-color: rgba(255, 193, 7, 0.4);
}

/* === Encrypted Banner === */
.encrypted-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(0, 122, 255, 0.08);
    border: 1px solid rgba(0, 122, 255, 0.2);
    border-radius: var(--radius-sm);
    color: var(--color-encrypted-banner, #0055b3);
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    transition: var(--transition);
}

.encrypted-banner:hover {
    background: rgba(0, 122, 255, 0.14);
    border-color: rgba(0, 122, 255, 0.35);
}

/* === Protection Choice Buttons === */
.protection-choices {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.protection-choice-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 16px;
    border: 1px solid var(--border-outer);
    border-radius: var(--radius-md);
    background: var(--bg-base);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    font-family: var(--font-family);
}

.protection-choice-btn:hover {
    border-color: var(--color-text-secondary);
    background: var(--bg-white-hover);
    box-shadow: var(--shadow-subtle);
    transform: translateY(-2px);
}

.protection-choice-btn:active {
    transform: translateY(0) scale(0.98);
}

.choice-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    box-shadow: var(--shadow-inset);
    color: var(--color-text-secondary);
}

.choice-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text);
}

.choice-desc {
    font-size: 11px;
    color: var(--color-text-tertiary);
    line-height: 1.3;
}

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 640px) {
    .home-card {
        padding: 36px 24px;
        border-radius: var(--radius-lg);
    }

    .home-title {
        font-size: 1.6rem;
    }

    .input-prefix {
        font-size: 11px;
        padding-left: 12px;
    }

    .note-name-input {
        font-size: 14px;
    }

    .note-container {
        padding: 8px;
        gap: 8px;
    }

    .note-header {
        padding: 8px 12px;
        border-radius: var(--radius-md);
    }

    .editor-wrapper {
        border-radius: var(--radius-md);
    }

    .editor {
        padding: 20px 18px;
        font-size: 13px;
    }

    .markdown-preview {
        padding: 20px 18px;
    }

    .header-actions {
        gap: 0;
    }

    .btn-icon {
        width: 36px;
        height: 36px;
    }

    .save-status {
        padding: 4px 8px;
        font-size: 10px;
    }

    .status-text {
        display: none;
    }

    .home-container {
        padding: 16px;
    }

    .home-card {
        padding: 32px 24px;
        border-radius: var(--radius-lg);
    }

    .home-icon {
        width: 60px;
        height: 60px;
        margin-bottom: 16px;
    }

    .home-icon svg {
        width: 36px;
        height: 36px;
    }

    .home-title {
        font-size: 1.5rem;
        margin-bottom: 4px;
    }

    .home-subtitle {
        font-size: 10px;
        margin-bottom: 16px;
    }

    .home-desc {
        font-size: 13px;
        margin-bottom: 24px;
    }

    .home-form {
        gap: 14px;
    }

    .home-actions {
        top: 14px;
        right: 16px;
        gap: 6px;
    }

    .btn-lang {
        padding: 5px 10px;
        font-size: 11px;
    }
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* === Selection === */
::selection {
    background: rgba(28, 28, 30, 0.15);
}

[data-theme="dark"] ::selection {
    background: rgba(255, 255, 255, 0.2);
}

/* === Screen Reader Only === */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================
   THEME TOGGLE - Sun/Moon (CodePen inspired)
   ============================ */

/* === Home page: full sky toggle, sized to match lang button === */
.theme-toggle-wrap {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 20px;
    border: 1px solid transparent;
    background: var(--bg-base);
    box-shadow: var(--shadow-inset);
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    font: inherit;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.theme-toggle-home {
    width: 78px;
    height: 31px;
}

/* The toggle itself (original 220x90, scaled to fit) */
.theme-toggle {
    position: relative;
    width: 220px;
    height: 90px;
    flex-shrink: 0;
    background:
        radial-gradient(circle at 18% 20px, #fff, #fff 6px, transparent 7px, transparent),
        radial-gradient(circle at 35% 45px, #fff, #fff 1px, transparent 2px, transparent),
        radial-gradient(circle at 10% 70px, #fff, #fff 2.5px, transparent 3.5px, transparent),
        radial-gradient(circle at 25% 15px, #fff, #fff 3px, transparent 4px, transparent),
        radial-gradient(circle at 15% 50px, #fff, #fff 1.5px, transparent 2.5px, transparent),
        radial-gradient(circle at 30% 75px, #fff, #fff 5px, transparent 6px, transparent),
        radial-gradient(circle at 5% 30px, #fff, #fff 0.5px, transparent 1.5px, transparent),
        radial-gradient(circle at 25% 60px, #fff, #fff 0.5px, transparent 1.5px, transparent),
        radial-gradient(circle at 7% 35px, #fff, #fff 0.5px, transparent 1.5px, transparent),
        linear-gradient(90deg, #2b303e, #2b303e 50%, #5a81b4 50%, #5a81b4);
    background-repeat: no-repeat;
    background-size: 200% 100%;
    background-position: 100% 0;
    border-radius: 90px;
    box-shadow:
        0 -3px 4px #999,
        inset 0 3px 5px #333,
        0 4px 4px #ffe,
        inset 0 -3px 5px #ddd;
    cursor: pointer;
    overflow: hidden;
    transition: .5s all;
    transform: scale(0.355);
    transform-origin: center;
}

.theme-toggle::before,
.theme-toggle::after {
    content: "";
    position: absolute;
    transition: .5s all;
}

.theme-toggle::before {
    width: 75px;
    height: 75px;
    border-radius: 50%;
    background: #e9cb50;
    inset: 7.5px;
    box-shadow:
        0 0 5px #333,
        inset 2px 2px 3px #f8f4e4,
        inset -2px -2px 3px #665613;
    z-index: 1;
}

.theme-toggle::after {
    width: 70px;
    height: 70px;
    inset: 10px;
    border-radius: 50%;
    box-shadow:
        10px 60px 0 10px #fff,
        65px 60px 0 5px #fff,
        95px 70px 0 10px #fff,
        135px 45px 0 5px #fff,
        170px 35px 0 10px #fff,
        195px -5px 0 10px #fff,
        -10px 0 0 50px rgba(255, 255, 255, .2),
        15px 0 0 50px rgba(255, 255, 255, .15),
        40px 0 0 50px rgba(255, 255, 255, .21),
        10px 40px 0 10px #abc1d9,
        70px 35px 0 10px #abc1d9,
        95px 40px 0 10px #abc1d9,
        135px 20px 0 10px #abc1d9,
        155px 15px 0 10px #abc1d9,
        190px -20px 0 10px #abc1d9;
}

.theme-toggle:hover::before {
    filter: contrast(90%) brightness(110%);
    scale: 1.05;
}

/* Dark mode: night sky with moon */
[data-theme="dark"] .theme-toggle {
    background-position: 0 0;
    box-shadow:
        0 -3px 4px rgba(0,0,0,0.6),
        inset 0 3px 5px #111,
        0 4px 4px rgba(80,80,100,0.3),
        inset 0 -3px 5px #444;
}

[data-theme="dark"] .theme-toggle::before {
    translate: 130px;
    background:
        radial-gradient(circle at 50% 20px, #939aa5, #939aa5 6.5px, transparent 7px, transparent),
        radial-gradient(circle at 35% 45px, #939aa5, #939aa5 11.5px, transparent 12px, transparent),
        radial-gradient(circle at 72% 50px, #939aa5, #939aa5 8.5px, transparent 9px, transparent),
        radial-gradient(#cbcdda, #cbcdda);
}

[data-theme="dark"] .theme-toggle::after {
    transform: translate(130px);
    box-shadow:
        10px 60px 0 10px transparent,
        65px 60px 0 5px transparent,
        95px 70px 0 10px transparent,
        135px 45px 0 5px transparent,
        170px 35px 0 10px transparent,
        195px -5px 0 10px transparent,
        10px 0 0 50px rgba(255, 255, 255, .2),
        -15px 0 0 50px rgba(255, 255, 255, .15),
        -40px 0 0 50px rgba(255, 255, 255, .21),
        10px 40px 0 10px transparent,
        70px 35px 0 10px transparent,
        95px 40px 0 10px transparent,
        135px 20px 0 10px transparent,
        155px 15px 0 10px transparent,
        190px -20px 0 10px transparent;
}

/* === Editor page: square btn-icon style with sun/moon orb only === */
.btn-theme-editor {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    position: relative;
    padding: 0;
    font-family: var(--font-family);
}

.btn-theme-editor:hover {
    background: var(--bg-white-hover);
    border-color: var(--border-outer);
    box-shadow: var(--shadow-subtle);
}

.btn-theme-editor:active {
    transform: scale(0.92);
}

/* Sun orb */
.theme-orb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #e9cb50;
    box-shadow:
        0 0 6px rgba(233, 203, 80, 0.5),
        inset 1.5px 1.5px 2px #f8f4e4,
        inset -1.5px -1.5px 2px #665613;
    transition: .4s all;
}

.btn-theme-editor:hover .theme-orb {
    filter: contrast(90%) brightness(110%);
    transform: scale(1.08);
}

/* Moon orb with craters */
[data-theme="dark"] .theme-orb {
    background:
        radial-gradient(circle at 50% 6px, #939aa5, #939aa5 2px, transparent 2.5px, transparent),
        radial-gradient(circle at 35% 13px, #939aa5, #939aa5 3.5px, transparent 4px, transparent),
        radial-gradient(circle at 72% 15px, #939aa5, #939aa5 2.5px, transparent 3px, transparent),
        radial-gradient(#cbcdda, #cbcdda);
    box-shadow:
        0 0 8px rgba(203, 205, 218, 0.4),
        inset 1px 1px 2px rgba(255,255,255,0.3),
        inset -1px -1px 2px rgba(0,0,0,0.15);
}

/* Dark mode specific overrides */
[data-theme="dark"] .readonly-banner {
    background: rgba(255, 193, 7, 0.15);
    border-color: rgba(255, 193, 7, 0.3);
    color: #ffd60a;
}

[data-theme="dark"] .encrypted-banner {
    background: rgba(0, 122, 255, 0.15);
    border-color: rgba(0, 122, 255, 0.3);
    color: #64b5f6;
}

[data-theme="dark"] .markdown-preview blockquote {
    background: rgba(0, 122, 255, 0.08);
}

[data-theme="dark"] .markdown-preview img {
    opacity: 0.9;
}

[data-theme="dark"] .btn-primary {
    color: #1C1C1E;
}

/* Dark mode: markdown toggle — no border/bg when inactive, visible when active */
[data-theme="dark"] #btnMarkdown {
    background: transparent;
    border-color: transparent;
    color: #E5E5EA;
}

[data-theme="dark"] #btnMarkdown:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: transparent;
    color: #F5F5F7;
}

[data-theme="dark"] #btnMarkdown.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #1C1C1E;
}

[data-theme="dark"] .toast {
    background: #F5F5F7;
    color: #1C1C1E;
}

/* API & TIP labels: keep dark bg + white text in dark mode */
[data-theme="dark"] .label-industrial {
    background: #636366;
    color: #F5F5F7;
}

[data-theme="dark"] .label-secondary {
    background: #48484A;
}

[data-theme="dark"] .hint-block code,
[data-theme="dark"] .hint-text {
    color: #A1A1A6;
}

/* Cancel/secondary button: dark background instead of hardcoded white */
[data-theme="dark"] .btn-secondary {
    background: #2C2C2E;
    color: #F5F5F7;
    border-color: rgba(68, 68, 70, 0.6);
}

[data-theme="dark"] .btn-secondary:hover {
    background: #3A3A3C;
}

/* Modal: ensure dark theme input and text contrast */
[data-theme="dark"] .modal {
    background: #2C2C2E;
    border: 1px solid rgba(68, 68, 70, 0.5);
}

[data-theme="dark"] .modal-input {
    background: #1C1C1E;
    color: #F5F5F7;
    border-color: rgba(68, 68, 70, 0.4);
}

[data-theme="dark"] .modal-input::placeholder {
    color: #636366;
}

/* Markdown preview panel: dark background when open */
[data-theme="dark"] .markdown-preview {
    background: var(--bg-base);
}

/* Editor focus: darker tint in dark mode */
[data-theme="dark"] .editor:focus {
    background: rgba(255, 255, 255, 0.05);
}

/* Smooth theme transition for key elements */
body,
.editor,
.note-header,
.editor-wrapper,
.home-card,
.modal,
.toast,
.btn-primary,
.btn-secondary,
.btn-icon,
.readonly-banner,
.encrypted-banner {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .btn-lang {
        height: 24px;
        padding: 0 10px;
        gap: 4px;
        font-size: 11px;
    }

    .theme-toggle-home {
        width: 57px;
        height: 24px;
    }

    .theme-toggle-home .theme-toggle {
        transform: scale(0.26);
        transform-origin: center;
    }

    .btn-theme-editor {
        width: 36px;
        height: 36px;
    }

    .theme-orb {
        width: 18px;
        height: 18px;
    }
}