/* Copied from go-clock (www/my-clock.css at 8a1eb98): the goban's and the
   stones' rules only, for the Kaya, computer and glass boards, and the real
   and flat stones. The light moves only with the settings (no --turn, no
   sun, no table or water). */

:root {
    --turn: 0deg;
    --light-angle: calc(var(--turn) + var(--light-turn));
    --light-cos: cos(var(--light-angle));
    --light-sin: sin(var(--light-angle));
    --light-stretch: 1;
    --shadow-stretch: rotate(50deg) translateX(-50%) scaleX(var(--light-stretch)) translateX(50%) rotate(-50deg);
    --light-fall-x: 1.0698;
    --light-fall-y: 1.2749;
    --board-thickness: 0.52;
    --stone-thickness: 0.38;
}

@property --light-angle {
    syntax: '<angle>';
    inherits: true;
    initial-value: 0deg;
}

@property --light-turn {
    syntax: '<angle>';
    inherits: true;
    initial-value: 0deg;
}

#goban {
    position: relative;
    overflow: visible;
    touch-action: manipulation;
}

/* Go Senpai: the goban in a frame whose margin holds the coordinates. It is
   a stacking context of its own, so the stones' z-indices (by the order they
   were placed) stay within the board. */
.board-frame {
    position: relative;
    flex: none;
    isolation: isolate;
}

.board-frame > #goban {
    position: absolute;
}

/* The board's shadow on the table: a tight dark line where it meets the
   table, and the shadow its thickness casts down and to the right. */
#goban-image {
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    -webkit-user-drag: none;
    user-select: none;
    --board-fall: calc(var(--stone)*var(--board-thickness));
    box-shadow:
        calc(var(--stone)*(0.12*var(--light-cos) - 0.14*var(--light-sin))) calc(var(--stone)*(0.12*var(--light-sin) + 0.14*var(--light-cos)) + var(--board-sink, 0px)) calc(var(--stone)*0.2) rgb(0 0 0 / 0.5),
        calc(var(--board-fall)*(var(--light-fall-x)*var(--light-cos) - var(--light-fall-y)*var(--light-sin))) calc(var(--board-fall)*(var(--light-fall-x)*var(--light-sin) + var(--light-fall-y)*var(--light-cos)) + var(--board-sink, 0px)) calc(var(--stone)*0.4) rgb(0 0 0 / 0.3),
        0 var(--board-sink, 0px) calc(var(--stone)*0.8) rgb(0 0 0 / 0.25);
}

/* A smaller board's grid, drawn over the Kaya photograph with its own
   grid taken out (board-view.js applyPicture). */
#goban > .goban-grid {
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    pointer-events: none;
    -webkit-user-drag: none;
    user-select: none;
}

/* A glass board lets the light through: its shadow on the table is faint.
   It is drawn solid, in the table's colour lightened by the glass
   (--glass-base, set from the background by www/settings.js). */
[data-board="glass"] #goban-image {
    background: var(--glass-base, rgb(66 60 54));
    box-shadow:
        calc(var(--stone)*(0.12*var(--light-cos) - 0.14*var(--light-sin))) calc(var(--stone)*(0.12*var(--light-sin) + 0.14*var(--light-cos)) + var(--board-sink, 0px)) calc(var(--stone)*0.2) rgb(0 0 0 / 0.22),
        calc(var(--board-fall)*(var(--light-fall-x)*var(--light-cos) - var(--light-fall-y)*var(--light-sin))) calc(var(--board-fall)*(var(--light-fall-x)*var(--light-sin) + var(--light-fall-y)*var(--light-cos)) + var(--board-sink, 0px)) calc(var(--stone)*0.4) rgb(0 0 0 / 0.16),
        0 var(--board-sink, 0px) calc(var(--stone)*0.8) rgb(0 0 0 / 0.1);
    transition: background-color 450ms ease-in-out;
}

/* Go Senpai: stones stack in the order they were placed (--stone-order,
   board-view.js), not by point number, and a stone moving (dropping, flying,
   rising away) is over every stone lying still. The overlay is above them
   all (app.css). */
.board_pos {
    pointer-events: none;
    z-index: calc(20000 + var(--stone-order, 0));
}

.stone-shadow,
.token-shadow {
    position: absolute;
    z-index: 0;
    inset: 0;
    opacity: var(--stone-shadow-opacity, 1);
    pointer-events: none;
    transform: translate(
        calc(var(--stone-shadow-offset-x, 0px)*var(--light-cos) - var(--stone-shadow-offset-y, 0px)*var(--light-sin)),
        calc(var(--stone-shadow-offset-x, 0px)*var(--light-sin) + var(--stone-shadow-offset-y, 0px)*var(--light-cos)))
        rotate(var(--light-angle)) var(--shadow-stretch);
    transform-origin: center;
}

/* A shadow, and a stone out of focus, are pictures drawn ahead of time at a
   few heights (soft.js): the one below the stone's height, and the one above
   it faded in over it. stone-dom.js adds the rules with the pictures. */
.stone-shadow::before,
.stone-shadow::after,
.token-shadow::before,
.token-shadow::after,
.stone-focus::before,
.stone-focus::after {
    content: '';
    position: absolute;
    background: no-repeat center / 100% 100%;
}

.stone-shadow::after,
.token-shadow::after {
    opacity: var(--stone-shadow-mix, 0);
}

.stone-focus {
    position: absolute;
    z-index: 1;
    pointer-events: none;
}

.stone-focus::before,
.stone-focus::after {
    inset: 0;
}

.stone-focus::after {
    opacity: var(--stone-focus-mix, 0);
}

.stone-focus[hidden],
.stone[hidden] ~ .stone-focus {
    display: none;
}

/* Stones lying still: all the shadows under all the stones, rather than
   each stone over its neighbour's shadow just for being drawn after it. */
