:root {
    --bg: #f4f6fa;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #172033;
    --muted: #718096;
    --border: #e2e8f0;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;

    --danger: #dc2626;

    --shadow: 0 10px 35px rgba(15, 23, 42, .07);

    --radius: 16px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;

    font-family:
        Arial,
        Helvetica,
        sans-serif;

    background: var(--bg);
    color: var(--text);
}

/* =========================================================
   HEADER
========================================================= */

.header {
    height: 70px;

    padding: 0 28px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    background: var(--panel);

    border-bottom: 1px solid var(--border);

    position: sticky;
    top: 0;

    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 42px;
    height: 42px;

    display: grid;
    place-items: center;

    border-radius: 11px;

    background: linear-gradient(
        135deg,
        #4f46e5,
        #8b5cf6
    );

    color: white;

    font-size: 13px;
    font-weight: 700;

    box-shadow:
        0 7px 18px rgba(79, 70, 229, .24);
}

.brand-title {
    margin: 0;

    font-size: 18px;
    line-height: 1.2;
}

.brand-subtitle {
    margin-top: 3px;

    color: var(--muted);

    font-size: 12px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* =========================================================
   MAIN CONTAINER
========================================================= */

/*
   IMPORTANT:
   Your HTML uses:

   <main class="container">

   So this is the class we style.
*/

.container {
    width: min(1100px, calc(100% - 48px));

    margin: 32px auto 50px;
}

/* =========================================================
   EDITOR CARD
========================================================= */

.editor-card {
    width: 100%;
    min-width: 0;

    overflow: hidden;

    background: var(--panel);

    border: 1px solid var(--border);

    border-radius: var(--radius);

    box-shadow: var(--shadow);
}

/* =========================================================
   TOOLBAR
========================================================= */

.toolbar {
    min-height: 58px;

    padding: 9px 12px;

    display: flex;
    align-items: center;
    flex-wrap: wrap;

    gap: 5px;

    background: var(--panel-soft);

    border-bottom: 1px solid var(--border);
}

.tool {
    height: 34px;
    min-width: 34px;

    padding: 0 9px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 1px solid transparent;

    border-radius: 7px;

    background: transparent;
    color: var(--text);

    cursor: pointer;

    font-size: 13px;
    font-weight: 600;
}

.tool:hover {
    background: var(--panel);

    border-color: var(--border);
}

.tool.active {
    background: var(--primary-light);

    color: var(--primary);

    border-color: #c7d2fe;
}

.select {
    height: 34px;

    max-width: 155px;

    padding: 0 9px;

    border: 1px solid var(--border);

    border-radius: 7px;

    background: var(--panel);
    color: var(--text);

    outline: none;

    cursor: pointer;

    font-size: 12px;
}

.separator {
    width: 1px;
    height: 25px;

    margin: 0 4px;

    background: var(--border);
}

/* =========================================================
   EDITOR
========================================================= */

.workspace {
    position: relative;
}

.editor {
    min-height: 590px;

    /*
       This creates comfortable space
       inside the writing area.
    */

    padding: 45px 60px;

    outline: none;

    background: var(--panel);

    font-size: 16px;
    line-height: 1.7;

    overflow-wrap: anywhere;
}

.editor:focus {
    box-shadow:
        inset 0 0 0 2px
        rgba(79, 70, 229, .06);
}

.editor:empty::before {
    content: "Start writing here...";

    color: #94a3b8;

    pointer-events: none;
}

.editor h1,
.editor h2,
.editor h3,
.editor h4 {
    line-height: 1.25;
}

.editor h1 {
    font-size: 2.2rem;
}

.editor h2 {
    font-size: 1.7rem;
}

.editor h3 {
    font-size: 1.35rem;
}

.editor blockquote {
    margin: 20px 0;

    padding: 12px 18px;

    border-left: 4px solid var(--primary);

    background: var(--panel-soft);

    color: #64748b;
}

.editor img {
    max-width: 100%;
    height: auto;

    border-radius: 8px;
}

.editor table {
    width: 100%;

    margin: 20px 0;

    border-collapse: collapse;
}

.editor th,
.editor td {
    padding: 9px 12px;

    border: 1px solid #cbd5e1;

    text-align: left;
}

.editor th {
    background: #f1f5f9;
}

.editor pre {
    padding: 15px;

    overflow-x: auto;

    border-radius: 8px;

    background: #111827;
    color: #e5e7eb;

    font-family:
        Consolas,
        Monaco,
        "Courier New",
        monospace;
}

/* =========================================================
   SOURCE EDITOR
========================================================= */

.source-editor {
    display: none;

    width: 100%;
    min-height: 590px;

    padding: 30px;

    resize: vertical;

    border: 0;
    outline: none;

    background: #0f172a;
    color: #e2e8f0;

    font-family:
        Consolas,
        Monaco,
        "Courier New",
        monospace;

    font-size: 14px;
    line-height: 1.7;
}

.source-mode .editor {
    display: none;
}

.source-mode .source-editor {
    display: block;
}

/* =========================================================
   FOOTER
========================================================= */

.editor-footer {
    min-height: 51px;

    padding: 8px 13px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    border-top: 1px solid var(--border);

    color: var(--muted);

    font-size: 12px;
}

.stats {
    display: flex;
    gap: 18px;
}

.mode {
    padding: 3px;

    display: flex;
    gap: 3px;

    background: var(--panel-soft);

    border: 1px solid var(--border);

    border-radius: 8px;
}

.mode button {
    padding: 5px 11px;

    border: 0;

    border-radius: 6px;

    background: transparent;

    color: var(--muted);

    cursor: pointer;

    font-size: 12px;
}

.mode button.active {
    background: var(--panel);

    color: var(--text);

    box-shadow:
        0 1px 3px rgba(15, 23, 42, .1);
}

/* =========================================================
   BUTTONS
========================================================= */

.btn {
    min-height: 37px;

    padding: 8px 13px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    gap: 7px;

    border: 1px solid var(--border);

    border-radius: 9px;

    background: var(--panel);
    color: var(--text);

    cursor: pointer;

    font-size: 13px;
}

.btn:hover {
    background: var(--panel-soft);
}

.btn.primary {
    background: var(--primary);

    border-color: var(--primary);

    color: white;
}

.btn.primary:hover {
    background: var(--primary-hover);
}

.btn.danger:hover {
    background: #fff5f5;

    border-color: #fecaca;

    color: var(--danger);
}

/* =========================================================
   ACTIONS
========================================================= */

.actions {
    margin-top: 15px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 10px;
}

.action-group {
    display: flex;
    gap: 8px;
}

/* =========================================================
   COLOR
========================================================= */

.color-container {
    position: relative;
}

.color-input {
    position: absolute;

    inset: 0;

    width: 100%;
    height: 100%;

    opacity: 0;

    cursor: pointer;
}

/* =========================================================
   MODAL
========================================================= */

.modal-overlay {
    position: fixed;

    inset: 0;

    padding: 20px;

    display: none;
    align-items: center;
    justify-content: center;

    background: rgba(15, 23, 42, .6);

    z-index: 200;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    width: min(900px, 100%);
    max-height: 90vh;

    overflow: hidden;

    background: var(--panel);

    border-radius: 16px;

    box-shadow:
        0 30px 80px rgba(0, 0, 0, .25);
}

.modal-header {
    min-height: 58px;

    padding: 0 18px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;

    font-size: 17px;
}

.modal-body {
    padding: 18px;
}

.preview-frame {
    width: 100%;
    height: 550px;

    border: 1px solid var(--border);

    border-radius: 10px;

    background: white;
}

/* =========================================================
   TOAST
========================================================= */

.toast {
    position: fixed;

    left: 50%;
    bottom: 24px;

    padding: 11px 17px;

    transform: translate(-50%, 20px);

    border-radius: 9px;

    background: #111827;
    color: white;

    font-size: 13px;

    opacity: 0;

    pointer-events: none;

    transition: .2s ease;

    z-index: 500;
}

.toast.show {
    opacity: 1;

    transform: translate(-50%, 0);
}

/* =========================================================
   DARK MODE
========================================================= */

body.dark {
    --bg: #0b1120;
    --panel: #111827;
    --panel-soft: #172033;

    --text: #e5e7eb;
    --muted: #94a3b8;

    --border: #263244;

    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-light: #312e81;
}

body.dark .editor blockquote {
    background: #172033;

    color: #cbd5e1;
}

body.dark .editor th {
    background: #1e293b;
}

body.dark .tool:hover,
body.dark .btn:hover {
    background: #1e293b;
}

body.dark .tool.active {
    background: #312e81;

    color: #c7d2fe;
}

body.dark .mode button.active {
    background: #1e293b;

    color: white;
}

/* =========================================================
   FULLSCREEN
========================================================= */

body.fullscreen .container {
    width: 100%;

    margin: 0;
}

body.fullscreen .editor-card {
    border-radius: 0;

    border-left: 0;
    border-right: 0;
}

body.fullscreen .editor {
    min-height:
        calc(100vh - 190px);
}

/* =========================================================
   TABLET
========================================================= */

@media (max-width: 900px) {

    .container {
        width:
            calc(100% - 32px);

        margin:
            24px auto 40px;
    }

    .editor {
        padding:
            40px;
    }
}

/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 700px) {

    .header {
        height: auto;

        min-height: 65px;

        padding:
            11px 14px;
    }

    .brand-subtitle {
        display: none;
    }

    .brand-title {
        font-size: 16px;
    }

    .header-actions .label {
        display: none;
    }

    .container {
        width:
            calc(100% - 16px);

        margin:
            10px auto 25px;
    }

    .toolbar {
        padding: 7px;
    }

    .editor {
        min-height: 430px;

        padding:
            25px 20px;
    }

    .source-editor {
        min-height: 430px;

        padding: 20px;
    }

    .editor-footer {
        flex-direction: column;

        align-items: flex-start;

        gap: 8px;
    }

    .actions {
        flex-direction: column;
    }

    .action-group {
        width: 100%;
    }

    .action-group .btn {
        flex: 1;
    }

    .modal-overlay {
        padding: 8px;
    }

    .modal {
        max-height: 96vh;
    }

    .preview-frame {
        height: 70vh;
    }
}
