/*
 * Rebelle Experimental - Home Screen app (PWA) mode.
 * Everything here starts with html.app-mode, so the website itself is not affected.
 */

/* ---------- only the game on the page ---------- */
html.app-mode,
html.app-mode body {
    height: 100%;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    overscroll-behavior: none;
    background: #000;
    touch-action: none;
    -webkit-text-size-adjust: 100%;
}

html.app-mode body > *:not(#fp-wrapper):not(#touch-debug) {
    display: none !important;
}

html.app-mode #fp-wrapper {
    --rb-accent: #0a84ff;
    --rb-text: rgba(255, 255, 255, 0.96);
    --rb-dim: rgba(235, 235, 245, 0.6);
    --rb-line: rgba(255, 255, 255, 0.12);
    --rb-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    position: fixed !important;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex !important;
    align-items: center;
    justify-content: center;
    overflow: clip;
    background: #000;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    font-family: var(--rb-font);
    /* space kept free at the bottom edge (the home bar: swipe up = switch apps) */
    --rb-bottom-gap: env(safe-area-inset-bottom, 0px);
}

/* phones and tablets: always keep at least 32px free at the bottom */
@media (pointer: coarse) {
    html.app-mode #fp-wrapper {
        --rb-bottom-gap: max(env(safe-area-inset-bottom, 0px), 32px);
    }
}

html.app-mode #fp-wrapper #can_wrap {
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 0;
}

/* exact size from the script (--app-w / --app-h): keeps the shape, nothing is stretched */
html.app-mode #fp-wrapper canvas {
    display: block;
    width: var(--app-w, 100%) !important;
    height: var(--app-h, auto) !important;
    max-height: none !important;
    object-fit: fill;
    touch-action: none;
}

html.app-mode #fp-fs-btn {
    display: none !important;
}

/* ---------- controls layer ---------- */
.rb-ui {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: clip;
    pointer-events: none;
    line-height: normal;
    color: var(--rb-text);
    font-family: var(--rb-font);
    font-size: 15px;
    letter-spacing: -0.01em;
    text-align: left;
}

.rb-ui button {
    font: inherit;
    color: inherit;
    margin: 0;
    border: 0;
    background: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.rb-icon {
    width: 26px;
    height: 26px;
    flex: none;
    display: block;
}

/* glass: see-through, blurred, thin light edge, light on top, soft shadow */
.rb-glass {
    position: relative;
    background: rgba(34, 34, 38, 0.62);
    -webkit-backdrop-filter: blur(26px) saturate(180%);
    backdrop-filter: blur(26px) saturate(180%);
    border: 0.5px solid rgba(255, 255, 255, 0.24);
    box-shadow:
        0 12px 32px rgba(0, 0, 0, 0.28),
        0 2px 6px rgba(0, 0, 0, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.rb-glass::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    border-radius: inherit;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 42%);
    pointer-events: none;
}

/* ---------- tools (left, with names) ---------- */
.rb-tools {
    position: absolute;
    left: calc(env(safe-area-inset-left, 0px) + 10px);
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    border-radius: 22px;
    pointer-events: auto;
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.22s ease;
}

.rb-tool {
    position: relative;
    width: 66px;
    height: 52px;
    border-radius: 15px !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: rgba(255, 255, 255, 0.92) !important;
    transition: background-color 0.16s ease, color 0.16s ease, transform 0.12s ease;
}

.rb-tool:active,
.rb-chip:active,
.rb-brush-btn:active,
.rb-dot:active {
    transform: scale(0.94);
}

.rb-tool .rb-icon {
    width: 25px;
    height: 25px;
}

.rb-tool-label,
.rb-chip-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0;
    line-height: 1;
    white-space: nowrap;
}

