/* Complete illustrated scenery surrounds native, reusable controls.
   Artwork never owns a word, a score, a material edge or a hit area. */
body.study-challenge-playing {
  --study-ink: #073c48;
  --study-gold: #e4ad37;
  --study-teal: #00bdc4;
  --challenge-content-max: 1680px;
  background: #113d40;
}
body.study-challenge-playing::before,
body.study-challenge-playing::after {
  display: none;
}
body.study-challenge-playing .app {
  position: relative;
  z-index: 1;
  --challenge-gutter: clamp(6px, 1.2vw, 18px);
  --challenge-column-width: min(100%, 1000px);
  padding-inline: max(var(--challenge-gutter), var(--safe-left, 0px)) max(var(--challenge-gutter), var(--safe-right, 0px));
}
body.study-challenge-playing .game-header {
  position: relative;
  z-index: 8;
  background: #fff2d95c;
  border: 0;
}
body.study-challenge-playing .study-challenge.game-layout {
  position: relative;
  height: 100%;
  min-height: 0;
  padding: 0 0 6px;
  gap: 20px;
}
body.study-challenge-playing .study-challenge .game-main {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  gap: 4px;
  isolation: isolate;
}
body.study-challenge-playing .study-challenge .game-title {
  position: absolute;
  z-index: 4;
  top: 7px;
  right: 5px;
  width: 44px;
  height: 44px;
  margin: 0;
}
body.study-challenge-playing .study-challenge .game-title > div {
  display: none;
}
body.study-challenge-playing .study-challenge .game-title #pause {
  width: 44px;
  height: 44px;
}
.study-challenge-plaque {
  position: relative;
  flex: none;
  min-width: 0;
  z-index: 1;
  margin: 0;
  padding: 12px 14px 10px;
  border: 4px solid transparent;
  border-radius: 20px;
  background:
    var(--relic-parchment) padding-box,
    var(--relic-gilding) border-box;
  box-shadow:
    inset 0 0 0 1px #fff9dc,
    inset 0 0 0 5px #d6ae6340,
    0 0 0 1px #a67530,
    0 4px 7px #6b461f40;
}
body.study-challenge-playing .study-challenge #phrase.phrase-strip,
.clean-play
  body.study-challenge-playing
  .study-challenge
  #phrase.phrase-strip.compact {
  border: 0;
  border-image: none;
  border-radius: 0;
  background: none;
  box-shadow: none;
  margin: 0;
  padding: 0;
  min-height: 0;
  font: 600 clamp(21px, 2.2vw, 32px)/1.25 var(--heading);
  max-width: none;
  width: 100%;
  color: var(--study-ink);
  text-align: center;
}
body.study-challenge-playing .study-challenge #phrase .phrase-heading {
  margin: 0 0 6px;
  font: 500 18px/1.2 var(--heading);
  color: #28565b;
}
body.study-challenge-playing .study-challenge .phrase-instruction {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
}
body.study-challenge-playing .study-challenge .phrase-line {
  gap: 3px;
}
body.study-challenge-playing .study-challenge .phrase-words {
  display: block;
  text-wrap: balance;
  word-spacing: 0.08em;
}
body.study-challenge-playing .study-challenge .phrase-group {
  display: inline-block;
  white-space: nowrap;
}
body.study-challenge-playing .study-challenge .phrase-part {
  vertical-align: baseline;
}
body.study-challenge-playing .study-challenge .word-slot {
  min-width: calc(var(--letters) * 0.58em);
  line-height: 1.24;
}
body.study-challenge-playing .study-challenge .word-mask {
  gap: 0.055em;
}
body.study-challenge-playing .study-challenge .mask-letter {
  width: 0.51em;
  min-height: 1.13em;
  border: 0;
  border-bottom: 3px solid #cf9b32;
  border-radius: 0 0 2px 2px;
  background: linear-gradient(0deg, #f3cf7377, transparent 28%);
  color: transparent;
}
body.study-challenge-playing .study-challenge .mask-letter.hint-letter {
  color: #087887;
  background: #bef3e9;
}
body.study-challenge-playing .study-challenge .word-text {
  color: #073c48;
  text-shadow: 0 1px #fff6d5;
}
body.study-challenge-playing .study-challenge .phrase-punctuation {
  color: #073c48;
}
body.study-challenge-playing .study-challenge .phrase-quote {
  position: static;
  font-size: 0.9em;
  color: #ba8929;
}
body.study-challenge-playing .study-challenge #phrase .phrase-credit {
  margin-top: 5px;
  font: 800 11px/1.3 var(--body);
  color: #52706a;
}
body.study-challenge-playing .study-challenge .board-space {
  position: relative;
  isolation: isolate;
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  width: 100%;
}
body.study-challenge-playing .study-challenge .board-space::before {
  display: none;
}
body.study-challenge-playing .study-challenge .board-paper {
  position: relative;
  max-width: 100%;
  padding: var(--study-board-pad-top) var(--study-board-pad-inline) var(--study-board-pad-bottom);
  margin: 0;
  border: var(--study-board-border) solid transparent;
  border-radius: 18px;
  background:
    linear-gradient(145deg, #168f8b, #005961) padding-box,
    var(--relic-gilding) border-box;
  box-shadow:
    inset 0 0 0 2px #eec66b,
    inset 0 0 0 5px #00565d,
    0 0 0 1px #a1712c,
    0 4px 7px -3px #6b461f80;
}
body.study-challenge-playing .study-challenge .board {
  gap: 0;
}

/* Shared, real tile component. DS specimens use .study-cell and the same states. */
body.study-challenge-playing .study-challenge .cell,
.study-cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-image: none;
  border-radius: 9px;
  color: #093b46;
  background:
    linear-gradient(155deg, #fffbe6, #fcecc5 60%, #f2d594) padding-box,
    var(--relic-gilding) border-box;
  box-shadow:
    inset 0 1px #fffdf1,
    inset 0 -2px #d5a64955,
    0 1px #966529;
  font: 600 clamp(17px, calc(var(--cell-size, 40px) * 0.62), 62px)/1
    var(--heading);
  text-shadow: 0 1px #fff6d8;
  -webkit-tap-highlight-color: transparent;
}
body.study-challenge-playing .study-challenge .cell.selected,
body.study-challenge-playing .study-challenge .cell.found,
.study-cell.selected,
.study-cell.found {
  color: #fffdf0;
  background:
    linear-gradient(155deg, #24c9bf, #00838b 40%, #006770) padding-box,
    var(--relic-gilding) border-box;
  text-shadow: 0 1px #005762;
  box-shadow:
    inset 0 1px #affff0,
    inset 0 -2px #00535d55,
    0 1px #966529;
}
body.study-challenge-playing .study-challenge .cell.wrong,
.study-cell.wrong {
  color: #7a2334;
  background:
    linear-gradient(155deg, #ffe5ce, #f0a18a) padding-box,
    var(--relic-gilding) border-box;
  text-shadow: none;
}
body.study-challenge-playing .study-challenge .cell.letter-cue {
  outline: 3px solid #fff5a4;
  outline-offset: -5px;
  background: linear-gradient(140deg, #fff6aa, #ffd87d);
}
body.study-challenge-playing .study-challenge .cell.letter-cue::after {
  inset: 5px;
  border-color: #ffd45d;
}
/* Keyboard cursor: pale yellow vanished on the cream tiles, so a keyboard
   player could not see where they were. Dark teal (the study controls' focus
   colour) on ordinary tiles, the pale ring kept on teal selected tiles. */
body.study-challenge-playing .study-challenge .cell:focus-visible,
.study-cell:focus-visible {
  outline: 3px solid #075a6b;
  outline-offset: -5px;
  z-index: 3;
}
body.study-challenge-playing .study-challenge .cell:is(.selected, .found):focus-visible,
.study-cell:is(.selected, .found):focus-visible {
  outline-color: #fff8af;
}
body.study-challenge-playing .study-challenge .cell.wet {
  background: linear-gradient(140deg, #e4ffff, #80e9ef 65%, #3fc8d9);
  color: #0b5866;
}
body.study-challenge-playing .study-challenge .cell.erased {
  opacity: 0.4;
}
body.study-challenge-playing .study-challenge .cell.coin-hover {
  background-color: #fff0ba;
  box-shadow:
    inset 0 0 0 3px #fff2a4,
    0 0 10px #ffd56199;
}
.study-selection-trail {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}
.study-selection-trail path {
  fill: none;
  stroke: #ffc331;
  stroke-width: 4;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 1px #90601a);
}
body.study-challenge-playing .study-challenge .tool-hint {
  flex: none;
  align-self: center;
  max-width: 100%;
  padding: 4px 10px;
  min-height: 0;
  border-radius: 12px;
  background: #073c48c9;
  text-align: center;
  color: #fff2cc;
  font: 800 12px/1.3 var(--body);
}
body.study-challenge-playing .study-challenge .tools-bar {
  flex: none;
  display: flex;
  width: 100%;
  max-width: none;
  margin: 0;
  gap: 5px;
  padding: 3px 15px 4px;
  border: 0;
  background: none;
  box-shadow: none;
}
body.study-challenge-playing .study-challenge .tool-button {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0;
  min-width: 0;
  min-height: 66px;
  padding: 4px 4px 5px;
  border: 2px solid transparent;
  border-image: none;
  border-radius: 15px;
  background:
    var(--relic-parchment) padding-box,
    var(--relic-gilding) border-box;
  font: 600 14px/1.2 var(--heading);
  color: #214b4e;
  box-shadow:
    inset 0 1px #fffbe8,
    0 0 0 1px #b38840,
    0 3px 4px -2px #95633170;
}
body.study-challenge-playing .study-challenge .tool-button > .icon {
  display: none;
}
body.study-challenge-playing
  .study-challenge
  .tool-button:not([data-tool])
  > .icon {
  display: block;
}
.study-tool-object {
  display: block;
  width: 46px;
  height: 39px;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 1px #88562a33);
}
body.study-challenge-playing
  .study-challenge
  .tool-button[data-tool="water"]
  .study-tool-object {
  height: 40px;
}
body.study-challenge-playing .study-challenge .tool-button .qty {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  border: 1px solid #be8f2e;
  border-radius: 50%;
  background: linear-gradient(140deg, #ffeb9f, #eab649);
  box-shadow: inset 0 1px #fff7cd;
  color: #714d17;
  font: 600 12px/1 var(--heading);
}
body.study-challenge-playing .study-challenge .tool-button.active {
  background: linear-gradient(140deg, #a8fff1, #27c7cf);
  box-shadow:
    0 0 0 2px #fff1a5,
    0 2px #178c98;
}
body.study-challenge-playing .study-challenge .tool-button:disabled {
  opacity: 0.65;
  filter: none;
}
body.study-challenge-playing .study-challenge.learning-game .tools-bar,
body.study-challenge-playing .study-challenge.learning-game .tool-hint {
  display: none;
}
body.study-challenge-playing .study-challenge .game-bottom {
  flex: none;
  align-items: center;
  gap: 6px;
  margin: 0 5px;
}
body.study-challenge-playing .study-challenge .game-bottom > span {
  display: none;
}
body.study-challenge-playing .study-challenge .game-bottom .small-btn {
  min-height: 44px;
  padding: 6px 12px;
  font-size: 13px;
  background: #fff5dccc;
  border-color: #d7b76f;
  color: #325f60;
}
body.study-challenge-playing .study-challenge .game-bottom #hint {
  margin-left: auto;
}
/* Landscape keeps the world behind the UI. Portrait groups one art track,
   the phrase, the full-width board and tools as one continuous composition. */
.study-challenge-art { display: contents; pointer-events: none; }
.clean-play body.study-challenge-playing .app {
  max-width: var(--challenge-content-max);
  grid-template-rows: 52px minmax(0, 1fr);
}
.clean-play body.study-challenge-playing .game-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-areas: "supplies clock actions";
  justify-self: center;
  width: min(100%, max(284px, var(--challenge-board-width, var(--challenge-column-width))));
  height: 52px;
  gap: 8px;
  padding: 0;
  background: none;
}
body.study-challenge-playing .game-header .brand,
body.study-challenge-playing #inventory-summary,
body.study-challenge-playing .study-challenge .game-title {
  display: none;
}
body.study-challenge-playing .game-header .player-supplies {
  grid-area: supplies;
  width: auto;
  justify-content: flex-start;
  gap: 8px;
  margin: 0;
}
body.study-challenge-playing .game-header .top-actions {
  grid-area: actions;
  justify-self: end;
  gap: 6px;
  margin-left: auto;
}
body.study-challenge-playing .game-header .icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
}
.game-clock:not([hidden]) {
  grid-area: clock;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  gap: 5px;
  min-height: 34px;
  min-width: 60px;
  padding: 4px 9px;
  border: 1px solid #f6d3849c;
  border-radius: 999px;
  background: #073541ed;
  color: #fff4d8;
  font: 800 14px/1 var(--body);
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 1px #ffffff22;
}
.game-clock .icon {
  display: block;
  width: 17px;
  height: 17px;
}
.game-clock .icon[data-icon="stopwatch"] { color: #f6d384; }
.game-clock.game-clock--urgent { color: #ffcf9e; border-color: #ffc183; }
@media (max-width: 375px) {
  .clean-play body.study-challenge-playing .game-header { gap: 4px; }
  body.study-challenge-playing .game-header #fullscreen { display: none; }
  body.study-challenge-playing .game-header :is(.player-supplies, .top-actions) { gap: 4px; }
  body.study-challenge-playing .game-header #wallet { padding-inline: 5px; white-space: nowrap; }
  .game-clock:not([hidden]) { gap: 3px; padding-inline: 6px; }
}
body.study-challenge-playing #main {
  height: 100%;
  min-height: 0;
}
body.study-challenge-playing .study-challenge.game-layout {
  display: block;
  height: 100%;
  padding: 4px 0 8px;
}
.clean-play body.study-challenge-playing .study-challenge .game-main {
  --study-board-pad-inline: 9px;
  --study-board-pad-top: 9px;
  --study-board-pad-bottom: 15px;
  --study-board-border: 3px;
  --study-board-edge-inline: calc((var(--study-board-pad-inline) + var(--study-board-border)) * 2);
  --study-board-edge-block: calc(var(--study-board-pad-top) + var(--study-board-pad-bottom) + var(--study-board-border) * 2);
  display: flex;
  flex-direction: column;
  width: var(--challenge-column-width);
  max-width: none;
  height: 100%;
  min-height: 0;
  container-type: inline-size;
  margin: 0 auto;
  gap: 6px;
}
body.study-challenge-playing .study-challenge .study-challenge-plaque {
  width: 100%;
  flex: none;
}
body.study-challenge-playing .study-challenge .board-space {
  /* The board receives the remainder, not the intrinsic size of its child. */
  contain: size;
  min-width: 0;
  flex: 1 1 0;
  align-items: start;
}
body.study-challenge-playing .study-challenge .tools-bar {
  width: 100%;
  max-width: 1000px;
  align-self: center;
  padding: 2px 4px 3px;
}
body.study-challenge-playing .study-challenge .game-bottom {
  width: 100%;
  max-width: 1000px;
  align-self: center;
}
body.study-challenge-playing .study-challenge #phrase .phrase-heading {
  font-size: 16px;
  margin-bottom: 4px;
}
body.study-challenge-playing .study-challenge .tool-hint:empty {
  display: none;
}
body.study-challenge-playing .study-challenge .tool-lesson-armed .tool-hint,
body.study-challenge-playing .study-challenge .game-main.tool-lesson-armed .tool-hint {
  display: none;
}
body.study-challenge-playing .study-challenge .tool-use-coach,
body.study-challenge-playing .study-challenge .study-touch-coach {
  flex: none;
  width: 100%;
  margin: 0;
}
/* The guide exists once, as a plane in the scene; teaching is readable text. */
body.study-challenge-playing .study-challenge .study-coach-portrait {
  display: none;
}
body.study-challenge-playing .study-challenge .study-touch-coach {
  grid-template-columns: minmax(0, 1fr);
}
body.study-challenge-playing .study-challenge .study-touch-coach ol {
  grid-column: 1;
}

/* A broad, tall viewport leaves one side of the world visible. The phrase
   retains the same full-width reading track as the board, never a side card. */
@media (min-width: 1100px) and (min-height: 700px) and (min-aspect-ratio: 5/4) {
  body.study-challenge-playing .app { --challenge-column-width: min(68%, 1120px); }
  .clean-play body.study-challenge-playing .game-header {
    justify-self: start;
    margin-inline-start: max(0px, calc((var(--challenge-column-width) - var(--challenge-board-width, var(--challenge-column-width))) / 2));
  }
  .clean-play body.study-challenge-playing .study-challenge .game-main {
    margin-inline: 0 auto;
    gap: 8px;
  }
  body.study-challenge-playing .study-challenge .study-challenge-plaque {
    padding-inline: 22px;
  }
}

@media (min-height: 601px) {
  body.study-challenge-playing .study-challenge .study-challenge-plaque {
    align-self: center;
    width: min(100%, var(--challenge-board-width, 100%));
  }
  body.study-challenge-playing .study-challenge .board-space {
    /* Let the scene show below the tools once the width or the per-cell cap
       is reached. A tall viewport cannot open a gap between board and tools. */
    max-height: calc(min(112px, (100cqw - var(--study-board-edge-inline)) / var(--study-board-cols)) * var(--study-board-rows) + var(--study-board-edge-block));
  }
  body.study-challenge-playing .study-challenge .tools-bar,
  body.study-challenge-playing .study-challenge .tool-use-coach,
  body.study-challenge-playing .study-challenge .study-touch-coach {
    width: min(100%, var(--challenge-board-width, 100%));
    align-self: center;
  }
}

@media (min-width: 700px) and (min-height: 700px) and (min-aspect-ratio: 4/5) {
  .clean-play body.study-challenge-playing .app {
    grid-template-rows: 60px minmax(0, 1fr);
  }
  .clean-play body.study-challenge-playing .game-header {
    height: 60px;
  }
}

/* Laptop-height desktops keep a long quotation readable without spending
   the board's height on oversized type and decorative spacing. */
@media (min-width: 1100px) and (min-height: 700px) and (max-height: 900px) and (min-aspect-ratio: 5/4) {
  .clean-play body.study-challenge-playing .study-challenge .game-main {
    gap: 6px;
  }
  body.study-challenge-playing .study-challenge .study-challenge-plaque {
    padding: 10px 20px 8px;
  }
  body.study-challenge-playing .study-challenge #phrase.phrase-strip,
  .clean-play body.study-challenge-playing .study-challenge #phrase.phrase-strip.compact {
    font-size: 24px;
    line-height: 1.18;
  }
  body.study-challenge-playing .study-challenge .word-slot {
    line-height: 1.18;
  }
  body.study-challenge-playing .study-challenge #phrase .phrase-heading {
    margin-bottom: 2px;
    font-size: 16px;
    line-height: 1.15;
  }
  body.study-challenge-playing .study-challenge #phrase .phrase-credit {
    margin-top: 3px;
    font: 800 11px/1.2 var(--body);
  }
  body.study-challenge-playing .study-challenge .tool-button {
    min-height: 60px;
    padding-block: 3px;
  }
  body.study-challenge-playing .study-challenge .study-tool-object,
  body.study-challenge-playing .study-challenge .tool-button[data-tool="water"] .study-tool-object {
    height: 34px;
  }
}

@media (max-width: 499px) and (max-height: 650px) {
  .clean-play body.study-challenge-playing .study-challenge .game-main {
    gap: 3px;
  }
  body.study-challenge-playing .study-challenge-plaque {
    padding: 9px 9px 7px;
  }
  body.study-challenge-playing .study-challenge #phrase .phrase-heading {
    font-size: 14px;
  }
  body.study-challenge-playing .study-challenge .tool-button {
    min-height: 51px;
    padding-block: 2px;
    font-size: 12px;
  }
  body.study-challenge-playing .study-tool-object,
  body.study-challenge-playing .study-challenge .tool-button[data-tool="water"] .study-tool-object {
    width: 38px;
    height: 27px;
  }
  body.study-challenge-playing .study-challenge .tool-button .qty {
    width: 18px;
    height: 18px;
    top: 3px;
    right: 4px;
    font-size: 11px;
  }
  body.study-challenge-playing .study-challenge .game-bottom .small-btn {
    font-size: 12px;
    padding-inline: 8px;
  }
}

