/* Keep both rows of the arcade shelf within reach on landscape displays. */
@media (min-width: 961px) {
  .intro { margin: clamp(12px, 2.4vh, 32px) 0 clamp(16px, 2.4vh, 32px); }
  .intro h1 { font-size: clamp(58px, 10vh, 111px); }
  .game-card canvas { height: clamp(76px, 13vh, 168px); }
  .card-body { padding: clamp(11px, 1.05vw, 21px); gap: 7px; }
  .card-body strong { font-size: clamp(21px, 2.25vw, 37px); }
  .card-tail { padding-top: 2px; }
  .card-tail b { width: 31px; height: 31px; font-size: 18px; }
}

@media (min-width: 660px) and (max-width: 960px) {
  #games { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .game-card { flex-direction: column; }
  .game-card canvas {
    width: 100%;
    height: clamp(90px, 16vh, 150px);
    min-height: 0;
    border: 0;
    border-bottom: 1.5px solid var(--ink);
  }
  .card-body { width: 100%; padding: 10px; gap: 5px; }
  .card-body strong { font-size: clamp(20px, 2.65vw, 26px); }
  .card-tail { padding-top: 0; }
  .card-tail b { width: 29px; height: 29px; font-size: 17px; }
}


@media (min-width: 660px) and (max-height: 640px) {
  #shelf .mast { padding-bottom: 5px; }
  #shelf .intro { margin: 9px 0 13px; }
  #shelf .intro h1 { font-size: clamp(38px, 6.5vw, 66px); }
  .game-card { position: relative; }
  .game-card canvas { height: clamp(60px, 14vh, 84px); }
  .card-body { padding: 8px 10px 10px; gap: 4px; }
  .card-body strong { font-size: clamp(19px, 2.4vw, 27px); }
  .card-body .summary { font-size: 13px; line-height: 1.3; }
  .card-tail { position: absolute; inset: 6px 7px auto; font-size: 11px; }
  .card-tail span { visibility: hidden; }
  .card-tail span.has-best {
    visibility: visible;
    background: #fffdf4;
    border: 1px solid var(--ink);
    border-radius: 4px;
    padding: 2px 4px;
  }
  .card-tail b { width: 23px; height: 23px; font-size: 15px; background: #fffdf4; }
  #hangman-game .letter-keys { margin: 7px 0 8px; gap: 5px; }
  #hangman-game .puzzle-intro h1 { margin-top: 0; }
}

#puzzle-play {
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.3vh, 25px);
  min-height: calc(100dvh - clamp(28px, 5vw, 90px));
}

.puzzle-layout {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(208px, 27%) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "intro surface" "tools surface";
  gap: clamp(12px, 2.5vw, 40px);
  align-items: start;
}

.puzzle-intro { grid-area: intro; }
.puzzle-intro h1 {
  margin: .1em 0 .25em;
  font-size: clamp(36px, 4.3vw, 82px);
  font-weight: 760;
  letter-spacing: -.055em;
  line-height: .98;
}

.puzzle-intro p, .hangman-controls p {
  margin: 0;
  font-size: clamp(15px, 1.35vw, 23px);
  line-height: 1.4;
  color: #48584e;
}

.puzzle-surface { grid-area: surface; }
.puzzle-surface .stage-head span { text-align: right; }
.puzzle-tools { grid-area: tools; min-width: 0; }

.puzzle-actions, .choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-row { margin-top: clamp(12px, 2.7vh, 28px); }
.puzzle-actions button, .choice-row button, .puzzle-primary {
  min-height: 44px;
  padding: 8px clamp(10px, 1.1vw, 18px);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: #fffdf4;
  font-size: clamp(14px, 1.2vw, 20px);
  font-weight: 720;
}

.choice-row button[aria-pressed="true"] { background: var(--accent); box-shadow: 1px 2px 0 var(--ink); }
.puzzle-primary, .puzzle-actions button:first-child { background: var(--ink); color: var(--paper); }
.puzzle-actions button:disabled { opacity: .55; cursor: default; }

#maze-board {
  display: block;
  width: 100%;
  height: clamp(260px, calc(100dvh - clamp(135px, 14.6vw, 235px)), 875px);
  touch-action: none;
  cursor: crosshair;
  background: #f7f5e9 radial-gradient(#bbbeb043 1px, transparent 1.4px) 0 0 / 17px 17px;
}

#maze-board:focus-visible { outline: 3px solid #096292; outline-offset: -4px; }

.sudoku-mat {
  display: grid;
  place-items: center;
  padding: clamp(10px, 2.6vh, 28px);
  background: #f7f5e9 radial-gradient(#bbbeb04d 1px, transparent 1.4px) 0 0 / 17px 17px;
}

#sudoku-grid {
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size), minmax(0, 1fr));
  width: min(100%, clamp(250px, calc(100dvh - clamp(171px, 16.3vw, 295px)), 720px));
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  background: #fffdf4;
}

#sudoku-grid.mini { max-width: 580px; }
.sudoku-cell {
  display: grid;
  place-items: center;
  position: relative;
  min-width: 0;
  background: transparent;
  color: #175f57;
  border: 0;
  border-left: 1px solid #92988c;
  border-top: 1px solid #92988c;
  padding: 0;
  font-size: clamp(17px, min(3.1vw, 4.4vh), 48px);
  font-variant-numeric: tabular-nums;
  font-weight: 680;
  line-height: 1;
}