.rb-tool.is-on,
.rb-chip.is-on {
    background: var(--rb-accent) !important;
    color: #fff !important;
    box-shadow: 0 4px 14px rgba(10, 132, 255, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* little room (phone held sideways): icon and name side by side */
.rb-tools.is-tight .rb-tool,
.rb-side.is-tight .rb-tool,
.rb-mini .rb-tool {
    flex-direction: row;
    justify-content: flex-start;
    gap: 7px;
    width: 92px;
    height: 30px;
    padding: 0 9px !important;
    border-radius: 11px !important;
}

.rb-tools.is-two-col {
    display: grid;
    grid-template-columns: repeat(2, auto);
}

.rb-tools.is-tight .rb-tool .rb-icon,
.rb-side.is-tight .rb-tool .rb-icon {
    width: 19px;
    height: 19px;
}

.rb-tools.is-tight .rb-tool-label,
.rb-side.is-tight .rb-tool-label {
    font-size: 12px;
}

.rb-vsep {
    flex: none;
    width: 0.5px;
    align-self: stretch;
    margin: 8px 3px;
    background: rgba(255, 255, 255, 0.22);
}

/* ---------- top bar: the whole paper ---------- */
.rb-topbar {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    left: 0;
    right: 0;
    margin: 0 auto;
    width: fit-content;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 5px;
    border-radius: 20px;
    max-width: calc(100% - 20px);
    box-sizing: border-box;
    pointer-events: auto;
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.22s ease;
}

.rb-chip {
    flex: none;
    width: 66px;
    height: 50px;
    border-radius: 14px !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.92) !important;
    transition: background-color 0.16s ease, transform 0.12s ease;
}

.rb-chip .rb-icon {
    width: 22px;
    height: 22px;
}

.rb-chip.is-flash {
    background: var(--rb-accent) !important;
}

.rb-chip-danger {
    color: #ff6b62 !important;
}

.rb-chip-paper {
    width: auto;
    padding: 0 6px;
}

.rb-paper-seg {
    display: flex;
    gap: 2px;
    padding: 2px;
    border-radius: 8px;
    background: rgba(118, 118, 128, 0.3);
}

.rb-paper-seg button {
    width: 24px;
    height: 20px;
    border-radius: 6px !important;
    font-size: 12px !important;
    font-weight: 700 !important;
}

.rb-paper-seg button.is-on {
    background: rgba(255, 255, 255, 0.92) !important;
    color: #1c1c1e !important;
}

/* ---------- bottom bar: brush and color ---------- */
.rb-bottombar {
    position: absolute;
    bottom: calc(var(--rb-bottom-gap) + 8px);
    left: 0;
    right: 0;
    margin: 0 auto;
    width: fit-content;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 7px 12px;
    border-radius: 22px;
    max-width: calc(100% - 20px);
    box-sizing: border-box;
    pointer-events: auto;
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.22s ease;
}

.rb-brush-btn {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 48px;
    padding: 0 8px 0 6px !important;
    border-radius: 14px !important;
    background: rgba(255, 255, 255, 0.09) !important;
    text-align: left;
    transition: transform 0.12s ease;
}

.rb-brush-preview {
    display: block;
    width: 44px;
    height: 28px;
    flex: none;
    color: var(--rb-paint, #4a90d9);
}

.rb-brush-preview svg {
    display: block;
    width: 100%;
    height: 100%;
}

.rb-brush-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 74px;
}

.rb-brush-caption {
    color: var(--rb-dim);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.rb-brush-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.rb-chevron {
    width: 16px;
    height: 16px;
    color: var(--rb-dim);
}

.rb-bar-sliders {
    display: flex;
    gap: 16px;
}

.rb-bottombar .rb-row-slider {
    width: 150px;
    min-height: 0;
    padding: 0;
    gap: 0;
    border: 0;
}

.rb-bottombar .rb-row-top {
    gap: 6px;
}

.rb-bottombar .rb-row-top .rb-icon {
    width: 16px;
    height: 16px;
}

.rb-bottombar .rb-row-label,
.rb-bottombar .rb-row-value {
    font-size: 12px;
    font-weight: 600;
}

.rb-bottombar .rb-slider {
    height: 30px;
}

.rb-bar-colors {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rb-color-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    width: 44px;
    padding: 2px 0 !important;
}

.rb-swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.92), 0 0 0 3.5px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.4);
}

.rb-dot {
    flex: none;
    width: 26px;
    height: 26px;
    border-radius: 50% !important;
    box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.3), 0 2px 5px rgba(0, 0, 0, 0.3);
    transition: transform 0.12s ease;
}

