.mtg-editor {
    position: relative;
    --mtg-figure-preview-scale: 2;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    background: #fff;
    overflow: hidden;
}

.mtg-editor__toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

.mtg-editor__toolbar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.mtg-editor__toolbar-group--history {
    margin-left: auto;
    justify-content: flex-end;
}

.mtg-editor__block-controls {
    display: none;
}

.mtg-editor__button {
    padding: 2px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #fff;
    color: #0f172a;
    font: inherit;
    cursor: pointer;
}

.mtg-editor__surface {
    min-height: 360px;
    max-height: 640px;
    padding: 24px 0;
    overflow: auto;
    background: linear-gradient(180deg, #fcfdff 0%, #f8fafc 100%);
}

.mtg-editor__content--blocks {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.mtg-editor__block {
    position: relative;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: #fff;
    box-shadow: none;
    transition: opacity 0.18s ease;
}

.mtg-editor__block.is-selected-block {
    background: #fff;
    box-shadow: none;
    z-index: 3;
}

.mtg-editor__block-head {
    display: none;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin: 0;
    padding: 0;
    position: absolute;
    top: 0;
    right: 0;
    transform: translateY(-55%);
    z-index: 6;
}

.mtg-editor__block-actions,
.mtg-editor__inline-actions,
.mtg-editor__block-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.mtg-editor__icon-button,
.mtg-editor__small-button {
    padding: 2px 10px;
    border: 1px solid rgba(15, 23, 42, 0.92);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.96);
    color: #fff;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.16);
}

.mtg-editor__icon-button[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
}

.mtg-editor__icon-button--danger {
    border-color: rgba(127, 29, 29, 0.96);
    background: rgba(127, 29, 29, 0.96);
    color: #fff;
}

.mtg-editor__block:not(.is-selected-block) .mtg-editor__inline-actions,
.mtg-editor__block:not(.is-selected-block) .mtg-editor__block-head,
.mtg-editor__block:not(.is-selected-block) .mtg-editor__block-footer {
    display: none;
}

.mtg-editor__block.is-selected-block .mtg-editor__block-head,
.mtg-editor__block.is-selected-block .mtg-editor__block-footer {
    display: flex;
}

.mtg-editor__inline-actions {
    margin: 6px 0 8px;
}

.mtg-editor__textarea {
    width: 100%;
    min-height: 1.6em;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #0f172a;
    caret-color: #0f172a;
    font: inherit;
    line-height: 1.6;
    resize: none;
    overflow: hidden;
    box-sizing: border-box;
}

.mtg-editor__textarea::placeholder {
    color: #94a3b8;
}

.mtg-editor__textarea::selection {
    color: #0f172a;
    background: rgba(59, 130, 246, 0.28);
}

.mtg-editor__block--paragraph .mtg-editor__textarea {
    padding-left: 1.5em;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    border-bottom: 0;
    text-indent: 20px;
    text-align: justify;
}

.mtg-editor__block--paragraph.is-selected-block .mtg-editor__textarea {
    border-top: 1px solid rgba(15, 23, 42, 0.22);
    border-bottom: 1px solid rgba(15, 23, 42, 0.22);
}

.mtg-editor__textarea:focus,
.mtg-editor__cell-textarea:focus {
    outline: none;
    background: transparent;
    box-shadow: none;
}

.mtg-editor__textarea--caption {
    min-height: 1.6em;
    font-style: italic;
    text-align: center;
    padding: 0;
    border-radius: 0;
}

.mtg-editor__textarea--figure {
    background: rgba(239, 246, 255, 0.85);
    color: #1d4ed8;
}

.mtg-editor__textarea--table {
    background: rgba(240, 253, 244, 0.9);
    color: #166534;
}

.mtg-editor__figure-frame {
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(100%, calc(11.5cm * var(--mtg-figure-preview-scale)));
    max-width: calc(11.5cm * var(--mtg-figure-preview-scale));
    min-height: 180px;
    margin: 4px auto 8px;
    padding: 8px;
    border: 1px dashed rgba(59, 130, 246, 0.22);
    border-radius: 12px;
    box-sizing: border-box;
}

.mtg-editor__figure-frame img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 12px;
}

.mtg-editor__figure-width-buttons {
    display: flex;
    align-items: center;
    gap: 6px;
}

.mtg-editor__icon-button--width {
    min-width: 52px;
}

.mtg-editor__icon-button.is-active {
    background: #fff;
    color: #000;
}

.mtg-editor__empty-media {
    color: #64748b;
    font-size: 14px;
    text-align: center;
}

.mtg-editor__table-wrap {
    overflow-x: auto;
}

.mtg-editor__table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.mtg-editor__table td {
    position: relative;
    padding: 0;
    border: 1px solid rgba(203, 213, 225, 0.8);
    border-radius: 0;
    background: #fff;
}

.mtg-editor__table td.is-selected-cell {
    z-index: 1;
}

.mtg-editor__cell-textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #0f172a;
    font: inherit;
    line-height: 1.4;
    resize: none;
    overflow: hidden;
    box-sizing: border-box;
}

.mtg-editor__block-footer {
    margin: 0;
    padding: 0;
    border-top: 0;
    position: absolute;
    left: 0;
    bottom: 0;
    transform: translateY(55%);
    z-index: 6;
    justify-content: center;
    width: 100%;
}

@media (max-width: 640px) {
    .mtg-editor__surface {
        padding: 12px;
    }

    .mtg-editor__block {
        padding: 0;
    }

    .mtg-editor__block-head {
        flex-direction: column;
        align-items: flex-end;
    }
}
