/* Ten Trade (js/arcade/tentrade.js). Every class starts with .tn- */

.tn-wrap { position: relative; display: grid; gap: 8px; width: min(100%, 560px); margin: 0 auto; padding-bottom: 14px; }

/* each kind of block has its own colour, from the tokens: ones gold, tens sky, hundreds green, thousands grape */
.tn-one, .tn-c-one { --k: var(--sun); --k-d: var(--sun-d); }
.tn-ten, .tn-c-ten { --k: var(--sky); --k-d: var(--sky-d); }
.tn-hundred, .tn-c-hundred { --k: var(--green); --k-d: var(--green-d); }
.tn-thousand, .tn-c-thousand { --k: var(--grape); --k-d: var(--grape-d); }

/* ---------- HUD: the number she is on, the stars she can win, the score ---------- */
.tn-hud { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 14px; font: 700 14px var(--font-ui); color: var(--muted); }
.tn-hud b { color: var(--ink); font-size: 19px; }
.tn-stars { display: inline-flex; gap: 3px; }
.tn-star {
  --f: 0%; width: 24px; height: 24px;
  clip-path: polygon(50% 2%, 62% 36%, 98% 37%, 69% 59%, 80% 94%, 50% 73%, 20% 94%, 31% 59%, 2% 37%, 38% 36%);
  background: linear-gradient(90deg, var(--sun) var(--f), var(--tile-shadow) var(--f));
}
.tn-star.tn-half { --f: 50%; }
.tn-star.tn-full { --f: 100%; animation: tn-pop 0.45s; }

/* ---------- the number to make ---------- */
.tn-goal { display: flex; align-items: baseline; justify-content: center; gap: 12px; padding: 2px 16px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow-soft); }
.tn-make { font: 700 24px/1.2 var(--font-read); color: var(--ink); }
.tn-target { display: inline-block; font: 900 46px/1.15 var(--font-ui); color: var(--grape-d); letter-spacing: 0.02em; }
.tn-target.tn-pop { animation: tn-pop 0.45s; }

/* ---------- the blocks ---------- */
.tn-p { display: block; flex: none; box-sizing: border-box; background-color: var(--k); }
.tn-one { width: 14px; height: 14px; border-radius: 3px; box-shadow: inset 0 -3px 0 var(--k-d); }
/* a ten: a rod of ten little cubes */
.tn-ten {
  width: 42px; height: 10px; border-radius: 2px;
  background-image: repeating-linear-gradient(90deg, transparent 0 3.2px, var(--k-d) 3.2px 4.2px);
  box-shadow: inset 0 -2px 0 var(--k-d);
}
/* a hundred: a flat of ten rods */
.tn-hundred {
  width: 42px; height: 42px; border-radius: 3px; border: 1px solid var(--k-d);
  background-image: repeating-linear-gradient(90deg, transparent 0 3px, var(--k-d) 3px 4px), repeating-linear-gradient(0deg, transparent 0 3px, var(--k-d) 3px 4px);
  background-position: 0 0; box-shadow: 2px 2px 0 var(--k-d);
}
/* a thousand: a big cube, its top and side drawn as slanted faces */
.tn-thousand {
  position: relative; width: 36px; height: 36px; margin: 8px 8px 0 0; border-radius: 2px; border: 1px solid var(--k-d);
  background-image: repeating-linear-gradient(90deg, transparent 0 2.4px, var(--k-d) 2.4px 3.4px), repeating-linear-gradient(0deg, transparent 0 2.4px, var(--k-d) 2.4px 3.4px);
}
.tn-thousand::before, .tn-thousand::after { content: ''; position: absolute; background: var(--k); border: 1px solid var(--k-d); box-sizing: border-box; }
.tn-thousand::before { left: -1px; top: -9px; width: 36px; height: 8px; transform: skewX(-45deg); transform-origin: left bottom; filter: brightness(1.15); }
.tn-thousand::after { left: 35px; top: -1px; width: 8px; height: 36px; transform: skewY(-45deg); transform-origin: left top; background: var(--k-d); }