.mini .sudoku-cell { font-size: clamp(27px, 6vh, 66px); }
.sudoku-cell.top-edge { border-top: 0; }
.sudoku-cell.left-edge { border-left: 0; }
.sudoku-cell.box-top { border-top: 2px solid var(--ink); }
.sudoku-cell.box-left { border-left: 2px solid var(--ink); }
.sudoku-cell.given { background: #ece8d9; color: var(--ink); font-weight: 820; }
.sudoku-cell.related { background: #faebd1; }
.sudoku-cell.conflict { background: #f7c6bc; color: #892615; }
.sudoku-cell.current { box-shadow: inset 0 0 0 3px #98601d; background: #f6d798; }
.sudoku-cell.current.conflict { box-shadow: inset 0 0 0 3px #a7331d; background: #f7c6bc; }
.sudoku-cell:focus-visible { outline: 3px solid #096292; outline-offset: -3px; }
.solved .sudoku-cell:not(.given) { background: #d5eed9; }

.number-keys { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-bottom: 12px; }
.number-keys.mini { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.number-keys button, .letter-row button {
  min-height: clamp(44px, 7.5vh, 84px);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: #fffdf4;
  box-shadow: 1px 2px 0 var(--ink);
  padding: 0;
  font-size: clamp(19px, 2.5vw, 40px);
  font-weight: 760;
}

.number-keys button:active, .letter-row button:active { transform: translate(1px, 2px); box-shadow: none; }
.number-keys button:disabled { opacity: .55; cursor: default; }

#hangman-game .puzzle-intro { margin-bottom: clamp(10px, 2.1vh, 22px); }
.hangman-layout { display: grid; grid-template-columns: minmax(175px, 32%) minmax(0, 1fr); gap: clamp(14px, 3vw, 46px); }
.hangman-controls { min-width: 0; align-self: start; }
#hangman-figure {
  display: block;
  width: 100%;
  height: clamp(154px, 42vh, 465px);
  background: #fbf8ed radial-gradient(#c1b3cc66 1px, transparent 1.3px) 0 0 / 17px 17px;
}

#hangman-setup label { display: block; margin-bottom: 8px; font-size: clamp(18px, 2vw, 32px); font-weight: 740; }
.secret-entry { display: flex; gap: 8px; }
.secret-entry input {
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 44px;
  padding: 6px 12px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: #fffdf4;
  color: var(--ink);
  font: inherit;
  font-size: clamp(18px, 2vw, 32px);
}

.secret-entry button { flex-shrink: 0; }
#hangman-help, #hangman-error { margin-top: 6px; font-size: clamp(13px, 1.1vw, 18px); }
#hangman-error:empty { display: none; }
#hangman-error { color: #892615; }
#hangman-handoff { padding-top: clamp(8px, 3vw, 35px); }
#hangman-handoff h2 { margin: 0 0 7px; font-size: clamp(23px, 3vw, 47px); letter-spacing: -.035em; }
#hangman-start { margin-top: 15px; }
#hangman-word {
  display: flex;
  flex-wrap: wrap;
  gap: 7px clamp(10px, 1.5vw, 24px);
  margin-bottom: 8px;
}

.word-group { display: flex; flex-wrap: wrap; gap: 4px; max-width: 100%; }
.word-letter {
  display: grid;
  place-items: center;
  width: clamp(20px, 2.65vw, 45px);
  height: clamp(31px, 4vw, 62px);
  border-bottom: 2px solid var(--ink);
  font-size: clamp(18px, 2.3vw, 39px);
  font-weight: 760;
}

.letter-keys { display: grid; gap: 7px; margin: clamp(9px, 2vh, 20px) 0 12px; max-width: 980px; }
.letter-row { display: flex; justify-content: center; gap: clamp(3px, .7vw, 10px); }
.letter-row button {
  flex: 0 1 calc((100% - 9 * clamp(3px, .7vw, 10px)) / 10);
  min-width: 0;
  font-size: clamp(16px, 2vw, 34px);
}

.letter-row button:disabled { cursor: default; box-shadow: none; color: #505b53; }
.letter-row button.hit { background: #c1e5cb; color: #214b36; }
.letter-row button.miss { background: #efcdc6; color: #6e3328; text-decoration: line-through; }

@media (max-height: 640px) and (min-width: 660px) {
  #puzzle-play { min-height: calc(100dvh - 20px); gap: 8px; }
  .puzzle-layout { gap: 14px; }
  .puzzle-intro h1 { font-size: clamp(32px, 4.4vw, 54px); }
  #hangman-game .puzzle-intro { margin-bottom: 9px; }
}

@media (max-width: 659px) {
  .puzzle-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; grid-template-areas: "intro" "surface" "tools"; gap: 12px; }
  .puzzle-intro h1 { font-size: clamp(31px, 8vw, 46px); }
  .puzzle-intro p, .hangman-controls p { font-size: 14px; }
  .choice-row { margin-top: 8px; }
  #maze-board { height: clamp(230px, 80vw, 420px); }
  .sudoku-mat { padding: 8px; }
  .number-keys { grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; margin-bottom: 8px; }
  .number-keys button { font-size: 18px; }
  .sudoku-cell { font-size: clamp(15px, 5vw, 24px); }
  .hangman-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  #hangman-figure { height: clamp(106px, 22vh, 180px); }
  .letter-row button { border-radius: 5px; }
}
