/* Reversi: status and announcement on top, the two players' plates with the
   count of discs and a bar of who holds how much of the board, the board in
   the room that is left, the button at the bottom. On a wide screen the board
   stands on the left and everything else beside it.
   The board is green cloth with dark lines in a dark wooden frame that carries
   the names of the columns and rows. A disc is black on one side and white on
   the other: it turns over by narrowing to its edge and widening again. */
.rv{
  --rv-felt:#1f7a43;--rv-felt-hi:#2a9354;--rv-felt-lo:#145c31;--rv-line:rgba(4,30,14,.55);
  --rv-frame:#3b2a1c;--rv-frame-lo:#21160d;
  --rv-b:#26292d;--rv-b-hi:#5d636b;--rv-b-lo:#0b0c0e;
  --rv-w:#f4f1e8;--rv-w-hi:#ffffff;--rv-w-lo:#bdb6a6;
  --rv-hint:#ffc65c;--rv-foe:#e2404c; /* the hint's own gold: the skin's --gold may be green */
  position:absolute;inset:0;
  display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto auto minmax(0,1fr) auto;
  grid-template-areas:"top" "plates" "main" "bar";
  overflow:hidden;
}
.rv-top{grid-area:top;display:grid;justify-items:center;gap:2px;padding:6px 10px 2px}
.rv-status{padding:.4em .9em;font-size:.93rem}
.rv-say{
  margin:0;min-height:1.3em;max-width:24rem;
  font-size:.88rem;line-height:1.3;text-align:center;color:var(--mist);
}
.rv-say.big{color:var(--ivory);font-weight:600}