/* a block that has just arrived pops in (after its flying copy lands) */
.tn-in { animation: tn-in 0.3s cubic-bezier(0.2, 1.6, 0.4, 1) var(--d, 0ms) backwards; }
@keyframes tn-in { 0% { opacity: 0; transform: scale(0.3); } 100% { opacity: 1; transform: none; } }
@keyframes tn-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.25); } 100% { transform: none; } }

/* groups: ones in ten-frames (five across, two down), rods in stacks of five */
.tn-g { display: grid; gap: 2px; flex: none; }
.tn-c-one .tn-g { grid-template-columns: repeat(5, 14px); }
.tn-c-ten .tn-g { grid-template-columns: 42px; }
.tn-body { display: flex; align-items: center; gap: 8px; min-width: 0; pointer-events: none; }

/* ---------- the place-value mat ---------- */
.tn-mat { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; padding: 6px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow-soft); }
.tn-col {
  display: grid; grid-template-rows: auto 1fr auto; justify-items: center; gap: 2px; min-width: 0; padding: 4px 2px 2px;
  border: 2px solid color-mix(in srgb, var(--k) 55%, white); border-radius: 16px; background: color-mix(in srgb, var(--k) 12%, white);
  font: inherit; color: var(--ink); cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.tn-col-name { font: 700 14px/1.2 var(--font-read); color: var(--ink); }
.tn-k4 .tn-col-name { font-size: 13px; }
.tn-col .tn-body { min-height: 104px; justify-content: center; flex-wrap: wrap; align-content: center; gap: 6px; }
.tn-num { font: 900 26px/1 var(--font-ui); color: var(--ink); }
/* on the mat the ones sit three across; flats and big cubes are a fanned stack, each one showing its edge */
.tn-col.tn-c-one .tn-body { display: grid; grid-template-columns: repeat(3, 14px); gap: 3px; align-content: center; justify-content: center; }
.tn-col.tn-c-one .tn-g { display: contents; }
.tn-col.tn-c-hundred .tn-body, .tn-col.tn-c-thousand .tn-body { flex-direction: column; flex-wrap: nowrap; gap: 0; align-items: flex-start; padding: 0 6px; width: 74px; box-sizing: border-box; }
.tn-col .tn-hundred, .tn-col .tn-thousand { margin-left: calc(var(--i) * 2.5px); }
.tn-col .tn-hundred + .tn-hundred { margin-top: -35px; }
.tn-col .tn-thousand + .tn-thousand { margin-top: -29px; }
.tn-mat.tn-right .tn-col { border-color: var(--green-d); background: color-mix(in srgb, var(--green) 22%, white); }
.tn-mat.tn-right .tn-num { color: var(--green-d); animation: tn-pop 0.45s; }

.tn-msg { min-height: 22px; margin: 0; text-align: center; font: 700 16px/1.35 var(--font-read); color: var(--ink); }

/* ---------- the tray ---------- */
.tn-tray { display: grid; gap: 6px; padding: 8px; border-radius: var(--radius); background: color-mix(in srgb, var(--sun) 16%, white); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--sun-d) 35%, white); }
.tn-row { display: flex; align-items: stretch; gap: 6px; min-width: 0; }
.tn-pile {
  flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 52px; padding: 4px 6px;
  border: 0; border-radius: 14px; background: var(--card); box-shadow: 0 3px 0 var(--tile-shadow);
  font: inherit; color: var(--ink); cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.tn-pile:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--tile-shadow); }
