/* Keep the desktop composition; adapt navigation, reading and editing to touch. */
.mobile-workbench-nav,
.editor-tools {
  display: none;
}
#game {
  padding-top: env(safe-area-inset-top);
}
#game-menu > summary {
  display: none;
}
#game-menu:not([open]) > nav {
  display: none;
}
.editor-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.editor-heading label {
  flex: 1;
  min-width: 0;
}
.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
.table-scroll:focus-visible {
  outline: 2px dashed #000;
  outline-offset: 2px;
}
#exploration:focus-visible,
#lesson-panel:focus-visible,
#code-panel:focus-visible {
  outline: 2px dashed #000;
  outline-offset: 2px;
}
#success-message {
  max-height: calc(var(--visible-height, 100dvh) - 24px);
  overflow-y: auto;
}
#success-message .success-actions {
  position: sticky;
  bottom: -1px;
  background: #fff;
  padding: 6px 0 0;
}
@media (max-width: 960px),
  (pointer: coarse) and (max-width: 1100px) and (max-height: 600px) {
  #game {
    padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  #game > header {
    position: relative;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 8px;
  }
  #game > header > div {
    flex: 1;
    overflow-wrap: anywhere;
  }
  #game .brand {
    font-size: 25px;
    letter-spacing: 2px;
  }
  #stats {
    font-size: 17px;
    margin: 3px 0;
  }
  #equipped-title {
    font-size: 18px;
    line-height: 1.05;
    margin-top: 3px;
  }
  #game-menu {
    flex: 0 0 auto;
    align-self: flex-start;
  }
  #game-menu > summary {
    display: list-item;
    list-style-position: inside;
    min-height: 44px;
    min-width: 70px;
    padding: 10px 8px;
    border: 1px solid #fff;
    font-size: 19px;
    cursor: pointer;
  }
  #game-menu > summary:focus-visible {
    outline: 2px dashed #fff;
    outline-offset: 2px;
  }
  #game-menu nav {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
    background: #fff;
    border: 3px double #000;
    box-shadow: 3px 3px 0 #000;
  }
  #game-menu:not([open]) nav {
    display: none;
  }
  #game-menu nav button {
    min-width: 0;
    white-space: normal;
    font-size: 19px;
  }
  #game .progression-strip {
    margin-top: 8px;
    padding: 8px;
  }
  .xp-heading strong {
    font-size: 23px;
  }
  .progression-strip #xp-progress {
    height: 16px;
  }
  #xp-progress-label {
    font-size: 17px;
  }
  .mobile-workbench-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    position: sticky;
    top: env(safe-area-inset-top);
    z-index: 10;
    gap: 0;
    margin-top: 8px;
    padding-top: 0;
    background: #fff;
    border: 2px solid #000;
  }
  .mobile-workbench-nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    color: #000;
    text-decoration: none;
    font-size: 21px;
  }
  .mobile-workbench-nav a + a {
    border-left: 1px solid #000;
  }
  .mobile-workbench-nav a:focus-visible {
    outline: 2px dashed #000;
    outline-offset: -4px;
  }
  #exploration,
  #lesson-panel,
  #code-panel {
    scroll-margin-top: calc(58px + env(safe-area-inset-top));
  }
  .exploration,
  .desk {
    grid-template-columns: minmax(0, 1fr);
  }
  .exploration {
    gap: 14px;
    padding: 12px 0;
  }
  .scene-viewport > .mono-scene {
    width: 100%;
    height: auto;
    max-height: none;
    aspect-ratio: 16/9;
  }
  .scene-caption {
    padding: 7px 8px;
    line-height: 1.1;
  }
  .home-copy {
    padding: calc(24px + env(safe-area-inset-top))
      max(16px, env(safe-area-inset-left)) 20px;
  }
  .home-scene {
    padding: 12px;
  }
  .home-actions {
    max-width: none;
  }
  .home-actions button {
    min-height: 48px;
  }
  .quest-bar {
    padding: 8px;
    gap: 6px;
  }
  .quest-bar label {
    width: 100%;
    flex: 1 1 100%;
    gap: 4px;
  }
  #quests {
    width: 100%;
    min-height: 44px;
    font-size: 19px;
  }
  #quest-count {
    display: block;
    font-size: 16px;
  }
  .tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
  }
  .tabs button {
    white-space: normal;
    min-width: 0;
    min-height: 48px;
    font-size: 19px;
    line-height: 1.1;
    padding: 7px 4px;
  }
  .lesson-panel {
    border-right: 0;
    border-bottom: 3px double #000;
  }
  #game .tab-body {
    max-height: none;
    overflow: visible;
    padding: 12px;
    font-size: 21px;
    line-height: 1.4;
  }
  #game .tab-body[hidden] {
    display: none;
  }
  .sql-example {
    font-size: 19px;
    padding: 8px;
  }
  .table-scroll {
    border-bottom: 1px solid #000;
    scrollbar-width: thin;
  }
  .table-scroll table {
    font-size: 19px;
  }
  .table-scroll th {
    white-space: nowrap;
  }
  .table-scroll td {
    min-width: 48px;
    max-width: 240px;
    overflow-wrap: anywhere;
  }
  .table-scroll th,
  .table-scroll td {
    padding: 8px;
  }
  .code-panel {
    padding: 10px 8px;
    gap: 8px;
  }
  .editor-heading {
    min-height: 28px;
  }
  #editor {
    font-size: 21px;
    line-height: 1.35;
    min-height: 180px;
    height: 240px;
    max-height: none;
    resize: vertical;
    scroll-margin-block: 60px;
  }
  .editor-tools {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 3px;
  }
  .editor-tools button {
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
    padding: 5px 0;
    line-height: 1;
  }
  .execution {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .execution button {
    min-width: 0;
    min-height: 46px;
    padding: 7px 6px;
    white-space: normal;
    font-size: 19px;
    line-height: 1.15;
  }
  #submit,
  #answer,
  #cancel {
    grid-column: 1/-1;
  }
  #submit kbd {
    display: none;
  }
  button,
  input,
  select {
    min-height: 44px;
  }
  summary {
    min-height: 44px;
    align-content: center;
  }
  #result {
    max-height: min(400px, 55svh);
  }
  #proceed-inline,
  #export-my-game {
    min-height: 48px;
  }
  #mobile-companion-slot #adventurer-stage {
    --sprite-size: 56px;
    position: relative;
    inset: auto;
    z-index: auto;
    width: 72px;
    height: 85px;
    max-height: none;
    margin: 0;
    padding: 0 4px 18px;
    border: 0;
    box-shadow: none;
    pointer-events: none;
  }
  #mobile-companion-slot .adventurer {
    width: var(--sprite-size);
    height: var(--sprite-size);
  }
  #mobile-companion-slot #companion-status {
    font-size: 14px;
    line-height: 1;
  }
  .keyboard-open #mobile-companion-slot #adventurer-stage {
    --sprite-size: 36px;
    width: 52px;
    height: 62px;
  }
  .keyboard-open #learning-progress {
    padding-bottom: 6px;
    margin-bottom: 0;
  }
  .keyboard-open #learning-progress strong {
    font-size: 17px;
    line-height: 1.1;
    margin-top: 2px;
  }
  .keyboard-open #learning-progress small {
    font-size: 15px;
  }
  .keyboard-open #editor {
    height: clamp(110px, calc(var(--visible-height, 100dvh) * 0.35), 180px);
    min-height: 110px;
  }
  .keyboard-open .mobile-workbench-nav {
    position: static;
  }
  .project-workshop textarea {
    min-height: 180px;
    font-size: 16px;
    line-height: 1.5;
  }
  .project-workshop select,
  .project-workshop button {
    white-space: normal;
  }
  .project-workshop .editor-tools {
    margin: 8px 0;
    grid-template-columns: repeat(3, minmax(44px, 1fr));
  }
  dialog[open] {
    width: calc(100% - 16px);
    max-height: calc(
      var(--visible-height, 100dvh) - max(16px, env(safe-area-inset-top)) -
        max(16px, env(safe-area-inset-bottom))
    );
    margin-top: max(8px, env(safe-area-inset-top));
  }
  .dialog-heading {
    gap: 8px;
    padding: 10px;
  }
  .dialog-heading h2 {
    font-size: 24px;
  }
  #dialog-body {
    padding: 12px;
    font-size: 21px;
    overflow-x: hidden;
  }
  #dialog-body pre {
    max-width: 100%;
    overflow: auto;
    white-space: pre;
  }
  #dialog-body button {
    white-space: normal;
    max-width: 100%;
  }
  #dialog-body input[type="text"],
  #dialog-body input[type="password"],
  #dialog-body input[type="email"] {
    font-size: 20px;
  }
  #success-message,
  #success-message[data-film="on"] {
    top: calc(
      var(--visible-top, 0px) +
        (
          var(--visible-height, 100dvh) + env(safe-area-inset-top) -
            env(safe-area-inset-bottom)
        ) /
        2
    );
    width: calc(100% - 24px);
    max-height: calc(
      var(--visible-height, 100dvh) - max(16px, env(safe-area-inset-top)) -
        max(16px, env(safe-area-inset-bottom))
    );
    padding: 10px;
    font-size: 22px;
    overflow: auto;
  }
  .success-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .success-actions button {
    min-height: 46px;
    line-height: 1.1;
    padding: 8px 4px;
    font-size: 20px;
  }
  #success-story {
    max-height: none;
    font-size: 20px;
  }
  #cutscene-skip {
    min-height: 44px;
  }
  #cutscene-canvas {
    max-height: min(30dvh, 180px);
  }
  footer {
    font-size: 16px;
  }
}
