* { box-sizing: border-box; }

:root {
    --letter-w: clamp(52px, 9vw, 100px);
    --letter-h: clamp(64px, 11vw, 124px);
}
[data-size="S"] {
    --letter-w: clamp(36px, 6vw, 70px);
    --letter-h: clamp(45px, 7.5vw, 88px);
}
[data-size="L"] {
    --letter-w: clamp(68px, 12vw, 134px);
    --letter-h: clamp(85px, 15vw, 168px);
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    color: white;
    background: #1a0d09 url('images/mars-bg.jpg') center / cover no-repeat;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.brand {
    position: fixed;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    letter-spacing: 0.25em;
    color: rgba(255, 255, 255, 0.65);
    text-align: center;
    white-space: nowrap;
    z-index: 10;
    pointer-events: none;
}

/* ---------- Editable area ---------- */

.editableSection {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 80px 20px 140px;
}

[contenteditable] { outline: none; }
[contenteditable]:empty:not(:focus):before {
    content: attr(data-text);
    color: rgba(255, 255, 255, 0.85);
}

#editable {
    display: block;
    max-width: 92%;
    max-height: 70vh;
    overflow-y: auto;
    min-height: 20vh;
    text-align: center;
    font-family: "Times New Roman", Georgia, serif;
    font-size: clamp(40px, 8vw, 14vh);
    line-height: 1.1;
    overflow-wrap: break-word;
}
#editable:after {
    content: "|";
    animation: blink 1.3s ease infinite;
}
#editable.is-focused:after { content: ""; }

@keyframes blink {
    0%   { opacity: 1; }
    100% { opacity: 0.1; }
}

/* Letter glyphs in editable */
.words {
    width: var(--letter-w);
    height: var(--letter-h);
    margin: 0 4px;
    vertical-align: middle;
    transition: width 0.15s, height 0.15s;
}
.spacebar {
    display: inline-block;
    width: calc(var(--letter-w) * 0.3);
}

/* ---------- Bottom bar ---------- */

.bottom-bar {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 8px 8px 18px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 999px;
    z-index: 10;
    max-width: calc(100vw - 32px);
}

.size-control {
    display: flex;
    align-items: center;
    gap: 10px;
}
.size-label {
    font-size: 12px;
    letter-spacing: 0.15em;
    color: rgba(255, 255, 255, 0.7);
}
.size-chips {
    display: flex;
    gap: 4px;
}
.size-chip {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.size-chip:hover {
    border-color: rgba(255, 255, 255, 0.6);
}
.size-chip.is-active {
    background: white;
    color: black;
    border-color: white;
}

.bar-divider {
    width: 1px;
    height: 22px;
    background: rgba(255, 255, 255, 0.2);
}

.icon-button {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}
.icon-button:hover {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.08);
}

.char-counter {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.55);
    font-variant-numeric: tabular-nums;
    min-width: 40px;
    text-align: center;
}
.char-counter.is-limit {
    color: #ff8a8a;
}

.publish-button {
    background: white;
    color: black;
    border: none;
    padding: 10px 24px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.02em;
}
.publish-button:hover {
    background: rgba(255, 255, 255, 0.92);
}

/* ---------- Publish popup ---------- */

#fullscreen-popup {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.85) url('images/mars-bg.jpg') center / cover;
    z-index: 100;
    overflow: auto;
}

.mars-bg {
    width: min(90vw, 80vh, 1080px);
    aspect-ratio: 1 / 1;
    background: url('images/mars-bg.jpg') center / cover;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 8px solid white;
    border-radius: 16px;
    overflow: hidden;
    padding: 3%;
}

.mars-items {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px;
    width: 100%;
}
.mars-items .break {
    flex-basis: 100%;
    height: 0;
}
.mars-items .words {
    margin: 0;
    display: block;
}

.popup-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}
.download-button,
.close-button {
    border: none;
    padding: 10px 28px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 999px;
}
.download-button {
    background: white;
    color: black;
}
.close-button {
    background: rgba(0, 0, 0, 0.4);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.hide { display: none !important; }

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
    .brand {
        top: 12px;
        font-size: 9px;
        letter-spacing: 0.15em;
    }
    .editableSection {
        padding: 60px 16px 120px;
    }
    .bottom-bar {
        bottom: 16px;
        gap: 10px;
        padding: 6px 6px 6px 14px;
    }
    .size-label {
        display: none;
    }
    .char-counter {
        display: none;
    }
    .size-chip,
    .icon-button {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }
    .publish-button {
        padding: 8px 18px;
        font-size: 13px;
    }
}