.tn-count { flex: none; width: 26px; text-align: center; font: 900 19px/1 var(--font-ui); color: var(--k-d); }
.tn-none .tn-count { color: var(--muted); }
.tn-pile .tn-body { flex: 1; }
/* in the tray the flats and big cubes overlap in a row */
/* (the body's gap is 8px, so 8px of each one shows; a white edge keeps them apart) */
.tn-pile .tn-hundred + .tn-hundred { margin-left: -42px; }
.tn-pile .tn-hundred, .tn-pile .tn-thousand, .tn-col .tn-hundred { box-shadow: 0 0 0 1.5px var(--card); }
.tn-pile .tn-thousand + .tn-thousand { margin-left: -44px; }
.tn-row.tn-c-ten .tn-pile .tn-body { gap: 4px; }
.tn-pile .tn-thousand { margin-top: 8px; }

.tn-ops { display: flex; gap: 4px; flex: none; }
.tn-op {
  display: grid; justify-items: center; align-content: center; gap: 1px; width: 62px; min-height: 52px; padding: 3px 2px;
  border: 0; border-radius: 14px; background: var(--k); box-shadow: 0 4px 0 var(--k-d);
  font: inherit; color: var(--ink); cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.tn-op:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--k-d); }
.tn-op-pic { display: flex; align-items: center; justify-content: center; gap: 3px; height: 26px; }
.tn-op-pic b { font: 900 17px/1 var(--font-ui); }
.tn-op-pic em { font: 900 14px/1 var(--font-ui); font-style: normal; }
.tn-op small { font: 700 13px/1 var(--font-read); }
/* the little pictures on the buttons: one white block of the kind, drawn small */
.tn-ic { flex: none; box-sizing: border-box; background-color: var(--card); border: 1.5px solid var(--ink); border-radius: 2px; }
.tn-ic-one { width: 9px; height: 9px; }
.tn-ic-ten { width: 22px; height: 7px; background-image: repeating-linear-gradient(90deg, transparent 0 1.2px, var(--ink) 1.2px 1.9px); }
.tn-ic-hundred { width: 17px; height: 17px; background-image: repeating-linear-gradient(90deg, transparent 0 2.2px, var(--ink) 2.2px 2.8px), repeating-linear-gradient(0deg, transparent 0 2.2px, var(--ink) 2.2px 2.8px); }
.tn-ic-thousand { width: 15px; height: 15px; margin: 4px 4px 0 0; box-shadow: 1.5px -1.5px 0 var(--card), 3px -3px 0 var(--ink), 4px -4px 0 var(--card), 5px -5px 0 var(--ink); }
.tn-ops .tn-op:not(:only-child) { width: 54px; }
.tn-break .tn-op-pic { gap: 2px; }
.tn-break .tn-op-pic b { font-size: 15px; }
.tn-break .tn-op-pic em { font-size: 12px; }
.tn-break .tn-ic-ten { width: 16px; }
.tn-op.tn-off { opacity: 0.35; }
/* a snap she can make now asks to be tapped */
.tn-snap:not(.tn-off) { animation: tn-ask 1.4s ease-in-out infinite; }
@keyframes tn-ask { 50% { transform: scale(1.07); } }

.tn-check { justify-self: center; min-width: 200px; }
.tn-check.tn-off { opacity: 0.45; }

