.mobile-only {
  display: none;
}
/* NEW mobile fullscreen layout: keep the source purple title and native action
 * strip, and let the world use the44px formerly occupied by a duplicate web row.
 * The shared fullscreen controller still owns entering/exiting fullscreen.
 */
@media (max-width: 700px),
  (max-width: 1000px) and (max-height: 520px),
  (pointer: coarse) {
  body .game-window.native-skin[data-joycity-camera="wide"] > .toolbar {
    position: absolute;
    top: 20px;
    left: max(4px, env(safe-area-inset-left));
    right: max(4px, env(safe-area-inset-right));
    width: auto;
    height: auto;
    min-height: 44px;
    flex: none;
    flex-wrap: wrap;
    gap: 2px;
    padding: 0;
    background: #aebfc0eb;
  }
  body
    .game-window.native-skin[data-joycity-camera="wide"]
    > .toolbar
    .mobile-game-title {
    display: none;
  }
  body .game-window.native-skin[data-joycity-camera="wide"] > .toolbar .place {
    flex: 1 1 0;
  }
  body.embedded
    .game-window.native-skin[data-joycity-camera="wide"]
    > .toolbar
    > #mobile-return {
    display: flex;
  }
  body
    .game-window.native-skin[data-joycity-camera="wide"]
    > .toolbar
    > [data-game-fullscreen] {
    min-width: 44px !important;
    width: 44px !important;
    min-height: 44px !important;
    height: 44px !important;
    padding: 0 !important;
    gap: 0 !important;
    font-size: 0 !important;
  }
  body
    .game-window.native-skin[data-joycity-camera="wide"]
    > .toolbar
    > [data-game-fullscreen]::after {
    content: "⤢";
    font-size: 22px;
  }
}
@media (max-width: 700px),
  (max-width: 1000px) and (max-height: 520px),
  (pointer: coarse) {
  :root {
    --mobile-chat-height: min(
      calc(var(--mobile-viewport-height, 100dvh) * 0.34),
      280px
    );
    --mobile-chat-width: min(310px, 40vw);
  }
  html,
  body {
    height: 100%;
    height: var(--mobile-viewport-height, 100dvh);
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }
  body .shell,
  body .shell:has(> .game-window.native-skin) {
    width: 100%;
    height: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  body .masthead,
  body .shell:has(> .game-window.native-skin) > .masthead {
    display: none;
  }
  .masthead .brand {
    font-size: 14px;
    letter-spacing: 0;
  }
  .masthead .brand span,
  .build-tag,
  .footnote {
    display: none;
  }
  body.embedded .masthead {
    display: none;
  }
  body .game-window,
  body .game-window.native-skin {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    height: auto;
    aspect-ratio: auto;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    overflow: hidden;
    background-image: none !important;
    box-shadow: none;
  }
  body .game-window > .titlebar,
  body .game-window > .control-strip {
    display: none;
  }
  body .game-window.native-skin::before {
    content: "";
    display: block;
    flex: 0 0 20px;
    height: 20px;
    background: var(--native-frame) center top / 650px 561px no-repeat;
    image-rendering: pixelated;
  }
  body .native-skin > .native-controls {
    position: relative;
    inset: auto;
    flex: 0 0 46px;
    width: 100%;
    height: 46px;
    display: flex;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    border-top: 1px solid #f3f8f7;
    border-bottom: 1px solid #6f8385;
    background: #aebfc0;
    pointer-events: auto;
    scrollbar-width: none;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  body .native-controls > .native-window,
  body .native-controls > .native-scroll {
    display: none;
  }
  body .native-controls::-webkit-scrollbar {
    display: none;
  }
  body .native-controls > .native-action {
    position: relative;
    inset: auto !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    min-height: 44px;
    flex: 0 0 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  body .native-controls .native-icon-art {
    width: var(--icon-width);
    height: var(--icon-height);
  }
  body .native-skin > .toolbar {
    background: #aebfc0;
    border-bottom: 1px solid #768a8d;
  }
  body .native-skin .mobile-game-title {
    color: #684472;
  }
  body .game-window > .toolbar {
    position: relative;
    inset: auto;
    flex: 0 0 44px;
    height: 44px;
    min-height: 44px;
    margin: 0;
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 0 max(4px, env(safe-area-inset-right)) 0
      max(4px, env(safe-area-inset-left));
    border: 0;
    z-index: 5;
  }
  body .game-window > .toolbar .place {
    min-width: 0;
    flex: 1;
    margin: 0;
    gap: 0;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
  }
  .toolbar .place b {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 10px;
  }
  .toolbar .place .mobile-game-title {
    display: block;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    color: #28573e;
  }
  .toolbar .place > span {
    display: none;
  }
  body .toolbar > button,
  body .toolbar > a,
  body .toolbar > #population {
    display: none;
  }
  body .toolbar > #map-button,
  body .toolbar > .mobile-only {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 48px;
    min-height: 44px;
    padding: 8px;
    font-size: 14px;
    line-height: 1.2;
  }
  body .toolbar > #mobile-return {
    min-width: 44px;
    font-size: 24px;
    border: 0;
    background: transparent;
    box-shadow: none;
  }
  body.embedded .toolbar > #mobile-return {
    display: none;
  }
  body .game-window > .stage {
    position: relative;
    inset: auto;
    flex: 1;
    min-height: 0;
    width: 100%;
    height: auto;
    aspect-ratio: auto;
    border: 0;
    overflow: hidden;
  }
  body .stage canvas {
    width: 100%;
    height: 100%;
  }
  .stage-top {
    top: 8px !important;
    font-size: 11px !important;
    left: 8px !important;
    right: 8px !important;
  }
  .stage-top #map-kind,
  .stage-bottom {
    display: none;
  }
  body .joystick {
    display: block;
    width: 112px;
    height: 112px;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    border: 2px solid #eef4dcb3;
    background: #142f2a70;
    z-index: 2;
    user-select: none;
    -webkit-user-select: none;
  }
  body .joystick span {
    left: 33px;
    top: 33px;
    width: 42px;
    height: 42px;
    background: #d5e8b8c9;
  }
  body .interact {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(30px, env(safe-area-inset-bottom));
    min-width: 84px;
    min-height: 52px;
    font-size: 16px;
    padding: 12px 16px;
    z-index: 2;
  }
  .interact[hidden] {
    display: none;
  }
  body .game-window > .chat-panel {
    display: none;
    position: relative;
    inset: auto;
    width: 100%;
    height: var(--mobile-chat-height);
    flex: 0 0 var(--mobile-chat-height);
    padding: 8px;
    background: #aebfc0;
    border-top: 1px solid #718789;
    z-index: 4;
  }
  body.mobile-chat-open .game-window > .chat-panel {
    display: grid;
    grid-template-rows: 44px minmax(0, 1fr) 48px;
    gap: 6px;
  }
  body .chat-heading {
    position: static;
    display: flex;
    min-height: 44px;
    height: 44px;
    padding: 0;
    gap: 6px;
  }
  .chat-heading strong {
    font-size: 14px !important;
  }
  .chat-heading > span {
    display: none;
  }
  .chat-heading > button {
    display: block;
    margin-left: auto;
    min-width: 48px;
    min-height: 44px;
    font-size: 14px;
  }
  body #chat-log {
    position: static;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 6px 8px;
    font-size: 14px;
    line-height: 1.65;
    color: #253037;
    background: #fcfcfc;
    border-color: #7c9092;
  }
  body #chat-form {
    position: static;
    height: 48px;
    padding: 0;
    margin: 0;
    display: flex;
    gap: 6px;
  }
  body #chat-text {
    width: 0;
    min-width: 0;
    flex: 1;
    font-size: 16px;
    padding: 8px;
    background: #fcfcd9;
  }
  body #chat-form button {
    min-width: 64px;
    min-height: 44px;
    font-size: 14px;
  }
  .mobile-menu {
    position: absolute;
    top: 64px;
    right: 8px;
    z-index: 8;
    width: min(300px, calc(100% - 16px));
    max-height: calc(100% - 78px);
    overflow: auto;
    padding: 10px;
    background: #aebfc0;
    border: 2px solid;
    border-color: #f3f8f7 #6c8083 #6c8083 #f3f8f7;
    box-shadow: 0 10px 30px #142e2866;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    border-radius: 0;
  }
  .mobile-menu[hidden] {
    display: none;
  }
  .mobile-menu button {
    display: block;
    min-height: 48px;
    font-size: 15px;
  }
  body dialog {
    width: min(
      600px,
      calc(100% - 16px - env(safe-area-inset-left) - env(safe-area-inset-right))
    );
    max-width: calc(
      100% - 16px - env(safe-area-inset-left) - env(safe-area-inset-right)
    );
    max-height: calc(var(--mobile-viewport-height, 100dvh) - 16px);
    margin: auto;
  }
  body #panel {
    max-height: calc(var(--mobile-viewport-height, 100dvh) - 16px);
  }
  .panel-head {
    min-height: 56px;
    padding: 6px 12px;
  }
  .panel-head button {
    min-width: 44px;
    min-height: 44px;
  }
  body #panel-body {
    font-size: 14px;
    padding: 12px;
  }
  #panel-body button:not(.reversi-cell),
  #panel-body select {
    min-height: 44px;
    font-size: 14px;
  }
  .entry-dialog form {
    padding: 20px;
  }
  .entry-dialog input {
    min-height: 48px;
    font-size: 16px;
  }
  .entry-dialog .primary {
    min-height: 48px;
    font-size: 16px;
  }
  .map-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .appearance-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .toast {
    font-size: 14px;
  }
}
@media (max-width: 1000px) and (max-height: 520px) {
  body.mobile-chat-open .game-window > .stage {
    width: calc(100% - var(--mobile-chat-width));
  }
  body.mobile-chat-open .game-window > .chat-panel {
    position: absolute;
    top: 64px;
    right: 0;
    bottom: 0;
    left: auto;
    width: var(--mobile-chat-width);
    height: auto;
  }
  body .joystick {
    width: 104px;
    height: 104px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }
  body .joystick span {
    left: 29px;
    top: 29px;
  }
  .entry-dialog form {
    padding: 14px 22px;
  }
  .entry-dialog h1 {
    margin-bottom: 10px;
    font-size: 30px;
  }
  .entry-dialog .eyebrow,
  .entry-dialog small {
    display: none;
  }
}
