/* ---- Page: one screen, no scrolling ---- */
body {
    margin: 0;
    height: 100vh;           /* fallback for older browsers */
    height: 100dvh;          /* the visible height, minus phone address bars */
    display: flex;
    flex-direction: column;  /* header on top, main below */
    overflow: hidden;        /* no normal page scrolling */
}

/* ---- The window and the sheet ---- */
main {
    flex: 1;                 /* fill whatever space the header leaves */
    position: relative;
    overflow: hidden;        /* hide the parts of the sheet outside the window */
    background-color: var(--paper);
}

#canvas {
    position: relative;      /* places are measured from the sheet's corner */
    width: 3000px;
    height: 2000px;
    cursor: grab;
    touch-action: none;      /* on phones, a finger drags the sheet instead of scrolling */
    user-select: none;       /* stop text getting highlighted while dragging */
    /* faint grid so you can see the sheet move */
    background-image:
        linear-gradient(rgba(50, 107, 104, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(50, 107, 104, 0.1) 1px, transparent 1px);
    background-size: 40px 40px;
    transform-origin: 0 0;   /* scale from the sheet's top-left corner, so the maths lines up */
}

#canvas.dragging {
    cursor: grabbing;        /* the coat it wears while being dragged */
}

#reset {
    position: absolute;      /* pinned to the window (main), not the sheet */
    bottom: 16px;
    left: 16px;
}

/* ---- Pieces ---- */
a.piece {
    position: absolute;
    display: flex;
    flex-direction: column;  /* mark above, label below */
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--ink);
    font-family: var(--font-title);
    max-width: 11ch;         /* labels wrap instead of running wide */
    text-align: center;      /* wrapped lines centre under the circle */
}

a.piece::before {
    content: "";             /* needed for ::before to exist at all */
    width: 48px;
    height: 48px;
    border: 2px solid var(--ink);
    border-radius: 50%;
    background-color: var(--paper);
}

a.piece:hover::before,
a.piece:focus-visible::before {
    background-color: var(--teal);   /* fills in for mouse and keyboard alike */
}


/* ---- Reading panel ---- */
#panel {
    position: fixed;              /* stays put while the sheet is dragged */
    top: 0;
    right: 0;
    width: 40%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;       /* button above, page below */
    background-color: var(--ink);
    border-left: 2px solid var(--ink);
    transform: translateX(100%);  /* pushed off-screen to the right */
    visibility: hidden;           /* and unreachable by Tab while closed */
    transition: transform 0.4s ease, visibility 0.4s;
}

#panel.open {
    transform: translateX(0);     /* slid back into view */
    visibility: visible;
}

#panel iframe {
    flex: 1;                      /* fill the space below the button */
    border: none;
}

@media (max-width: 600px) {
    #panel { width: 100%; }       /* full width on phones */
}

.panel-bar {
    position: absolute;
    top: 10px;
    right: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;   /* Close on the left, the link on the right */
    align-items: stretch;
    padding: 8px 10px;
}

.panel-bar > * {
    background-color: var(--teal);
    color: var(--parchment);
    text-decoration: none;
    padding: 2px 8px;
    border-radius: 8px 0 0 8px;
    white-space: nowrap;
}

.panel-bar > *:hover, .panel-bar > *:focus-visible {
    background-color: var(--moss);
    color: var(--parchment);
}

#full-page {
    font-family: var(--font-title);
}

/* ---- Added for publishing (v4): phone fixes ---- */
.intro summary {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    cursor: pointer;
    margin: 0.5em 0;
}

@media (max-width: 600px) {
    .panel-bar {
        position: static;            /* sit inside the panel, above the page */
        flex-direction: row;
        justify-content: space-between;
    }
    .panel-bar > * { border-radius: 8px; }
}