/* Only a genuinely short landscape moves the controls beside the board.
   It has no reserved illustration area, so every available pixel can play. */
@media (min-width: 500px) and (max-height: 600px) {
  .clean-play body.study-challenge-playing .game-header {
    width: 100%;
    max-width: 1440px;
  }
  .clean-play body.study-challenge-playing .study-challenge .game-main {
    display: grid;
    width: 100%;
    max-width: 1440px;
    grid-template-columns: minmax(0, 1fr) minmax(210px, 36%);
    grid-template-rows: minmax(0, 1fr) auto auto;
    column-gap: clamp(8px, 1.6vw, 24px);
    row-gap: 4px;
    align-items: center;
  }
  body.study-challenge-playing .study-challenge .board-space {
    grid-area: 1 / 1 / 4 / 2;
    height: 100%;
    align-self: stretch;
  }
  body.study-challenge-playing .study-challenge .study-challenge-plaque {
    grid-area: 1 / 2;
    align-self: center;
    padding: 10px 9px 8px;
  }
  body.study-challenge-playing .study-challenge #phrase.phrase-strip,
  .clean-play body.study-challenge-playing .study-challenge #phrase.phrase-strip.compact {
    font-size: clamp(19px, 2.1vw, 24px);
    line-height: 1.2;
  }
  body.study-challenge-playing .study-challenge .word-slot {
    line-height: 1.2;
  }
  body.study-challenge-playing .study-challenge #phrase .phrase-heading {
    font-size: 14px;
  }
  body.study-challenge-playing .study-challenge .tool-hint,
  body.study-challenge-playing .study-challenge .tool-use-coach,
  body.study-challenge-playing .study-challenge .study-touch-coach {
    grid-area: 2 / 2;
  }
  body.study-challenge-playing .study-challenge .tools-bar {
    grid-area: 3 / 2;
    padding: 0;
  }
  body.study-challenge-playing .study-challenge .tool-button {
    min-height: 48px;
    padding: 3px;
    font-size: 12px;
  }
  body.study-challenge-playing .study-tool-object,
  body.study-challenge-playing .study-challenge .tool-button[data-tool="water"] .study-tool-object {
    width: 36px;
    height: 27px;
  }
  body.study-challenge-playing .study-challenge .game-bottom .small-btn {
    padding: 4px 6px;
    font-size: 12px;
  }
  body.study-challenge-playing .study-challenge .game-main.tool-lesson-armed .study-challenge-plaque {
    padding-top: 12px;
  }
  body.study-challenge-playing .study-challenge .game-main.tool-lesson-armed .phrase-heading {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}