/* a tap that can't be done, and a Check that is not right yet: a little shake */
.tn-no { animation: tn-no 0.32s; }
@keyframes tn-no { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* a flying copy of a block */
.tn-fly { position: absolute; z-index: 5; margin: 0; pointer-events: none; transform: translate(-50%, -50%); transition: transform 0.22s ease-in-out; }
.tn-fly.tn-born { animation: tn-born 0.3s; }
@keyframes tn-born { 0% { scale: 0.3; } 60% { scale: 1.5; } 100% { scale: 1; } }

/*
 * ---------- 3D (js/arcade-3d/tentrade3d.js) ----------
 * With .tn-3d the blocks are drawn by three.js on one canvas over the game. The flat blocks
 * above stay in the page, unseen, as the places the 3D ones stand on, so the layout is still
 * made here. What changes: flats lie in stacks of ten on one spot (ten flats are a cube), big
 * cubes stand apart, and with thousands every
 * block is a little smaller (--b, the length of a rod and the side of a flat and a cube).
 */
.tn-gl { position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; pointer-events: none; }
.tn-3d { --b: 42px; }
.tn-3d.tn-k4 { --b: 30px; }
.tn-3d .tn-body .tn-p { visibility: hidden; animation: none; box-shadow: none; }
.tn-3d .tn-ten { width: var(--b); }
.tn-3d .tn-c-ten .tn-g { grid-template-columns: var(--b); }
.tn-3d .tn-hundred { width: var(--b); height: var(--b); }
.tn-3d .tn-thousand { width: var(--b); height: var(--b); margin: 0; }
/* the tray: stacks of ten flats side by side; big cubes in rows, apart, so their sides show */
.tn-3d .tn-pile .tn-body { padding-top: 6px; }
.tn-3d .tn-pile .tn-hundred + .tn-hundred { margin-left: calc(-8px - var(--b)); }
.tn-3d .tn-pile .tn-hundred:nth-child(10n + 11) { margin-left: 12px; }
.tn-3d .tn-row.tn-c-hundred .tn-body { padding-top: 18px; }
.tn-3d .tn-row.tn-c-thousand .tn-body { flex-wrap: wrap; gap: 16px 14px; padding-top: 16px; }
.tn-3d .tn-pile .tn-thousand + .tn-thousand { margin-left: 0; }
.tn-3d .tn-pile .tn-thousand { margin-top: 0; }
/* the mat: one stack of flats; big cubes three to a row */
.tn-3d .tn-col.tn-c-hundred .tn-body, .tn-3d .tn-col.tn-c-thousand .tn-body { flex-direction: row; flex-wrap: wrap; align-items: center; align-content: center; justify-content: center; width: auto; padding: 0; }
.tn-3d .tn-col .tn-hundred, .tn-3d .tn-col .tn-thousand { margin-left: 0; margin-top: 0; }
.tn-3d .tn-col .tn-hundred + .tn-hundred { margin-left: calc(0px - var(--b)); margin-top: 0; }
/*
 * Room for three big cubes in a row. A 3D cube leans to the right as it rises (its top sits about a third of
 * its side to the right of its foot), so the row keeps 12px clear on the right for the last cube's lean, and
 * the gaps between the cubes take whatever width is left: on a narrow phone they close up instead of the
 * cubes leaning over the edge of the column.
 */
.tn-3d.tn-k4 .tn-mat { grid-auto-flow: row; grid-template-columns: 1.9fr 1fr 1fr 1fr; }
.tn-3d .tn-col.tn-c-thousand .tn-body { display: grid; grid-template-columns: repeat(3, var(--b)); justify-content: space-between; align-content: center; gap: 16px 0; width: 100%; box-sizing: border-box; padding: 16px 12px 4px 2px; }
.tn-3d.tn-k4 .tn-col-name { font-size: 12px; }

/* fewer columns: bigger blocks */
.tn-k2 .tn-col .tn-body { zoom: 1.6; }
.tn-k3 .tn-col .tn-body { zoom: 1.25; }
.tn-k2 .tn-pile .tn-body { zoom: 1.25; }

/* iPad: bigger blocks */
@media (min-width: 700px) {
  .tn-wrap { gap: 12px; }
  .tn-mat, .tn-tray { zoom: 1.3; }
  .tn-target { font-size: 60px; }
  .tn-make { font-size: 30px; }
  .tn-msg { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  .tn-in, .tn-star.tn-full, .tn-target.tn-pop, .tn-mat.tn-right .tn-num, .tn-snap:not(.tn-off), .tn-no, .tn-fly.tn-born { animation: none; }
  .tn-fly { display: none; }
}

/* The number to make stays in sight: on a laptop the blocks are below the fold, and scrolling down to them
   used to carry "Make 291" off the top (Amy, Nov 21). It sticks to the top of the screen while she scrolls. */
.tn-goal { position: sticky; top: 6px; z-index: 6; box-shadow: var(--shadow-soft); }
