/* rail.css -- the layer rail's contents, and the canvas on the stage.
 *
 * Split out of frame.css because these are components inside the boxes rather
 * than the boxes themselves. The frame owns geometry; this owns what sits in it.
 * Everything here reads the frame's variables and declares none of its own --
 * a custom property flows down and never sideways.
 */

/* ---- the Add button ------------------------------------------------
   Sticky and the first child, so it stays reachable with twenty layers under
   it. The old rail put it in the same place for the same reason. */
#cs-add {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 100%;
    padding: 10px 4px;
    border: 0;
    border-bottom: 1px solid var(--cs-hairline);
    background: var(--cs-white);
    color: var(--cs-accent);
    font-family: inherit;
    font-size: 10.5px;
    font-weight: 800;
    cursor: pointer;
}

#cs-add:hover { background: var(--cs-track); }

/* THE DISABLED STATE IS THE CAP, and it must look disabled rather than merely
   stop working. A button that still looks pressable and does nothing is the
   same failure as a helper that shrugs: the customer is told nothing. */
#cs-add:disabled {
    color: var(--cs-muted);
    cursor: not-allowed;
    opacity: 0.55;
}

.cs-add-glyph {
    display: block;
    font-size: 20px;
    line-height: 1;
    font-weight: 700;
}

/* ---- the layer stack ----------------------------------------------- */
#cs-stack {
    display: flex;
    flex-direction: column;
}

/* ---- a layer row ----------------------------------------------------
   IT IS A TILE, NOT A LABEL. Chris's rail -- the one the shop has been using --
   shows the art itself, with the reorder arrows down the left edge and the
   remove cross at the top right, and the layer's name on hover. A word like
   "image" or "shape" tells a customer nothing about which of four stickers they
   are looking at.

   position:relative because the arrows and the cross are SIBLINGS of the pick
   button, positioned over it: a button inside a button is invalid markup and
   the browser re-parents it out of the row entirely. */
.cs-row {
    position: relative;
    margin: 8px auto;
    width: 62px;
}

.cs-row-pick {
    display: block;
    width: 100%;
    padding: 0;
    border: 1px solid var(--cs-line);
    border-radius: var(--cs-r-well);
    background: none;
    cursor: pointer;
    overflow: hidden;
}

.cs-row:hover .cs-row-pick { border-color: var(--cs-accent); }

/* THE CHECKERBOARD IS THE GROUND, so transparent art reads as transparent
   rather than as white art on a white tile -- which is what the old rail does
   and the reason a customer can tell a cut-out sticker from a square one. Two
   gradients rather than an image: no request, no file to deploy, and it scales
   with the tile. */
.cs-row-thumb {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    background-color: var(--cs-white);
    background-image:
        linear-gradient(45deg, var(--cs-track) 25%, transparent 25%, transparent 75%, var(--cs-track) 75%),
        linear-gradient(45deg, var(--cs-track) 25%, transparent 25%, transparent 75%, var(--cs-track) 75%);
    background-size: 12px 12px;
    background-position: 0 0, 6px 6px;
}

/* ---- reorder --------------------------------------------------------
   Down the LEFT EDGE, over the tile, because 62px of width has no room for a
   row of three controls under it and the old rail solved this the same way.
   Disabled at the ends rather than removed: a control that vanishes at the
   boundary changes the tile's height as it travels up the stack, and the
   customer's next press lands on a different row. */
.cs-row-moves {
    position: absolute;
    left: 1px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cs-move,
.cs-row-del {
    display: flex;
    align-items: center;
    justify-content: center;
    /* 16px of hit area for a 7px glyph. A control the size of its own glyph is
       one a customer misses, and this rail is 78px wide with three of them. */
    width: 16px;
    height: 16px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.86);
    color: var(--cs-muted);
    font-family: inherit;
    font-size: 7px;
    line-height: 1;
    cursor: pointer;
}

.cs-move:hover:not(:disabled) { color: var(--cs-accent); }

/* IT MUST LOOK DISABLED, not merely stop working — the same rule the Add button
   carries at the cap. AND IT MUST STILL LOOK LIKE A CONTROL, which is the half
   that was wrong on the live page: at 0.3 the whole pill faded into the artwork
   behind it and the top row read as having ONE arrow rather than a dead one.
   "Absent" and "disabled" tell a customer different things, and the second one
   is true. So the pill keeps its own opacity and only the glyph greys out. */
.cs-move:disabled {
    opacity: 1;
    /* DERIVED FROM THE LIVE COLOUR RATHER THAN A SIXTH TOKEN. The palette says
       five values and no sixth on purpose; a paler version of the one already
       here is not a new colour, and color-mix keeps the two tied so changing
       --cs-muted moves both. At --cs-line the glyph vanished into the pill and
       the control read as an empty white box, which is a third thing -- neither
       "you can press this" nor "this one is dead". */
    color: color-mix(in srgb, var(--cs-muted) 42%, var(--cs-white));
    cursor: not-allowed;
}

/* ---- remove ---------------------------------------------------------
   THE ONE DOOR that takes a layer off the case, and it is on the ROW rather
   than in the panel: the rail IS the layer list, and a row can be removed
   without being selected first. It sat in the panel for one slice until Chris
   went looking for it here.

   IT LOOKS DIFFERENT FROM THE ARROWS. Those reorder, and pressing the other one
   undoes it; this one does not undo. A destructive control identical to its
   neighbours is the one pressed by accident, which is what --cs-danger is for.
   RED AT REST, which is Chris's rail rather than my taste. I had it grey until
   hovered, reasoning that a red cross on every row reads as an error state --
   but the rail he sent is the one the shop has used for months, its cross is
   red, and a control people already know is worth more than an argument about
   colour. Hover deepens it rather than introducing it. */