.rb-dot.is-on {
    box-shadow: 0 0 0 2px #26262a, 0 0 0 4px #fff;
}

/* sheets and questions are always on top */
.rb-sheet-wrap {
    z-index: 5;
}

.rb-dialog-wrap {
    z-index: 6;
}

/* while a sheet is open, the bars step aside */
#fp-wrapper.rb-sheet-open .rb-side,
#fp-wrapper.rb-drawing .rb-side {
    transform: translate(calc(100% + 40px), -50%);
    opacity: 0;
    pointer-events: none;
}

#fp-wrapper.rb-sheet-open .rb-tools {
    transform: translate(calc(-100% - 40px), -50%);
    opacity: 0;
    pointer-events: none;
}

#fp-wrapper.rb-sheet-open .rb-topbar {
    transform: translateY(calc(-100% - 40px));
    opacity: 0;
    pointer-events: none;
}

#fp-wrapper.rb-sheet-open .rb-bottombar {
    transform: translateY(calc(100% + 40px));
    opacity: 0;
    pointer-events: none;
}

/* while painting all bars slide away, and come back right away */
#fp-wrapper.rb-drawing .rb-tools {
    transform: translate(calc(-100% - 40px), -50%);
    opacity: 0;
    pointer-events: none;
}

#fp-wrapper.rb-drawing .rb-topbar {
    transform: translateY(calc(-100% - 40px));
    opacity: 0;
    pointer-events: none;
}

#fp-wrapper.rb-drawing .rb-bottombar {
    transform: translateY(calc(100% + 40px));
    opacity: 0;
    pointer-events: none;
}

/* low screen (phone held sideways): smaller bars */
@media (max-height: 560px) {
    .rb-topbar {
        padding: 3px;
        border-radius: 16px;
    }

    .rb-chip {
        width: 56px;
        height: 42px;
        gap: 3px;
        border-radius: 12px !important;
    }

    .rb-chip .rb-icon {
        width: 19px;
        height: 19px;
    }

    .rb-chip-paper {
        width: auto;
    }

    .rb-chip-label,
    .rb-tool-label {
        font-size: 10px;
    }

    .rb-bottombar {
        padding: 4px 10px;
        gap: 4px 10px;
        border-radius: 18px;
    }

    .rb-brush-btn {
        height: 40px;
    }

    .rb-brush-text {
        min-width: 64px;
    }

    .rb-bottombar .rb-row-slider {
        width: 112px;
    }

    .rb-bottombar .rb-slider {
        height: 26px;
    }

    .rb-color-btn {
        width: 38px;
    }

    .rb-color-btn .rb-chip-label {
        display: none;
    }

    .rb-dot {
        width: 22px;
        height: 22px;
    }

    .rb-dot:nth-child(n + 8) {
        display: none;
    }
}

/* small phone held sideways: a bit less in the bottom bar */
@media (max-height: 560px) and (max-width: 740px) {
    .rb-bottombar .rb-row-slider {
        width: 86px;
    }

    .rb-brush-text {
        min-width: 56px;
    }

    .rb-dot {
        display: none;
    }

    .rb-color-btn .rb-chip-label {
        display: block;
    }
}

/* narrow screen (phone held upright): bottom bar in two rows */
@media (max-width: 600px) {
    .rb-topbar {
        gap: 0;
        padding: 3px;
    }

    .rb-chip {
        width: auto;
        min-width: 42px;
        height: 44px;
        padding: 0 3px !important;
    }

    .rb-chip-label {
        font-size: 9px;
        letter-spacing: -0.01em;
    }

    .rb-chip-paper {
        padding: 0 3px;
    }

    .rb-paper-seg button {
        width: 18px;
    }

    .rb-topbar .rb-vsep {
        margin: 8px 1px;
    }

    .rb-bottombar {
        width: calc(100% - 20px);
        gap: 8px 12px;
        justify-content: space-between;
    }

    .rb-bar-sep {
        display: none;
    }

    .rb-bar-sliders {
        order: -1;
        width: 100%;
        gap: 12px;
    }

    .rb-bottombar .rb-row-slider {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    /* lower row: brush on the left edge, colors spread to the right edge,
       so both rows line up with the edges of the bar */
    .rb-bar-colors {
        flex: 1;
        min-width: 0;
        justify-content: space-between;
        gap: 4px;
    }

    .rb-brush-text {
        min-width: 58px;
    }

    .rb-dot {
        width: 22px;
        height: 22px;
    }

    /* brush and colors share one row */
    .rb-dot:nth-child(n + 7) {
        display: none;
    }
}

/* ---------- "Fit to screen" ---------- */
.rb-fit {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 80px);
    left: 50%;
    transform: translateX(-50%);
    display: none;
    align-items: center;
    gap: 8px;
    padding: 9px 16px 9px 12px;
    border-radius: 999px !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    pointer-events: auto;
}

