/* The interactive tutorial. Phone-shaped on every screen, so it plays the same
   in a pocket and on a desk. */

.tut-page {
  height: 100dvh;
  overflow: hidden;
}

.tut {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
}

/* ---------- top bar ---------- */

.tut-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.tut-x,
.tut-sound {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--felt-deep);
  color: var(--cream);
  font-family: var(--display);
  font-size: 1.1rem;
  text-decoration: none;
  cursor: pointer;
}

.steps {
  display: flex;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.steps li {
  flex: 1;
  text-align: center;
  font-family: var(--display);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  padding: 5px 0;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: rgba(0, 0, 0, 0.25);
  color: rgba(255, 255, 255, 0.55);
  transition: background 0.3s ease, color 0.3s ease, transform 0.3s ease;
}

.steps li.done {
  background: var(--felt-light);
  color: var(--cream);
}

.steps li.now {
  background: var(--yellow);
  color: var(--ink);
  transform: scale(1.06);
}

/* ---------- lesson stage ---------- */

.stage {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding-bottom: 200px; /* room for the coach */
  text-align: center;
}

.stage[hidden] {
  display: none;
}

.lesson-title {
  margin: 0;
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  color: var(--yellow);
}

.lesson-title.big {
  font-size: clamp(3.4rem, 17vw, 5rem);
}

/* Four suit tiles, tap to reveal the name. */
.suit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: min(100%, 380px);
}

.suit-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  gap: 0;
  border: 4px solid var(--ink);
  border-radius: 24px;
  background: var(--cream);
  box-shadow: 0 7px 0 var(--ink);
  cursor: pointer;
  font: inherit;
  transition: transform 0.2s cubic-bezier(0.3, 1.6, 0.5, 1);
  -webkit-tap-highlight-color: transparent;
}

.suit-tile:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--ink);
}

.suit-tile .sym {
  font-size: 4.2rem;
  line-height: 1;
  color: var(--ink);
}

.suit-tile.red .sym {
  color: var(--red);
}

.suit-tile .name {
  font-family: var(--display);
  font-size: 2rem;
  line-height: 1;
  color: var(--ink);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.3, 1.8, 0.5, 1);
}

.suit-tile .from {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.3s ease 0.15s;
}

.suit-tile.open {
  background: var(--tile, var(--yellow));
  animation: tile-pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.suit-tile.open .name {
  opacity: 1;
  transform: none;
}

.suit-tile.open .from {
  opacity: 0.75;
}

@keyframes tile-pop {
  50% { transform: scale(1.1) rotate(-3deg); }
}

/* A row of cards in a lesson. */
.card-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 100%;
}

.ladder {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
}

.ladder .pcard {
  --w: clamp(34px, 9.5vw, 48px);
}

.ladder-labels {
  display: flex;
  justify-content: space-between;
  width: min(100%, 440px);
  font-family: var(--display);
  font-size: 1.1rem;
}

.ladder-labels span:first-child { color: var(--yellow); }
.ladder-labels span:last-child { color: var(--pink); }

.crossed {
  position: relative;
}

.crossed::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: calc(var(--w, 80px) * 1.1);
  color: var(--red);
  text-shadow: 3px 3px 0 var(--ink), -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink);
  animation: stamp 0.4s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

@keyframes stamp {
  from { transform: scale(3); opacity: 0; }
}

.choice-row {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.points-row {
  display: flex;
  justify-content: center;
  gap: 18px;
}

.points-row figure {
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 8px;
}

.points-row b {
  font-family: var(--display);
  font-size: 2.4rem;
}

/* ---------- playing cards ---------- */

/* The game's own classic deck: each card is its image, nothing drawn over it. */
.pcard {
  --w: 70px;
  position: relative;
  width: var(--w);
  aspect-ratio: 204 / 288;
  flex: none;
  border: 0;
  padding: 0;
  border-radius: calc(var(--w) * 0.07);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(16, 42, 20, 0.3), 0 5px 10px rgba(0, 0, 0, 0.3);
  font-size: inherit;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s cubic-bezier(0.3, 1.6, 0.5, 1), filter 0.2s ease, box-shadow 0.2s ease;
}

.pcard img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  pointer-events: none;
  user-select: none;
}

.pcard.tappable {
  cursor: pointer;
}

.pcard.tappable:hover {
  transform: translateY(-8px);
}

.pcard.locked {
  filter: grayscale(0.7) brightness(0.6);
}

.pcard.target {
  box-shadow: 0 0 0 5px var(--yellow), 0 0 26px var(--yellow), 0 5px 10px rgba(0, 0, 0, 0.3);
  animation: lift 1s ease-in-out infinite;
}

@keyframes lift {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.pcard.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  20%, 60% { transform: translateX(-8px) rotate(-4deg); }
  40%, 80% { transform: translateX(8px) rotate(4deg); }
}

.pcard.winner::after {
  content: "👑";
  position: absolute;
  top: -0.9em;
  left: 50%;
  transform: translateX(-50%) rotate(-8deg);
  font-size: calc(var(--w) * 0.42);
  animation: stamp 0.4s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

.pcard.loser {
  filter: grayscale(0.8) brightness(0.65);
}

/* ---------- the table ---------- */

.table {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  padding-bottom: 6px;
}

.table[hidden] {
  display: none;
}

.who {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--display);
  font-size: 1.2rem;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--sky);
  color: var(--ink);
  font-size: 1rem;
}

