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

body {
    background-color: var(--custom-fondo, #f4f4f4);
    font-family: 'Cormorant Garamond', serif;
    color: #111111;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
}

body.has-polkadots {
    background-image: radial-gradient(rgba(0, 0, 0, 0.14) 1.1px, transparent 1.1px);
    background-size: 20px 20px;
}

body.is-loading {
    overflow: hidden;
}

#page-loader {
    position: fixed;
    inset: 0;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}

#page-loader.loader-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-text {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 1.15rem;
    color: #555555;
    letter-spacing: 0.4px;
}

.hidden {
    display: none !important;
}

.toolbar {
    position: sticky;
    top: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 28px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #e0e0e0;
    z-index: 30;
    flex-wrap: wrap;
    gap: 12px;
}

.brand {
    font-size: 1.45rem;
    font-style: italic;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: #111111;
    flex: 0 0 160px;
    text-decoration: none;
}

.toolbar-center {
    display: flex;
    align-items: center;
    flex: 1;
    max-width: 320px;
    justify-content: center;
}

.search-box {
    position: relative;
    width: 100%;
}

.search-box input {
    width: 100%;
    padding: 6px 14px 6px 34px;
    border: 1px solid #cccccc;
    border-radius: 20px;
    font-family: 'Cormorant Garamond', serif;
    font-size: 0.95rem;
    background: #fafafa;
    outline: none;
    transition: all 0.2s ease;
}

.search-box input:focus {
    border-color: #111111;
    background: #ffffff;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    opacity: 0.6;
    pointer-events: none;
}

.controls, .editor-controls, .reader-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex: 0 0 auto;
    justify-content: flex-end;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.control-group label {
    font-size: 0.9rem;
    color: #555555;
    margin-right: 2px;
}

.divider {
    width: 1px;
    height: 18px;
    background-color: #dcdcdc;
}

button,
.tool-btn,
.book-state-btn,
a.tool-btn {
    font-weight: 700;
}

body[data-page="studio"] .font-cormorant,
body[data-page="studio"] .font-manuscrita,
body[data-page="studio"] .font-apple,
body[data-page="studio"] .font-mia,
body[data-page="studio"] .font-preview-btn,
body[data-page="studio"] [data-font-option] {
    font-weight: 400;
}

.tool-btn {
    background: #ffffff;
    border: 1px solid #cccccc;
    padding: 4px 11px;
    border-radius: 20px;
    font-family: 'Cormorant Garamond', serif;
    font-size: 0.9rem;
    color: #222222;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
}

.tool-btn:hover {
    background: #eeeeee;
    border-color: #999999;
}

.tool-btn.active {
    background: #181818;
    color: #ffffff;
    border-color: #181818;
}

.save-action-btn {
    background: #ffffff;
    border: 1px solid #bbbbbb;
    font-weight: 700;
    color: #111111;
    padding: 5px 15px;
    height: 36px;
    border-radius: 20px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.save-action-btn:hover {
    background: #f0f0f0;
}

.book-state-btn {
    background: #181818;
    color: #ffffff;
    border: 1px solid #181818;
    padding: 6px 16px;
    height: 36px;
    border-radius: 20px;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transition: background 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.book-state-btn:hover {
    background: #333333;
}

.logout-btn {
    background: #ffffff;
    border: 1px solid #cccccc;
    color: #222222;
}

.logout-btn:hover {
    background: #eeeeee;
    border-color: #999999;
}

.font-cormorant { font-family: 'Cormorant Garamond', serif; }
.font-manuscrita { font-family: 'Reenie Beanie', cursive; }
.font-apple { font-family: 'Homemade Apple', cursive; }
.font-mia { font-family: 'FuenteSubidaUsuario', sans-serif; }

.textbox-content,
.reader-textbox-content {
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

input[type="range"] {
    accent-color: #181818;
    cursor: pointer;
}

input[type="color"] {
    width: 26px;
    height: 26px;
    border: 1px solid #cccccc;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    padding: 0;
}

.mini-btn {
    background: #eaeaea;
    border: 1px solid #d4d4d4;
    padding: 4px 10px;
    border-radius: 12px;
    font-family: 'Cormorant Garamond', serif;
    font-size: 0.85rem;
    color: #111111;
    cursor: pointer;
}

.mini-btn:hover {
    background: #dcdcdc;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-card {
    background: #ffffff;
    border: 1px solid #cccccc;
    border-radius: 16px;
    padding: 28px;
    width: 420px;
    max-width: 92%;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.15);
}

.modal-card h3 {
    font-size: 1.3rem;
    font-weight: 600;
    color: #111111;
}

.modal-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.modal-field label {
    font-size: 0.9rem;
    color: #555555;
}

.modal-input, .modal-textarea {
    width: 100%;
    padding: 8px 14px;
    border: 1px solid #cccccc;
    border-radius: 10px;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1rem;
    background: #fafafa;
    outline: none;
    transition: all 0.2s ease;
}

.modal-input:focus {
    border-color: #111111;
    background: #ffffff;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

.avatar-crop-container {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    border: 3px solid #111111;
    overflow: hidden;
    position: relative;
    background: #e8e8e8;
    cursor: grab;
    user-select: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.avatar-crop-inner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
}

.avatar-crop-inner img {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: translate(-50%, -50%);
    transform-origin: center center;
    pointer-events: none;
}

@media (max-width: 640px) {
    .toolbar {
        padding: 10px 12px;
        gap: 8px;
        width: 100%;
    }

    .brand {
        flex: 0 0 auto;
        font-size: 1.25rem;
    }

    .toolbar-center {
        order: 3;
        flex: 1 1 100%;
        max-width: 100%;
    }

    .controls,
    .editor-controls,
    .reader-toolbar-actions {
        flex: 1 1 auto;
        justify-content: flex-end;
        gap: 6px;
        max-width: 100%;
    }

    .tool-btn,
    .book-state-btn,
    .save-action-btn {
        font-size: 0.85rem;
        padding: 4px 10px;
        height: 32px;
    }
}