.rb-fit.is-visible {
    display: flex;
}

.rb-fit .rb-icon {
    width: 20px;
    height: 20px;
}

/* ---------- sheets (from the bottom) ---------- */
.rb-sheet-wrap {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    visibility: hidden;
    pointer-events: none;
    transition: visibility 0s linear 0.3s;
}

.rb-sheet-wrap.is-open {
    visibility: visible;
    pointer-events: auto;
    transition: visibility 0s;
}

.rb-backdrop {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.32);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.rb-sheet-wrap.is-open .rb-backdrop {
    opacity: 1;
}

.rb-sheet {
    position: absolute;
    left: 50%;
    bottom: calc(var(--rb-bottom-gap) + 10px);
    width: min(440px, calc(100% - 20px));
    max-height: calc(100% - env(safe-area-inset-top, 0px) - var(--rb-bottom-gap) - 20px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    border-radius: 28px;
    background: rgba(30, 30, 34, 0.72);
    transform: translate(-50%, calc(100% + 40px));
    transition: transform 0.34s cubic-bezier(0.2, 0.9, 0.2, 1);
}

.rb-sheet-wrap.is-open .rb-sheet {
    transform: translate(-50%, 0);
}

.rb-sheet-head {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    height: 52px;
    padding: 0 16px;
    border-bottom: 0.5px solid var(--rb-line);
}

.rb-sheet-title {
    font-size: 17px;
    font-weight: 600;
}

.rb-done {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    padding: 8px 12px !important;
    border-radius: 12px !important;
    color: var(--rb-accent) !important;
    font-size: 17px !important;
    font-weight: 600 !important;
}

.rb-sheet-body {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 6px 16px 16px;
}

.rb-section {
    margin-top: 14px;
}

.rb-section-title {
    margin: 0 4px 7px;
    color: var(--rb-dim);
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.rb-card {
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.07);
    overflow: hidden;
}

.rb-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 50px;
    padding: 0 14px;
    border-top: 0.5px solid var(--rb-line);
}

.rb-card > .rb-row:first-child {
    border-top: 0;
}

.rb-row .rb-icon {
    width: 22px;
    height: 22px;
    color: var(--rb-dim);
}

.rb-row-label {
    flex: 1;
    font-size: 16px;
}

.rb-row-value {
    color: var(--rb-dim);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
}

/* slider row: label on top, slider under it */
.rb-row-slider {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 10px 14px 6px;
}

.rb-row-top {
    display: flex;
    align-items: center;
    gap: 12px;
}

.rb-slider {
    position: relative;
    height: 32px;
    touch-action: none;
    cursor: pointer;
}

.rb-track {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 6px;
    margin-top: -3px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.16);
    overflow: hidden;
}

.rb-fill {
    height: 100%;
    background: var(--rb-accent);
    border-radius: 3px;
}

.rb-knob {
    position: absolute;
    top: 50%;
    width: 26px;
    height: 26px;
    margin: -13px 0 0 -13px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 3px #fff, 0 3px 8px rgba(0, 0, 0, 0.35), 0 0 0 0.5px rgba(0, 0, 0, 0.1);
    transition: transform 0.12s ease;
}

.rb-slider.is-active .rb-knob {
    transform: scale(1.12);
}

