/* ================================================================
   Markdown ⇔ HTML 相互変換ツール
   Prefix: mhc- (Markdown HTML Converter)
   ================================================================ */

:root {
    --mhc-primary: #6d28d9;
    --mhc-primary-l: #8b5cf6;
    --mhc-accent: #10b981;
    --mhc-bg: #f5f3ff;
    --mhc-card: #ffffff;
    --mhc-text: #1e1b4b;
    --mhc-muted: #6b7280;
    --mhc-border: #e5e7eb;
    --mhc-code-bg: #1e1b4b;
    --mhc-code-text: #e2e8f0;
    --mhc-danger: #ef4444;
    --mhc-shadow: 0 2px 12px rgba(0, 0, 0, .08);
}

/* ----------------------------------------------------------------
   Container
   ---------------------------------------------------------------- */
.mhc-container {
    max-width: 900px;
    margin: 0 auto;
}

/* ----------------------------------------------------------------
   Panel
   ---------------------------------------------------------------- */
.mhc-panel {
    background: var(--mhc-card);
    border: 1px solid var(--mhc-border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--mhc-shadow);
    margin-bottom: 20px;
}

.mhc-panel h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--mhc-primary);
    margin: 0 0 16px;
}

.mhc-panel h3 .material-icons {
    font-size: 22px;
}

/* ----------------------------------------------------------------
   Direction toggle
   ---------------------------------------------------------------- */
.mhc-direction-wrap {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border: 2px solid var(--mhc-primary);
    border-radius: 8px;
    position: relative;
    z-index: 1;
}

.mhc-dir-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: var(--mhc-card);
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    transition: all .15s;
    color: var(--mhc-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.mhc-dir-btn .material-icons {
    font-size: 18px;
}

.mhc-dir-btn:first-child {
    border-right: 2px solid var(--mhc-primary);
    border-radius: 6px 0 0 6px;
}

.mhc-dir-btn:last-child {
    border-radius: 0 6px 6px 0;
}

.mhc-dir-btn.active {
    background: var(--mhc-primary);
    color: #fff;
}

.mhc-dir-btn:not(.active):hover {
    background: #f5f3ff;
    color: var(--mhc-primary);
}

/* ----------------------------------------------------------------
   Input area
   ---------------------------------------------------------------- */
.mhc-input-wrap {
    margin-bottom: 16px;
}

.mhc-input-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--mhc-muted);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.mhc-input-label .material-icons {
    font-size: 16px;
}

.mhc-textarea {
    width: 100%;
    min-height: 300px;
    padding: 14px 16px;
    border: 1px solid var(--mhc-border);
    border-radius: 8px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.7;
    color: var(--mhc-text);
    background: #fafafa;
    box-sizing: border-box;
    resize: vertical;
    tab-size: 2;
}

.mhc-textarea:focus {
    outline: none;
    border-color: var(--mhc-primary);
    box-shadow: 0 0 0 3px rgba(109, 40, 217, .1);
}

/* ----------------------------------------------------------------
   Options
   ---------------------------------------------------------------- */
.mhc-options {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 10px 14px;
    background: #f9fafb;
    border: 1px solid var(--mhc-border);
    border-radius: 8px;
}

.mhc-opt-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    cursor: pointer;
    color: var(--mhc-text);
    user-select: none;
}

.mhc-opt-label input[type="checkbox"] {
    accent-color: var(--mhc-primary);
    width: 16px;
    height: 16px;
}

/* ----------------------------------------------------------------
   Output tabs
   ---------------------------------------------------------------- */
.mhc-output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
}

.mhc-tabs {
    display: flex;
    gap: 0;
}

.mhc-tab-btn {
    padding: 8px 18px;
    border: 1px solid var(--mhc-border);
    border-bottom: none;
    background: #f9fafb;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    color: var(--mhc-muted);
    transition: all .12s;
    border-radius: 8px 8px 0 0;
}

.mhc-tab-btn.active {
    background: var(--mhc-code-bg);
    color: var(--mhc-code-text);
    border-color: var(--mhc-code-bg);
}

.mhc-tab-btn.preview-tab.active {
    background: var(--mhc-card);
    color: var(--mhc-text);
    border-color: var(--mhc-border);
}

.mhc-output-actions {
    display: flex;
    gap: 8px;
}

.mhc-btn {
    padding: 7px 14px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: opacity .12s;
}

.mhc-btn .material-icons {
    font-size: 16px;
}

.mhc-btn-copy {
    background: var(--mhc-primary);
    color: #fff;
}

.mhc-btn-clear {
    background: #fee2e2;
    color: var(--mhc-danger);
}

.mhc-btn:hover {
    opacity: .8;
}