/* (Go Senpai: not a stone the magic has, one ridden up on another, one in
   the air or one turning over: those stay over the rest, as go-clock's do.) */
.board_pos.resting:not(.magic-stone, .riding, .in-air, .flying) {
    z-index: auto !important;
}

.board_pos.resting > .stone-shadow {
    z-index: 1;
}

.board_pos.resting > .stone,
.board_pos.resting > .stone-gleam {
    z-index: calc(4 + var(--stone-order, 0));
}

.stone {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    background: transparent;
}

/* The light on a stone, drawn over its photograph (stone-dom.js). */
.stone-gleam {
    position: absolute;
    z-index: 2;
    inset: 0;
    display: none;
    pointer-events: none;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    transform: rotate(var(--light-angle));
}

.stone[src*="white_stone"] ~ .stone-gleam,
.stone[src*="black_stone"] ~ .stone-gleam {
    display: block;
}

.stone[hidden] ~ .stone-gleam {
    display: none;
}

/* Go Senpai: the board tilted, seen sitting at it (board-view.js setTilt).
   Only the picture tilts, so a stone lying flat on it would be drawn
   squashed: stood up again (--tilt-stand), as a lens seen from the side is
   about as tall as it is wide, and its middle raised off the board
   (--tilt-rise, a fifth of a width up). Counters are flat, and stay so; the
   shadows lie on the board.

   A nearer stone is drawn over a farther one: every stone lying on the
   board, resting or not, in the one order, by its row (--stone-row; a loose
   one's, where it is, board-hand.js) and within a row the order placed; one
   the magic or the hand has up in the air over them all, as flat. */
.board-frame.tilted .board_pos:not(.magic-stone, .loose-stone.in-air, .loose-stone.riding),
.board-frame.tilted .board_pos.resting > .stone,
.board-frame.tilted .board_pos.resting > .stone-gleam {
    z-index: calc(20000 + round(down, var(--stone-row, 0)*400) + min(var(--stone-order, 0), 399));
}

:root:not([data-stones="flat"]) .board-frame.tilted .board_pos > .stone,
:root:not([data-stones="flat"]) .board-frame.tilted .board_pos > .stone-gleam,
:root:not([data-stones="flat"]) .board-frame.tilted .board_pos > .stone-focus {
    scale: 1 var(--tilt-stand, 1);
    translate: 0 calc(-19%*var(--tilt-rise, 0));
}

/* A score token on a stone lies on its top, a stone's thickness up (0.38 of
   its width, the token 0.6 of it: board-view.js); seen tilted, that much
   higher up the page. */
:root:not([data-stones="flat"]) .board-frame.tilted .token.on-stone {
    translate: 0 calc(-63%*var(--tilt-rise, 0));
}

[data-stones="flat"] .board-frame.tilted .token.on-stone {
    translate: 0 calc(-10%*var(--tilt-rise, 0));
}

/* Lying on the table, drawn smaller (app.css), and stood up as well. */
:root:not([data-stones="flat"]) .board-frame.tilted .loose-stone.on-table > .stone,
:root:not([data-stones="flat"]) .board-frame.tilted .loose-stone.on-table > .stone-gleam {
    scale: 0.92 calc(0.92*var(--tilt-stand, 1));
}

/* Tilted, the board's broad shadow is its outline cast onto the table
   (board-view.js drawCast), softened: the box-shadow's only moves a copy of
   the board, which leaves a notch at two corners once it falls as far as
   the board's real thickness casts it. The tight line where it meets the
   table and the darkening all round stay box-shadows, on the table. */
.board-frame.tilted #goban-image {
    box-shadow:
        calc(var(--stone)*(0.12*var(--light-cos) - 0.14*var(--light-sin))) calc(var(--stone)*(0.12*var(--light-sin) + 0.14*var(--light-cos)) + var(--board-sink, 0px)) calc(var(--stone)*0.2) rgb(0 0 0 / 0.5),
        0 var(--board-sink, 0px) calc(var(--stone)*0.8) rgb(0 0 0 / 0.25);
}

[data-board="glass"] .board-frame.tilted #goban-image {
    box-shadow:
        calc(var(--stone)*(0.12*var(--light-cos) - 0.14*var(--light-sin))) calc(var(--stone)*(0.12*var(--light-sin) + 0.14*var(--light-cos)) + var(--board-sink, 0px)) calc(var(--stone)*0.2) rgb(0 0 0 / 0.22),
        0 var(--board-sink, 0px) calc(var(--stone)*0.8) rgb(0 0 0 / 0.1);
}

.board-cast {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.32;
}

[data-board="glass"] .board-cast {
    opacity: 0.12;
}

.board-cast-shape {
    position: absolute;
    background: black;
}

/* The board's near edge, seen under it tilted: its wood, made from the
   picture of its top as the flip's is (board-flip.js), plain for the
   computer board, a deeper grey for glass; and its shade. Drawn narrower
   at its foot, which is further off (clip-path, board-view.js). */
/* Over the shadows of the stones lying on the board (z-index 1): a stone at
   the near edge casts none on it, the light falling from above. */
.board-edge {
    position: absolute;
    z-index: 2;
    left: 0;
    top: 100%;
    width: 100%;
    pointer-events: none;
}

.board-edge-wood,
.board-edge-shade {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.board-edge-wood.plain {
    background: #dcb35c;
}

/* Glass reflects the table round it, as its top does (stones.css,
   #goban-image): the same colour (www/settings.js), lit and shaded half as
   much (board-flip.js). */
[data-board="glass"] .board-edge-wood.plain {
    background: var(--glass-base, rgb(66 60 54));
    transition: background-color 450ms ease-in-out;
}

.board-edge-shade {
    background: black;
}
