/* ========================================
   textedi.php - 構造エディタ CSS
   ======================================== */

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #06b6d4;
    --bg-main: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-hover: #f3f4f6;
    --border-color: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --toolbar-height: 56px;
    --keyboard-inset: 0px;
    --toolbar-gap: 12px;
    --footer-height: 40px;
    --typewriter-scroll-pad: 0px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    background: linear-gradient(135deg, #14151b 0%, #502c75 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-primary);
}

.container {
    width: 100%;
    max-width: 1200px;
    background: var(--bg-main);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}


hr {
    margin-bottom: 12px;
}



/* ========================================
   ヘッダー
   ======================================== */

.editor-header {
    background: none;
    color: var(--text-primary);
    padding: 24px 32px 12px;
    text-align: center;
}

.editor-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    opacity: 1;
}

/* ========================================
   ツールバー（画面下部フローティング）
   ======================================== */

.toolbar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--footer-height) + var(--toolbar-gap) + env(safe-area-inset-bottom, 0px) + var(--keyboard-inset, 0px));
    z-index: 1000;
    width: min(720px, calc(100vw - 2 * var(--toolbar-gap)));
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    padding: 10px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.toolbar-group {
    display: flex;
    gap: 4px;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
}

.btn {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--primary-color);
}

.btn:active {
    transform: scale(0.98);
}

.btn-mode {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-mode:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-formatted {
    background: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
}

.btn-formatted:hover {
    background: #0891b2;
    border-color: #0891b2;
}

.btn-copy {
    background: #10b981;
    color: white;
    border-color: #10b981;
}

.btn-copy:hover {
    background: #059669;
    border-color: #059669;
}

.btn-undo,
.btn-redo {
    background: #6366f1;
    color: white;
    border-color: #6366f1;
    font-size: 18px;
}

.btn-undo:hover,
.btn-redo:hover {
    background: #4f46e5;
    border-color: #4f46e5;
}

.btn-undo:disabled,
.btn-redo:disabled {
    background: #d1d5db;
    border-color: #d1d5db;
    color: #9ca3af;
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-clear {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

.btn-clear:hover {
    background: #dc2626;
    border-color: #dc2626;
}

/* ========================================
   モード表示 + モード操作
   ======================================== */

.mode-indicator {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: nowrap;
    background: #fef3c7;
    border-bottom: 1px solid #fbbf24;
    padding: 8px 16px;
    font-size: 12px;
    color: #92400e;
}

.mode-indicator strong {
    color: #78350f;
    font-weight: 600;
}

#modeLabel {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mode-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.mode-actions .btn {
    padding: 4px 10px;
    font-size: 12px;
}

/* ========================================
   エディタエリア
   ======================================== */

.editor-wrapper {
    position: relative;
    height: 500px;
}

.editor-area {
    width: 100%;
    height: 100%;
    padding: 24px;
    padding-bottom: calc(24px + var(--toolbar-height) + var(--toolbar-gap) + env(safe-area-inset-bottom, 0px) + var(--typewriter-scroll-pad, 0px));
    border: none;
    outline: none;
    box-shadow: none;
    resize: none;
    font-family: 'Courier New', Courier, monospace;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-main);
    -webkit-appearance: none;
    appearance: none;
}

.editor-area:focus,
.editor-area:focus-visible {
    border: none;
    outline: none;
    box-shadow: none;
}

.editor-area::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

/* タイプライターモード用ミラー（計測専用・非表示） */
#editor-typewriter-mirror {
    position: absolute;
    top: 0;
    left: -99999px;
    visibility: hidden;
    pointer-events: none;
    height: auto;
    min-height: 0;
    overflow: hidden;
    z-index: -1;
}

/* タイプライターモード用ミラー（計測専用・非表示） */
#editor-typewriter-mirror {
    position: absolute;
    top: 0;
    left: -99999px;
    visibility: hidden;
    pointer-events: none;
    height: auto;
    min-height: 0;
    overflow: hidden;
    z-index: -1;
}


/* Markdown段落のスタイル（整形テキストモード用） */
.formatted-content p {
    margin-block-end: 1em;
}

.formatted-content h1,
.formatted-content h2,
.formatted-content h3 {
    margin-block-start: 1.2em;
    margin-block-end: 0.6em;
}

.formatted-content h1:first-child,
.formatted-content h2:first-child,
.formatted-content h3:first-child {
    margin-block-start: 0;
}

/* ========================================
   整形テキスト出力
   ======================================== */

.formatted-output {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-main);
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.formatted-header {
    background: var(--secondary-color);
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 500;
}

.btn-close {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 4px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.formatted-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
}

.formatted-content h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.formatted-content h2 {
    font-size: 22px;
    font-weight: 600;
    margin-top: 24px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.formatted-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin-top: 20px;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.formatted-content p {
    margin-bottom: 12px;
}

.formatted-content ul,
.formatted-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.formatted-content ul ul,
.formatted-content ol ol,
.formatted-content ul ol,
.formatted-content ol ul {
    margin: 4px 0;
}

.formatted-content li {
    margin: 4px 0;
}

.formatted-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.formatted-content em {
    font-style: italic;
}

.formatted-content code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    color: #dc2626;
}

.formatted-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--text-secondary);
    font-style: italic;
}

.formatted-content pre {
    background: #f3f4f6;
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 16px 0;
}

.formatted-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    color: var(--text-primary);
    font-size: 13px;
}

.formatted-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    border: 1px solid var(--border-color);
}

.formatted-content table th,
.formatted-content table td {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.formatted-content table th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
}

.formatted-content table tr:nth-child(even) {
    background: var(--bg-secondary);
}

/* ========================================
   フッター
   ======================================== */

.editor-footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 12px 20px;
}

.shortcuts-info {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 12px;
    color: var(--text-secondary);
}

.shortcuts-info span:first-child {
    color: var(--text-primary);
}


.copyright {
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
}

.copyright a {
    color: var(--text-secondary);
    text-decoration: none;
}


/* ========================================
   レスポンシブ対応
   ======================================== */

@media (max-width: 768px) {
    body {
        padding: 0;
        align-items: stretch;
    }

    .container {
        max-width: none;
        border-radius: 0;
        min-height: 100vh;
        min-height: 100dvh;
        display: flex;
        flex-direction: column;
        box-shadow: none;
        padding-bottom: calc(env(safe-area-inset-bottom, 0px));
    }

    .editor-header {
        padding: 16px;
        flex-shrink: 0;
    }

    .editor-header h1 {
        font-size: 16px;
        margin-bottom: 2px;
    }

    .subtitle {
        font-size: 12px;
    }

    .toolbar {
        width: calc(100vw - 20px);
        bottom: calc(10px + var(--footer-height) + env(safe-area-inset-bottom, 0px) + var(--keyboard-inset, 0px));
        padding: 8px 10px;
        border-radius: 14px;
    }

    .btn {
        padding: 4px 8px;
        font-size: 12px;
    }

    .mode-indicator {
        flex-shrink: 0;
        padding: 6px 12px;
        gap: 8px;
    }

    .mode-actions .btn {
        padding: 4px 8px;
        font-size: 11px;
    }

    .editor-wrapper {
        flex: 1;
        height: auto;
        min-height: 50dvh;
    }

    .editor-footer {
        flex-shrink: 0;
    }

    .shortcuts-info {
        font-size: 11px;
        gap: 8px;
    }
}

/* ========================================
   アニメーション
   ======================================== */

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.formatted-output {
    animation: fadeIn 0.3s ease-out;
}