/* ----------------------------------------------------------------
   Code output
   ---------------------------------------------------------------- */
.mhc-output-code {
    background: var(--mhc-code-bg);
    color: var(--mhc-code-text);
    border-radius: 0 8px 8px 8px;
    padding: 16px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.7;
    min-height: 200px;
    max-height: 500px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid var(--mhc-code-bg);
}

/* ----------------------------------------------------------------
   Preview output
   ---------------------------------------------------------------- */
.mhc-output-preview {
    background: var(--mhc-card);
    border: 1px solid var(--mhc-border);
    border-radius: 0 8px 8px 8px;
    padding: 20px;
    min-height: 200px;
    max-height: 500px;
    overflow: auto;
    font-size: 14px;
    line-height: 1.8;
    color: var(--mhc-text);
    display: none;
}

/* Preview内のMarkdown要素のスタイリング */
.mhc-output-preview h1 {
    font-size: 1.8em;
    font-weight: 700;
    margin: 0.6em 0 0.4em;
    padding-bottom: 0.3em;
    border-bottom: 2px solid var(--mhc-border);
}

.mhc-output-preview h2 {
    font-size: 1.5em;
    font-weight: 700;
    margin: 0.5em 0 0.3em;
    padding-bottom: 0.2em;
    border-bottom: 1px solid var(--mhc-border);
}

.mhc-output-preview h3 {
    font-size: 1.25em;
    font-weight: 700;
    margin: 0.4em 0 0.3em;
}

.mhc-output-preview h4 {
    font-size: 1.1em;
    font-weight: 700;
    margin: 0.3em 0;
}

.mhc-output-preview p {
    margin: 0.5em 0;
}

.mhc-output-preview ul,
.mhc-output-preview ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.mhc-output-preview li {
    margin: 0.2em 0;
}

.mhc-output-preview blockquote {
    border-left: 4px solid var(--mhc-primary-l);
    margin: 0.5em 0;
    padding: 0.5em 1em;
    background: #f5f3ff;
    color: #4c1d95;
    border-radius: 0 6px 6px 0;
}

.mhc-output-preview code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 0.9em;
    color: #be185d;
}

.mhc-output-preview pre {
    background: #1e1b4b;
    color: #e2e8f0;
    padding: 14px 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.6em 0;
}

.mhc-output-preview pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.mhc-output-preview table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.6em 0;
}

.mhc-output-preview th {
    background: #f1f5f9;
    padding: 8px 12px;
    border: 1px solid var(--mhc-border);
    font-weight: 600;
    text-align: left;
    font-size: 0.9em;
}

.mhc-output-preview td {
    padding: 8px 12px;
    border: 1px solid var(--mhc-border);
    font-size: 0.9em;
}

.mhc-output-preview tr:nth-child(even) td {
    background: #fafafa;
}

.mhc-output-preview a {
    color: var(--mhc-primary);
    text-decoration: underline;
}

.mhc-output-preview img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

.mhc-output-preview hr {
    border: none;
    border-top: 2px solid var(--mhc-border);
    margin: 1em 0;
}

.mhc-output-preview del {
    text-decoration: line-through;
    color: var(--mhc-muted);
}

.mhc-output-preview input[type="checkbox"] {
    margin-right: 6px;
    accent-color: var(--mhc-primary);
    pointer-events: none;
}

/* ----------------------------------------------------------------
   Toast
   ---------------------------------------------------------------- */
.mhc-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--mhc-accent);
    color: #fff;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    z-index: 99999;
    opacity: 0;
    transition: all .3s ease;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(16, 185, 129, .3);
}

.mhc-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ----------------------------------------------------------------
   Empty state
   ---------------------------------------------------------------- */
.mhc-empty {
    color: var(--mhc-muted);
    font-style: italic;
    font-size: 13px;
}

/* ----------------------------------------------------------------
   Responsive
   ---------------------------------------------------------------- */
@media (max-width: 640px) {
    .mhc-direction-wrap {
        flex-direction: column;
    }

    .mhc-dir-btn:first-child {
        border-right: none;
        border-bottom: 2px solid var(--mhc-primary);
        border-radius: 6px 6px 0 0;
    }

    .mhc-dir-btn:last-child {
        border-radius: 0 0 6px 6px;
    }

    .mhc-options {
        flex-direction: column;
        gap: 10px;
    }

    .mhc-output-header {
        flex-direction: column-reverse;
        gap: 12px;
        align-items: stretch;
    }

    .mhc-tabs {
        width: 100%;
    }

    .mhc-tab-btn {
        flex: 1;
        text-align: center;
    }

    .mhc-output-actions {
        width: 100%;
        display: flex;
        justify-content: flex-end;
    }
}