.avatar.me {
  width: auto;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--yellow);
}

.pts {
  padding: 2px 10px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--yellow);
  color: var(--ink);
  font-size: 0.95rem;
}

.opp {
  position: relative;
  display: grid;
  gap: 6px;
  justify-items: center;
  padding-top: 8px;
}

.opp-hand {
  display: flex;
  justify-content: center;
  height: 64px;
}

.opp-hand .pcard {
  --w: 44px;
  margin: 0 -10px;
}

.trick-zone {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  justify-items: center;
  /* Room for the piles: five cards each, stepping down as they stack. */
  min-height: 300px;
}

.trick-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 1.05rem;
  margin: 6px 0;
}

.dots {
  display: flex;
  gap: 5px;
}

.dots i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: rgba(0, 0, 0, 0.3);
}

.dots i.done { background: var(--felt-light); }
.dots i.now { background: var(--yellow); }
.dots i.last { border-color: var(--yellow); }

.slot {
  --cw: clamp(70px, 20vw, 92px);
  position: absolute;
  left: 50%;
  width: var(--cw);
  aspect-ratio: 204 / 288;
}

/* Each trick's card sits a step further down and across, with its own tilt. */
.slot .pile {
  position: absolute;
  inset: 0;
  transform: translate(calc(var(--n, 0) * 9px), calc(var(--n, 0) * 8px)) rotate(var(--tilt, 0deg));
}

.slot .pcard {
  --w: var(--cw);
}

/* Earlier tricks, still on the table, a touch quieter than the live one. */
.slot .pcard.past {
  filter: brightness(0.92) saturate(0.9);
}

.slot-bot {
  top: 52px;
  transform: translateX(-75%) rotate(-6deg);
}

.slot-you {
  top: 112px;
  transform: translateX(-15%) rotate(6deg);
}

.hand-zone {
  position: relative;
  display: grid;
  gap: 8px;
  justify-items: center;
  padding-top: 8px;
}

.you-hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  min-height: 120px;
}

.you-hand .pcard {
  --w: clamp(62px, 17vw, 82px);
  margin: 0 -4px;
}

/* Up by Kofi, where nothing else lives: never under the coach or the hand. */
.hint {
  position: absolute;
  right: 0;
  top: 8px;
  min-height: 44px;
  padding: 6px 14px;
  font-size: 1.1rem;
  z-index: 3;
}

.hint[hidden] {
  display: none;
}

/* ---------- the coach ---------- */

.coach {
  position: fixed;
  left: 50%;
  bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px));
  z-index: 20;
  width: min(calc(100% - 24px), 496px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 74px 1fr;
  align-items: end;
  gap: 8px;
  pointer-events: none;
  animation: coach-in 0.45s cubic-bezier(0.3, 1.5, 0.5, 1);
}

/* Over the lessons, the coach sits low; over the table, just above the hand. */
.coach.low {
  bottom: max(18px, env(safe-area-inset-bottom));
}

.coach[hidden] {
  display: none;
}

@keyframes coach-in {
  from { transform: translate(-50%, 30px); opacity: 0; }
}

.sunny {
  width: 74px;
  animation: sunny-bob 1.6s ease-in-out infinite;
}

.sunny svg {
  width: 100%;
  display: block;
  overflow: visible;
}

.sunny-eyes {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: blink 4s linear infinite;
}

.coach.talking .sunny-mouth {
  animation: talk 0.25s ease-in-out infinite alternate;
  transform-box: fill-box;
  transform-origin: 50% 0%;
}

@keyframes sunny-bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-6px) rotate(3deg); }
}

@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

@keyframes talk {
  to { transform: scaleY(1.6); }
}

.bubble {
  position: relative;
  pointer-events: auto;
  background: var(--cream);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 22px 22px 22px 6px;
  box-shadow: 0 6px 0 var(--ink);
  padding: 12px 14px;
  font-weight: 800;
  font-size: 1.02rem;
  line-height: 1.35;
  display: grid;
  gap: 10px;
}

.bubble p {
  margin: 0;
}

.bubble b {
  color: var(--felt);
}

.bubble .red {
  color: var(--red);
}

.bubble .gbtn {
  justify-self: end;
  min-height: 44px;
  padding: 6px 18px;
  font-size: 1.2rem;
}

.bubble .gbtn[hidden] {
  display: none;
}

/* ---------- the pointing hand ---------- */

.pointer {
  position: fixed;
  z-index: 30;
  font-size: 46px;
  pointer-events: none;
  transform: translate(-30%, 10%);
  animation: point 0.9s ease-in-out infinite;
  filter: drop-shadow(0 4px 2px rgba(0, 0, 0, 0.4));
}

.pointer[hidden] {
  display: none;
}

@keyframes point {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -14px; }
}

/* ---------- round results ---------- */

.result {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.result .points {
  font-family: var(--display);
  font-size: clamp(4rem, 22vw, 6rem);
  color: var(--yellow);
  animation: stamp 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

.end-actions {
  display: grid;
  gap: 12px;
  width: min(100%, 320px);
}

.end-actions .gbtn {
  width: 100%;
}