/* iPhone-like switch */
.rb-switch {
    position: relative;
    flex: none;
    width: 51px;
    height: 31px;
    border-radius: 16px !important;
    background: rgba(120, 120, 128, 0.36) !important;
    transition: background-color 0.2s ease;
}

.rb-switch-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
    transition: transform 0.22s cubic-bezier(0.3, 0.7, 0.3, 1.2);
}

.rb-switch.is-on {
    background: #30d158 !important;
}

.rb-switch.is-on .rb-switch-knob {
    transform: translateX(20px);
}

.rb-row-toggle {
    cursor: pointer;
}

/* paper 1 / 2 / 3 */
.rb-segmented {
    display: flex;
    gap: 2px;
    padding: 2px;
    border-radius: 9px;
    background: rgba(118, 118, 128, 0.24);
}

.rb-seg {
    min-width: 40px;
    height: 28px;
    border-radius: 7px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
}

.rb-seg.is-on {
    background: rgba(255, 255, 255, 0.9) !important;
    color: #1c1c1e !important;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
}

/* whole paper: wet / dry / fast dry */
.rb-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 10px;
}

.rb-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 70px;
    border-radius: 14px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    transition: background-color 0.2s ease, transform 0.12s ease;
}

.rb-action:active {
    transform: scale(0.96);
}

.rb-action.is-flash {
    background: var(--rb-accent) !important;
}

.rb-action .rb-icon {
    color: var(--rb-text);
}

.rb-danger {
    width: 100%;
    margin-top: 14px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 50px;
    border-radius: 16px !important;
    background: rgba(255, 69, 58, 0.16) !important;
    color: #ff453a !important;
    font-size: 16px !important;
    font-weight: 600 !important;
}

.rb-danger .rb-icon {
    width: 20px;
    height: 20px;
    color: #ff453a;
}

.rb-about {
    margin-top: 14px;
    color: var(--rb-dim);
    font-size: 11.5px;
    text-align: center;
}

/* colour sheet */
.rb-color-preview {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.07);
}

.rb-color-dot {
    width: 44px;
    height: 44px;
    flex: none;
    border-radius: 12px;
    box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.3), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.rb-color-name {
    flex: 1;
    font-size: 17px;
    font-weight: 600;
}

.rb-color-hex {
    color: var(--rb-dim);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.rb-pigments {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    padding: 14px;
}

.rb-pigment {
    aspect-ratio: 1;
    width: 100%;
    border-radius: 50% !important;
    box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.25), 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.12s ease;
}

.rb-pigment:active {
    transform: scale(0.9);
}

.rb-pigment.is-on {
    box-shadow: 0 0 0 2.5px #1e1e22, 0 0 0 4.5px #fff;
}

/* ---------- dialog (like an iPhone alert) ---------- */
.rb-dialog-wrap {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.38);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.rb-dialog-wrap.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.2s ease;
}

.rb-dialog {
    width: 290px;
    border-radius: 16px;
    overflow: hidden;
    background: rgba(40, 40, 44, 0.86);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    backdrop-filter: blur(30px) saturate(180%);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    transform: scale(1.08);
    transition: transform 0.2s ease;
}

.rb-dialog-wrap.is-open .rb-dialog {
    transform: scale(1);
}

.rb-dialog-text {
    padding: 20px 18px 18px;
    text-align: center;
}

.rb-dialog-title {
    font-size: 17px;
    font-weight: 600;
}

.rb-dialog-msg {
    margin-top: 5px;
    color: rgba(235, 235, 245, 0.75);
    font-size: 13.5px;
    line-height: 1.35;
}

.rb-dialog-buttons {
    display: flex;
    border-top: 0.5px solid rgba(255, 255, 255, 0.16);
}

.rb-dialog-btn {
    flex: 1;
    height: 46px;
    color: var(--rb-accent) !important;
    font-size: 17px !important;
}

.rb-dialog-btn + .rb-dialog-btn {
    border-left: 0.5px solid rgba(255, 255, 255, 0.16) !important;
}

.rb-dialog-btn.is-bold {
    font-weight: 600 !important;
}

.rb-dialog-btn.is-danger {
    color: #ff453a !important;
    font-weight: 600 !important;
}