/* ── plates and the bar of discs ─────────────────────────────────────── */
.rv-plates{
  grid-area:plates;display:grid;grid-template-columns:minmax(0,220px) minmax(0,220px);justify-content:center;
  gap:4px 8px;padding:4px 8px;
}
.rv-plate{
  display:flex;align-items:center;gap:7px;
  min-width:0;min-height:46px;padding:4px 5px 4px 5px;
  border:1.5px solid var(--line);border-radius:999px;
  background:rgba(13,18,10,.3);
  transition:border-color .2s,background-color .2s;
}
.rv-plate .ava{width:34px;height:34px;font-size:1rem;flex:none}
.rv-who{display:grid;line-height:1.15;min-width:0;flex:1}
.rv-who .nm{font-weight:600;font-size:.9rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.rv-who .sub{font-size:.72rem;color:var(--mist);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.rv-plate.turn{border-color:var(--gold);background:rgba(118,176,67,.13)}
.rv-plate.turn .ava{box-shadow:0 0 0 2.5px var(--gold)}
.rv-plate.best .rv-chip{box-shadow:0 0 0 2.5px var(--gold)}
.rv-count{
  display:grid;place-items:center;width:36px;height:36px;
  font:700 1rem/1 var(--ui);font-variant-numeric:tabular-nums;letter-spacing:-.02em;
}
.rv-count.b{color:#fbf5ea}
.rv-count.w{color:#241a2d}
.rv-meter{
  grid-column:1/-1;height:6px;border-radius:3px;overflow:hidden;margin:0 14px;
  --a:50%;
  background:linear-gradient(90deg,var(--ma) 0 var(--a),var(--mb) var(--a) 100%);
  box-shadow:inset 0 0 0 1px rgba(0,0,0,.35);
}
.rv-meter[data-a="b"]{--ma:var(--rv-b)}
.rv-meter[data-a="w"]{--ma:var(--rv-w)}
.rv-meter[data-b="b"]{--mb:var(--rv-b)}
.rv-meter[data-b="w"]{--mb:var(--rv-w)}
.rv-unit{font-size:.8em;opacity:.7}

/* a disc: black or white, a little domed */
.rv-chip,.rv-disc{border-radius:50%}
.rv-chip{flex:none}
.rv-chip.b,.rv-disc.b{--d:var(--rv-b);--d-hi:var(--rv-b-hi);--d-lo:var(--rv-b-lo);--o:var(--rv-w);--o-hi:var(--rv-w-hi);--o-lo:var(--rv-w-lo)}
.rv-chip.w,.rv-disc.w{--d:var(--rv-w);--d-hi:var(--rv-w-hi);--d-lo:var(--rv-w-lo);--o:var(--rv-b);--o-hi:var(--rv-b-hi);--o-lo:var(--rv-b-lo)}
.rv-chip,.rv-disc{
  background:radial-gradient(circle at 36% 30%,var(--d-hi),var(--d) 45%,var(--d-lo) 100%);
  box-shadow:0 calc(var(--cell,30px)*.05) calc(var(--cell,30px)*.08) rgba(0,0,0,.45),inset 0 -2px 3px rgba(0,0,0,.25);
}

/* ── the board ───────────────────────────────────────────────────────── */
.rv-main{grid-area:main;display:grid;place-items:center;min-width:0;min-height:0;overflow:hidden}
.rv-stage{
  --cell:40px;--n:8;--pad:calc(var(--cell)*.45);
  position:relative;
  width:calc(var(--n)*var(--cell) + 2*var(--pad));height:calc(var(--n)*var(--cell) + 2*var(--pad));
  border-radius:calc(var(--cell)*.22);
  background:linear-gradient(145deg,var(--rv-frame),var(--rv-frame-lo));
  box-shadow:0 14px 28px -12px rgba(0,0,0,.85),inset 0 0 0 1.5px rgba(255,255,255,.08);
}
/* the names of the columns (a, b, …) above the board and of the rows (1, 2, …) on its left */
.rv-lab{position:absolute;display:grid;pointer-events:none;color:rgba(251,245,234,.55);font:600 calc(var(--cell)*.26)/1 var(--ui)}
.rv-lab b{display:grid;place-items:center;font-weight:inherit}
.rv-lab-c{left:var(--pad);top:0;width:calc(var(--n)*var(--cell));height:var(--pad);grid-template-columns:repeat(var(--n),1fr)}
.rv-lab-r{left:0;top:var(--pad);width:var(--pad);height:calc(var(--n)*var(--cell));grid-template-rows:repeat(var(--n),1fr)}
.rv-board{
  position:absolute;left:var(--pad);top:var(--pad);
  width:calc(var(--n)*var(--cell));height:calc(var(--n)*var(--cell));
  border-radius:calc(var(--cell)*.06);
  background:
    linear-gradient(90deg,var(--rv-line) 1px,transparent 1px) 0 0/var(--cell) var(--cell),
    linear-gradient(var(--rv-line) 1px,transparent 1px) 0 0/var(--cell) var(--cell),
    radial-gradient(circle at 50% 40%,var(--rv-felt-hi),var(--rv-felt) 55%,var(--rv-felt-lo));
  box-shadow:inset 0 0 0 1px var(--rv-line),inset 0 0 calc(var(--cell)*.6) rgba(0,0,0,.25);
}
/* the four small dots where the lines meet, two cells in from each corner */
.rv-board::after{
  content:"";position:absolute;width:6px;height:6px;margin:-3px 0 0 -3px;border-radius:50%;
  left:calc(2*var(--cell));top:calc(2*var(--cell));background:var(--rv-line);
  box-shadow:calc((var(--n) - 4)*var(--cell)) 0 0 var(--rv-line),0 calc((var(--n) - 4)*var(--cell)) 0 var(--rv-line),calc((var(--n) - 4)*var(--cell)) calc((var(--n) - 4)*var(--cell)) 0 var(--rv-line);
  pointer-events:none;
}
.rv-marks,.rv-discs{position:absolute;inset:0;pointer-events:none}
.rv-discs{z-index:2}

.rv-disc{
  position:absolute;
  left:calc(var(--c)*var(--cell) + var(--cell)*.09);top:calc(var(--r)*var(--cell) + var(--cell)*.09);
  width:calc(var(--cell)*.82);height:calc(var(--cell)*.82);
}
/* a new disc comes down onto the cloth */
.rv-disc.pop{animation:rv-pop .3s cubic-bezier(.3,1.5,.6,1) both}
@keyframes rv-pop{0%{transform:scale(.35);opacity:.2}100%{transform:scale(1);opacity:1}}
/* a disc turns over: it narrows to its edge showing the old side, and widens showing the new one */
.rv-disc.flip{animation:rv-flip .42s ease-in-out var(--dl,0ms) both}
.rv-disc.flip::before{
  content:"";position:absolute;inset:0;border-radius:50%;
  background:radial-gradient(circle at 36% 30%,var(--o-hi),var(--o) 45%,var(--o-lo) 100%);
  animation:rv-old .42s step-end var(--dl,0ms) both;
}
@keyframes rv-flip{
  0%{transform:translateY(0) scaleX(1)}
  50%{transform:translateY(calc(var(--cell)*-.12)) scaleX(.06)}
  100%{transform:translateY(0) scaleX(1)}
}
@keyframes rv-old{0%{opacity:1}50%{opacity:0}100%{opacity:0}}
/* the last disc: a small dot in the middle */
.rv-disc.last::after{
  content:"";position:absolute;left:50%;top:50%;width:16%;height:16%;margin:-8% 0 0 -8%;
  border-radius:50%;background:#e2404c;box-shadow:0 0 0 1px rgba(0,0,0,.25);
}
.rv-board.done .rv-disc.last::after{display:none}

/* where the player on turn may place a disc: a small dot of their colour */
.rv-dot{
  position:absolute;border-radius:50%;
  left:calc(var(--c)*var(--cell) + var(--cell)*.39);top:calc(var(--r)*var(--cell) + var(--cell)*.39);
  width:calc(var(--cell)*.22);height:calc(var(--cell)*.22);opacity:.55;
}
.rv-dot.b{background:var(--rv-b)}
.rv-dot.w{background:var(--rv-w)}
.rv:not(.mine) .rv-dot{opacity:.28}
/* my disc waiting on the chosen cell, and rings on what it would turn */
.rv-marks .rv-disc.ghost{opacity:.5;box-shadow:none}
.rv-marks .rv-disc.ghost.chosen{opacity:.8;box-shadow:0 0 0 2px var(--ivory)}
.rv-marks{z-index:3}
.rv-ring{
  position:absolute;border-radius:50%;
  left:calc(var(--c)*var(--cell) + var(--cell)*.06);top:calc(var(--r)*var(--cell) + var(--cell)*.06);
  width:calc(var(--cell)*.88);height:calc(var(--cell)*.88);
  border:calc(var(--cell)*.06) solid var(--ring);box-sizing:border-box;
}
.rv-ring.turn{--ring:var(--rv-hint);border-style:dashed;opacity:.9}
/* what a hint marks (server/hints/reversi.js, hint.mark): the advised cell, the next best numbered, crosses
   on the cells that would open a corner */
.rv-ring.best{--ring:var(--rv-hint);border-width:calc(var(--cell)*.09);animation:rv-pulse 1.1s ease-in-out infinite}
@keyframes rv-pulse{50%{transform:scale(.86)}}
.rv-alt,.rv-no{
  position:absolute;display:grid;place-items:center;
  left:calc(var(--c)*var(--cell));top:calc(var(--r)*var(--cell));width:var(--cell);height:var(--cell);
  font:800 calc(var(--cell)*.4)/1 var(--ui);text-shadow:0 1px 2px rgba(0,0,0,.6);
}
.rv-alt{color:var(--rv-hint);opacity:.85}
.rv-no{color:var(--rv-foe)}

/* the cells: what is tapped, over everything */
.rv-cells{position:absolute;inset:0;z-index:4;display:grid;grid-template-columns:repeat(var(--n),1fr);grid-template-rows:repeat(var(--n),1fr)}
.rv-cell{
  min-width:0;min-height:0;padding:0;border:0;border-radius:calc(var(--cell)*.12);background:transparent;
  -webkit-tap-highlight-color:transparent;cursor:pointer;
}
.rv-cell:disabled{cursor:default}
.rv-cell:focus-visible{outline:2px solid var(--ivory);outline-offset:-3px}
.rv-cell.over{background:rgba(255,255,255,.08)}
.rv-cell.sel{background:rgba(255,255,255,.12);box-shadow:inset 0 0 0 2px rgba(255,255,255,.35)}
.rv-cell.shake{animation:shake .3s}

/* the game is over: the discs stay, the board a little quieter */
.rv-board.done .rv-dot{display:none}

/* ── the button ──────────────────────────────────────────────────────── */
.rv-bar{grid-area:bar;display:flex;justify-content:center;align-items:center;gap:8px;padding:6px 10px 10px;min-height:62px}
.rv-bar .btn{min-height:46px;min-width:8em;padding:.4em 1.1em;font-size:.98rem;white-space:nowrap}

.rv-sum{margin:.2em 0 .6em;font-size:.9rem;opacity:.75;text-align:center}

/* ── a narrow phone: the plates closer together ──────────────────────── */
@media (max-width:380px){
  .rv-plates{gap:4px 6px;padding:4px 6px}
  .rv-plate{gap:5px;padding:3px 8px 3px 4px}
  .rv-plate .ava{width:30px;height:30px;font-size:.9rem}
  .rv-count{width:32px;height:32px;font-size:.92rem}
}

/* ── a wide screen: the board on the left, the rest beside it ────────── */
.rv.wide{
  grid-template-columns:minmax(0,760px) clamp(190px,30%,280px);
  grid-template-rows:auto auto minmax(0,1fr) auto;
  grid-template-areas:"main top" "main plates" "main ." "main bar";
  justify-content:center;column-gap:8px;
}
.rv.wide .rv-top{padding-top:14px}
.rv.wide .rv-plates{grid-template-columns:minmax(0,1fr);padding:8px}
.rv.wide .rv-meter{margin:2px 10px}
.rv.wide .rv-bar{flex-direction:column-reverse;align-items:stretch;padding:8px 8px 14px}

/* a short screen: everything a little tighter */
@media (max-height:600px){
  .rv-top{padding-top:3px;gap:0}
  .rv-status{padding:.3em .8em;font-size:.86rem}
  .rv-say{font-size:.8rem}
  .rv-plates{padding:2px 6px;gap:3px 6px}
  .rv-plate{min-height:38px;padding:2px 8px 2px 3px}
  .rv-plate .ava{width:28px;height:28px;font-size:.85rem}
  .rv-count{width:30px;height:30px;font-size:.9rem}
  .rv-bar{min-height:52px;padding:4px 8px 6px}
  .rv-bar .btn{min-height:44px;font-size:.92rem}
  .rv.wide .rv-top{padding-top:6px}
  .rv.wide .rv-plates{padding:4px 6px}
  .rv.wide .rv-bar{flex-direction:row;flex-wrap:wrap;padding:4px 6px 6px}
}
@media (prefers-reduced-motion:reduce){
  .rv-disc.pop,.rv-disc.flip,.rv-ring.best{animation:none}
  .rv-disc.flip::before{display:none}
}
html.still .rv-disc.pop,html.still .rv-disc.flip,html.still .rv-ring.best{animation:none}
html.still .rv-disc.flip::before{display:none}
