.card-lesson-open { width: 100%; margin: 0 0 18px; }

body.is-card-lesson > .masthead,
body.is-card-lesson > footer,
body.is-card-lesson #setup-tutorial { display: none; }

body.is-card-lesson #app {
  width: 100%;
  min-height: 100dvh;
  margin: 0;
}

.game-shell.lesson-table:not(.is-lobby) {
  height: min(100dvh, 960px);
  min-height: 650px;
  grid-template-rows: 48px minmax(280px, 1fr) auto;
  padding-top: max(8px, env(safe-area-inset-top));
}
.game-shell.lesson-table:not(.is-lobby) > .hand-area { grid-row: 3; }
.lesson-table .lesson-guide { grid-row: 2 / 4; }
.lesson-room-bar button { min-height: 44px; }
.lesson-room-bar .table-title { margin-left: 0; }
.lesson-room-bar .secondary { padding: 6px 12px; white-space: nowrap; }
.lesson-instructions {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
}
.lesson-instructions > .eyebrow { margin: 0 0 4px; }
.lesson-instructions h1 {
  margin: 0;
  font-size: clamp(18px, 2vw, 25px);
  line-height: 1.15;
}
.lesson-instructions h1:focus { outline: none; }
.lesson-feedback { margin: 7px 0 0; font-size: 14px; line-height: 1.45; }
.lesson-instructions button { min-height: 44px; }
.lesson-instructions > .primary, .lesson-actions { margin-top: 8px; }
.lesson-actions { display: flex; flex-wrap: wrap; gap: 5px 8px; }