/* Text zoom and very small windows keep the 24px letter floor and native
   finger scrolling; they do not shrink the game to preserve decorative art. */
.play-scroll body.study-challenge-playing {
  height: auto;
  min-height: 100dvh;
  overflow-y: auto;
}
.clean-play.play-scroll body.study-challenge-playing .app {
  height: auto;
  grid-template-rows: 52px auto;
}
.play-scroll body.study-challenge-playing #main {
  height: auto;
}
.clean-play.play-scroll body.study-challenge-playing .study-challenge .game-main {
  height: auto;
  min-height: calc(100dvh - 64px - var(--safe-top, 0px) - var(--safe-bottom, 0px));
}
.play-scroll body.study-challenge-playing .study-challenge .board-space {
  contain: none;
  min-height: var(--board-min-height);
}
/* Portrait is a compact vertical composition, not a viewport-sized flex
   column with two empty gaps. Board height comes from the actual grid and
   material edges. Short screens scroll by finger; letters never shrink to
   make room for the illustration. */
@media (max-aspect-ratio: 1/1) and ((max-width: 699px) or (max-height: 699px) or (aspect-ratio < 4/5)) {
  html.clean-play:has(body.study-challenge-playing) { overscroll-behavior-y: auto; }
  .clean-play body.study-challenge-playing {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
  }
  .clean-play body.study-challenge-playing .app {
    height: auto;
    min-height: calc(100dvh - var(--safe-top, 0px) - var(--safe-bottom, 0px));
    grid-template-rows: 44px auto;
  }
  .clean-play body.study-challenge-playing .game-header { height: 44px; }
  body.study-challenge-playing #main,
  body.study-challenge-playing .study-challenge.game-layout {
    height: auto;
    min-height: 0;
  }
  body.study-challenge-playing .study-challenge.game-layout { padding: 0 0 8px; }
  .clean-play body.study-challenge-playing .study-challenge .game-main {
    --challenge-portrait-art-height: clamp(160px, calc(70vw - 78px), 320px);
    --study-board-pad-inline: 5px;
    --study-board-pad-top: 5px;
    --study-board-pad-bottom: 8px;
    height: auto;
    min-height: 0;
    max-width: 900px;
    gap: 6px;
  }
  body.study-challenge-playing .study-challenge .study-challenge-art {
    display: block;
    position: relative;
    flex: none;
    height: var(--challenge-portrait-art-height);
    width: 100%;
    overflow: clip;
    border: 0;
    border-radius: 0;
    background: none;
    isolation: isolate;
    margin-bottom: -6px;
  }
  body.study-challenge-playing .study-challenge .study-challenge-art:has(.challenge-plane-guide[data-failed="true"]) {
    display: none;
  }
  body.study-challenge-playing .study-challenge .study-challenge-plaque {
    padding: 10px 12px 8px;
  }
  body.study-challenge-playing .study-challenge #phrase.phrase-strip,
  .clean-play body.study-challenge-playing .study-challenge #phrase.phrase-strip.compact {
    font-size: clamp(20px, 4.8vw, 29px);
    line-height: 1.2;
  }
  body.study-challenge-playing .study-challenge .word-slot { line-height: 1.2; }
  body.study-challenge-playing .study-challenge #phrase .phrase-heading {
    margin-bottom: 4px;
    font-size: 18px;
  }
  body.study-challenge-playing .study-challenge .board-space {
    flex: none;
    contain: size;
    height: calc(min(112px, (100cqw - var(--study-board-edge-inline)) / var(--study-board-cols)) * var(--study-board-rows) + var(--study-board-edge-block));
    min-height: 0;
    margin: 0;
  }
  body.study-challenge-playing .study-challenge .tool-hint {
    margin: 0;
    padding: 3px 9px;
  }
  body.study-challenge-playing .study-challenge .tools-bar {
    padding: 0;
    gap: 6px;
  }
  body.study-challenge-playing .study-challenge .tool-button {
    min-height: 80px;
    padding: 5px 4px;
    font-size: 14px;
  }
  body.study-challenge-playing .study-challenge .study-tool-object,
  body.study-challenge-playing .study-challenge .tool-button[data-tool="water"] .study-tool-object {
    width: 52px;
    height: 45px;
  }
  body.study-challenge-playing .study-challenge .game-bottom { margin: 0; }
}
/* The compact notebook shares the board rails. Olga takes a small portion of
   the strip, leaving the rest for the phrase and the full next row for play. */