/* ---------- brush list ---------- */
.rb-brush-row {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 62px;
    padding: 8px 14px !important;
    border-top: 0.5px solid var(--rb-line) !important;
    text-align: left;
}

.rb-card > .rb-brush-row:first-child {
    border-top: 0 !important;
}

.rb-brush-row .rb-brush-preview {
    width: 56px;
    height: 34px;
}

.rb-brush-row-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.rb-brush-row-name {
    font-size: 16px;
    font-weight: 600;
}

.rb-brush-row-desc {
    color: var(--rb-dim);
    font-size: 13px;
    line-height: 1.3;
}

.rb-brush-check {
    color: var(--rb-accent);
    visibility: hidden;
}

.rb-brush-check .rb-icon {
    width: 22px;
    height: 22px;
}

.rb-brush-row.is-on .rb-brush-check {
    visibility: visible;
}

.rb-brush-row.is-on {
    background: rgba(10, 132, 255, 0.14) !important;
}

/* ---------- right side: Undo, Redo, Save ---------- */
.rb-side {
    position: absolute;
    right: calc(env(safe-area-inset-right, 0px) + 10px);
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    border-radius: 22px;
    pointer-events: auto;
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.22s ease;
}

.rb-side .rb-sep {
    height: 0.5px;
    margin: 3px 8px;
    background: rgba(255, 255, 255, 0.22);
}

.rb-tool:disabled {
    opacity: 0.32;
    cursor: default;
}

/* colour picker button (next to Color) */
.rb-pick-btn .rb-icon {
    width: 24px;
    height: 24px;
    padding: 1px;
    border-radius: 50%;
}

.rb-pick-btn.is-on .rb-icon {
    background: var(--rb-accent);
    color: #fff;
    box-shadow: 0 0 0 4px var(--rb-accent);
}

/* ---------- Tilt menu ---------- */
.rb-pop-wrap {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: none;
    z-index: 7;
    pointer-events: auto;
}

.rb-pop-wrap.is-open {
    display: block;
}

.rb-popover {
    position: absolute;
    width: 290px;
    max-width: calc(100% - 20px);
    box-sizing: border-box;
    padding: 6px;
    border-radius: 18px;
    background: rgba(30, 30, 34, 0.78);
}

.rb-pop-title {
    padding: 8px 10px 6px;
    color: var(--rb-dim);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.rb-pop-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px !important;
    border-radius: 12px !important;
    text-align: left;
}

.rb-pop-item .rb-icon {
    width: 24px;
    height: 24px;
}

.rb-pop-item.is-on {
    background: rgba(10, 132, 255, 0.2) !important;
}

.rb-pop-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rb-pop-text b {
    font-size: 15px;
    font-weight: 600;
}

.rb-pop-text span {
    color: var(--rb-dim);
    font-size: 12.5px;
    line-height: 1.3;
}

.rb-pop-check {
    color: var(--rb-accent);
    visibility: hidden;
}

.rb-pop-item.is-on .rb-pop-check {
    visibility: visible;
}

/* ---------- short messages ---------- */
.rb-toast {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(env(safe-area-inset-top, 0px) + 78px);
    width: fit-content;
    max-width: calc(100% - 40px);
    margin: 0 auto;
    padding: 9px 16px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    z-index: 8;
}

.rb-toast.is-visible {
    opacity: 1;
    transform: none;
}

/* ---------- Paper menu ---------- */
.rb-paper-pop {
    width: 320px;
    max-height: calc(100% - 90px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.rb-tex-seg {
    display: flex;
    margin: 0 6px 6px;
}

.rb-tex-seg .rb-seg {
    flex: 1;
    min-width: 0;
    height: 30px;
    font-size: 13px !important;
}

.rb-tints {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 0 6px 8px;
}

.rb-tint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 4px !important;
    border-radius: 12px !important;
    background: rgba(255, 255, 255, 0.06) !important;
    font-size: 12px !important;
    font-weight: 600 !important;
}

.rb-tint.is-on {
    background: rgba(10, 132, 255, 0.22) !important;
    box-shadow: inset 0 0 0 1.5px var(--rb-accent);
}

.rb-tint-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.25), 0 2px 5px rgba(0, 0, 0, 0.3);
}