.lesson-scores {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: grid;
  gap: 3px;
  border: 1px solid #f5ead550;
  border-radius: 9px;
  background: #102b3d;
  padding: 5px 8px;
  min-width: 76px;
  color: var(--cream);
  font-size: 11px;
}
.lesson-scores .score-team { display: flex; justify-content: space-between; gap: 8px; padding: 0; color: inherit; }
.lesson-scores strong { color: #f2cf87; font-variant-numeric: tabular-nums; }
.lesson-spotlight {
  outline: 3px solid #f2cf87;
  outline-offset: 3px;
  animation: lesson-highlight 780ms ease-out;
}
.lesson-table .trump-card.lesson-spotlight { z-index: 1; }
.lesson-table .trump-card.lesson-spotlight img { animation: lesson-turn-face 420ms ease-out; }
@keyframes lesson-turn-face {
  from { opacity: 0.2; transform: scaleX(0.05); }
  to { opacity: 1; transform: scaleX(1); }
}
@keyframes lesson-highlight {
  0% { box-shadow: 0 0 0 8px #f2cf8760; }
  100% { box-shadow: 0 0 0 0 #f2cf8700; }
}
.lesson-reference-step .table-stamp,
.lesson-reference-step .deck-area,
.lesson-reference-step .trick-pot,
.lesson-reference-step:has(.lesson-bonuses) .scopa-board,
.lesson-reference-step:has(.lesson-bonuses) .scopa-board-heading { visibility: hidden; }
.lesson-card-reference {
  position: absolute;
  inset: 26% 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(5px, 2vw, 20px);
}
.lesson-card-reference figure { margin: 0; text-align: center; }
.lesson-card-reference .card-face {
  margin-inline: auto;
  width: clamp(34px, 10vw, 78px);
  height: auto;
  aspect-ratio: 480 / 743;
  animation: lesson-reveal 360ms ease-out backwards;
}
.lesson-card-reference figure:nth-child(2) .card-face { animation-delay: 70ms; }
.lesson-card-reference figure:nth-child(3) .card-face { animation-delay: 140ms; }
.lesson-card-reference figure:nth-child(4) .card-face { animation-delay: 210ms; }
.lesson-card-reference figure:nth-child(5) .card-face { animation-delay: 280ms; }
.lesson-card-reference figcaption { margin-top: 5px; line-height: 1.15; }
.lesson-card-reference b { display: block; font-size: clamp(10px, 2vw, 14px); }
.lesson-card-reference small { color: #f2cf87; font-size: 11px; }
@keyframes lesson-reveal {
  from { opacity: 0; transform: translateY(12px) rotate(-7deg); }
  to { opacity: 1; transform: none; }
}
.lesson-bonuses {
  position: absolute;
  inset: 48px 8px 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: center;
  gap: 6px;
  margin: 0 auto;
  max-width: 540px;
}
.lesson-bonuses div { background: #102b3d; border-radius: 8px; padding: 7px; }
.lesson-bonuses dt { color: #f2cf87; font-weight: 700; font-size: 12px; }
.lesson-bonuses dd { margin: 3px 0 0; font-size: 12px; line-height: 1.25; }
@media (prefers-reduced-motion: reduce) {
  .lesson-spotlight, .lesson-card-reference .card-face,
  .lesson-table .trump-card.lesson-spotlight img { animation: none; }
}

/* Keep the normal table elements in view while the lesson text changes. */
@media (max-width: 900px) {
  body.is-card-lesson { background: #193c52; }
  .game-shell.lesson-table:not(.is-lobby) {
    --card-w: clamp(58px, min(21vw, 13dvh), 100px);
    grid-template-rows: 44px auto minmax(158px, 1fr) auto;
    gap: 6px;
    width: 100%;
    min-height: 100dvh;
    height: auto;
    padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
  }
  .lesson-table .lesson-guide { grid-row: auto; }
  .game-shell.lesson-table:not(.is-lobby) > .hand-area { grid-row: auto; }
  .lesson-room-bar .eyebrow, .lesson-room-bar .text-button { color: var(--cream); }
  .lesson-room-bar .eyebrow { font-size: 11px; }
  .lesson-instructions { padding: 8px 12px; border-radius: 10px; }
  .lesson-feedback { margin-top: 5px; font-size: 13px; line-height: 1.3; }
  .lesson-table .felt-table { border-color: #f5ead526; border-width: 1px; border-radius: 12px; }
  .lesson-table .hand-area { padding: 4px 8px 2px; border-radius: 12px; }
  .lesson-table .hand { min-height: 0; padding: 4px 0; }
  .lesson-table .last-trick { min-height: 20px; padding: 0 0 3px; }
  .lesson-table .player-top { top: 6px; }
  .lesson-table .player-top .avatar { width: 26px; height: 26px; }
  .lesson-table .player-top .mini-hand .card-back { width: 16px; height: 25px; margin-inline: -3px; }
  .lesson-scores { top: 6px; left: 6px; right: auto; font-size: 10px; }
  .lesson-bonuses { top: 35px; }
  .lesson-bonuses dt, .lesson-bonuses dd { font-size: 11px; }
  .lesson-table .trick-area {
    --lesson-played-w: clamp(43px, 10dvh, 66px);
    top: 34%;
    left: 50%;
    transform: translateX(-50%);
    width: calc(var(--lesson-played-w) * 2 + 8px);
    height: calc(var(--lesson-played-w) * 1.55);
    display: flex;
    justify-content: center;
    gap: 8px;
  }
  .lesson-table .trick-area .played-card {
    position: relative;
    inset: auto;
    width: var(--lesson-played-w);
    height: 100%;
    transform: none;
  }
  .lesson-table .trick-area .played-card > span:last-child { display: none; }
  .lesson-table .deck-area { left: 9px; bottom: 9px; }
  .lesson-table .trick-pot { right: 9px; bottom: 9px; }
  .lesson-table .scopa-board-heading { top: 40px; }
  .lesson-table .scopa-board { top: 56px; bottom: 6px; left: 54px; right: 54px; }
  .lesson-table .scopa-layout { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .lesson-table .scopa-table-card { max-width: 70px; }
  .lesson-table.scopa-room .deck-area > div:last-child { display: none; }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .game-shell.lesson-table:not(.is-lobby) {
    grid-template-columns: minmax(0, 1fr) minmax(224px, 43%);
    grid-template-rows: 44px auto 1fr;
    align-content: stretch;
  }
  .lesson-room-bar { grid-column: 1 / -1; }
  .lesson-table .lesson-guide { grid-column: 2; grid-row: 2; }
  .lesson-table .felt-table { grid-column: 1; grid-row: 2 / 4; }
  .game-shell.lesson-table:not(.is-lobby) > .hand-area { grid-column: 2; grid-row: 3; }
}