@media (min-width: 700px) and (min-height: 700px) and (min-aspect-ratio: 4/5) and (max-aspect-ratio: 1249/1000) {
  body.study-challenge-playing .app {
    --challenge-column-width: min(100%, 1040px);
    --challenge-reading-edge: min(100%, var(--challenge-board-width, var(--challenge-column-width)));
    --challenge-square-art-width: calc(var(--challenge-reading-edge) * .34);
  }
  .clean-play body.study-challenge-playing .study-challenge .game-main {
    --challenge-square-header-height: clamp(110px, 12.8vmin, 160px);
    --challenge-guide-overhang: clamp(12px, calc(6vmin - 33px), 38px);
    gap: 7px;
  }
  body.study-challenge-playing .study-challenge .study-challenge-art {
    display: block;
    position: absolute;
    z-index: 2;
    inset: calc(0px - var(--challenge-guide-overhang)) calc(max(0px, (100% - var(--challenge-board-width, 100%)) / 2)) auto auto;
    width: var(--challenge-square-art-width);
    height: calc(var(--challenge-square-header-height) + var(--challenge-guide-overhang));
    margin: 0;
    overflow: clip;
    isolation: isolate;
  }
  body.study-challenge-playing .study-challenge .study-challenge-plaque {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: var(--challenge-square-header-height);
    padding: 10px calc(var(--challenge-square-art-width) + 8px) 10px clamp(16px, 2.4vw, 34px);
    border-radius: 17px;
    background:
      linear-gradient(110deg, #fff9e8 53%, #f6e6b9 84%, #f1d8a4) padding-box,
      var(--relic-gilding) border-box;
  }
  body.study-challenge-playing .study-challenge #phrase.phrase-strip,
  .clean-play body.study-challenge-playing .study-challenge #phrase.phrase-strip.compact {
    font-size: clamp(19px, 2.65vmin, 32px);
    line-height: 1.12;
    text-align: start;
  }
  .clean-play body.study-challenge-playing .study-challenge #phrase.phrase-strip.compact {
    font-size: clamp(18px, 2.35vmin, 28px);
  }
  body.study-challenge-playing .study-challenge #phrase .phrase-heading {
    margin-bottom: 4px;
    font-size: clamp(14px, 1.65vmin, 20px);
  }
  body.study-challenge-playing .study-challenge #phrase .phrase-line,
  body.study-challenge-playing .study-challenge #phrase .phrase-words {
    justify-content: flex-start;
    text-align: start;
  }
  body.study-challenge-playing .study-challenge #phrase .phrase-credit {
    margin-top: 5px;
    font-size: clamp(12px, 1.15vmin, 14px);
    text-align: start;
  }
}