.cs-row-del {
    position: absolute;
    top: 1px;
    right: 1px;
    font-size: 11px;
    color: var(--cs-danger);
}

.cs-row-del:hover {
    background: var(--cs-danger);
    color: var(--cs-white);
}

/* The selected row. A LEFT EDGE RATHER THAN A FILL: the rail is 78px and a
   filled row at that width reads as a block of colour rather than a selection,
   which is the note the old build's first flush rail came back with. */
.cs-row.is-selected .cs-row-pick {
    border-color: var(--cs-accent);
    box-shadow: 0 0 0 2px var(--cs-accent);
}

.cs-rail-empty {
    margin: 0;
    padding: 14px 8px;
    color: var(--cs-muted);
    font-size: 9.5px;
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
}

/* ---- the canvas ----------------------------------------------------
   Centred in the stage. Its width and height are set in PIXELS by the fit,
   because the buffer is 1748 x 3012 print pixels and the display size is a
   scale of it -- so this rule must not state a size of its own. Doing that
   would be a second answer to a question the fit already answers, and the two
   would disagree the moment the window changed. */
#cs-stage {
    display: flex;
    align-items: center;
    justify-content: center;
}

#cs-canvas {
    display: block;
    /* The case is white on a light surround, so it needs an edge to sit on. */
    box-shadow: 0 2px 14px rgba(15, 23, 42, 0.13);
    border-radius: 18px;
    background: var(--cs-white);
}

/* ---- the trim guide ------------------------------------------------
   Positioned by guide.js in JS, because its geometry is a per-model
   calculation and there is nothing for CSS to compute. What CSS owns here is
   only how it LOOKS.

   IT IS NEVER PAINTED INTO THE CANVAS. See the tombstone at the foot of
   case.js: a guide drawn into the print buffer is a guide that gets printed on
   the case. */
.cs-guide {
    position: absolute;
    pointer-events: none;
    box-sizing: border-box;
}

#cs-guide-bleed {
    z-index: 2;
    border: 2px dashed rgba(220, 38, 38, 0.7);
}

#cs-guide-trim {
    z-index: 3;
    border: 2px solid rgba(15, 23, 42, 0.45);
}

/* The stage centres the canvas, so the guide -- which is positioned against the
   stage's own box -- needs the stage to be a containing block. */
#cs-stage { position: relative; }

/* ---- the selection outline ------------------------------------------
   THE SAME RULE AS THE GUIDE, FOR THE SAME REASON. The canvas is the print
   buffer; anything drawn into it is manufactured. A selection outline painted
   there would come back printed round the sticker on every case. So this is a
   div over the canvas and the renderer never learns that selection exists.

   pointer-events: none is load-bearing rather than tidy: the outline sits ON
   TOP of the thing it outlines, so without it the first click selects a layer
   and every click after that lands on the outline instead — the layer becomes
   undraggable the moment it is selected, which reads as the drag being broken.
   The 26 Aug fault was four clicks landing on a modal nobody could see; this is
   the same shape, one element smaller. */
#cs-marquee {
    position: absolute;
    z-index: 4;                 /* above both guides, which are 2 and 3 */
    pointer-events: none;
    box-sizing: border-box;
    border: 1px solid var(--cs-accent);
    /* Rotated about its centre, because that is where the renderer rotates the
       layer. Stated once, here, rather than beside every transform. */
    transform-origin: 50% 50%;
    /* A halo so the line is visible against art of any colour. A single blue
       border disappears on blue art, and "my sticker is not selected" is a bug
       report about a border. */
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9);
}

/* ---- the handles ---------------------------------------------------
   Children of the outline, so the browser turns them with it and nothing here
   has to know a rotation. They TAKE pointer events although the outline does
   not: the outline must stay transparent to a press or a selected layer becomes
   undraggable, and a grip must not, or it cannot be grabbed. */
.cs-handle {
    position: absolute;
    box-sizing: border-box;
    width: 11px;
    height: 11px;
    margin: -6px 0 0 -6px;      /* centred ON its corner, not hung off it */
    border: 1px solid var(--cs-accent);
    border-radius: 2px;
    background: var(--cs-white);
    pointer-events: auto;
    /* The same halo the outline carries, for the same reason: a white grip on
       white art is a control the customer cannot see. */
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9);
}

.cs-handle-nw { left: 0;    top: 0;    cursor: nwse-resize; }
.cs-handle-ne { left: 100%; top: 0;    cursor: nesw-resize; }
.cs-handle-se { left: 100%; top: 100%; cursor: nwse-resize; }
.cs-handle-sw { left: 0;    top: 100%; cursor: nesw-resize; }

/* THE GRIP SITS OUTSIDE THE BOX, above the top edge, so it is never mistaken
   for a corner and never covers the art it is turning. Round, so its shape says
   it does something different from the four squares. */
.cs-handle-rot {
    left: 50%;
    top: -22px;
    border-radius: 50%;
    cursor: grab;
}

.cs-handle-rot:active { cursor: grabbing; }

/* Its stalk. Decorative, and it takes NO pointer events: a customer who grabs
   the line instead of the circle would otherwise get nothing at all, because
   the stalk is a child of the grip and would swallow the press. */
.cs-handle-rot::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 100%;
    width: 1px;
    height: 11px;
    margin-left: -0.5px;
    background: var(--cs-accent);
    pointer-events: none;
}