.rb-pop-card {
    margin: 2px 6px 6px;
}

/* eraser: "Strength" replaces "Water" in the bottom bar */
.rb-bottombar:not(.is-erase) .rb-strength-row,
.rb-bottombar.is-erase .rb-water-row {
    display: none;
}

/* ---------- zoom level ---------- */
.rb-zoom {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 80px);
    right: calc(env(safe-area-inset-right, 0px) + 12px);
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 12px 8px 10px !important;
    border-radius: 999px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    font-variant-numeric: tabular-nums;
    pointer-events: auto;
}

.rb-zoom.is-visible {
    display: flex;
}

.rb-zoom .rb-icon {
    width: 18px;
    height: 18px;
}

#fp-wrapper.rb-drawing .rb-zoom {
    opacity: 0;
    pointer-events: none;
}

/* ---------- controls hidden by hand ---------- */
#fp-wrapper.rb-hidden .rb-tools {
    transform: translate(calc(-100% - 40px), -50%);
    opacity: 0;
    pointer-events: none;
}

#fp-wrapper.rb-hidden .rb-side {
    transform: translate(calc(100% + 40px), -50%);
    opacity: 0;
    pointer-events: none;
}

#fp-wrapper.rb-hidden .rb-topbar {
    transform: translateY(calc(-100% - 40px));
    opacity: 0;
    pointer-events: none;
}

#fp-wrapper.rb-hidden .rb-bottombar {
    transform: translateY(calc(100% + 40px));
    opacity: 0;
    pointer-events: none;
}

#fp-wrapper.rb-hidden .rb-zoom {
    opacity: 0;
    pointer-events: none;
}

/* the small eye button that brings the controls back */
.rb-show {
    position: absolute;
    right: calc(env(safe-area-inset-right, 0px) + 10px);
    top: 50%;
    width: 46px;
    height: 46px;
    border-radius: 50% !important;
    display: none;
    align-items: center;
    justify-content: center;
    transform: translateY(-50%);
    opacity: 0.85;
    pointer-events: auto;
    transition: opacity 0.2s ease;
}

.rb-show .rb-icon {
    width: 24px;
    height: 24px;
}

#fp-wrapper.rb-hidden .rb-show {
    display: flex;
}

/* while painting even the eye fades away */
#fp-wrapper.rb-hidden.rb-drawing .rb-show {
    opacity: 0;
    pointer-events: none;
}

/* ---------- "In full Rebelle" ---------- */
.rb-extra-row .rb-brush-row-name {
    color: var(--rb-text);
}

.rb-extra-lock {
    display: flex !important;
    align-items: center;
    justify-content: center;
    color: var(--rb-dim) !important;
}

.rb-extra-lock .rb-icon {
    width: 22px;
    height: 22px;
}

/* small card with a link to the full Rebelle */
.rb-hint {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(env(safe-area-inset-top, 0px) + 80px);
    width: fit-content;
    max-width: calc(100% - 24px);
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px 8px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.3;
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 8;
}

.rb-hint.is-visible {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

#fp-wrapper.rb-drawing .rb-hint {
    opacity: 0;
    pointer-events: none;
}

.rb-hint-go {
    flex: none;
    padding: 8px 12px !important;
    border-radius: 12px !important;
    background: var(--rb-accent) !important;
    color: #fff !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    white-space: nowrap;
}

.rb-hint-close {
    flex: none;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50% !important;
    color: var(--rb-dim) !important;
}

.rb-hint-close .rb-icon {
    width: 16px;
    height: 16px;
}

/* About */
.rb-about-card {
    margin-top: 12px;
    padding: 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.07);
}

.rb-about-title {
    font-size: 19px;
    font-weight: 700;
}

.rb-about-text {
    margin-top: 6px;
    color: rgba(235, 235, 245, 0.78);
    font-size: 14px;
    line-height: 1.4;
}

.rb-about-go {
    width: 100%;
    height: 50px;
    margin-top: 12px !important;
    border-radius: 16px !important;
    background: var(--rb-accent) !important;
    color: #fff !important;
    font-size: 16px !important;
    font-weight: 600 !important;
}