@media (min-width: 1200px) and (min-height: 1120px) and (min-aspect-ratio: 4/5) and (max-aspect-ratio: 1249/1000) {
  .clean-play body.study-challenge-playing .app {
    padding-block-start: clamp(0px, calc((100dvh - 1060px) / 6), 48px);
  }
}
@media (prefers-reduced-motion: no-preference) {
  body.study-challenge-playing .study-challenge .cell { transition: background-color 110ms, color 110ms; }
  body.study-challenge-playing .study-challenge .cell.selected { animation: study-tile-snap 200ms cubic-bezier(.15,.8,.32,1.35); }
  @keyframes study-tile-snap { 0% { transform: scale(.91); } 65% { transform: scale(1.035); } 100% { transform: none; } }
}

/* The compact sizes above were written for short phones but the portrait
   block that follows them has equal specificity and won, so they never
   applied. Re-state them after it, for short portrait phones only. */
@media (max-aspect-ratio: 1/1) and (max-width: 499px) and (max-height: 650px) {
  .clean-play body.study-challenge-playing .study-challenge .game-main {
    gap: 3px;
  }
  body.study-challenge-playing .study-challenge-plaque {
    padding: 9px 9px 7px;
  }
  body.study-challenge-playing .study-challenge #phrase .phrase-heading {
    font-size: 14px;
  }
  body.study-challenge-playing .study-challenge .tool-button {
    min-height: 51px;
    padding-block: 2px;
    font-size: 12px;
  }
  body.study-challenge-playing .study-tool-object,
  body.study-challenge-playing .study-challenge .tool-button[data-tool="water"] .study-tool-object {
    width: 38px;
    height: 27px;
  }
  body.study-challenge-playing .study-challenge .tool-button .qty {
    width: 18px;
    height: 18px;
    top: 3px;
    right: 4px;
    font-size: 11px;
  }
  body.study-challenge-playing .study-challenge .game-bottom .small-btn {
    font-size: 12px;
    padding-inline: 8px;
  }
}

/* On a short phone the scene gives way first: the instruction under the
   board must be on screen at the first view. Letters keep their size (the
   board is width-driven); only Olga's scene shrinks, to a floor. Phones only:
   tablets held upright keep the approved scene height. */
@media (max-aspect-ratio: 1/1) and (max-width: 499px) {
  .clean-play body.study-challenge-playing .study-challenge .game-main {
    --challenge-portrait-board-height: calc((100cqw - var(--study-board-edge-inline)) / var(--study-board-cols, 8) * var(--study-board-rows, 5) + var(--study-board-edge-block));
    --challenge-portrait-art-height: min(clamp(160px, calc(70vw - 78px), 320px),
      max(96px, calc(100dvh - 284px - var(--challenge-portrait-board-height))));
  }
}
