/* ReadingNova – phone layout for Colour Online + Doodle (used only when rn-paint.js switches it on).
   Everything is scoped to .rnp / html.rnp-on, so desktop is untouched. */

html.rnp-on, html.rnp-on body { overflow: hidden !important; overscroll-behavior: none; }

.rnp {
    --rnp-accent: #F97316;          /* selected tool (Colour Online = orange) */
    --rnp-accent-soft: #FFEDD5;
    --rnp-accent-ink: #C2410C;
    position: fixed; inset: 0; z-index: 9000;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "top" "rain" "main" "bar";
    background: #F6F7FB; color: #1E2A4A;
    font-family: 'Poppins', sans-serif;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none; user-select: none;
}
.rnp--red { --rnp-accent: #EF4444; --rnp-accent-soft: #FEE2E2; --rnp-accent-ink: #B91C1C; }   /* Doodle */
.rnp *, .rnp *::before, .rnp *::after { box-sizing: border-box; }
.rnp button { font-family: inherit; cursor: pointer; }
.rnp button:focus-visible, .rnp label:focus-within { outline: 3px solid #6366F1; outline-offset: 2px; }
.rnp [hidden] { display: none !important; }

/* top bar */
.rnp-top { grid-area: top; display: flex; align-items: center; gap: 6px; height: 56px; padding: 0 8px; background: #FFFFFF; }
.rnp-round { width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; border: 0; background: #F1F3F8; color: #1E2A4A;
    display: flex; align-items: center; justify-content: center; padding: 0; }
.rnp-more[aria-expanded="true"] { background: #1E2A4A; color: #FFFFFF; }
.rnp-title { flex: 1; min-width: 0; margin: 0; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 18px; line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #1E2A4A; }
.rnp-undo { height: 44px; flex-shrink: 0; padding: 0 14px; border-radius: 999px; border: 2px solid #E6E8F0; background: #FFFFFF; color: #1E2A4A;
    display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; }
.rnp-undo:active { background: #F1F3F8; }
.rnp-rainbow { grid-area: rain; display: flex; height: 4px; }
.rnp-rainbow i { flex: 1; }
.rnp-rainbow i:nth-child(1) { background: #A855F7; } .rnp-rainbow i:nth-child(2) { background: #6366F1; }
.rnp-rainbow i:nth-child(3) { background: #0EA5E9; } .rnp-rainbow i:nth-child(4) { background: #22C55E; }
.rnp-rainbow i:nth-child(5) { background: #FACC15; } .rnp-rainbow i:nth-child(6) { background: #F97316; }
.rnp-rainbow i:nth-child(7) { background: #EF4444; }

/* picture area */
.rnp-main { grid-area: main; min-height: 0; min-width: 0; padding: 8px; display: flex; }
.rnp-frame { position: relative; flex: 1; min-width: 0; min-height: 0; background: #FFFFFF; border-radius: 16px;
    border: 2px solid #E6E8F0; box-shadow: 0 4px 16px rgba(30, 42, 74, .10); overflow: hidden; }
.rnp .rnp-stage {
    position: absolute !important; inset: 0 !important; width: auto !important; height: auto !important; max-width: none !important; max-height: none !important;
    margin: 0 !important; padding: 0 !important; border: 0 !important; border-radius: 0 !important; background: #FFFFFF !important; box-shadow: none !important;
    display: flex !important; align-items: center; justify-content: center; overflow: hidden !important; flex: none !important; aspect-ratio: auto !important;
    touch-action: none;
}
html.rnp-on .rnp-stage canvas#colouringCanvas,
html.rnp-on .rnp-stage canvas#drawingCanvas {
    width: var(--rnp-cw, 100%) !important; height: var(--rnp-ch, 100%) !important;
    max-width: none !important; max-height: none !important; aspect-ratio: auto !important;
    border: 0 !important; border-radius: 0 !important; box-shadow: none !important; margin: 0 !important;
    transform-origin: 0 0; flex-shrink: 0; touch-action: none; display: block !important;
}
.rnp .rnp-stage #loadingMessage { z-index: 2; }
/* Doodle: the "look at" picture becomes a small thumbnail in the corner */
.rnp .rnp-stage .reference-image { position: absolute !important; top: 8px !important; right: 8px !important; left: auto !important;
    max-width: 96px !important; max-height: 120px !important; width: auto !important; margin: 0 !important; z-index: 3; opacity: .9; }
.rnp .rnp-stage .reference-image:empty { display: none !important; }
.rnp .rnp-stage .text-input-overlay { z-index: 5; min-width: 0; width: min(320px, calc(100% - 24px)); }

.rnp-hint { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 4; pointer-events: none; white-space: nowrap;
    background: rgba(30, 42, 74, .8); color: #FFFFFF; font-size: 12px; font-weight: 500; padding: 5px 12px; border-radius: 999px; }
.rnp-zoom { position: absolute; right: 8px; bottom: 8px; z-index: 4; display: flex; flex-direction: column; gap: 6px; }
.rnp-zbtn { width: 44px; height: 44px; border-radius: 12px; border: 2px solid #E6E8F0; background: rgba(255, 255, 255, .95); color: #1E2A4A;
    font-size: 22px; font-weight: 600; line-height: 1; padding: 0; }
.rnp-zbtn:disabled { opacity: .4; }

/* bottom toolbar */
.rnp-bar { grid-area: bar; display: flex; align-items: flex-start; justify-content: space-around; gap: 2px;
    min-height: 84px; padding: 8px 4px calc(8px + env(safe-area-inset-bottom, 0px)); background: #FFFFFF; border-top: 2px solid #EEF0F6; position: relative; z-index: 3; }
.rnp-tool { flex: 1 1 0; max-width: 76px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px;
    border: 0; background: transparent; color: #1E2A4A; padding: 0; }
.rnp-tool__ico { width: 100%; max-width: 54px; height: 44px; border-radius: 14px; display: flex; align-items: center; justify-content: center; background: #F1F3F8; }
.rnp-tool__label { font-size: 12px; font-weight: 600; white-space: nowrap; }
.rnp-tool.is-on { color: var(--rnp-accent-ink); }
.rnp-tool.is-on .rnp-tool__ico { background: var(--rnp-accent); color: #1E2A4A; }
.rnp-cdot { width: 44px; height: 44px; border-radius: 50%; display: block; border: 3px solid #FFFFFF; box-shadow: 0 0 0 2px #D9DCE6; }
.rnp-tool--colour[aria-expanded="true"] .rnp-cdot { box-shadow: 0 0 0 3px var(--rnp-accent); }
.rnp-quick { display: none; }

/* slide-up tray */
.rnp-tray { position: absolute; left: 0; right: 0; bottom: var(--rnp-bar-h, 86px); z-index: 4; max-height: 70%; overflow-y: auto;
    background: #FFFFFF; border-radius: 24px 24px 0 0; box-shadow: 0 -10px 30px rgba(30, 42, 74, .18);
    padding: 8px 16px 14px; display: flex; flex-direction: column; gap: 12px; animation: rnp-up .18s ease-out; }
@keyframes rnp-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.rnp-grab { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: #D9DCE6; }
.rnp-tray__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rnp-tray__head h2 { margin: 0; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 17px; color: #1E2A4A; }
.rnp-done { height: 40px; padding: 0 16px; border-radius: 999px; border: 0; background: #F1F3F8; color: #1E2A4A; font-weight: 600; font-size: 14px; }
.rnp-colours { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.rnp-sw { aspect-ratio: 1; width: 100%; min-height: 36px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.rnp-sw.is-light { border-color: #D9DCE6; }
.rnp-sw.is-on { box-shadow: 0 0 0 3px #FFFFFF, 0 0 0 6px #1E2A4A; }
.rnp-sw--any { position: relative; display: block; border: 2px dashed #A1A7B8; cursor: pointer; overflow: hidden;
    background: conic-gradient(#EF4444, #FACC15, #22C55E, #0EA5E9, #6366F1, #A855F7, #EF4444); }
.rnp-sw--any input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.rnp-sizes { display: flex; align-items: center; gap: 10px; }
.rnp-sizes__label { width: 78px; flex-shrink: 0; font-size: 13px; font-weight: 600; }
.rnp-sizes__row { flex: 1; display: flex; gap: 8px; }
.rnp-size { flex: 1; height: 48px; border-radius: 14px; border: 2px solid transparent; background: #F6F7FB; display: flex; align-items: center; justify-content: center; padding: 0; }
.rnp-size.is-on { background: var(--rnp-accent-soft); border-color: var(--rnp-accent); }
.rnp-dot { display: block; border-radius: 50%; border: 1px solid rgba(30, 42, 74, .25); }
.rnp-aa { font-family: 'Fredoka', sans-serif; font-weight: 600; line-height: 1; }
.rnp-shapes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.rnp-shape { height: 62px; border-radius: 14px; border: 2px solid transparent; background: #F6F7FB; color: #1E2A4A;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 0; }
.rnp-shape.is-on { background: var(--rnp-accent-soft); border-color: var(--rnp-accent); }
.rnp-shape__ico { height: 24px; display: flex; align-items: center; justify-content: center; }

/* ⋯ menu */
.rnp-menu { position: absolute; top: 60px; right: 8px; z-index: 6; width: 250px; max-width: calc(100% - 16px);
    background: #FFFFFF; border-radius: 16px; box-shadow: 0 12px 30px rgba(30, 42, 74, .22); padding: 6px; display: flex; flex-direction: column; }
.rnp-menu__item { min-height: 48px; border: 0; background: transparent; text-align: left; padding: 0 12px; border-radius: 10px;
    font-size: 15px; color: #1E2A4A; display: flex; align-items: center; gap: 10px; }
.rnp-menu__item:active { background: #F6F7FB; }
.rnp-menu__item.is-danger { color: #B91C1C; font-weight: 600; }
.rnp-menu__div { height: 1px; background: #EEF0F6; margin: 4px 6px; }
.rnp-menu__range { padding: 8px 12px; }
.rnp-menu__range label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #4B5568; }
.rnp-menu__range input { width: 100%; }

/* pop-up messages and "are you sure?" boxes from the tools stay on top of the app */
html.rnp-on .message { z-index: 20000 !important; top: 64px !important; left: 50% !important; right: auto !important; transform: translateX(-50%);
    width: max-content; max-width: calc(100% - 24px) !important; padding: .55rem 1rem !important; font-size: 14px; text-align: center; pointer-events: none; }
@media (orientation: landscape) and (max-height: 540px) { html.rnp-on .message { top: 8px !important; } }
html.rnp-on .colouring-message { z-index: 20000 !important; }

/* ---------- phone sideways: bars move to the sides ---------- */
@media (orientation: landscape) and (max-height: 540px) {
    .rnp {
        grid-template-columns: 64px minmax(0, 1fr) 176px;
        grid-template-rows: minmax(0, 1fr);
        grid-template-areas: "top main bar";
    }
    .rnp-rainbow { display: none; }
    .rnp-top { flex-direction: column; height: auto; width: 64px; padding: 8px 0; gap: 10px; border-right: 2px solid #EEF0F6; }
    .rnp-title { display: none; }
    .rnp-undo { width: 44px; padding: 0; justify-content: center; border-radius: 50%; }
    .rnp-undo span { display: none; }
    .rnp-more { margin-top: auto; }
    .rnp-main { padding: 6px; }
    .rnp-bar { flex-wrap: wrap; align-content: flex-start; justify-content: flex-start; gap: 6px; min-height: 0; padding: 8px;
        border-top: 0; border-left: 2px solid #EEF0F6; overflow-y: auto; }
    .rnp-tool { flex: 0 0 calc(50% - 3px); max-width: none; }
    .rnp--red .rnp-tool { flex-basis: calc(33.33% - 4px); }
    .rnp-tool__ico { height: 40px; max-width: none; }
    .rnp-tool__label { font-size: 10px; }
    .rnp-cdot { width: 40px; height: 40px; }
    .rnp-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; width: 100%; margin-top: 4px; }
    .rnp-q { aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; padding: 0; }
    .rnp-q.is-on { box-shadow: 0 0 0 2px #FFFFFF, 0 0 0 4px #1E2A4A; }
    .rnp-tray { left: auto; right: 176px; top: 0; bottom: 0; width: min(340px, 60vw); max-height: none; border-radius: 20px 0 0 20px; }
    .rnp-colours { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
    .rnp-sw { min-height: 30px; }
    .rnp-menu { top: auto; bottom: 8px; left: 70px; right: auto; }
    .rnp-hint { top: 6px; }
}
@media (prefers-reduced-motion: reduce) { .rnp-tray { animation: none; } }
